/* ------------------------------------------------------------------ tokens */

:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --border: #e3e7ef;
  --border-strong: #d3d9e4;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-soft-text: #4338ca;
  --on-accent: #ffffff;

  --ok: #16a34a;
  --bad: #dc2626;
  --rec: #ef4444;
  --warn-bg: #fff7e6;
  --warn-text: #9a5b00;
  --files-bg: #e8f7ee;
  --files-text: #15803d;
  --none-bg: #f1f5f9;
  --none-text: #475569;
  --code-bg: #f5f7fb;

  /* The sidebar stays dark in both themes, for a stable brand frame. */
  --side-bg: #0f172a;
  --side-bg-2: #1e293b;
  --side-border: #1f2a3d;
  --side-text: #e2e8f0;
  --side-muted: #94a3b8;
  --side-active: #273449;

  --shadow-sm: 0 1px 2px rgb(15 23 42 / .06);
  --shadow: 0 1px 3px rgb(15 23 42 / .06), 0 8px 24px rgb(15 23 42 / .06);
  --shadow-lg: 0 12px 40px rgb(15 23 42 / .18);
  --radius: 14px;
  --font: "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, -apple-system, Roboto, sans-serif;
  --mono: "Cascadia Code", "Cascadia Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #172033;
    --border: #1f2a3d;
    --border-strong: #2b374d;
    --text: #e5e9f0;
    --text-2: #b6c0cf;
    --muted: #8b97a8;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-soft: #1e1b4b;
    --accent-soft-text: #c7d2fe;
    --ok: #22c55e;
    --bad: #f87171;
    --warn-bg: #362a12;
    --warn-text: #f6c566;
    --files-bg: #10301f;
    --files-text: #6ee7a0;
    --none-bg: #1b2436;
    --none-text: #b6c0cf;
    --code-bg: #0d1424;
    --side-bg: #080d19;
    --side-bg-2: #111a2c;
    --side-border: #172136;
    --side-active: #18233a;
    --shadow: 0 1px 3px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

/* ------------------------------------------------------------------ base */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; flex: none; }
.i { width: 15px; height: 15px; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; overflow: hidden; }

/* ------------------------------------------------------------------ sidebar */

.sidebar {
  background: var(--side-bg);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 14px;
  gap: 22px;
  overflow-y: auto;
  border-right: 1px solid var(--side-border);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 2px 6px; }
.logo {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  box-shadow: 0 6px 18px rgb(79 70 229 / .45);
}
.logo svg { width: 21px; height: 21px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--side-muted); }
.brand .icon-btn { margin-left: auto; color: var(--side-muted); }

.nav-section { display: flex; flex-direction: column; gap: 4px; }
.nav-label {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--side-muted); padding: 0 8px 6px;
}

