@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 300; font-display: swap; src: url('../../assets/fonts/poppins-300.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 400; font-display: swap; src: url('../../assets/fonts/poppins-400.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 500; font-display: swap; src: url('../../assets/fonts/poppins-500.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 600; font-display: swap; src: url('../../assets/fonts/poppins-600.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 700; font-display: swap; src: url('../../assets/fonts/poppins-700.woff2') format('woff2'); }

/* ── CSS Custom Properties ─────────────────────────────────────────────────── */

:root {
  --bg: #F7F6F3;
  --surface: #FFFFFF;
  --surface-alt: #F1EFE8;
  --border: #E5E3DD;
  --border-light: #F1EFE8;
  --text: #1A1A1A;
  --text-sec: #5F5E5A;
  --text-ter: #8C8A84;
  --text-hint: #B4B2A9;
  --brand: #8B1A1A;
  --brand-bg: #FCEBEB;
  --brand-text: #8B1A1A;
  --brand-border: #D4A0A0;
  --user-bubble: #FFFFFF;
  --user-border: #E5E3DD;
  --user-text: #2C2C2A;
  --bot-bubble: #E8DBD5;
  --bot-border: #D9C8C0;
  --input: #FFFFFF;
  --input-border: #D8D6D0;
  --locate-btn: #FCEBEB;
  --locate-border: #F0C5C5;
  --locate-text: #8B1A1A;
  --edit-old-bg: #FCEBEB;
  --edit-old-text: #791F1F;
  --edit-new-bg: #EAF3DE;
  --edit-new-text: #27500A;
  --meta-text: #B4B2A9;
  --date-sep-bg: #F1EFE8;
  --date-sep-text: #8C8A84;
  --amber-bg: #FFFBF0;
  --amber-border: #FAEEDA;
  --amber-text: #854F0B;
  --green-bg: #F1F8F4;
  --green-border: #C5E0D0;
  --green-text: #3B6D11;
}

[data-theme="dark"] {
  --bg: #1A1A1A;
  --surface: #222222;
  --surface-alt: #2A2A2A;
  --border: #333333;
  --border-light: #2E2E2E;
  --text: #E0E0E0;
  --text-sec: #AAAAAA;
  --text-ter: #777777;
  --text-hint: #555555;
  --brand: #C44040;
  --brand-bg: #3A2020;
  --brand-text: #E89090;
  --brand-border: #5A3030;
  --user-bubble: #2E2E2E;
  --user-border: #3C3C3C;
  --user-text: #D0D0D0;
  --bot-bubble: #3B2828;
  --bot-border: #4C3636;
  --input: #1A1A1A;
  --input-border: #3A3A3A;
  --locate-btn: #3A2020;
  --locate-border: #4A2828;
  --locate-text: #E89090;
  --edit-old-bg: #2C1A1A;
  --edit-old-text: #E89090;
  --edit-new-bg: #1A2A1A;
  --edit-new-text: #B0D880;
  --meta-text: #555555;
  --date-sep-bg: #2A2A2A;
  --date-sep-text: #666666;
  --amber-bg: #2A2218;
  --amber-border: #352A18;
  --amber-text: #E8C070;
  --green-bg: #1A2A1A;
  --green-border: #2A3A2A;
  --green-text: #90C050;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ── Sideload ────────────────────────────────────────────────────────────────── */

.ms-welcome__main { padding: 20px; }

/* ── Auth / Login Screen ─────────────────────────────────────────────────────── */

.auth-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow-y: auto;
  min-height: 0;
}

.login-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 32px;
}

.login-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: contain;
}

.login-title {
  font-family: 'Poppins', system-ui, sans-serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin: 14px 0 3px;
  letter-spacing: -0.4px;
}

.login-sub {
  font-family: 'Poppins', system-ui, sans-serif;
  font-size: 11.5px;
  color: var(--text-ter);
  margin: 0 0 30px;
}

