/* ---------- theme tokens ----------
   Light is the default. Dark applies only when the user picks it
   (html[data-theme="dark"], persisted in localStorage "ask.theme"). */
:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --sidebar: #f3f1ec;
  --surface-2: #f0eee9;
  --surface-3: #e6e3dc;
  --border: #e6e2da;
  --border-strong: #d6d1c7;
  --text: #1d1c1a;
  --text-soft: #3b3935;
  --muted: #7a756c;
  --accent: #4a5bd4;
  --accent-hover: #3c4cc0;
  --accent-soft: rgba(74, 91, 212, 0.10);
  --accent-ink: #ffffff;
  --user-bubble: #efece6;
  --code-bg: #f4f2ed;
  --ok: #2f8a4c;
  --err: #c43c33;
  --err-soft: rgba(196, 60, 51, 0.08);
  --shadow-sm: 0 1px 2px rgba(30, 25, 15, 0.05);
  --shadow-md: 0 2px 6px rgba(30, 25, 15, 0.05), 0 8px 24px rgba(30, 25, 15, 0.06);
  --shadow-lg: 0 12px 40px rgba(30, 25, 15, 0.16);
  --backdrop: rgba(30, 25, 15, 0.28);

  --font: "Inter", -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI",
          Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo,
          Consolas, monospace;
  --radius: 10px;
  --radius-lg: 16px;
  --col: 760px;
  --header-h: 54px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121417;
  --surface: #191c20;
  --sidebar: #16181c;
  --surface-2: #20242a;
  --surface-3: #2a2f37;
  --border: #2a2e35;
  --border-strong: #3a3f48;
  --text: #e6e3dd;
  --text-soft: #cfcbc4;
  --muted: #8d8980;
  --accent: #8293ff;
  --accent-hover: #97a5ff;
  --accent-soft: rgba(130, 147, 255, 0.14);
  --accent-ink: #11131a;
  --user-bubble: #23272e;
  --code-bg: #1d2025;
  --ok: #5cc27e;
  --err: #f0776d;
  --err-soft: rgba(240, 119, 109, 0.10);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --backdrop: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  display: flex;
  overflow: hidden;
  /* Pinned to the viewport rather than height: 100dvh. In an iOS home-screen
     app, 100dvh comes out wrong after a reload (until the app is relaunched),
     pushing the message box down. */
  position: fixed; inset: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px calc(14px + var(--safe-bottom));
  padding-left: calc(12px + var(--safe-left));
  gap: 6px;
  z-index: 30;
  transition: transform 220ms cubic-bezier(.2,.7,.2,1);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 6px 10px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 17px; letter-spacing: -0.2px;
}
.brand-mark { width: 22px; height: 22px; display: block; flex-shrink: 0; }
.auth-card .brand-mark { width: 26px; height: 26px; }
#sidebar-close { display: none; }

.btn-new {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-weight: 500; box-shadow: var(--shadow-sm);
}
.btn-new span { font-size: 17px; line-height: 1; color: var(--accent); }
.btn-new:hover { border-color: var(--border-strong); background: var(--surface); }

.list-label {
  font-size: 11.5px; font-weight: 500; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.6px;
  padding: 14px 8px 4px;
}
#conv-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 1px;
  margin: 0 -4px; padding: 0 4px;
  scrollbar-width: thin;
}
.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px 7px 10px; border-radius: 8px;
  cursor: pointer; color: var(--text-soft);
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}
.conv-item:hover { background: var(--surface-2); color: var(--text); }
.conv-item.active { background: var(--surface-3); color: var(--text); }
.conv-item .title {
  flex: 1; overflow: hidden; text-overflow: ellipsis;
  font-size: 13.5px;
}
.conv-item .del {
  opacity: 0; transition: opacity 0.12s, color 0.12s;
  background: transparent; border: 0; color: var(--muted);
  font-size: 16px; line-height: 1; padding: 2px 5px;
}
.conv-item:hover .del, .conv-item.active .del { opacity: 1; }
.conv-item .del:hover { color: var(--err); background: transparent; }
.sidebar-footer {
  padding: 10px 8px 0; border-top: 1px solid var(--border);
  font-size: 12.5px;
}
.sidebar-footer a { color: var(--muted); text-decoration: none; }
.sidebar-footer a:hover { color: var(--text); }
.me-wrap { position: relative; display: flex; align-items: center; gap: 2px; }
#settings-gear { flex-shrink: 0; margin-right: -6px; }
.sidebar-footer .me {
  display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; text-align: left; font: inherit;
  border: 0; background: transparent; padding: 6px 8px; margin-left: -8px; border-radius: 9px; color: var(--text);
}
.sidebar-footer .me:hover, .sidebar-footer .me[aria-expanded="true"] { background: var(--surface-2); }
.me-chev { color: var(--muted); flex-shrink: 0; }
.me-menu {
  position: absolute; left: -8px; right: -8px; bottom: calc(100% + 6px); z-index: 40;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 5px; display: flex; flex-direction: column; gap: 1px;
}
.me-menu[hidden] { display: none; }
@media (min-width: 721px) { .me-menu .theme-menu { display: none; } }
.me-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; font-size: 14px;
  border: 0; background: transparent; color: var(--text); padding: 9px 10px; border-radius: 8px;
}
.me-menu button svg { color: var(--muted); flex-shrink: 0; }
.me-menu button:hover, .me-menu button:focus-visible { background: var(--surface-2); outline: none; }
.me-avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
}
.me-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; color: var(--text); }
.link-btn {
  background: transparent; border: 0; padding: 4px 6px; color: var(--muted);
  font-size: 12.5px; border-radius: 6px;
}
.link-btn:hover { color: var(--text); background: var(--surface-2); }