.workspace-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.workspace {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--side-text);
  text-align: left;
  transition: background .15s;
}
.workspace:hover:not(:disabled) { background: var(--side-bg-2); }
.workspace.active { background: var(--side-active); box-shadow: inset 3px 0 0 #818cf8; }
.workspace:disabled { opacity: .55; cursor: not-allowed; }
.ws-icon {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  background: var(--side-bg-2); color: #a5b4fc;
}
.workspace.active .ws-icon { background: #4f46e5; color: #fff; }
.ws-icon svg { width: 16px; height: 16px; }
.ws-text { min-width: 0; display: flex; flex-direction: column; }
.ws-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-meta { font-size: 12px; color: var(--side-muted); }
.ws-meta.warn { color: #fbbf24; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 8px; border-radius: 10px; cursor: pointer;
}
.switch-row:hover { background: var(--side-bg-2); }
.switch-text { font-size: 14px; font-weight: 500; display: flex; flex-direction: column; line-height: 1.35; }
.switch-text small { font-size: 12px; color: var(--side-muted); font-weight: 400; }

.switch {
  appearance: none; -webkit-appearance: none;
  width: 36px; height: 20px; border-radius: 999px; flex: none;
  background: #334155; position: relative; cursor: pointer;
  transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  transition: transform .2s; box-shadow: 0 1px 2px rgb(0 0 0 / .3);
}
.switch:checked { background: #6366f1; }
.switch:checked::after { transform: translateX(16px); }
.switch:disabled { opacity: .45; cursor: not-allowed; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--side-border);
  padding: 14px 8px 2px;
  display: flex; flex-direction: column; gap: 8px;
  font-size: 13px;
}
.status-line { display: flex; align-items: center; gap: 8px; }
.status-line.muted { color: var(--side-muted); }
.status-line span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--side-muted); margin: 0 3.5px; flex: none; }
.dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgb(34 197 94 / .2); }
.dot.bad { background: #ef4444; box-shadow: 0 0 0 3px rgb(239 68 68 / .2); }
.privacy-note {
  margin-top: 6px;
  display: flex; gap: 8px; align-items: flex-start;
  background: rgb(99 102 241 / .12);
  border: 1px solid rgb(129 140 248 / .25);
  color: #c7d2fe;
  padding: 9px 10px; border-radius: 10px;
  font-size: 12px; line-height: 1.45;
}
.privacy-note .i { margin-top: 1px; }

/* ------------------------------------------------------------------ main */

.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  min-height: 68px;
}
.topbar-title { min-width: 0; flex: 1; }
.topbar-title h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.topbar-meta .path { font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-soft-text);
}
.pill.ok { background: var(--files-bg); color: var(--files-text); }
.pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.topbar-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2);
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: background .15s, border-color .15s, color .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }
.btn.primary-soft { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary-soft:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.spinning svg { animation: spin 1s linear infinite; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 0;
  display: grid; place-items: center;
  background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.only-mobile { display: none; }

/* ------------------------------------------------------------------ messages */

.messages {
  flex: 1; overflow-y: auto;
  padding: 28px max(20px, calc((100% - 860px) / 2)) 12px;
  display: flex; flex-direction: column; gap: 22px;
  scroll-behavior: smooth;
}

.welcome { margin: auto 0; text-align: center; display: flex; flex-direction: column; align-items: center; padding: 20px 0; }
/* On a short window there is nothing to centre, and the full-size welcome does
   not fit: start at the top and tighten it, so the last card is not left
   half-hidden under the composer. */
@media (max-height: 780px) {
  .welcome { margin-block: 0 4px; padding: 4px 0 0; }
  .welcome-logo { width: 42px; height: 42px; border-radius: 12px; box-shadow: none; }
  .welcome-logo svg { width: 22px; height: 22px; }
  .welcome h2 { font-size: 21px; }
  .welcome-sub { margin: 6px 0 14px; font-size: 14px; }
  .call-me { margin-top: 12px; padding: 12px 14px; }
  .call-tips { display: none; }
  .messages { padding-top: 14px; gap: 16px; }
}
.welcome-logo {
  width: 56px; height: 56px; border-radius: 16px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  box-shadow: 0 10px 30px rgb(79 70 229 / .35);
  margin-bottom: 18px;
}
.welcome-logo svg { width: 28px; height: 28px; }
.welcome h2 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.welcome-sub { margin: 8px 0 24px; color: var(--muted); max-width: 520px; }

.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 640px; }
.suggestion {
  text-align: left; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-sm);
  font-size: 14px; color: var(--text-2);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.suggestion svg { width: 15px; height: 15px; color: var(--muted); }
.suggestion:hover:not(:disabled) { border-color: var(--accent); color: var(--text); box-shadow: var(--shadow); transform: translateY(-1px); }
.suggestion:disabled { opacity: .5; cursor: not-allowed; }

.voice-tips {
  margin-top: 26px; width: 100%; max-width: 640px;
  border: 1px dashed var(--border-strong); border-radius: 12px;
  padding: 12px 16px; text-align: left;
}
.voice-tips-title { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.tips-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 14px; font-size: 13px; color: var(--text-2); }
.tips-grid em { font-style: normal; color: var(--accent-soft-text); font-weight: 600; }

/* user */
.msg-user { align-self: flex-end; max-width: 78%; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.bubble {
  background: var(--accent); color: var(--on-accent);
  padding: 10px 15px; border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  box-shadow: 0 4px 14px rgb(79 70 229 / .22);
}
.via-voice { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.via-voice svg { width: 12px; height: 12px; }

/* assistant */
.msg-ai { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #6366f1, #4338ca);
}
.avatar svg { width: 18px; height: 18px; }
.ai-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 14px 18px 12px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
  min-width: 0;
}
.ai-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-name { font-weight: 650; font-size: 14px; }

.badge { font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: var(--none-bg); color: var(--none-text); }
.badge.files { background: var(--files-bg); color: var(--files-text); }
.badge.general { background: var(--warn-bg); color: var(--warn-text); }
.badge.error { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }

.progress { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; }
.progress .elapsed { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 12px; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }
@keyframes spin { to { transform: rotate(360deg); } }

.answer { overflow-wrap: anywhere; font-size: 15px; line-height: 1.7; }
.answer p { margin: 0 0 .75em; }
.answer p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { margin: 0 0 .75em; padding-left: 1.4em; }
.answer li { margin: .2em 0; }
.answer code { font-family: var(--mono); font-size: 13px; background: var(--code-bg); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }
.answer pre, .evidence pre {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; margin: 0 0 .75em;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55; white-space: pre;
}
.answer pre code { background: none; border: 0; padding: 0; }
.answer.refusal { color: var(--muted); font-style: italic; }
.caret { display: inline-block; width: 8px; height: 1.05em; background: var(--accent); margin-left: 2px; vertical-align: text-bottom; border-radius: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.sources-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-right: 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 12px;
  padding: 3px 9px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.chip svg { width: 12px; height: 12px; color: var(--muted); }

.evidence { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.evidence > summary {
  list-style: none; cursor: pointer; padding: 8px 12px;
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.evidence > summary::-webkit-details-marker { display: none; }
.evidence > summary svg { width: 14px; height: 14px; transition: transform .15s; color: var(--muted); }
.evidence[open] > summary svg { transform: rotate(90deg); }
.evidence .inner { padding: 0 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.evidence .note { font-size: 13px; color: var(--muted); padding: 2px 4px; }
.evidence h4 { margin: 6px 2px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.evidence .prompt-text { white-space: pre-wrap; max-height: 320px; overflow: auto; }

.chunk { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.chunk > summary { list-style: none; cursor: pointer; padding: 7px 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.chunk > summary::-webkit-details-marker { display: none; }
.chunk .path { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.chunk .lines { color: var(--muted); font-size: 12px; }
.chunk .dropped { font-size: 11px; font-weight: 600; background: var(--warn-bg); color: var(--warn-text); padding: 1px 6px; border-radius: 5px; }
.score { margin-left: auto; display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.score-bar { width: 48px; height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.score-bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.chunk pre { margin: 0 8px 8px; max-height: 300px; overflow: auto; }

.ai-foot { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px; }
.ai-foot .stats { font-size: 12px; color: var(--muted); margin-right: auto; font-variant-numeric: tabular-nums; }
.ai-foot .icon-btn { width: 30px; height: 30px; }
.ai-foot .icon-btn svg { width: 15px; height: 15px; }
.ai-foot .icon-btn.speaking { color: var(--accent); background: var(--accent-soft); }
.warn-line { font-size: 12.5px; color: var(--warn-text); background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; }
.error-line { font-size: 14px; color: var(--bad); background: color-mix(in srgb, var(--bad) 9%, transparent); padding: 9px 12px; border-radius: 9px; white-space: pre-wrap; }

/* ------------------------------------------------------------------ composer */

.composer-wrap { padding: 10px max(20px, calc((100% - 860px) / 2)) 16px; }
.composer {
  position: relative;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent), var(--shadow); }
.composer textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent;
  max-height: 200px; padding: 9px 0; line-height: 1.5; font-size: 15px;
}
.composer textarea::placeholder { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.round-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; flex: none;
  display: grid; place-items: center;
  transition: background .15s, color .15s, transform .1s;
}
.round-btn:active:not(:disabled) { transform: scale(.95); }
.round-btn.send { background: var(--accent); color: var(--on-accent); }
.round-btn.send:hover:not(:disabled) { background: var(--accent-hover); }
.round-btn.mic { background: var(--surface-2); color: var(--text-2); }
.round-btn.mic:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-soft-text); }
.round-btn.mic.recording, .round-btn.mic.recording:hover:not(:disabled) { background: var(--rec); color: #fff; animation: pulse 1.4s infinite; }
.round-btn.mic.working { background: var(--accent-soft); color: var(--accent-soft-text); }
.round-btn.mic.working svg { animation: spin 1s linear infinite; }
.round-btn:disabled { opacity: .45; cursor: not-allowed; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(239 68 68 / .5); } 70% { box-shadow: 0 0 0 10px rgb(239 68 68 / 0); } 100% { box-shadow: 0 0 0 0 rgb(239 68 68 / 0); } }

.listening {
  position: absolute; inset: 0 104px 0 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-radius: 18px 0 0 18px;
  font-size: 14.5px; font-weight: 500;
  z-index: 1;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: blink 1s steps(1) infinite; flex: none; }
.listening-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { display: flex; align-items: center; gap: 3px; height: 26px; margin-left: auto; }
.meter i { width: 4px; height: 4px; border-radius: 2px; background: var(--rec); transition: height .08s; }

.composer-hint { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 8px 6px 0; }
kbd { font-family: var(--font); font-size: 11px; padding: 0 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface); }

/* ------------------------------------------------------------------ dialog & toasts */

.modal {
  border: 1px solid var(--border); border-radius: 16px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(680px, calc(100vw - 32px)); max-height: 82vh;
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgb(15 23 42 / .45); backdrop-filter: blur(2px); }
.modal header { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.modal h3 { margin: 0; font-size: 16px; }
.modal header p { margin: 2px 0 0; font-size: 13px; }
.files-list { padding: 6px 18px 16px; overflow-y: auto; max-height: calc(82vh - 80px); }
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.file-row:last-child { border-bottom: 0; }
.file-row svg { width: 15px; height: 15px; color: var(--muted); }
.file-row .fp { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; flex: 1; }

.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.voice { background: var(--accent); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ uploads */

.nav-label-row { display: flex; align-items: center; justify-content: space-between; }
.nav-add {
  display: inline-flex; align-items: center; gap: 3px;
  border: 1px solid rgb(129 140 248 / .35); background: rgb(99 102 241 / .15); color: #c7d2fe;
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 8px 2px 5px; border-radius: 999px;
}
.nav-add svg { width: 13px; height: 13px; }
.nav-add:hover:not(:disabled) { background: rgb(99 102 241 / .3); color: #fff; }
.nav-add:disabled { opacity: .5; cursor: not-allowed; }
.ws-badge { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #a5b4fc; margin-left: 6px; }

.modal form { display: flex; flex-direction: column; max-height: 82vh; margin: 0; }
.modal footer {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}
.footer-actions { display: flex; gap: 8px; margin-left: auto; }
.upload-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input {
  height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); font-size: 14.5px; font-weight: 400;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 26px 16px; border-radius: 14px; cursor: pointer;
  border: 2px dashed var(--border-strong); background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { font-size: 14.5px; }
.dropzone u { color: var(--accent); text-decoration: none; }
.dropzone small { color: var(--muted); font-size: 12.5px; }
.dz-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.dz-icon svg { width: 22px; height: 22px; }

.upload-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.upload-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  font-size: 13px;
}
.file-type {
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 800; letter-spacing: .02em; color: #fff; background: #64748b;
}
.file-type.pdf { background: #dc2626; }
.file-type.docx { background: #2563eb; }
.file-type.xlsx, .file-type.csv { background: #16a34a; }
.file-type.pptx { background: #ea580c; }
.upload-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.upload-item .size { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.upload-item .icon-btn { width: 28px; height: 28px; }
.upload-item .icon-btn svg { width: 14px; height: 14px; }
.upload-item.bad { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.upload-item.bad .size { color: var(--bad); }

.upload-progress { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.upload-progress .bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.upload-progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-progress .bar.indeterminate i { width: 35%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }

.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 10%, transparent); border-color: var(--bad); color: var(--bad); }

.drop-overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, rgb(15 23 42 / .5));
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-overlay > div {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 30px 44px; border-radius: 18px; border: 2px dashed #fff; color: #fff; font-size: 18px;
}
.drop-overlay svg { width: 40px; height: 40px; }

/* system notice in the chat, e.g. "workspace ready" */
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow-sm); font-size: 14px;
}
.notice-icon { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; background: var(--files-bg); color: var(--files-text); }
.notice-icon.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice-icon svg { width: 16px; height: 16px; }
.notice strong { display: block; margin-bottom: 4px; }
.notice ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); font-size: 13px; }
.notice .skip { color: var(--warn-text); }

.chunk .loc { font-size: 11.5px; font-weight: 600; color: var(--accent-soft-text); background: var(--accent-soft); padding: 1px 7px; border-radius: 5px; }

/* ------------------------------------------------------------------ small screens */

.scrim { display: none; }

@media (max-width: 900px) {
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 0 10px; }
  .topbar-meta .path { max-width: 200px; }
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgb(15 23 42 / .45); z-index: 30; }
  .only-mobile { display: grid; }
  .topbar { padding: 10px 16px; min-height: 58px; gap: 10px; }
  .topbar-meta .path { display: none; }
  .messages { padding: 18px 16px 8px; }
  .composer-wrap { padding: 8px 16px 12px; }
  .composer-hint span:first-child { display: none; }
  .suggestions, .tips-grid { grid-template-columns: 1fr; }
  .msg-user { max-width: 90%; }
  .msg-ai { grid-template-columns: minmax(0, 1fr); }
  .avatar { display: none; }
  .ai-body { border-radius: var(--radius); padding: 12px 14px 10px; }
  .welcome h2 { font-size: 22px; }
}

/* One scroll area inside dialogs (not two), so headers and buttons stay put
   on short screens, and a compact dropzone once files are chosen. */
.modal { overflow: hidden; }
.modal form { max-height: min(82vh, 760px); }
.modal .upload-body { flex: 1; min-height: 0; }
.dropzone.compact { flex-direction: row; justify-content: center; gap: 12px; padding: 12px 16px; }
.dropzone.compact .dz-icon { width: 32px; height: 32px; box-shadow: none; }
.dropzone.compact .dz-icon svg { width: 17px; height: 17px; }
.dropzone.compact small { display: none; }
@media (max-height: 700px) {
  .modal header { padding: 12px 18px 10px; }
  .modal header p { display: none; }
  .upload-body { padding: 12px 18px; gap: 10px; }
  .upload-item { padding: 5px 10px; }
  .file-type { width: 28px; height: 28px; font-size: 9px; }
}

/* ------------------------------------------------------------------ guided assistants */

.flow-q { display: flex; flex-direction: column; gap: 10px; }
.flow-q .prompt { font-size: 15px; line-height: 1.6; }
.flow-q .hint { font-size: 12.5px; color: var(--muted); margin-top: -4px; }
.flow-progress { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.flow-progress .bar { flex: 1; max-width: 180px; height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.flow-progress .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .25s; }
.qchips { display: flex; flex-wrap: wrap; gap: 8px; }
.qchip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  padding: 7px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  transition: border-color .15s, background .15s, color .15s;
}
.qchip:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-soft-text); background: var(--accent-soft); }
.qchip.secondary { border-style: dashed; color: var(--muted); }
.qchip:disabled { opacity: .45; cursor: not-allowed; }
.qchips.used .qchip { pointer-events: none; opacity: .5; }

.flow-summary { width: 100%; border-collapse: collapse; font-size: 14px; }
.flow-summary td { padding: 7px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.flow-summary td:first-child { color: var(--muted); width: 42%; }
.flow-summary tr:last-child td { border-bottom: 0; }
.flow-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.flow-done { display: flex; flex-direction: column; gap: 10px; }
.flow-done .ref { font-family: var(--mono); font-size: 20px; font-weight: 700; letter-spacing: .04em; }
.flow-done .facts { display: flex; flex-wrap: wrap; gap: 8px; }
.score-hot { background: #fee2e2; color: #b91c1c; }
.score-warm { background: var(--warn-bg); color: var(--warn-text); }
.score-cold { background: var(--none-bg); color: var(--none-text); }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: 100%; max-width: 720px; }
.template-card {
  text-align: left; padding: 16px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.template-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.template-card .ti { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-soft-text); }
.template-card strong { font-size: 14.5px; }
.template-card span { font-size: 12.5px; color: var(--muted); }

.modal-wide { width: min(1000px, calc(100vw - 32px)); }
.records-wrap { overflow: auto; max-height: calc(82vh - 90px); padding: 0 18px 16px; }
.records-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.records-table th { position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 600; color: var(--muted); padding: 10px 8px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.records-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.records-table td.mono { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.records-empty { padding: 28px 8px; text-align: center; color: var(--muted); }

@media (max-width: 760px) {
  .template-grid { grid-template-columns: 1fr; }
}

.status-booked, .status-placed, .status-received { background: var(--files-bg); color: var(--files-text); }
.status-cancelled { background: var(--none-bg); color: var(--none-text); }
.status-new-lead { background: var(--warn-bg); color: var(--warn-text); }
.manage-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.manage-head .ref { font-family: var(--mono); font-weight: 700; }
.template-card .ti.order { background: var(--files-bg); color: var(--files-text); }
.template-card .ti.manage { background: var(--warn-bg); color: var(--warn-text); }

/* ------------------------------------------------------------------ virtual receptionist */

.call-start {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 4px;
  border: 0; border-radius: 999px; padding: 14px 26px; font-size: 16px; font-weight: 700;
  background: #16a34a; color: #fff; box-shadow: 0 10px 26px rgb(22 163 74 / .35);
}
.call-start:hover:not(:disabled) { background: #15803d; }
.call-start svg { width: 20px; height: 20px; }
.call-tips { margin-top: 18px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 640px; }
.call-tips span { font-size: 13px; color: var(--text-2); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: 999px; padding: 6px 12px; }

.call-bar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 14px;
  background: var(--side-bg); color: var(--side-text);
  border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow);
}
.call-avatar { position: relative; width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; background: #16a34a; color: #fff; }
.call-avatar svg { width: 20px; height: 20px; }
.call-avatar.speaking::after, .call-avatar.listening::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid #22c55e; animation: ring 1.4s infinite;
}
.call-avatar.listening { background: var(--rec); }
.call-avatar.listening::after { border-color: var(--rec); }
@keyframes ring { 0% { transform: scale(.9); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }
.call-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.call-info strong { font-size: 14.5px; }
.call-info span { font-size: 12.5px; color: var(--side-muted); font-variant-numeric: tabular-nums; }
.call-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--side-bg-2); color: var(--side-text); }
.call-btn.on { background: #f59e0b; color: #111; }
.call-btn.end { background: var(--rec); color: #fff; width: 52px; }
.call-btn svg { width: 19px; height: 19px; }
.call-btn.skip { width: auto; border-radius: 21px; padding: 0 14px; gap: 6px; display: inline-flex; align-items: center; font-weight: 600; font-size: 13px; }
.call-btn.skip svg { width: 14px; height: 14px; }
.call-btn[hidden] { display: none; }
.call-ended { align-self: center; font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 6px 14px; }

.cal-feed { margin: 0 18px 10px; font-size: 13px; background: var(--accent-soft); color: var(--accent-soft-text); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cal-feed code { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; flex: 1; }
.cal-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; padding: 0 18px 18px; overflow: auto; max-height: calc(82vh - 110px); }
.cal-day { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); min-height: 180px; display: flex; flex-direction: column; }
.cal-day.today { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent); }
.cal-day h4 { margin: 0; padding: 9px 10px; font-size: 13px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.cal-day h4 span { color: var(--muted); font-weight: 500; }
.cal-items { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.cal-item { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; line-height: 1.35; }
.cal-item.call { border-left-color: #16a34a; }
.cal-item .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-item .n { font-weight: 600; }
.cal-item .w, .cal-item .s { color: var(--muted); }
.cal-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 16px 4px; }
@media (max-width: 760px) { .cal-grid { grid-template-columns: 1fr; } }

/* Embedded view (?embed=true): just the bot, as it would sit on a website. */
.embed .sidebar, .embed .scrim, .embed #open-sidebar { display: none; }
.embed .app { grid-template-columns: 1fr; }
/* A visitor may add and see their own documents, but not the saved records of
   other people, the business calendar, or the re-index button. */
.embed #records-btn, .embed #calendar-btn, .embed #index-btn { display: none; }
.embed .topbar-meta .pill.ok { display: none; }  /* where data is kept is our business, not the visitor's */

/* Reminder & follow-up calls: who to ring, and how the last calls went. */
.rem-body { width: 100%; max-width: 640px; margin-top: 18px; text-align: left; }
.rem-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.rem-head strong { font-size: 14.5px; }
.rem-head .hint { margin: 0; }
.rem-list { display: flex; flex-direction: column; gap: 10px; }
.rem-item { padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); display: flex; flex-direction: column; gap: 10px; }
.rem-who { display: flex; align-items: baseline; gap: 10px; }
.rem-who strong { font-size: 15px; }
.rem-who span { font-size: 13px; color: var(--muted); font-family: var(--mono); }
.rem-send { margin-top: -2px; }
.rem-auto { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border: 1px dashed var(--border-strong); border-radius: 14px; background: var(--surface); }
.rem-auto .hint { flex: 1; min-width: 200px; margin: 0; }
.rem-email .call-me-row input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 14px; }
.chip.sent { background: var(--files-bg); color: var(--files-text); }
.rem-log { margin-top: 22px; }
.rem-log h4 { margin: 0 0 8px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.rem-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-top: 1px solid var(--border); font-size: 13.5px; }
.rem-row .n { font-weight: 600; min-width: 120px; }
.rem-row .w { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-note { align-self: center; margin: 10px 0 2px; font-size: 13px; color: var(--muted); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: 999px; padding: 6px 14px; }
.qchip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge.ok { background: var(--files-bg); color: var(--files-text); }
.status-confirmed, .status-booked, .status-rescheduled { background: var(--files-bg); color: var(--files-text); }
.status-voicemail-left, .status-calling, .status-call-back-later { background: var(--warn-bg); color: var(--warn-text); }
.status-no-answer, .status-not-interested { background: var(--none-bg); color: var(--none-text); }

.call-me { margin-top: 18px; width: 100%; max-width: 520px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); text-align: left; }
.call-me-title { font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 8px; }
.call-me-row { display: flex; gap: 8px; }
.call-me-row input { flex: 1; min-width: 0; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); font-size: 14.5px; }
.call-me .hint { margin: 8px 0 0; }

/* Forms: section headings and multi-select */
.flow-section { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.qchip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.qchip.done { border-color: var(--accent); color: var(--accent); font-weight: 650; }