.login-fields {
  width: 100%;
  max-width: 270px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.auth-label {
  font-size: 11.5px;
  color: var(--text-sec);
  font-weight: 500;
  display: block;
  margin-bottom: 5px;
}

.auth-input {
  width: 100%;
  padding: 9px 12px;
  border: 0.5px solid var(--input-border);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text);
  background: var(--input);
  font-family: 'Poppins', system-ui, sans-serif;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-bg);
  margin-bottom: 12px;
}

/* Password field */
.auth-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.auth-input-wrap .auth-input {
  padding-right: 36px;
  margin-bottom: 0;
}

.auth-pw-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  color: var(--text-ter);
  display: flex;
  align-items: center;
}

.auth-pw-toggle:hover { color: var(--text-sec); }
.pw-icon { width: 14px; height: 14px; }

.auth-forgot-row {
  text-align: right;
  margin-bottom: 18px;
}

.auth-error {
  font-size: 11px;
  color: #E24B4A;
  margin: 0 0 10px;
}

.auth-btn {
  width: 100%;
  padding: 10px 0;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: 'Poppins', system-ui, sans-serif;
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.2s;
  margin-bottom: 0;
}

.auth-btn:hover:not(:disabled) { opacity: 0.88; }
.auth-btn:disabled { opacity: 0.7; cursor: not-allowed; }

.auth-or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
}

.auth-or-line { flex: 1; height: 0.5px; background: var(--border); }
.auth-or-text { font-size: 10.5px; color: var(--text-hint); }

.auth-btn-outline {
  width: 100%;
  padding: 9px 0;
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: 'Poppins', system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.15s;
}

.auth-btn-outline:hover { background: var(--brand-bg); }

.auth-link { color: var(--brand); text-decoration: none; font-size: 11px; }
.auth-link:hover { text-decoration: underline; }
.auth-link-sep { color: var(--border); }

.auth-links-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  margin-top: 8px;
}

.login-footer {
  text-align: center;
  font-size: 10px;
  color: var(--text-hint);
  padding: 14px;
  margin: 0;
  font-family: 'Poppins', system-ui, sans-serif;
}