/* ---------- main ---------- */
#main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0;
  padding-right: var(--safe-right);
}
#header {
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; min-height: var(--header-h);
  padding-top: calc(8px + var(--safe-top));
  flex-shrink: 0;
}
.conv-title {
  flex: 1; min-width: 0; font-weight: 500; font-size: 14.5px; color: var(--text-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-title.renamable { cursor: text; border-radius: 6px; }
.conv-title.renamable:hover { color: var(--text); }
.title-input {
  width: 100%; font: inherit; font-weight: 500; color: var(--text); background: var(--surface);
  border: 1px solid var(--accent); border-radius: 7px; padding: 3px 7px; outline: none;
}
.conv-title:has(.title-input) { display: flex; align-items: center; gap: 6px; overflow: visible; }
.title-input { flex: 1; min-width: 0; }
.title-suggest {
  display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0; font: inherit; font-size: 12.5px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--accent);
  border-radius: 999px; padding: 4px 10px;
}
.title-suggest.busy { opacity: 0.6; }
.title-undo { color: var(--text-soft); padding: 5px 7px; }
.title-undo[hidden] { display: none; }
.title-suggest.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 720px) { .title-suggest span { display: none; } .title-suggest { padding: 5px 7px; } }
.conv-item .ren { display: inline-flex; padding: 3px 4px; }
.cs-storage { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.cs-storage[hidden] { display: none; }
.cs-storage > span { font-size: 13px; font-weight: 500; }
.cs-storage-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.cs-storage-options button { border: 1px solid var(--border); background: var(--surface); border-radius: 9px;
  padding: 8px 4px; font: inherit; font-size: 13px; color: var(--text-soft); }
.cs-storage-options button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.cs-storage .note { margin: 0; }
.controls { display: flex; align-items: center; gap: 2px; }

/* ---------- form controls ---------- */
select, button, input[type="text"], textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 7px 10px;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}
select:focus, textarea:focus, input:focus { outline: none; border-color: var(--accent); }
button { cursor: pointer; }
.btn-danger {
  background: transparent; border-color: var(--border-strong); color: var(--err);
}
.btn-danger:hover { background: var(--err-soft); border-color: var(--err); }

.icon-btn {
  background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 7px;
  border-radius: 8px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; min-height: 34px;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* theme toggle shows the icon of the mode you'd switch TO */
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }

/* hamburger */
.nav-toggle { display: none; flex-direction: column; gap: 3.5px; padding: 9px; }
.nav-toggle span {
  display: block; width: 16px; height: 1.6px;
  background: currentColor; border-radius: 2px;
}

/* ---------- messages ---------- */
#messages {
  flex: 1; overflow-y: auto;
  padding: 8px 0 24px;
  display: flex; flex-direction: column;
  scrollbar-gutter: stable;
}
.msg {
  width: 100%; max-width: var(--col);
  margin: 0 auto; padding: 6px 24px;
  display: flex; flex-direction: column;
  animation: rise 220ms cubic-bezier(.2,.7,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

/* user: right-aligned bubble */
.msg.user { align-items: flex-end; }
.msg.user .body {
  background: var(--user-bubble);
  padding: 9px 15px; border-radius: 18px 18px 6px 18px;
  max-width: min(85%, 600px);
  white-space: pre-wrap;
}

/* assistant: open text, model label above */
.msg.assistant { padding-top: 12px; }
.msg-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  margin-bottom: 4px;
}
.msg-head .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--model-color, var(--accent));
}
.msg[data-model="haiku"] { --model-color: #3aa37a; }
.msg[data-model="sonnet"] { --model-color: var(--accent); }
.msg[data-model="opus"] { --model-color: #b0623f; }

.msg .body {
  min-width: 0;
  overflow-wrap: anywhere;
}
.msg.assistant .body { color: var(--text); }
.msg .meta {
  font-size: 11.5px; color: var(--muted);
  margin-top: 6px; font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity 150ms ease;
}
.msg:hover .meta, .msg:last-child .meta { opacity: 1; }
.msg.error .body {
  color: var(--err); background: var(--err-soft);
  padding: 9px 14px; border-radius: var(--radius);
}
.msg.pending .body:empty::before {
  content: ""; display: inline-block;
  width: 36px; height: 10px;
  background:
    radial-gradient(circle, var(--muted) 3px, transparent 3.5px) 0 50% / 12px 10px repeat-x;
  animation: pulse 1.6s ease-in-out infinite;
}
.msg.pending .body:not(:empty)::after {
  content: ""; display: inline-block;
  width: 7px; height: 1em; vertical-align: -0.15em;
  background: var(--model-color, var(--accent)); border-radius: 2px;
  margin-left: 3px;
  animation: breathe 1.6s ease-in-out infinite;
}
/* Calm, slow motion only: a hard on/off blink at <1s reads as a strobe
   during long waits. */
@keyframes breathe { 50% { opacity: 0.25; } }
@keyframes pulse { 50% { opacity: 0.3; } }

/* model-switch divider */
.switch-note {
  max-width: var(--col); width: 100%; margin: 6px auto 0; padding: 0 24px;
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px; color: var(--muted);
}
.switch-note::before, .switch-note::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* assistant rich content */
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body p { margin: 0 0 0.75em; }
.msg .body h1, .msg .body h2, .msg .body h3, .msg .body h4 {
  margin: 1.1em 0 0.45em; line-height: 1.3; font-weight: 600;
  letter-spacing: -0.2px;
}
.msg .body h1 { font-size: 1.3em; }
.msg .body h2 { font-size: 1.16em; }
.msg .body h3, .msg .body h4 { font-size: 1.02em; }
.msg .body ul, .msg .body ol { margin: 0 0 0.75em; padding-left: 1.4em; }
.msg .body li { margin: 0.2em 0; }
.msg .body li::marker { color: var(--muted); }
.msg .body blockquote {
  margin: 0 0 0.75em; padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong); color: var(--text-soft);
}
.msg .body hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.msg .body strong { font-weight: 600; }
.msg .body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.msg .body code {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px;
  font-family: var(--mono); font-size: 0.86em;
}
.codeblock {
  position: relative; margin: 0.6em 0 0.9em;
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.codeblock-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 4px 12px; border-bottom: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted); font-family: var(--mono);
}
.copy-btn {
  background: transparent; border: 0; color: var(--muted);
  font: 500 11.5px var(--font); padding: 3px 8px; border-radius: 6px;
}
.copy-btn:hover { background: var(--surface-3); color: var(--text); }
.codeblock pre {
  margin: 0; padding: 12px 14px; overflow-x: auto;
  font-family: var(--mono); font-size: 13px; line-height: 1.55;
  tab-size: 4;
}
/* Must out-rank `.msg .body code` (inline code), or every line gets a chip. */
.msg .body .codeblock pre code {
  background: transparent; border: 0; border-radius: 0; padding: 0;
  font-size: inherit;
}

