/* Squiggle — notebook paper, ink, and one marker highlight.
   The squiggle line is the signature: it marks streaming, the active session,
   and the thread connector. Everything else stays quiet. */

:root {
  --paper: #eef1f6;
  --sheet: #f8f9fc;
  --ink: #1c2340;
  --ink-soft: #4d5577;
  --rule: #d5dae6;
  --marker: #ffd84d;
  --action: #127c7a;
  --action-ink: #ffffff;
  --danger: #b3261e;
  --user-bubble: #e2e7f2;
  --selected: #f3f5f9;
  --code-bg: #e6e9f1;
  --shadow: 0 1px 0 var(--rule);
  --radius-s: 6px;
  --radius-m: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151a2e; --sheet: #1b2139; --ink: #e6e9f2; --ink-soft: #a3aac4; --rule: #2c3454;
    --action: #4fc1b8; --action-ink: #0d1a1a; --danger: #ff8a80; --user-bubble: #242c4a; --code-bg: #10142a; --selected: #181d33;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #151a2e; --sheet: #1b2139; --ink: #e6e9f2; --ink-soft: #a3aac4; --rule: #2c3454;
  --action: #4fc1b8; --action-ink: #0d1a1a; --danger: #ff8a80; --user-bubble: #242c4a; --code-bg: #10142a; --selected: #181d33;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--action); }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ── Layout ─────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 264px minmax(0, 1fr) auto auto; height: 100dvh; }
.sidebar { border-right: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; background: var(--paper); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.drawer { width: 400px; border-left: 1px solid var(--rule); background: var(--sheet); display: flex; flex-direction: column; min-height: 0; }

.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--rule); min-height: 52px; }
.topbar h1 { font-size: 1rem; font-weight: 600; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.only-mobile { display: none; }

/* ── Sidebar ────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; font-weight: 700; font-size: 1.15rem; letter-spacing: -0.01em; }
.brand svg { width: 34px; height: 18px; }
.new-chat { margin: 4px 12px 10px; }
.session-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.session-list li button {
  display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: var(--radius-s);
  padding: 8px 10px 9px; cursor: pointer; color: var(--ink-soft);
}
.session-list li button .t { display: block; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-list li button .when { font-size: 0.78rem; display: block; }
.session-list li button:hover { background: var(--sheet); }
.session-list li button[aria-current="true"] { background: var(--selected); }
.session-list li button[aria-current="true"]:hover { background: var(--sheet); }
.session-list .archived-group { margin-top: 10px; }
.session-list .archived > summary { cursor: pointer; font-size: 0.78rem; color: var(--ink-soft); padding: 6px 10px; list-style: none; display: flex; align-items: center; gap: 6px; }
.session-list .archived > summary::-webkit-details-marker { display: none; }
.session-list .archived > summary::before { content: '›'; display: inline-block; transition: transform 0.15s; }
.session-list .archived[open] > summary::before { transform: rotate(90deg); }
.session-list .archived ul { list-style: none; margin: 0; padding: 0; }
.session-list .archived .t { color: var(--ink-soft); }
.sidebar-foot { border-top: 1px solid var(--rule); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.side-nav { display: flex; gap: 2px; }
.side-nav button {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 4px 6px;
  background: none; border: 0; border-radius: var(--radius-s); cursor: pointer; color: var(--ink-soft); font-size: 0.74rem; line-height: 1;
}
.side-nav button svg { width: 20px; height: 20px; }
.side-nav button:hover { background: var(--sheet); color: var(--ink); }
.sync-line { font-size: 0.78rem; color: var(--ink-soft); padding: 2px 8px 8px; display: flex; gap: 6px; align-items: center; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--action); }
.sync-dot.busy { background: var(--marker); }
.sync-dot.err { background: var(--danger); }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn { border: 1px solid var(--rule); background: var(--sheet); border-radius: var(--radius-s); padding: 7px 12px; cursor: pointer; }
.btn:hover { border-color: var(--ink-soft); }
.btn.primary { background: var(--action); color: var(--action-ink); border-color: var(--action); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { color: var(--ink); background: var(--sheet); }
.btn[disabled] { opacity: 0.5; cursor: default; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: var(--radius-s); cursor: pointer; color: var(--ink-soft); line-height: 0; }
.icon-btn:hover { background: var(--sheet); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.recording { color: var(--danger, #c0392b); animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .icon-btn.recording { animation: none; } }

/* ── Messages ───────────────────────────────────────────────────────── */
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.messages-inner { max-width: 720px; margin: 0 auto; }
.msg { margin: 0 0 22px; position: relative; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .body { background: var(--user-bubble); padding: 10px 14px; border-radius: var(--radius-m) var(--radius-m) 4px var(--radius-m); max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .body { overflow-wrap: anywhere; }
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body pre { background: var(--code-bg); padding: 12px; border-radius: var(--radius-s); overflow-x: auto; font: 0.86rem/1.5 var(--mono); }
.msg .body code { font-family: var(--mono); font-size: 0.9em; background: var(--code-bg); padding: 1px 4px; border-radius: 4px; }
.msg .body pre code { background: none; padding: 0; }
.msg .body table { border-collapse: collapse; }
.msg .body td, .msg .body th { border: 1px solid var(--rule); padding: 4px 8px; }

.msg-actions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity 0.12s; }
.msg.user .msg-actions { position: absolute; right: 0; bottom: -28px; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions, .msg-actions.pinned { opacity: 1; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.msg-actions .icon-btn svg { width: 16px; height: 16px; }
.msg-actions .icon-btn[aria-pressed="true"], .msg-actions .icon-btn.done { color: var(--action); }
.msg-actions .icon-btn.danger:hover { color: var(--danger); }

.tool-trail { margin: 6px 0 8px; display: flex; flex-direction: column; gap: 2px; font-size: 0.86rem; color: var(--ink-soft); }
.tool-trail .tool { display: flex; gap: 6px; align-items: baseline; }
.tool-trail .tool.fail { color: var(--danger); }
.tool-trail .tool-error { display: block; color: var(--ink-soft); font-size: 0.8rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.tool-trail .tool-result summary { cursor: pointer; font-size: 0.8rem; }
.tool-trail .tool-result pre { max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 0.76rem/1.4 var(--mono); background: var(--code-bg); padding: 6px 8px; border-radius: var(--radius-s); margin: 4px 0; }
.thinking { font-size: 0.86rem; color: var(--ink-soft); margin: 0 0 8px; }
.thinking summary { cursor: pointer; }
.thinking div { white-space: pre-wrap; max-height: 240px; overflow-y: auto; padding: 6px 0 0 12px; border-left: 2px solid var(--rule); }

/* Thread link under a message: a squiggle connects it to its parent. */
.thread-link {
  display: flex; align-items: center; gap: 10px; margin-top: 10px; background: none; border: 0; padding: 0;
  cursor: pointer; color: var(--ink-soft); font-size: 0.88rem; text-align: left; max-width: 100%;
}
.thread-link svg { width: 30px; height: 14px; flex: none; color: var(--action); }
.thread-link .count { color: var(--action); font-weight: 600; white-space: nowrap; }
.thread-link .sum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-link:hover .count { text-decoration: underline; }
.msg.user .thread-link { justify-content: flex-end; margin-left: auto; }

/* Working indicator: the logo squiggle wiggling like a snake (animated WebP mask, coloured by currentColor). */
.squiggle-wait { display: inline-block; width: 46px; height: 16px; color: var(--action); vertical-align: middle; background: currentColor;
  -webkit-mask: url(icons/squiggle.webp) center / contain no-repeat; mask: url(icons/squiggle.webp) center / contain no-repeat; }
@media (prefers-reduced-motion: reduce) { .squiggle-wait { -webkit-mask-image: url(icons/squiggle-still.webp); mask-image: url(icons/squiggle-still.webp); } }
.tool-trail .squiggle-wait { width: 28px; height: 10px; }

.empty { max-width: 520px; margin: 14vh auto 0; text-align: center; color: var(--ink-soft); }
.empty svg { width: 120px; height: 40px; color: var(--ink); }
.empty h2 { color: var(--ink); font-size: 1.5rem; margin: 12px 0 6px; letter-spacing: -0.01em; }
.chat-setup { margin: 16px auto 0; max-width: 440px; text-align: left; border: 1px solid var(--rule); border-radius: 12px; background: var(--sheet); font-size: 0.9rem; }
.chat-setup > summary { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; list-style: none; color: var(--ink); }
.chat-setup > summary::-webkit-details-marker { display: none; }
.chat-setup > summary svg { width: 16px; height: 16px; flex: none; }
.chat-setup > summary .muted { margin-left: auto; }
.chat-setup[open] > summary { border-bottom: 1px solid var(--rule); }
.chat-setup-body { padding: 10px 12px 12px; display: grid; gap: 10px; }
.chat-setup fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.chat-setup legend { font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.chat-setup .choice { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.chat-setup .choice input { margin-top: 3px; }
.chat-setup .choice-label { display: block; color: var(--ink); }
.chat-setup .choice-hint { display: block; color: var(--ink-soft); font-size: 0.82rem; line-height: 1.35; }
.chat-setup .muted { color: var(--ink-soft); margin: 0; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.suggestions button { border: 1px solid var(--rule); background: var(--sheet); border-radius: 999px; padding: 6px 12px; cursor: pointer; color: var(--ink); font-size: 0.9rem; }

/* ── Composer ───────────────────────────────────────────────────────── */
.composer { padding: 8px 16px calc(14px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 6px 6px 6px 14px; }
.composer-inner:focus-within { border-color: var(--ink-soft); }
.composer textarea { flex: 1; border: 0; background: none; resize: none; padding: 7px 0; max-height: 40vh; outline: none; line-height: 1.45; }
.composer.dragging .composer-inner { border-color: var(--action); border-style: dashed; }
.attach-chips { max-width: 720px; margin: 0 auto 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.attach-chips[hidden], .attach-notice[hidden] { display: none; }
.attach-chips.sent { margin: 6px 0 0; justify-content: flex-end; max-width: 85%; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 4px 3px 10px; border: 1px solid var(--rule); border-radius: 999px; background: var(--sheet); font-size: 0.8rem; color: var(--ink); }
.attach-chips.sent .chip { padding-right: 10px; }
.chip svg { width: 14px; height: 14px; flex: none; color: var(--ink-soft); }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28ch; }
.chip-size { color: var(--ink-soft); font-size: 0.75rem; white-space: nowrap; }
.chip-x { background: none; border: 0; padding: 3px; border-radius: 50%; cursor: pointer; color: var(--ink-soft); line-height: 0; }
.chip-x:hover { background: var(--rule); color: var(--ink); }
.chip-x svg { width: 12px; height: 12px; }
.attach-notice { max-width: 720px; margin: 0 auto 6px; font-size: 0.78rem; color: var(--ink-soft); }
.composer .note { max-width: 720px; margin: 6px auto 0; font-size: 0.78rem; color: var(--ink-soft); }

/* ── Voice call ─────────────────────────────────────────────────────── */
.main.in-call > .composer { display: none; }
.call { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--rule); background: var(--sheet); cursor: pointer; }
.call-inner { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.call-head { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.call-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--action); flex: none; }
.call[data-state="listening"] .call-dot { animation: call-pulse 1.4s ease-in-out infinite; }
.call[data-state="thinking"] .call-dot { background: var(--marker); }
.call[data-state="error"] .call-dot { background: var(--danger); }
@keyframes call-pulse { 50% { transform: scale(1.6); opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) { .call[data-state="listening"] .call-dot { animation: none; } }
.call .squiggle-wait { margin-left: auto; }
.call-transcript { min-height: 1.55em; max-height: 6.2em; overflow-y: auto; overflow-wrap: anywhere; }
.call-transcript.interim { color: var(--ink-soft); font-style: italic; }
.call-hint, .call-error { font-size: 0.82rem; color: var(--ink-soft); }
.call-error { color: var(--danger); }
.call-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.call[data-state="ask"] { cursor: default; }
.voice-status { font-size: 0.82rem; color: var(--ink-soft); }
.call-actions .btn { min-height: 44px; min-width: 88px; }
#call[aria-pressed="true"] { color: var(--action); }

/* ── Drawer panels ──────────────────────────────────────────────────── */
.drawer .topbar h2 { font-size: 1rem; margin: 0; flex: 1; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer .messages { padding: 16px 14px 8px; }
.drawer .composer { padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); }
.thread-parent { border-bottom: 1px solid var(--rule); padding-bottom: 12px; margin-bottom: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field label, .field .label { font-weight: 600; font-size: 0.92rem; }
.field .hint { font-size: 0.82rem; color: var(--ink-soft); line-height: 1.45; }
.field .value { font-size: 0.95rem; overflow-wrap: anywhere; }
.field input[type="text"], .field select, .field textarea, .search { border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--paper); padding: 8px 10px; }
.field select { padding-right: 28px; max-width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius-s); overflow: hidden; align-self: flex-start; background: var(--paper); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; color: var(--ink-soft); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--action); color: var(--action-ink); font-weight: 600; }

/* Settings: sections, on/off rows with a switch */
.settings .settings-sec { padding: 4px 0 8px; border-bottom: 1px solid var(--rule); margin-bottom: 18px; }
.settings .settings-sec:last-child { border-bottom: 0; margin-bottom: 0; }
.settings .settings-sec h3 { margin: 0 0 14px; font-size: 0.76rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); }
.toggle { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; cursor: pointer; }
.toggle .toggle-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toggle .toggle-text strong { font-weight: 600; font-size: 0.92rem; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 38px; height: 22px; margin: 2px 0 0; border-radius: 11px;
  background: var(--rule); position: relative; cursor: pointer; transition: background 0.15s;
}
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--sheet); box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform 0.15s; }
.switch:checked { background: var(--action); }
.switch:checked::after { transform: translateX(16px); background: #fff; }
.switch:disabled { opacity: 0.5; cursor: default; }
@media (prefers-reduced-motion: reduce) { .switch, .switch::after { transition: none; } }
.model-more { margin-top: 2px; }
.model-more > summary { cursor: pointer; font-size: 0.86rem; color: var(--ink-soft); padding: 4px 0; list-style: none; }
.model-more > summary::-webkit-details-marker { display: none; }
.model-more > summary::before { content: '›'; display: inline-block; width: 1em; transition: transform 0.15s; }
.model-more[open] > summary::before { transform: rotate(90deg); }
.model-more .model-list { margin-top: 6px; }
.voice-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.voice-row select { flex: 1; min-width: 160px; }
.relay-row input { flex: 1; min-width: 180px; }
.btn svg { width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; }

.fact-list { list-style: none; padding: 0; margin: 0; }
.fact-list li { padding: 8px 0; border-bottom: 1px solid var(--rule); display: flex; gap: 8px; align-items: flex-start; }
.fact-list .fact { flex: 1; }
.fact-list .s, .fact-list .o { font-weight: 600; }
.fact-list .p { color: var(--ink-soft); }
.fact-list .auto { font-size: 0.75rem; color: var(--ink-soft); display: block; }
.search { width: 100%; margin-bottom: 12px; }

.ctx-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); font-size: 0.9rem; }
.ctx-item .kind { color: var(--ink-soft); font-size: 0.8rem; }
.ctx-item .tok { color: var(--ink-soft); font-variant-numeric: tabular-nums; text-align: right; }
.trace { margin-top: 18px; }
.trace h3 { font-size: 1rem; margin: 0 0 4px; }
.trace details { margin: 4px 0; }
.trace summary { cursor: pointer; padding: 3px 0; }
.trace .kind { color: var(--ink-soft); font-size: 0.8rem; margin-top: 6px; }
.trace-conv { border-top: 1px solid var(--rule); padding-top: 6px; }
.trace-conv > summary { font-weight: 600; }
.trace-conv > details, .trace-conv > p { margin-left: 12px; }
.trace-tool { margin-left: 12px; }
.trace-pre { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 0.78rem; background: var(--code-bg); border-radius: 6px; padding: 8px; margin: 4px 0; max-height: 420px; overflow: auto; }
.trace-named { font-size: 0.85rem; }
.meter { height: 8px; background: var(--rule); border-radius: 4px; overflow: hidden; margin: 6px 0 14px; }
.meter > div { height: 100%; background: var(--action); }

.file-tree { list-style: none; padding: 0; margin: 0; font-size: 0.92rem; }
.file-tree li button { background: none; border: 0; padding: 4px 0; cursor: pointer; text-align: left; width: 100%; color: var(--ink); }
.file-view { white-space: pre-wrap; font: 0.84rem/1.5 var(--mono); background: var(--code-bg); padding: 12px; border-radius: var(--radius-s); overflow-x: auto; }

/* ── Setup ──────────────────────────────────────────────────────────── */
.setup { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.setup-card { width: min(520px, 100%); }
.setup-card .brand { padding: 0 0 18px; font-size: 1.6rem; }
.setup-card .brand svg { width: 52px; height: 26px; }
.steps { list-style: none; padding: 0; margin: 0 0 22px; display: flex; gap: 6px; }
.steps li { flex: 1; height: 4px; border-radius: 2px; background: var(--rule); }
.steps li.done { background: var(--action); }
.steps li.now { background: var(--marker); }
.setup h2 { font-size: 1.35rem; margin: 0 0 8px; letter-spacing: -0.01em; }
.setup p { color: var(--ink-soft); margin: 0 0 16px; }
.code-box { font: 600 2rem/1 var(--mono); letter-spacing: 0.12em; padding: 18px; text-align: center; background: var(--sheet); border: 1px dashed var(--ink-soft); border-radius: var(--radius-m); margin: 8px 0 14px; user-select: all; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.choice { display: block; width: 100%; text-align: left; border: 1px solid var(--rule); background: var(--sheet); border-radius: var(--radius-m); padding: 14px 16px; margin-bottom: 10px; cursor: pointer; }
.choice:hover { border-color: var(--ink-soft); }
.choice strong { display: block; }
.choice span { color: var(--ink-soft); font-size: 0.9rem; }
.repo-list { max-height: 280px; overflow-y: auto; border: 1px solid var(--rule); border-radius: var(--radius-m); margin-bottom: 12px; }
.repo-list button { display: flex; width: 100%; justify-content: space-between; gap: 8px; background: none; border: 0; border-bottom: 1px solid var(--rule); padding: 10px 14px; cursor: pointer; text-align: left; }
.repo-list button:last-child { border-bottom: 0; }
.repo-list button:hover { background: var(--sheet); }
.repo-list .pub { color: var(--danger); font-size: 0.82rem; }
.error { color: var(--danger); font-size: 0.92rem; margin: 8px 0; }
.progress { height: 10px; background: var(--rule); border-radius: 5px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; width: 0; background: var(--action); transition: width 0.3s; }
.muted { color: var(--ink-soft); font-size: 0.88rem; }

.banner { background: var(--sheet); border-bottom: 1px solid var(--rule); padding: 10px 16px; font-size: 0.92rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner .progress { flex: 1; min-width: 120px; margin: 0; }
.banner.demo { border-left: 4px solid var(--marker); gap: 8px 12px; }
.banner.demo .try { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.banner.demo .try button { font: inherit; font-size: 0.86rem; color: var(--ink); background: var(--paper); border: 1px solid var(--rule); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
.banner.demo .try button:hover { border-color: var(--action); color: var(--action); }
.banner .dl { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.banner .dl-head { display: flex; align-items: center; gap: 10px; }
.banner .dl .progress { flex: none; width: 100%; }
.progress.indeterminate > div { width: 30%; animation: indeterminate 1.3s ease-in-out infinite; }
@keyframes indeterminate { from { margin-left: -30%; } to { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .progress.indeterminate > div { animation: none; width: 100%; opacity: 0.35; } }

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-flex; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-100%); transition: transform 0.2s; box-shadow: 0 0 0 100vmax transparent; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(10, 14, 30, 0.35); }
  .drawer { position: fixed; inset: 0; width: auto; z-index: 30; border-left: 0; }
  .msg.user .body { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* ── Chat details sidebar ───────────────────────────────────────────── */
:root {
  --part-instructions: #7c86b8; --part-tools: #a274c4; --part-conversation: #127c7a; --part-memory: #c98a1c;
  --part-recalled: #c95b7f; --part-message: #3a86d0; --part-turn: #6f8f2f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --part-instructions: #9aa4d6; --part-tools: #c39ae0; --part-conversation: #4fc1b8; --part-memory: #e8b04a;
    --part-recalled: #ec8aa9; --part-message: #6fb0ee; --part-turn: #a6c65c;
  }
}
:root[data-theme="dark"] {
  --part-instructions: #9aa4d6; --part-tools: #c39ae0; --part-conversation: #4fc1b8; --part-memory: #e8b04a;
  --part-recalled: #ec8aa9; --part-message: #6fb0ee; --part-turn: #a6c65c;
}
.ctx-side { width: 300px; border-left: 1px solid var(--rule); background: var(--sheet); display: flex; flex-direction: column; min-height: 0; }
.ctx-side .topbar h2 { font-size: 1rem; margin: 0; flex: 1; }
.side-body { flex: 1; overflow-y: auto; padding: 4px 14px 16px; font-size: 0.88rem; }
.side-sec { border-bottom: 1px solid var(--rule); padding: 10px 0; }
.side-sec:last-child { border-bottom: 0; }
.side-sec > summary { cursor: pointer; font-weight: 600; display: flex; align-items: baseline; gap: 8px; list-style: none; }
.side-sec > summary::-webkit-details-marker { display: none; }
.side-sec > summary::before { content: '›'; display: inline-block; width: 0.8em; color: var(--ink-soft); transition: transform 0.15s; }
.side-sec[open] > summary::before { transform: rotate(90deg); }
.side-sec > summary .aside { margin-left: auto; font-weight: 400; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.side-sec .sec-body { padding: 8px 0 2px 0.8em; }
.side-sec .empty-line { color: var(--ink-soft); margin: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ctx-total { color: var(--ink-soft); margin: 0 0 6px; font-variant-numeric: tabular-nums; }
.ctx-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--rule); margin: 0 0 10px; }
.ctx-bar > span { height: 100%; min-width: 2px; }
.ctx-bar > span + span { box-shadow: inset 1px 0 0 var(--sheet); }
.ctx-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.ctx-rows li { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.ctx-rows .sw { width: 10px; height: 10px; border-radius: 3px; }
.ctx-rows .sw.free { background: transparent; box-shadow: inset 0 0 0 1.5px var(--rule); }
.ctx-rows .n { color: var(--ink-soft); text-align: right; }
.ctx-rows .p { color: var(--ink-soft); text-align: right; min-width: 3.2em; }
.ctx-note { color: var(--ink-soft); margin: 8px 0 0; font-size: 0.82rem; }
.side-body .plan { margin: 0; }
.side-body .plan.chip > summary { display: none; }
.side-body .plan.chip { border: 0; border-radius: 0; background: none; padding: 0; }
.side-body .plan.chip .plan-steps, .side-body .plan.chip[open] .plan-steps { border-left: 0; padding-left: 0; margin-top: 0; }
.side-body .plan.live { padding: 8px 10px; }
.use-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.use-list li { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.use-list .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.use-list .count { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.use-list .fail { color: var(--danger); }
.side-link { background: none; border: 0; padding: 0; color: var(--action); cursor: pointer; font-size: 0.82rem; margin-top: 8px; display: inline-flex; gap: 6px; align-items: center; }
.side-link svg { width: 16px; height: 16px; }
.side-field { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.side-field label { color: var(--ink-soft); font-size: 0.82rem; }
.side-select { border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--paper); padding: 6px 8px; font-size: 0.86rem; max-width: 100%; }
.side-hint { font-size: 0.78rem; color: var(--ink-soft); }
.side-actions .btn { font-size: 0.86rem; padding: 5px 10px; }
.use-list.notes .label { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#toggle-side[aria-expanded="true"] { color: var(--action); }
/* Not enough room for both: an open panel covers the details. */
@media (max-width: 1500px) { .app:has(.drawer:not([hidden])) .ctx-side { display: none; } }
@media (max-width: 1199px) {
  .ctx-side { position: fixed; inset: 0 0 0 auto; width: min(320px, 90vw); z-index: 25; box-shadow: -8px 0 24px rgba(10, 14, 30, 0.18); }
}
@media (prefers-reduced-motion: reduce) { .side-sec > summary::before { transition: none; } }

/* Permission card (push to a non-agent branch) */
.approval { border: 1px solid var(--rule); border-left: 4px solid var(--marker); background: var(--sheet); border-radius: var(--radius-m); padding: 12px 14px; margin: 8px 0 10px; }
.approval .q { margin: 0 0 6px; }
.approval .commits { margin: 0 0 10px; padding-left: 18px; font-size: 0.9rem; }
.approval .commits code { font-family: var(--mono); font-size: 0.85em; }
.approval.settled { border-left-color: var(--rule); padding: 6px 12px; }
.approval.settled p { margin: 0; }
.approval .warn { margin: 0 0 8px; font-size: 0.9rem; color: var(--danger); }

/* Model picker (setup + Settings) */
.model-list { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 12px; }
.model-option { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%; text-align: left; border: 1px solid var(--rule); background: var(--sheet); color: inherit; border-radius: var(--radius-m); padding: 10px 14px; cursor: pointer; font: inherit; }
.model-option[aria-checked="true"] { border-color: var(--action); box-shadow: inset 0 0 0 1px var(--action); background: var(--selected); }
.model-option .model-name { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.model-option .model-size { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.model-option .model-note { grid-column: 1 / -1; color: var(--ink-soft); font-size: 0.86rem; }
.model-option .tag { font-weight: 500; font-size: 0.72rem; padding: 1px 7px; border-radius: 999px; background: var(--action); color: var(--action-ink); }

/* Agent notes panel */
.notes-list .note-text { white-space: pre-wrap; margin-top: 2px; }

/* Plan checklist (step mode): live above the reply, a chip on finished replies */
.plan { font-size: 0.88rem; margin: 4px 0 8px; }
.plan.live { border: 1px solid var(--rule); border-left: 4px solid var(--marker); border-radius: var(--radius-m); background: var(--sheet); padding: 10px 12px; }
.plan .plan-head { margin-bottom: 6px; line-height: 1.35; }
.plan.chip summary { cursor: pointer; color: var(--ink-soft); width: fit-content; }
.plan.chip summary strong, .plan.chip summary { font-weight: 600; }
.plan.chip summary .muted { font-weight: 400; }
.plan.chip[open] .plan-steps { border-left: 2px solid var(--rule); padding-left: 12px; margin-top: 6px; }
.plan-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.plan-steps .step { display: flex; gap: 8px; align-items: baseline; color: var(--ink-soft); }
.plan-steps .step .mark { width: 1em; flex: none; text-align: center; }
.plan-steps .step .text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.plan-steps .step.now { color: var(--ink); font-weight: 600; }
.plan-steps .step.done .text { color: var(--ink); }
.plan-steps .step.blocked { color: var(--danger); }
.plan-steps .step .result { display: block; font-size: 0.8rem; font-weight: 400; color: var(--ink-soft); margin-top: 1px; }
.plan-steps .squiggle-wait { width: 22px; height: 9px; flex: none; }
.approval.checkin .plan { margin: 4px 0 10px; }

/* Recipes (Memory panel) */
.recipes { margin-top: 22px; }
.recipes h3 { margin: 0 0 4px; font-size: 1rem; }
.recipe-list li { align-items: flex-start; }
.recipe-list li.pending { border-left: 3px solid var(--marker); padding-left: 8px; }
.recipe-list .recipe { flex: 1; min-width: 0; }
.recipe-list .recipe summary { cursor: pointer; }
.recipe-list .recipe summary .muted { font-size: 0.8rem; }
.recipe-list .recipe-steps { margin: 6px 0; padding-left: 20px; font-size: 0.9rem; }
.recipe-list .recipe p { margin: 4px 0; font-size: 0.85rem; overflow-wrap: anywhere; }
.recipe-actions { display: flex; gap: 2px; align-items: center; flex: none; }
.btn.small { padding: 2px 8px; font-size: 0.8rem; min-height: 0; }
.recipe-form { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.recipe-edit { width: 100%; font: inherit; font-size: 0.9rem; border: 1px solid var(--rule); border-radius: var(--radius-s, 6px); padding: 6px 8px; background: var(--paper, transparent); color: var(--ink); box-sizing: border-box; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(520px, calc(100vw - 32px)); background: var(--ink, #1c2233); color: var(--paper, #fff); padding: 10px 16px; border-radius: 12px; font-size: 0.9rem; box-shadow: 0 6px 24px rgba(0,0,0,0.2); z-index: 50; }