/* 2FA */
.twofa-hint { font-size: 11px; color: var(--text-sec); margin: 0 0 12px; line-height: 1.4; }
.twofa-code-input { letter-spacing: 0.25em; font-size: 20px; font-weight: 600; text-align: center; padding: 10px !important; }
.twofa-timer { font-size: 10px; color: var(--text-hint); text-align: center; min-height: 14px; margin-top: 4px; }
.twofa-timer.warning { color: #dc2626; font-weight: 600; }

/* ── Main App ─────────────────────────────────────────────────────────────────── */

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  min-height: 0;
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── Header (inside main-view) ───────────────────────────────────────────────── */

.jewel-logo {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  object-fit: contain;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.ms-welcome__header {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.title-main {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.title-sub {
  font-size: 10px;
  color: var(--text-ter);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 6px;
}

/* Status */
.header-status       { display: flex; align-items: center; gap: 4px; flex-shrink: 0; max-width: 80px; }
.header-status-label { font-size: 10px; color: var(--text-ter); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-status-label.ready   { color: var(--text-ter); }
.header-status-label.loading { color: var(--text-ter); }
.header-status-label.error   { color: #dc2626; }

.header-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
  transition: background 0.3s;
}

.header-status-dot.ready   { background: #2D9F6F; }
.header-status-dot.loading { background: #fbbf24; animation: pulse-dot 1.2s ease-in-out infinite; }
.header-status-dot.error   { background: #f87171; }

@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Jurisdiction pill */
.jurisdiction-wrap { position: relative; }

.jurisdiction-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-sec);
  cursor: pointer;
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: all 0.15s;
}

.jurisdiction-pill.open,
.jurisdiction-pill:hover {
  border-color: var(--brand);
  background: var(--brand-bg);
  color: var(--brand);
}

.juris-chevron { transition: transform 0.15s; color: currentColor; }
.jurisdiction-pill.open .juris-chevron { transform: rotate(180deg); }

.jurisdiction-dropdown {
  position: fixed;
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
  z-index: 9999;
  min-width: 90px;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.jurisdiction-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 14px;
  font-size: 11.5px;
  font-family: 'Poppins', system-ui, sans-serif;
  color: var(--text);
  font-weight: 400;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.1s;
}

.jurisdiction-option:hover   { background: var(--surface-alt); }
.jurisdiction-option.active  { color: var(--brand); font-weight: 600; background: var(--brand-bg); }

/* Profile button */
.profile-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 3px 5px;
  color: var(--text-ter);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  height: 28px;
  width: 28px;
}

.profile-btn:hover { color: var(--brand); border-color: var(--brand-border); background: var(--brand-bg); }

/* ── AutoSave banner ────────────────────────────────────────────────────────── */

.autosave-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 10px;
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  flex-shrink: 0;
}

.autosave-banner-text { font-size: 0.68rem; color: #92400e; font-weight: 500; flex: 1; }
.autosave-dismiss     { font-size: 0.7rem; color: #92400e; background: none; border: none; cursor: pointer; padding: 0 2px; opacity: 0.7; line-height: 1; flex-shrink: 0; }
.autosave-dismiss:hover { opacity: 1; }

/* ── Mode bar ────────────────────────────────────────────────────────────────── */

.mode-bar {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}

.mode-btn {
  flex: 1;
  font-size: 11px;
  padding: 5px 4px;
  border-radius: 8px;
  border: 1.5px solid var(--brand-border);
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 500;
  transition: all 0.15s;
  text-align: center;
  white-space: nowrap;
}

.mode-btn:hover { background: var(--brand-bg); border-color: var(--brand); }
.mode-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── Search ──────────────────────────────────────────────────────────────────── */

/* Search icon button — identical shape/size to profile-btn */
.search-icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  padding: 3px 5px;
  color: var(--text-ter);
  display: flex;
  align-items: center;
  transition: all 0.15s;
  flex-shrink: 0;
  height: 28px;
  width: 28px;
  justify-content: center;
}
.search-icon-btn:hover { color: var(--brand); border-color: var(--brand-border); background: var(--brand-bg); }

/* Search overlay — slides over the full header when search is active */
.header-search-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 14px;
  background: var(--surface);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 10;
}

.ms-welcome__header.search-active .header-search-overlay {
  opacity: 1;
  pointer-events: auto;
}

.ms-welcome__header.search-active .header-left,
.ms-welcome__header.search-active .header-right {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.search-overlay-icon { color: var(--text-hint); flex-shrink: 0; }

.header-search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 13px;
  font-family: 'Poppins', system-ui, sans-serif;
  color: var(--text);
  padding: 4px 0;
  min-width: 0;
}
.header-search-input::placeholder { color: var(--text-hint); }

.search-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 5px;
  color: var(--text-ter);
  display: flex;
  align-items: center;
  border-radius: 4px;
  flex-shrink: 0;
  transition: all 0.12s;
}
.search-close-btn:hover { color: var(--text); background: var(--surface-alt); }

/* Search results panel */
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.search-hint,
.search-no-results {
  text-align: center;
  color: var(--text-hint);
  font-size: 12px;
  padding: 32px 16px;
  line-height: 1.6;
}

.search-result-item {
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.search-result-item.user {
  background: var(--user-bubble);
  border: 0.5px solid var(--user-border);
}
.search-result-item.ai {
  background: var(--bot-bubble);
  border: 0.5px solid var(--bot-border);
}

.search-result-header {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-result-role {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-sec);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.search-result-role.ai { color: var(--brand); }

.search-result-time {
  font-size: 10px;
  color: var(--text-hint);
  margin-left: auto;
}
.search-result-item.ai .search-result-time { color: #C09088; }
[data-theme="dark"] .search-result-item.ai .search-result-time { color: #9B6A66; }

.search-result-body {
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
}
.search-result-body p { margin: 0 0 4px; }
.search-result-body p:last-child { margin: 0; }
.search-result-body a { color: var(--brand); }

mark.srch-highlight {
  background: #fef08a;
  color: #713f12;
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 600;
  font-style: normal;
}
[data-theme="dark"] mark.srch-highlight {
  background: #854d0e;
  color: #fef9c3;
}

.search-load-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
  padding: 7px 0;
  background: none;
  border: 0.5px dashed var(--border);
  border-radius: 7px;
  color: var(--text-ter);
  font-size: 11.5px;
  font-family: 'Poppins', system-ui, sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.search-load-more-btn:hover:not(:disabled) { color: var(--brand); border-color: var(--brand-border); background: var(--brand-bg); }
.search-load-more-btn:disabled { opacity: 0.5; cursor: default; }

@keyframes spin { to { transform: rotate(360deg); } }
.search-load-more-btn .spin { animation: spin 0.8s linear infinite; }

/* ── Chat area ───────────────────────────────────────────────────────────────── */

.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.load-more-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  align-self: center;
  font-size: 10.5px;
  padding: 5px 14px;
  border-radius: 6px;
  border: 0.5px solid var(--border);
  background: var(--surface);
  color: var(--text-ter);
  cursor: pointer;
  font-family: 'Poppins', system-ui, sans-serif;
  margin-bottom: 12px;
  transition: background 0.15s, color 0.15s;
  font-weight: 500;
}

.load-more-btn:hover { background: var(--surface-alt); color: var(--text-sec); }
.load-more-btn svg { flex-shrink: 0; }

.msg.history { opacity: 0.85; }

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 20px;
  color: var(--text-hint);
}

.chat-empty-icon  { font-size: 2.5rem; margin-bottom: 8px; opacity: 0.6; }
.chat-empty-title { font-size: 15px; font-weight: 600; color: var(--text-sec); margin-bottom: 4px; }
.chat-empty-hint  { font-size: 11px; color: var(--text-hint); line-height: 1.4; }

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 12px;
}

.date-sep-line { flex: 1; height: 0.5px; background: var(--border); }

.date-sep-label {
  font-size: 10px;
  color: var(--date-sep-text);
  background: var(--date-sep-bg);
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Chat bubbles ─────────────────────────────────────────────────────────────── */

.msg {
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
  max-width: 92%;
  font-size: 12.5px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg.user { align-items: flex-end; align-self: flex-end; }
.msg.ai   { align-items: flex-start; align-self: flex-start; }

.msg-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-ter);
  margin-bottom: 2px;
  padding: 0 2px;
}

.msg.user .msg-label { color: var(--text-ter); }
.msg.ai   .msg-label { color: var(--brand); }

.msg-body {
  padding: 9px 11px;
  max-width: 100%;
}

.msg.user .msg-body {
  background: var(--user-bubble);
  border: 0.5px solid var(--user-border);
  border-radius: 10px 10px 2px 10px;
  color: var(--user-text);
}

.msg.ai .msg-body {
  background: var(--bot-bubble);
  border: 0.5px solid var(--bot-border);
  border-radius: 10px 10px 10px 2px;
  color: var(--text);
}

.msg-time { font-size: 9.5px; color: var(--meta-text); margin-top: 3px; padding: 0 2px; }
.msg.user .msg-time { text-align: right; }

/* AI body markdown */
.msg.ai .msg-body h1,
.msg.ai .msg-body h2,
.msg.ai .msg-body h3,
.msg.ai .msg-body h4 { margin: 8px 0 4px; line-height: 1.3; color: var(--text); }
.msg.ai .msg-body h1  { font-size: 15px; }
.msg.ai .msg-body h2  { font-size: 14px; }
.msg.ai .msg-body h3  { font-size: 13px; }
.msg.ai .msg-body h4  { font-size: 12px; font-weight: 600; }
.msg.ai .msg-body p   { margin: 4px 0; }
.msg.ai .msg-body ul,
.msg.ai .msg-body ol  { margin: 4px 0; padding-left: 18px; }
.msg.ai .msg-body li  { margin-bottom: 2px; }
.msg.ai .msg-body strong { font-weight: 600; }
.msg.ai .msg-body em  { font-style: italic; color: var(--text-sec); }

.msg.ai .msg-body code {
  background: rgba(0,0,0,0.07);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11px;
}

.msg.ai .msg-body pre {
  background: #1c1917;
  color: #a3e635;
  padding: 8px;
  border-radius: 8px;
  font-size: 10px;
  overflow-x: auto;
  margin: 6px 0;
}

.msg.ai .msg-body pre code { background: none; padding: 0; color: inherit; }

.msg.ai .msg-body a {
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px dotted var(--brand);
  font-weight: 500;
}

.msg.ai .msg-body a[href]::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 3px;
  vertical-align: middle;
  background-color: var(--brand);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M6 3H3a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-3M9 3h4m0 0v4m0-4L7.5 8.5' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M6 3H3a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-3M9 3h4m0 0v4m0-4L7.5 8.5' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  opacity: 0.8;
}

.msg.ai .msg-body a:hover { border-bottom-style: solid; }

.msg.ai .msg-body blockquote {
  border-left: 3px solid var(--brand);
  margin: 6px 0;
  padding: 4px 10px;
  background: var(--brand-bg);
  color: var(--text-sec);
  font-style: italic;
  border-radius: 0 6px 6px 0;
}

.recommendation-block {
  background: var(--amber-bg);
  border: 0.5px solid var(--amber-border);
  border-radius: 6px;
  padding: 7px 10px;
  margin-top: 7px;
}
.recommendation-block p {
  font-size: 11px;
  color: var(--amber-text);
  margin: 0;
  line-height: 1.5;
}
[data-theme="dark"] .recommendation-block {
  background: color-mix(in srgb, var(--amber-bg) 60%, var(--surface));
}

.msg.ai .msg-body hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

.msg.ai .msg-body table { border-collapse: separate; border-spacing: 0; width: 100%; table-layout: fixed; margin: 0; font-size: 11px; }
.msg.ai .msg-body { overflow-x: hidden; }

.msg.ai .msg-body .table-scroll { margin: 6px 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }

.msg.ai .msg-body th,
.msg.ai .msg-body td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 5px 8px;
  text-align: left;
  word-break: break-word;
  overflow-wrap: break-word;
}
.msg.ai .msg-body th:first-child,
.msg.ai .msg-body td:first-child { border-left: none; }
.msg.ai .msg-body tr:last-child td { border-bottom: none; }
.msg.ai .msg-body tr th:last-child,
.msg.ai .msg-body tr td:last-child { border-right: none; }

.msg.ai .msg-body th { background: var(--brand-bg); color: var(--brand-text); font-weight: 600; }
.msg.ai .msg-body td { background: color-mix(in srgb, var(--brand-bg) 25%, var(--surface)); }

.msg.ai .msg-body.thinking { color: var(--brand); font-style: italic; opacity: 0.75; }
[data-theme="dark"] .msg.ai .msg-body.thinking { color: var(--brand-text); opacity: 0.85; }

/* Msg footer row (time + copy btn) */
.msg-footer-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  padding: 0 2px;
}

.msg.user .msg-footer-row { justify-content: flex-end; }

.copy-response-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  color: var(--brand);
  opacity: 0.6;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.copy-response-btn:hover { opacity: 1; }

/* Selection context pill (above user message body) */
.msg-ctx-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--locate-text);
  background: var(--locate-btn);
  border: 0.5px solid var(--locate-border);
  border-radius: 5px;
  padding: 3px 8px;
  cursor: pointer;
  margin-bottom: 4px;
  align-self: flex-end;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: opacity 0.15s;
  user-select: none;
}