.cb-actions { display: flex; gap: 2px; }
.cb-toggle, .cb-expand {
  background: transparent; border: 0; color: var(--muted);
  font: 500 11.5px var(--font); padding: 3px 8px; border-radius: 6px;
}
.cb-toggle:hover, .cb-expand:hover { background: var(--surface-3); color: var(--text); }
.cb-toggle { color: var(--accent); }

/* live previews (html / svg / mermaid / react) */
.cb-preview { background: #fff; }
.cb-preview iframe {
  display: block; width: 100%; height: 160px; border: 0;
  background: #fff; color-scheme: light;
}
.codeblock[data-view="preview"] pre { display: none; }
.codeblock[data-view="code"] .cb-preview { display: none; }
.codeblock[data-view="code"] .cb-expand { display: none; }

.artifact-modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: var(--bg);
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.artifact-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 8px 16px; border-bottom: 1px solid var(--border);
  font: 500 12.5px var(--mono); color: var(--muted);
}
.artifact-modal iframe { flex: 1; width: 100%; border: 0; background: #fff; color-scheme: light; }

/* tables, images, task lists */
.msg .body table {
  display: block; max-width: 100%; overflow-x: auto;
  border-collapse: collapse; margin: 0.4em 0 0.9em;
  font-size: 0.94em; font-variant-numeric: tabular-nums;
}
.msg .body th, .msg .body td {
  border: 1px solid var(--border); padding: 6px 11px; text-align: left; vertical-align: top;
}
.msg .body th { background: var(--surface-2); font-weight: 600; }
.msg .body tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.msg .body img { max-width: 100%; height: auto; border-radius: 8px; }
.msg .body li > input[type="checkbox"] { margin: 0 6px 0 0; vertical-align: -1px; }
.msg .body ul:has(> li > input[type="checkbox"]) { list-style: none; padding-left: 0.4em; }
.msg .body h5, .msg .body h6 { font-size: 0.95em; margin: 1em 0 0.4em; font-weight: 600; }
.msg .body del { color: var(--muted); }
.msg .body p.plain { white-space: pre-wrap; }

.msg .body .img-blocked {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0;
  padding: 7px 12px; font-size: 12.5px; color: var(--muted);
  background: transparent; border: 1px dashed var(--border-strong); border-radius: 8px;
}
.msg .body .img-blocked u { color: var(--accent); text-decoration: none; font-weight: 500; }
.msg .body .img-blocked:hover { border-color: var(--accent); color: var(--text-soft); }

/* math */
.msg .body .math-block { margin: 0.6em 0 0.9em; overflow-x: auto; overflow-y: hidden; }
.msg .body .katex { font-size: 1.06em; }

/* syntax highlighting (highlight.js classes, themed by tokens below) */
:root {
  --hl-kw: #8a3fb5; --hl-str: #2f7a3e; --hl-num: #b05a14; --hl-com: #8a857c;
  --hl-fn: #2a5bc4; --hl-type: #a3651a; --hl-tag: #b8392f; --hl-attr: #8a5a12;
}
:root[data-theme="dark"] {
  --hl-kw: #c69bf5; --hl-str: #9fd38a; --hl-num: #f0a868; --hl-com: #7f7b73;
  --hl-fn: #82aaff; --hl-type: #e6c07b; --hl-tag: #f0776d; --hl-attr: #e5b567;
}
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-meta .hljs-keyword { color: var(--hl-kw); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: var(--hl-str); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: var(--hl-num); }
.hljs-comment, .hljs-quote { color: var(--hl-com); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--hl-fn); }
.hljs-type, .hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: var(--hl-type); }
.hljs-tag, .hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-deletion { color: var(--hl-tag); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-property, .hljs-params { color: var(--hl-attr); }
.hljs-meta { color: var(--hl-com); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }

/* ---------- composer ---------- */
.composer-wrap {
  flex-shrink: 0;
  padding: 0 16px calc(16px + var(--safe-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
}
.composer {
  max-width: calc(var(--col) - 32px); margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 10px 10px 8px 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-soft); }
#input {
  display: block; width: 100%;
  resize: none; border: 0; background: transparent;
  padding: 4px 2px; min-height: 28px; max-height: 240px;
  font: inherit; line-height: 1.55; color: var(--text);
}
#input:focus { outline: none; }
#input::placeholder { color: var(--muted); }
.composer-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-top: 6px;
}

/* segmented model picker */
.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border-radius: 9px;
}
.seg button {
  border: 0; background: transparent; color: var(--muted);
  padding: 4px 11px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.seg button .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--model-color); opacity: 0.55; }
.seg button[data-model="haiku"] { --model-color: #3aa37a; }
.seg button[data-model="sonnet"] { --model-color: var(--accent); }
.seg button[data-model="opus"] { --model-color: #b0623f; }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm);
}
:root[data-theme="dark"] .seg button[aria-checked="true"] { background: var(--surface-3); }
.seg button[aria-checked="true"] .dot { opacity: 1; }

.btn-send {
  width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 0;
  background: var(--accent); color: var(--accent-ink);
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- settings panel ---------- */
#settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 360px;
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 20px calc(20px + var(--safe-right)) calc(20px + var(--safe-bottom)) 20px;
  padding-top: calc(20px + var(--safe-top));
  display: flex; flex-direction: column; gap: 18px;
  z-index: 40; box-shadow: var(--shadow-lg);
  transform: translateX(0);
  transition: transform 220ms cubic-bezier(.2,.7,.2,1);
}
#settings-panel { overflow-y: auto; }
.panel-section { display: flex; flex-direction: column; gap: 10px; padding-top: 16px; border-top: 1px solid var(--border); }
.panel-section[hidden] { display: none; }
.panel-section h4 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.row-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.row-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13.5px; }
.row-list .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-list .sub { font-size: 12px; color: var(--muted); }
.row-list .link-btn.danger { color: var(--err); }
.invite-out { display: flex; gap: 6px; }
.invite-out[hidden] { display: none; }
.invite-out input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; }
#settings-panel[hidden] {
  display: flex; transform: translateX(105%); pointer-events: none; box-shadow: none;
}
.panel-head { display: flex; align-items: center; }
.panel-head h3 { flex: 1; margin: 0; font-size: 16px; font-weight: 600; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-soft); }
label.toggle { flex-direction: row; align-items: center; gap: 9px; }
label.toggle input { margin: 0; accent-color: var(--accent); width: 16px; height: 16px; }
label textarea { color: var(--text); font-weight: 400; resize: vertical; }
label select { font-weight: 400; }
.note { font-size: 12.5px; color: var(--muted); margin: 0; line-height: 1.55; }

/* ---------- backdrop (mobile drawers) ---------- */
#backdrop {
  position: fixed; inset: 0;
  background: var(--backdrop);
  z-index: 25;
  opacity: 0; transition: opacity 200ms ease;
}
#backdrop.show { opacity: 1; }
#backdrop[hidden] { display: none; }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: calc(110px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  border-radius: 999px;
  padding: 8px 16px; font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 50; max-width: calc(100% - 32px);
}
#toast.error { background: var(--err); color: #fff; }
.update-bar {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(10px + env(safe-area-inset-top, 0px)); max-width: calc(100vw - 24px); box-sizing: border-box;
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 13px; box-shadow: var(--shadow-lg); white-space: nowrap;
}
.update-bar span { overflow: hidden; text-overflow: ellipsis; }
.update-bar button { border: 0; border-radius: 999px; padding: 5px 12px; font: inherit; font-weight: 600;
  background: var(--accent); color: var(--accent-ink); }
.update-bar .update-x { background: transparent; color: inherit; opacity: 0.7; padding: 2px 8px; font-size: 16px; }

/* ---------- empty state ---------- */
.empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px; padding: 40px 24px 24px;
  text-align: center;
}
.empty h2 {
  margin: 0; font-weight: 600; font-size: 28px; letter-spacing: -0.6px;
}
.empty p { margin: 0; color: var(--muted); max-width: 440px; font-size: 14px; }

/* ---------- responsive: tablet ---------- */
@media (max-width: 900px) {
  #sidebar { width: 240px; }
  #settings-panel { width: 320px; }
  .msg, .switch-note { padding-left: 18px; padding-right: 18px; }
}

/* ---------- responsive: mobile ---------- */
@media (max-width: 720px) {
  body { font-size: 15px; }
  #sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(82vw, 320px);
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open #sidebar { transform: translateX(0); }
  /* The drawer's head mirrors the header, with × exactly where the menu
     button was: the same tap opens and closes it. */
  #sidebar { padding-top: 0; }
  .sidebar-head {
    justify-content: flex-start; gap: 4px; min-height: var(--header-h);
    margin: 0 -12px 4px calc(-12px - var(--safe-left));
    padding: calc(6px + var(--safe-top)) 8px 6px calc(8px + var(--safe-left));
  }
  #sidebar-close { display: inline-flex; order: -1; }
  .nav-toggle { display: inline-flex; }
  /* Room for the title: storage moves to Chat settings, theme to your name's menu. */
  #theme-btn, .storage-wrap { display: none; }

  #header { padding: 6px 8px; padding-top: calc(6px + var(--safe-top)); gap: 4px; }

  #settings-panel { width: min(92vw, 380px); }

  .msg, .switch-note { padding-left: 14px; padding-right: 14px; }
  .msg.user .body { max-width: 88%; }

  .composer-wrap { padding: 0 8px calc(16px + var(--safe-bottom)); }
  .composer { padding: 8px 8px 6px 12px; }
  .seg button { padding: 4px 9px; }
  #toast { bottom: calc(120px + var(--safe-bottom)); }
}

/* ---------- search ---------- */
.search-box {
  display: flex; flex-direction: row; align-items: center; gap: 7px;
  margin: 10px 0 2px; padding: 0 8px; min-height: 36px;
  background: var(--surface-2); border: 1px solid transparent; border-radius: 9px;
  color: var(--muted); font-weight: 400;
}
.search-box:focus-within { border-color: var(--accent); background: var(--surface); }
.search-box input {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 6px 0;
  font-size: 13.5px; color: var(--text); outline: none;
}
.search-box input::-webkit-search-cancel-button { cursor: pointer; }
.search-box kbd {
  font: 500 10.5px var(--font); color: var(--muted); border: 1px solid var(--border-strong);
  border-radius: 5px; padding: 1px 5px; white-space: nowrap;
}
.search-box:focus-within kbd { display: none; }
@media (max-width: 720px) { .search-box kbd { display: none; } }
.search-hit {
  display: flex; flex-direction: column; align-items: stretch; gap: 3px; width: 100%;
  text-align: left; border: 0; border-radius: 8px; padding: 8px 10px; background: transparent;
  color: var(--text-soft);
}
.search-hit:hover, .search-hit:focus-visible { background: var(--surface-2); color: var(--text); }
.hit-title { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 500; color: var(--text); }
.hit-title .storage-icon { margin-left: auto; }
.hit-snippet { font-size: 12.5px; color: var(--muted); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-hit mark { background: var(--accent-soft); color: var(--text); border-radius: 3px; padding: 0 1px; }
.msg.flash .body { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 3px transparent; } }