.msg-ctx-pill:hover { opacity: 0.8; }
.ctx-pill-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* System / debug messages */
.msg.system { max-width: 100%; align-self: stretch; }
.msg.system .msg-body {
  background: #1c1917;
  color: #a3e635;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 10px;
  line-height: 1.35;
  border: 1px solid #44403c;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
}

.msg.system .msg-label { color: var(--text-ter); }

/* Selection context snippet inside user message */
.msg-selection-ctx {
  margin-top: 4px;
  padding: 5px 8px;
  border-radius: 4px;
  background: rgba(139,26,26,0.06);
  border-left: 2px solid var(--brand);
  font-size: 10px;
  line-height: 1.35;
  color: var(--text-sec);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg.user .msg-selection-ctx {
  background: rgba(0,0,0,0.04);
  border-left-color: var(--brand-border);
}

.msg-ctx-snippet { font-style: italic; word-break: break-word; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.msg-ctx-jump {
  font-size: 9px;
  font-weight: 600;
  color: var(--brand);
  text-decoration: none;
  cursor: pointer;
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.msg-ctx-jump:hover { text-decoration: underline; }
.locate-arrow { width: 12px; height: 12px; flex-shrink: 0; }

/* Inline clause refs */
.inline-clause-ref {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: var(--locate-btn);
  border: 0.5px solid var(--locate-border);
  border-radius: 5px;
  color: var(--locate-text);
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  vertical-align: middle;
  transition: opacity 0.15s;
  user-select: none;
}
.inline-clause-ref:hover { opacity: 0.8; }

/* ── Selection / Context bar ─────────────────────────────────────────────────── */

.context-box {
  flex-shrink: 0;
  background: var(--surface-alt);
  border-top: 0.5px solid var(--border);
}

/* Empty state: invisible (no height) */
.ctx-empty { display: none; }

/* Content bar */
.ctx-content {
  padding: 7px 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.ctx-bar-left {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.ctx-bar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-ter);
  flex-shrink: 0;
}

.ctx-text {
  font-size: 11px;
  color: var(--text-sec);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ctx-locate-btn {
  background: var(--locate-btn);
  border: 0.5px solid var(--locate-border);
  border-radius: 4px;
  padding: 2px 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--locate-text);
  text-decoration: none;
}

.ctx-locate-btn:hover { opacity: 0.8; }

.ctx-unpin {
  background: none;
  border: none;
  cursor: pointer;
  padding: 1px;
  flex-shrink: 0;
  color: var(--text-hint);
  display: flex;
  align-items: center;
  text-decoration: none;
}

.ctx-unpin:hover { color: var(--text-sec); }

/* ── Input area ──────────────────────────────────────────────────────────────── */

.input-area {
  padding: 9px 12px;
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.input-row {
  display: flex;
  gap: 7px;
  align-items: center;
  margin-bottom: 7px;
}

#user-input {
  flex: 1;
  padding: 8px 11px;
  border: 0.5px solid var(--input-border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--input);
  font-family: 'Poppins', system-ui, sans-serif;
  outline: none;
  transition: border-color 0.15s;
}

#user-input:focus { border-color: var(--brand); }
#user-input::placeholder { color: var(--text-hint); }

.send-btn,
#ask-btn {
  width: 34px;
  height: 34px;
  background: var(--brand);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:hover:not(:disabled),
#ask-btn:hover:not(:disabled) { opacity: 0.85; }

.send-btn:disabled,
#ask-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Actions bar */
.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

button {
  padding: 5px 12px;
  border-radius: 5px;
  border: none;
  font-size: 12px;
  font-weight: 600;
  font-family: 'Poppins', system-ui, sans-serif;
  cursor: pointer;
}

.get-selection-btn {
  font-size: 10.5px;
  padding: 4px 9px;
  border-radius: 5px;
  border: 0.5px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-sec);
  cursor: pointer;
  font-family: 'Poppins', system-ui, sans-serif;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
}

.get-selection-btn svg { color: var(--text-ter); }
.get-selection-btn:hover:not(:disabled) { background: var(--border); }
.get-selection-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Suggest edits — tiny checkbox + text */
.suggest-edits-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
}

.suggest-check-btn {
  width: 15px;
  height: 15px;
  border-radius: 3px;
  border: 0.5px solid var(--input-border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.suggest-check-btn.active {
  background: var(--brand);
  border-color: var(--brand);
}

.suggest-check-icon { display: none; }
.suggest-check-btn.active .suggest-check-icon { display: block; }

.suggest-edits-label {
  font-size: 10.5px;
  color: var(--text-sec);
  font-family: 'Poppins', system-ui, sans-serif;
  cursor: pointer;
  user-select: none;
}

/* Debug toggle */
.debug-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--text-hint);
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}

.debug-toggle:hover  { color: var(--text-sec); background: var(--surface-alt); }
.debug-toggle.active { color: var(--brand-text); background: var(--brand-bg); border-color: var(--brand-border); }

/* ── Settings View ───────────────────────────────────────────────────────────── */

.settings-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  flex-shrink: 0;
}