/* ---------- thinking ---------- */
.thinking-block { margin: 2px 0 8px; font-size: 13px; color: var(--muted); max-width: 100%; }
.thinking-block summary { cursor: pointer; width: fit-content; padding: 2px 0; }
.thinking-block summary.no-detail { cursor: default; list-style: none; }
.thinking-block summary.no-detail::-webkit-details-marker { display: none; }
.thinking-block.live summary { animation: breathe 1.6s ease-in-out infinite; }
.thinking-text {
  margin: 6px 0 4px; padding: 2px 0 2px 12px; border-left: 2px solid var(--border-strong);
  white-space: pre-wrap; line-height: 1.55; color: var(--text-soft); font-size: 13px;
}
.thinking-text:empty { display: none; }

/* ---------- retry / edit ---------- */
.turn-actions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity 120ms ease; }
.msg:hover .turn-actions, .msg:focus-within .turn-actions, .msg:last-child .turn-actions { opacity: 1; }
@media (hover: none) { .turn-actions { opacity: 1; } }
.msg.user .turn-actions { justify-content: flex-end; }
.turn-actions button {
  border: 0; background: transparent; color: var(--muted); font-size: 12.5px;
  padding: 4px 8px; border-radius: 6px;
}
.turn-actions button:hover { background: var(--surface-2); color: var(--text); }
.edit-box { width: min(85%, 600px); display: flex; flex-direction: column; gap: 8px; }
.edit-box textarea {
  width: 100%; box-sizing: border-box; resize: none; min-height: 60px; max-height: 300px;
  border: 1px solid var(--accent); border-radius: 14px; padding: 10px 14px; background: var(--surface);
  font: inherit; color: var(--text); box-shadow: 0 0 0 3px var(--accent-soft);
}
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
.edit-actions button { min-height: 34px; padding: 0 14px; border-radius: 9px; }
.edit-actions .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- web search ---------- */
.web-toggle {
  display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 12.5px;
}
.web-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.web-toggle { white-space: nowrap; flex-shrink: 0; }
@media (max-width: 720px) { .web-toggle span { display: none; } .web-toggle { padding: 0 8px; } }
.msg-activity, .web-summary { margin: 2px 0 8px; }
.activity-line { font-size: 12.5px; color: var(--muted); padding: 2px 0; }
.activity-line::before { content: "↳ "; }
.web-summary { font-size: 12.5px; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; }
.web-summary summary { cursor: pointer; }
.web-summary ul { margin: 6px 0 2px; padding-left: 18px; display: flex; flex-direction: column; gap: 3px; }
.web-summary a { color: var(--accent); }
.approval {
  border: 2px solid var(--accent); border-radius: 14px; background: var(--surface);
  padding: 14px 16px; margin: 6px 0 10px; display: flex; flex-direction: column; gap: 10px; max-width: 620px;
}
.approval.allowed, .approval.denied, .approval.expired { border-width: 1px; border-color: var(--border); opacity: 0.85; }
.approval-title { font-weight: 600; font-size: 14px; }
.approval-query, .approval-url {
  font-family: var(--mono); font-size: 13px; background: var(--code-bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; color: var(--text); word-break: break-all;
}
.approval-query:disabled { color: var(--text-soft); }
.approval-note { margin: 0; font-size: 12.5px; color: var(--muted); }
.approval-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.approval-actions button { min-height: 38px; padding: 0 16px; border-radius: 10px; }
.approval-actions .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.approval-state { font-size: 12.5px; font-weight: 500; color: var(--text-soft); }
.approval-actions .approval-all { margin-left: auto; border-style: dashed; color: var(--text-soft); }
.web-toggle.auto { border-style: dashed; }

/* ---------- usage ---------- */
.usage-wrap { position: relative; }
.usage-chip {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}
.usage-chip[hidden] { display: none; }
.usage-chip .u-5h { display: inline-flex; align-items: center; gap: 5px; }
.u-bar { width: 28px; height: 5px; border-radius: 3px; background: var(--surface-3); display: inline-flex; overflow: hidden; }
.u-bar span { background: var(--accent); border-radius: 3px; }
.usage-chip .u-chat { color: var(--text); font-weight: 500; }
.usage-chip[data-level="warn"] { border-color: #e2b44d; background: #fdf6e3; color: #7a5300; }
.usage-chip[data-level="warn"] .u-bar span { background: #d49a1c; }
.usage-chip[data-level="crit"] { border-color: var(--err); background: var(--err-soft); color: var(--err); }
.usage-chip[data-level="crit"] .u-bar span { background: var(--err); }
:root[data-theme="dark"] .usage-chip[data-level="warn"] { background: #2e2716; color: #f0c86a; border-color: #6b5420; }
.usage-chip, .storage-chip { white-space: nowrap; }
.storage-chip .label-short { display: none; }
@media (max-width: 720px) {
  .usage-chip .u-week, .usage-chip .u-label, .usage-chip .u-bar { display: none; }
  .usage-chip { gap: 7px; padding: 5px 9px; }
  .storage-chip { padding: 5px 9px; }
  .storage-chip .label-full { display: none; }
  .storage-chip .label-short { display: inline; }
}
.usage-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 320px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 14px 16px; display: flex; flex-direction: column; gap: 12px;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.usage-pop[hidden] { display: none; }
/* Phones: the chips sit mid-header, so a menu anchored to one would run off
   the left edge. Span the screen under the header instead. */
@media (max-width: 720px) {
  .usage-wrap .usage-pop, .storage-wrap .storage-menu {
    position: fixed; left: 12px; right: 12px; top: var(--drop-top, 60px);
    width: auto; max-width: none; max-height: calc(100dvh - var(--drop-top, 60px) - 12px); overflow-y: auto;
  }
}
.u-section { display: flex; flex-direction: column; gap: 6px; }
.u-section + .u-section { border-top: 1px solid var(--border); padding-top: 12px; }
.u-title { font-weight: 600; }
.u-row { display: flex; justify-content: space-between; gap: 12px; }
.u-row.strong span:last-child { font-weight: 500; }
.u-row.muted { color: var(--muted); }
.u-track { height: 8px; border-radius: 4px; background: var(--surface-3); display: flex; overflow: hidden; margin-bottom: 4px; }
.u-track span { background: var(--accent); border-radius: 4px; }
.u-track[data-level="warn"] span { background: #d49a1c; }
.u-track[data-level="crit"] span { background: var(--err); }
.u-note { margin: 0; font-size: 12px; color: var(--muted); }
.u-foot { border-top: 1px solid var(--border); padding-top: 10px; }
.usage-summary { display: flex; flex-direction: column; gap: 4px; }
.usage-big { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.usage-sub-h { font-size: 12px; font-weight: 600; color: var(--text-soft); margin-top: 8px; }

/* ---------- attachments ---------- */
.composer-bar { justify-content: flex-start; }
.composer-bar .btn-send { margin-left: auto; }
.attach-btn { color: var(--muted); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 8px; }
.attachments[hidden] { display: none; }
.attach-chip, .file-chip {
  display: flex; align-items: center; gap: 9px; max-width: 260px;
  padding: 6px 8px 6px 6px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); text-decoration: none;
}
.attach-chip.uploading { opacity: 0.75; }
.attach-chip.error { border-color: var(--err); background: var(--err-soft); }
.attach-chip.error .attach-sub { color: var(--err); white-space: normal; }
.attach-chip img, .file-chip.image img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; display: block; }
.file-badge {
  width: 32px; height: 36px; flex-shrink: 0; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font: 600 10px var(--font); letter-spacing: 0.3px;
  background: var(--surface-3); color: var(--text-soft);
}
.file-badge.pdf { background: #fbe9e6; color: #a2352b; }
.file-badge.text { background: #e9f4ee; color: #1f6b3a; }
:root[data-theme="dark"] .file-badge.pdf { background: #3a2220; color: #f2a59c; }
:root[data-theme="dark"] .file-badge.text { background: #1d3226; color: #9fd38a; }
.attach-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.attach-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-remove {
  margin-left: auto; flex-shrink: 0; width: 24px; height: 24px; padding: 0;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 16px; line-height: 1;
}
.attach-remove:hover { background: var(--surface-3); color: var(--text); }

.msg-files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-bottom: 6px; max-width: min(85%, 600px); }
.file-chip { background: var(--surface); }
.file-chip:hover { border-color: var(--border-strong); }
.file-chip.image { padding: 0; overflow: hidden; border-radius: 12px; max-width: none; }
.file-chip.image img { width: auto; height: auto; max-width: 240px; max-height: 200px; border-radius: 0; }

#main.dragging .composer { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#main.dragging #messages { outline: 2px dashed var(--accent); outline-offset: -10px; border-radius: 16px; }

/* ---------- storage modes ---------- */
.storage-icon { display: inline-flex; flex-shrink: 0; color: var(--muted); }
.storage-icon.device { color: #b0623f; }
:root[data-theme="dark"] .storage-icon.device { color: #e0956f; }
.conv-item .storage-icon { margin-left: auto; }

.storage-wrap { position: relative; }
.storage-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-soft);
}
.storage-chip[hidden] { display: none; }
.storage-chip[data-storage="device"] { border-color: #e8c3a8; color: #8a4b1c; background: #fdf3ea; }
.storage-chip[data-storage="temporary"] { border-style: dashed; }
:root[data-theme="dark"] .storage-chip[data-storage="device"] { background: #2b211b; color: #e9b48f; border-color: #5a3b28; }
.storage-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 290px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.storage-menu[hidden] { display: none; }
.storage-menu button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left;
  border: 0; border-radius: 8px; padding: 9px 11px; background: transparent;
}
.storage-menu button:hover { background: var(--surface-2); }
.storage-menu button[aria-checked="true"] { background: var(--accent-soft); }
.storage-menu strong { font-weight: 600; font-size: 13.5px; }
.storage-menu span { font-size: 12px; color: var(--muted); }

.storage-picker { border: 0; padding: 0; margin: 26px auto 0; width: 100%; max-width: 560px; }
.storage-picker legend { font-size: 12.5px; font-weight: 600; color: var(--text-soft); margin: 0 auto 10px; padding: 0; }
.storage-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.storage-options button {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; border-radius: 10px; font-size: 13px;
}
.storage-options button[aria-checked="true"] {
  border-color: var(--accent); background: var(--accent-soft); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--accent);
}
/* Out-ranks the generic `.empty p` (max-width 440px, margin 0), which
   otherwise pins the note to the left of the wider picker. */
.empty .storage-note { margin: 10px 0 0; max-width: none; font-size: 12.5px; color: var(--muted); }
.empty .storage-note.device { text-align: center; color: #8a4b1c; background: #fdf3ea; border: 1px solid #f0d2bb; padding: 9px 12px; border-radius: 10px; }
:root[data-theme="dark"] .empty .storage-note.device { background: #2b211b; color: #e9b48f; border-color: #5a3b28; }
@media (max-width: 520px) { .storage-options { grid-template-columns: 1fr; } }

dialog.sheet {
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); padding: 22px; width: min(92vw, 440px);
  box-shadow: var(--shadow-lg);
}
dialog.sheet::backdrop { background: var(--backdrop); }
dialog.sheet form { display: flex; flex-direction: column; gap: 14px; }
dialog.sheet h3 { margin: 0; font-size: 17px; font-weight: 600; }
dialog.sheet .warn {
  background: #fdf3ea; border: 1px solid #f0d2bb; color: #6e3a12;
  border-radius: 10px; padding: 4px 14px; font-size: 13px;
}
:root[data-theme="dark"] dialog.sheet .warn { background: #2b211b; color: #e9b48f; border-color: #5a3b28; }
dialog.sheet .warn p { margin: 8px 0; }
dialog.sheet label.toggle { font-weight: 400; color: var(--text); align-items: flex-start; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sheet-actions button { min-height: 40px; padding: 0 16px; }
.sheet-actions .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sheet-actions .primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- projects ---------- */
.list-label-row { display: flex; align-items: center; justify-content: space-between; }
.list-label-row .link-btn { font-size: 11.5px; padding: 2px 6px; text-transform: none; letter-spacing: 0; }
#project-list { display: flex; flex-direction: column; gap: 1px; margin: 0 -4px 6px; padding: 0 4px;
  max-height: 45vh; overflow-y: auto; scrollbar-width: thin; flex-shrink: 0; }
.project-item {
  display: flex; align-items: center; gap: 6px; width: 100%; box-sizing: border-box; cursor: pointer;
  padding: 6px 10px 6px 2px; border-radius: 8px; color: var(--text-soft); font-size: 14px;
}
.project-item .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item:hover { background: var(--surface-2); color: var(--text); }
.project-item.active { background: var(--surface-3); color: var(--text); }
.project-item .storage-icon { margin-left: 0; }
.project-item .unread-dot { margin-left: 0; }
.folder-chev { border: 0; background: transparent; color: var(--muted); padding: 3px; border-radius: 5px;
  display: inline-flex; flex-shrink: 0; transition: transform 120ms ease; }
.folder-chev.open { transform: rotate(90deg); }
.folder-chev:hover:not(:disabled) { color: var(--text); background: var(--surface-3); }
.folder-chev:disabled { cursor: default; opacity: 0.6; }
.folder-chats { display: flex; flex-direction: column; gap: 1px; margin: 1px 0 4px 21px;
  padding-left: 6px; border-left: 1px solid var(--border); }
.folder-chat { width: 100%; box-sizing: border-box; border: 0; background: transparent; text-align: left;
  padding: 5px 8px; font: inherit; }
.folder-chat .title { font-size: 13px; }
.folder-empty { font-size: 12.5px; color: var(--muted); padding: 4px 8px; }
.folder-all { align-self: flex-start; font-size: 12.5px; padding: 3px 8px; }
.shared-badge {
  font-size: 10.5px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: 1px 6px;
}
.storage-icon.project { color: var(--accent); }
.unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-left: auto; }
.unread-dot + .storage-icon { margin-left: 6px; }
.project-chip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--accent);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px; white-space: nowrap; max-width: 30%;
  overflow: hidden; text-overflow: ellipsis; flex-shrink: 1;
}
.project-chip[hidden] { display: none; }
.project-chip::after { content: " ›"; color: var(--muted); }
body.project-view .composer-wrap { display: none; }
.msg-author { font-size: 12px; color: var(--muted); margin: 0 4px 3px; }
.project-note { margin: 18px 0 0; font-size: 13px; color: var(--muted); max-width: 520px; }
.project-page { width: 100%; max-width: 1040px; margin: 0 auto; padding: 28px 24px 60px; box-sizing: border-box;
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.pp-main, .pp-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.pp-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.pp-head h1 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -0.3px; }
.pp-ask { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 10px 10px 10px 14px; box-shadow: var(--shadow-sm); }
.pp-ask:focus-within { border-color: var(--accent); }
.pp-ask textarea { flex: 1; border: 0; background: transparent; resize: none; font: inherit; font-size: 15px;
  outline: none; padding: 4px 0; color: var(--text); min-height: 44px; }
.pp-ask-note { margin: -6px 4px 4px; }
.pp-chats { display: flex; flex-direction: column; }
.pp-chats h2 { margin: 6px 2px 6px; font-size: 13px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.pp-chat { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; border-top: 1px solid var(--border);
  background: transparent; padding: 12px 6px; border-radius: 0; color: var(--text); font: inherit; }
.pp-chat .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }
.pp-chat .unread-dot { margin-left: 0; }
.pp-chat:hover { background: var(--surface-2); }
.pp-chat .sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.pp-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px; }
.pp-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pp-card-head .link-btn { font-size: 13px; padding: 2px 6px; }
.pp-card h2 { margin: 0; font-size: 14px; font-weight: 600; }
.pp-card textarea { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; font-size: 14px; }
.pp-card button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pp-card button:not(.link-btn):not(.pp-x) { min-height: 34px; padding: 0 14px; border-radius: 9px; }
.pp-card .row-list li { gap: 8px; }
.pp-preview { margin: 0; font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.pp-editor { display: flex; flex-direction: column; gap: 8px; }
.pp-editor[hidden] { display: none; }
.pp-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pp-members { display: flex; flex-wrap: wrap; gap: 6px; }
.pp-member { display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 13px; }
.pp-x { border: 0; background: transparent; color: var(--muted); padding: 0 4px; font-size: 15px; line-height: 1; }
.pp-x:hover { color: var(--err); }
.pp-delete { align-self: flex-start; font-size: 13px; }
.pp-card > .link-btn { align-self: flex-start; padding-left: 0; }
.pp-card .note[hidden] { display: none; }
@media (max-width: 900px) {
  .project-page { grid-template-columns: minmax(0, 1fr); gap: 22px; }
}
@media (max-width: 720px) { .project-page { padding: 16px 14px 48px; } .project-chip { max-width: 40%; } }

/* ---------- settings modal ---------- */
.settings-page {
  position: fixed; inset: 0; z-index: 50; background: var(--backdrop);
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  animation: sp-fade 140ms ease;
}
.settings-page[hidden] { display: none; }
@keyframes sp-fade { from { opacity: 0; } }
.sp-dialog {
  background: var(--bg); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: min(980px, 100%); height: min(780px, 100%); display: flex; flex-direction: column; overflow: hidden;
}
.sp-top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px 14px 24px; border-bottom: 1px solid var(--border); }
.sp-top h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.2px; }
.sp-close { font-size: 22px; line-height: 1; width: 36px; height: 36px; padding: 0; }
.sp-body { flex: 1; min-height: 0; display: flex; gap: 24px; padding: 0 0 0 14px; }
.sp-nav { flex: 0 0 196px; padding-top: 14px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sp-nav a { padding: 8px 12px; border-radius: 8px; color: var(--text-soft); text-decoration: none; font-size: 14px; }
.sp-nav a:hover { background: var(--surface-2); color: var(--text); }
.sp-nav a[hidden] { display: none; }
.sp-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto; padding: 14px 20px 28px 4px; box-sizing: border-box; }
.sp-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; scroll-margin-top: 16px;
}
.sp-section[hidden] { display: none; }
.sp-section.danger { border-color: color-mix(in srgb, var(--err) 35%, var(--border)); }
.sp-section h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.sp-section h3 { margin: 8px 0 2px; font-size: 13.5px; font-weight: 600; color: var(--text-soft); }
.sp-section > label:not(.sp-field):not(.sp-check) { font-size: 13px; font-weight: 500; color: var(--text-soft); }
.sp-section textarea { width: 100%; box-sizing: border-box; resize: vertical; font: inherit; font-size: 14px; }
.sp-sub { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.sp-sub + .sp-sub { border-top: 1px solid var(--border); padding-top: 14px; }
.sp-field { display: flex; flex-direction: row; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  font-size: 14px; font-weight: 400; color: var(--text); padding: 4px 0; }
.sp-field select { min-height: 36px; }
.sp-check { display: flex; flex-direction: row; align-items: flex-start; gap: 9px; font-size: 14px; font-weight: 400; color: var(--text); }
.sp-check input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }
.sp-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sp-row .primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); min-height: 36px; padding: 0 16px; }
.sp-status { font-size: 12.5px; color: var(--ok); }
.sp-status.error { color: var(--err); }
.sp-table-wrap { overflow-x: auto; max-width: 100%; }
.sp-section, .sp-sub { min-width: 0; }
.sp-table { border-collapse: collapse; width: 100%; min-width: 560px; font-size: 13px; }
.sp-table th, .sp-table td { border-top: 1px solid var(--border); padding: 8px 10px; text-align: left; vertical-align: top; }
.sp-table th { background: var(--surface-2); font-weight: 600; border-top: 0; }
.sp-table td:first-child { font-weight: 500; }
@media (max-width: 720px) {
  .settings-page { padding: 0; }
  .sp-dialog { width: 100%; height: 100%; border-radius: 0; border: 0; }
  .sp-top { padding-top: calc(12px + var(--safe-top)); }
  .sp-body { flex-direction: column; gap: 12px; align-items: stretch; padding: 0 12px; overflow-y: auto; }
  .sp-content { overflow: visible; padding: 0 0 calc(24px + var(--safe-bottom)); }
  .sp-nav { position: static; flex: none; flex-direction: row; overflow-x: auto; width: 100%; gap: 6px; padding: 12px 0 4px; }
  .sp-nav a { white-space: nowrap; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
  .sp-section { padding: 14px; }
}

/* ---------- sign-in / invite page ---------- */
body.auth-page {
  position: static; overflow: auto; height: auto; min-height: 100dvh;
  align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  box-sizing: border-box;
}
.auth-card {
  width: 100%; max-width: 400px; box-sizing: border-box;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  padding: 32px 28px; display: flex; flex-direction: column; gap: 16px;
}
.auth-card .brand { font-size: 18px; }
.auth-card h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.2px; }
.auth-card section { display: flex; flex-direction: column; gap: 14px; }
.auth-card section[hidden] { display: none; }
.auth-sub { margin: 0; color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card form[hidden] { display: none; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.auth-card label[hidden] { display: none; }
.auth-card input[type="text"] {
  min-height: 44px; padding: 0 12px; font: inherit; font-size: 15px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
}
.auth-primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink);
  font: 500 15px var(--font); cursor: pointer;
}
.auth-primary:hover { background: var(--accent-hover); }
.auth-primary:disabled { opacity: 0.6; cursor: progress; }
.auth-foot {
  margin: 0; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--muted);
}
.auth-notes { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-soft); display: flex; flex-direction: column; gap: 6px; }
.auth-error {
  margin: 0; padding: 10px 12px; border-radius: var(--radius);
  background: var(--err-soft); color: var(--err); font-size: 13.5px;
}
.auth-error[hidden] { display: none; }

/* ---------- scrollbars ---------- */
#conv-list::-webkit-scrollbar, #messages::-webkit-scrollbar,
textarea::-webkit-scrollbar, .codeblock pre::-webkit-scrollbar { width: 8px; height: 8px; }
#conv-list::-webkit-scrollbar-thumb, #messages::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb, .codeblock pre::-webkit-scrollbar-thumb {
  background: var(--surface-3); border-radius: 8px;
}
#conv-list::-webkit-scrollbar-track, #messages::-webkit-scrollbar-track { background: transparent; }

/* ---------- reduced motion ---------- */
/* Iteration count matters: a 0.01ms *infinite* animation repaints a
   different random frame every refresh — a strobe, the opposite of
   reduced motion. Run once so loops (typing dots, cursor) sit still. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