.settings-back-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  color: var(--text-sec);
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.settings-back-btn:hover { color: var(--text); }

.settings-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-user-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--brand-bg);
  color: var(--brand);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.settings-user-info { min-width: 0; }
.settings-name  { font-size: 14px; font-weight: 600; color: var(--text); margin: 0; }
.settings-email { font-size: 11.5px; color: var(--text-ter); margin: 2px 0 0; }

/* Credits card */
.credits-card {
  background: var(--brand-bg);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.credits-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.credits-icon { color: var(--brand); flex-shrink: 0; }
.credits-count { font-size: 13px; font-weight: 600; color: var(--brand); margin: 0; }
.credits-label { font-size: 10.5px; color: var(--text-ter); margin: 1px 0 0; }

.credits-usage-btn {
  font-size: 10.5px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 0.5px solid var(--brand);
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 500;
  transition: background 0.15s;
}

.credits-usage-btn:hover { background: rgba(139,26,26,0.08); }

/* Settings card */
.settings-card {
  background: var(--surface);
  border-radius: 10px;
  border: 0.5px solid var(--border);
}

.settings-section-title {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-ter);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 10px 14px 0;
  margin: 0;
}

.settings-info-row {
  padding: 9px 14px;
  border-top: 0.5px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-info-row:first-of-type { border-top: none; }
.settings-info-label { font-size: 12px; color: var(--text-ter); }
.settings-info-value { font-size: 12px; color: var(--text); font-weight: 500; max-width: 140px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Preferences row */
.settings-pref-row {
  padding: 10px 14px;
  border-top: 0.5px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-pref-row:first-of-type { border-top: none; }

.pref-row-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-sec);
}

.pref-row-label { font-size: 12px; color: var(--text-sec); }

.pref-badge {
  font-size: 11px;
  color: var(--brand);
  font-weight: 500;
  background: var(--brand-bg);
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.3px;
}

/* Theme toggle switch */
.theme-toggle-track {
  width: 38px;
  height: 20px;
  border-radius: 10px;
  background: var(--border-light);
  border: 0.5px solid var(--border);
  cursor: pointer;
  position: relative;
  padding: 0;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.theme-toggle-track.on { background: var(--brand); }

.theme-toggle-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  transition: left 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.theme-toggle-track.on .theme-toggle-thumb { left: 21px; }

/* Sign out button */
.settings-signout {
  width: 100%;
  padding: 10px 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  color: #E24B4A;
  font-weight: 500;
  cursor: pointer;
  font-family: 'Poppins', system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s;
}

.settings-signout:hover { background: rgba(226,75,74,0.06); }

/* ── Suggested edits ─────────────────────────────────────────────────────────── */

.suggested-edits-container {
  margin-top: 10px;
  border-radius: 10px;
  border: 0.5px solid var(--border);
  overflow: hidden;
}

.suggested-edits-heading {
  padding: 7px 10px;
  background: var(--surface-alt);
  border-bottom: 0.5px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sec);
  display: flex;
  align-items: center;
  gap: 5px;
}

.edit-card {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  transition: opacity 0.2s;
}

.edit-card:last-child   { border-bottom: none; }
.edit-card.edit-dismissed { opacity: 0.45; }
.edit-card.edit-undone    { opacity: 0.5; }

.edit-card-header { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.edit-card-num    { font-weight: 700; font-size: 11px; color: var(--text); flex-shrink: 0; }

.edit-card-location {
  font-size: 10px;
  font-weight: 600;
  color: var(--locate-text);
  background: var(--locate-btn);
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.edit-card-location:hover { opacity: 0.8; text-decoration: underline; }
.edit-card-reason { font-size: 11px; color: var(--text-sec); line-height: 1.4; margin-bottom: 4px; }

.edit-diff { display: flex; gap: 6px; padding: 4px 6px; border-radius: 4px; font-size: 11px; line-height: 1.45; margin-bottom: 3px; }

.edit-diff-remove            { background: var(--edit-old-bg); border-left: 3px solid #ef4444; }
.edit-diff-remove .diff-text { color: var(--edit-old-text); text-decoration: line-through; }
.edit-diff-add               { background: var(--edit-new-bg); border-left: 3px solid #22c55e; }
.edit-diff-add .diff-text    { color: var(--edit-new-text); }

.diff-label { font-weight: 700; font-size: 13px; line-height: 1.3; flex-shrink: 0; width: 12px; text-align: center; }
.edit-diff-remove .diff-label { color: #ef4444; }
.edit-diff-add    .diff-label { color: #22c55e; }
.diff-text { word-break: break-word; }

.edit-card-actions { display: flex; align-items: center; gap: 6px; margin-top: 6px; }

.edit-accept-btn,
.edit-reject-btn,
.edit-undo-btn {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 10.5px;
  font-weight: 500;
  font-family: 'Poppins', system-ui, sans-serif;
  cursor: pointer;
  border: 1px solid;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.edit-accept-btn          { background: var(--brand); border-color: var(--brand); color: #fff; }
.edit-accept-btn.applied  { background: var(--green-bg); border-color: var(--green-border); color: var(--green-text); }
.edit-accept-btn:disabled { opacity: 0.6; cursor: default; }
.edit-reject-btn          { background: var(--surface); border-color: var(--border); color: var(--text-sec); }
.edit-reject-btn:hover    { background: var(--surface-alt); }
.edit-undo-btn            { background: var(--surface); border-color: #fbbf24; color: #92400e; }
.edit-undo-btn:hover      { background: #fefce8; }

.edit-applied-label    { font-size: 11px; font-weight: 600; color: var(--green-text); }
.edit-dismissed-label  { font-size: 11px; color: var(--text-hint); font-style: italic; }
.edit-undone-label     { font-size: 11px; color: #92400e; font-style: italic; }

/* Recommendation box (amber) */
.recommendation-box {
  background: var(--amber-bg);
  border-radius: 6px;
  padding: 7px 10px;
  margin-top: 7px;
  border: 0.5px solid var(--amber-border);
  font-size: 11px;
  color: var(--amber-text);
  line-height: 1.5;
}

/* ── Clause tree panel ────────────────────────────────────────────────────────── */

.clause-tree-panel  { flex-shrink: 0; border-bottom: 0.5px solid var(--border); background: var(--surface); }
.clause-tree-header { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; cursor: pointer; user-select: none; }
.clause-tree-header:hover { background: var(--surface-alt); }
.clause-tree-title  { font-size: 12px; font-weight: 600; color: var(--text); }
.clause-tree-chevron { font-size: 12px; color: var(--text-sec); transition: transform 0.15s; }
.clause-tree-chevron.open { transform: rotate(90deg); }
.clause-tree-body { max-height: 200px; overflow-y: auto; padding: 0 6px 6px; }
.clause-node { padding: 3px 6px; font-size: 11px; color: var(--text); border-radius: 3px; cursor: pointer; line-height: 1.3; transition: background 0.1s; }
.clause-node:hover { background: var(--surface-alt); }
.clause-node .clause-number { font-weight: 600; color: var(--brand); margin-right: 4px; }

/* ── Chat links fallback ─────────────────────────────────────────────────────── */

.msg-body a {
  color: var(--brand);
  text-decoration: none;
  border-bottom: 1px dotted var(--brand);
  word-break: break-all;
}

.msg-body a:hover { border-bottom-style: solid; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */

::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Tooltips (data-tooltip attribute) ───────────────────────────────────────── */

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1A1A1A;
  color: #F0F0F0;
  font-size: 10px;
  font-weight: 400;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-tooltip]:hover::after { opacity: 1; }

/* Tooltip below for top-edge elements */
[data-tooltip-pos="below"]::after {
  bottom: auto;
  top: calc(100% + 6px);
}

[data-theme="dark"] [data-tooltip]::after {
  background: #E0E0E0;
  color: #1A1A1A;
}

/* ── Legacy header-user-strip — kept for auth.js null-safe refs ─────────────── */
.header-user-strip { display: none !important; }
