:root {
  --paper: #f7f5f1;
  --rail: #efede8;
  --card: #fcfaf7;
  --card-soft: #f2f0ea;
  --border: #e3dfd7;
  --border-strong: #ccc6ba;
  --ink: #2a2721;
  --muted: #7c7669;
  --faint: #98917f;
  --on-accent: #fdfaf6;
  --accent: #c7673e;
  --accent-ink: #a34e28;
  --accent-soft: rgba(199, 103, 62, 0.10);
  --danger: #b3402e;
  --ok: #4a8a56;
  --warn: #b8862e;
  --code-bg: #f1efe9;
  --font-size: 15px;
  --chat-max: 800px;
  --rail-w: 248px;
  --topbar-h: 52px;
  --radius: 12px;
  --sans: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
  --mono: 'Cascadia Code', 'Cascadia Mono', Consolas, 'Courier New', monospace;
  --shadow: 0 1px 2px rgba(37, 39, 36, 0.05), 0 8px 24px rgba(37, 39, 36, 0.06);
  --shadow-lg: 0 12px 48px rgba(37, 39, 36, 0.16);
}

[data-theme="dark"], [data-theme="system"] {
  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #181511;
  --rail: #131110;
  --card: #211d19;
  --card-soft: #1c1915;
  --border: #322c25;
  --border-strong: #4a4136;
  --ink: #ede7dd;
  --muted: #a79d8e;
  --faint: #8b8272;
  --on-accent: #261a10;
  --accent: #d98a5b;
  --accent-ink: #e29d70;
  --accent-soft: rgba(217, 138, 91, 0.10);
  --danger: #d4755f;
  --ok: #7fb389;
  --warn: #d0a95c;
  --code-bg: #23201a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    color-scheme: dark;
    --paper: #181511;
    --rail: #131110;
    --card: #211d19;
    --card-soft: #1c1915;
    --border: #322c25;
    --border-strong: #4a4136;
    --ink: #ede7dd;
    --muted: #a79d8e;
    --faint: #8b8272;
    --on-accent: #261a10;
    --accent: #d98a5b;
    --accent-ink: #e29d70;
    --accent-soft: rgba(217, 138, 91, 0.09);
    --danger: #d4755f;
    --ok: #7fb389;
    --warn: #d0a95c;
    --code-bg: #23241f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 8px 24px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--font-size);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

[data-density="compact"] .msg { margin-bottom: 14px; }
[data-density="compact"] .thread-item { padding: 6px 8px; }
[data-density="compact"] .composer textarea { min-height: 40px; }
[data-density="compact"] .chat-inner { padding-top: 12px; }

button { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.project-filter { width: 100%; font-size: 12px; margin: 4px 0 12px; }
.rail-tools { display: flex; gap: 8px; padding-top: 10px; }
.rail-tools > button { flex: 1; font-size: 12px; }
.usage-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 24px 0; }
.usage-stat { border: 1px solid var(--border); border-radius: 8px; padding: 16px 10px; display: flex; flex-direction: column; }
.usage-stat strong { font: 24px var(--mono); }
.usage-stat span { color: var(--muted); font-size: 11px; margin-top: 8px; }
.extension-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 12px 0; }
.extension-card textarea { width: 100%; resize: vertical; font: 12px/1.6 var(--mono); }
.extension-card > button { margin-top: 8px; }
.thread-item:focus-within .thread-actions { opacity: 1; }
@media (max-width: 480px) { .usage-grid { grid-template-columns: 1fr; } }
input, textarea, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.icon { width: 18px; height: 18px; flex: none; }
.kbd {
  font-family: var(--mono); font-size: 10.5px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px;
  background: var(--card-soft);
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Rail ---------- */
.rail {
  width: var(--rail-w); flex: none; display: flex; flex-direction: column;
  background: var(--rail); border-right: 1px solid var(--border);
  padding: 14px 12px 12px; gap: 8px; z-index: 30;
}
.rail-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 2px 4px 8px; }
.brand { display: flex; flex-direction: column; gap: 2px; }
.brand-row { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  color: var(--on-accent); font-family: var(--serif); font-size: 16px;
  display: grid; place-items: center; line-height: 1;
}
.brand-word { font-weight: 600; letter-spacing: 0.22em; font-size: 13px; }
.brand-sub { font-size: 9.5px; letter-spacing: 0.14em; color: var(--muted); }
.rail-close { display: none; }

.new-thread {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 10px;
  background: transparent; cursor: pointer; font-weight: 500; font-size: 13.5px;
  transition: background 0.15s, border-color 0.15s;
}
.new-thread:hover { background: var(--card); border-color: var(--accent); }
.new-thread .kbd { margin-left: auto; }
.nt-icon, .rs-icon, .conn-gear { display: inline-flex; }
.nt-icon .icon, .rs-icon .icon, .conn-gear .icon { width: 15px; height: 15px; }

.rail-search {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card-soft); cursor: pointer; color: var(--muted); font-size: 13px;
}
.rail-search:hover { border-color: var(--border-strong); color: var(--ink); }
.rail-search .kbd { margin-left: auto; }

.threads { flex: 1; overflow-y: auto; margin: 4px -4px 0; padding: 0 4px; }
.thread-group-label {
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--faint); padding: 12px 8px 4px;
}
.thread-item {
  position: relative; display: flex; align-items: center; gap: 4px; width: 100%;
  border-radius: 8px; padding: 4px; color: var(--ink); font-size: 13px;
}
.thread-item:hover { background: var(--card); }
.thread-item.active { background: var(--card); box-shadow: inset 0 0 0 1px var(--border-strong); }
.thread-item .t-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: inherit; font: inherit; text-align: left;
  padding: 4px; border-radius: 6px; cursor: pointer;
}
.thread-item .t-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item .t-pin { color: var(--accent); display: inline-flex; }
.thread-item .t-pin .icon { width: 12px; height: 12px; }
.thread-actions { display: none; gap: 2px; }
.thread-item:hover .thread-actions, .thread-item.active .thread-actions,
.thread-item:focus-within .thread-actions { display: inline-flex; }
.thread-actions button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 3px; border-radius: 5px; display: inline-flex;
}
.thread-actions button:hover { color: var(--ink); background: var(--rail); }
.thread-actions .icon { width: 13px; height: 13px; }
.threads-empty { color: var(--muted); font-size: 12.5px; padding: 16px 10px; line-height: 1.5; }

.rail-foot { display: flex; flex-direction: column; gap: 6px; }
.conn-card {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card-soft); cursor: pointer; text-align: left;
}
.conn-card:hover { border-color: var(--border-strong); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--faint); }
.conn-dot[data-status="ready"], .conn-dot[data-status="connected"] { background: var(--ok); }
.conn-dot[data-status="working"], .conn-dot[data-status="permission"], .conn-dot[data-status="connecting"] { background: var(--warn); }
.conn-dot[data-status="sleeping"] { background: var(--faint); }
.conn-dot[data-status="error"] { background: var(--danger); }
.conn-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conn-name { font-size: 12px; font-weight: 600; }
.conn-status { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-gear { color: var(--muted); }
.rail-note { font-size: 10.5px; color: var(--faint); padding: 0 4px; }

.scrim {
  position: fixed; inset: 0; background: rgba(20, 20, 18, 0.35); z-index: 25;
}

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--paper);
}
.rail-toggle { display: none; }
.crumb { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.crumb-sep { color: var(--faint); }
#crumb-title { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--ink); }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.icon-btn.rail-close, .icon-btn.rail-toggle { display: none; }

/* Desktop: the rail can be collapsed away entirely; the topbar toggle and
   the in-rail close button then swap roles as expander/collapser. */
@media (min-width: 901px) {
  .icon-btn.rail-close { display: inline-flex; }
  [data-rail="collapsed"] .rail { display: none; }
  [data-rail="collapsed"] .icon-btn.rail-toggle { display: inline-flex; }
}

/* ---------- Landing ---------- */
.landing { flex: 1; min-height: 0; overflow-y: auto; display: flex; }
.landing-inner {
  margin: auto; width: 100%; max-width: 780px; padding: 32px 24px 40px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.overline {
  font-size: 10.5px; letter-spacing: 0.3em; color: var(--muted); margin: 0 0 18px;
}
.sigma-mark { width: 56px; height: 56px; color: var(--accent); margin-bottom: 24px; }
.landing-title {
  font-family: var(--sans); font-weight: 500; font-size: 32px; line-height: 1.2;
  margin: 0 0 32px; letter-spacing: -0.04em;
}
.landing-title em { color: var(--muted); font-style: italic; }
.lede { color: var(--muted); font-size: 15.5px; margin: 0 0 26px; }

.focus-pills {
  display: flex; gap: 2px; padding: 3px; margin: 16px 0 8px;
  background: var(--rail); border: 1px solid var(--border); border-radius: 12px;
}
.focus-pill {
  display: inline-flex; flex: 1; justify-content: center; align-items: center; gap: 7px; border: 0; border-radius: 6px;
  padding: 7px 14px; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 13px; font-weight: 500;
}
.focus-pill .icon { width: 15px; height: 15px; }
.focus-pill:hover { color: var(--ink); }
.focus-pill[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.focus-pill[aria-pressed="true"] .icon { color: var(--accent); }

.composer-slot { width: 100%; }

.boot-note {
  margin: 0 0 14px; font-size: 12.5px; color: var(--faint);
  animation: boot-note-in 0.4s ease;
}
@keyframes boot-note-in { from { opacity: 0; } }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 18px; }
.tile {
  position: relative; text-align: left; padding: 14px 16px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--card-soft); cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.tile:hover { border-color: var(--accent); background: var(--card); }
.tile-t { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; }
.tile-t .icon { width: 15px; height: 15px; color: var(--accent); }
.tile-s { color: var(--muted); font-size: 12px; }
.tile-arrow { position: absolute; top: 12px; right: 12px; color: var(--faint); }
.tile-arrow .icon { width: 14px; height: 14px; }
.tile:hover .tile-arrow { color: var(--accent); }

.landing-foot {
  margin-top: 34px; font-size: 10.5px; letter-spacing: 0.22em; color: var(--faint);
}
.foot-sigma { font-family: var(--serif); color: var(--accent); letter-spacing: 0; }

/* ---------- Composer ---------- */
.composer {
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); padding: 12px 14px 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  border: 0; outline: 0; resize: none; background: transparent;
  font: inherit; font-size: 15px; line-height: 1.5; color: var(--ink);
  min-height: 52px; max-height: 40vh; width: 100%;
}
.composer textarea::placeholder { color: var(--faint); }
.composer-att { display: flex; flex-wrap: wrap; gap: 6px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px;
  background: var(--card-soft); color: var(--ink); max-width: 240px;
}
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip .att-size { color: var(--faint); font-size: 11px; }
.att-chip button { border: 0; background: none; color: var(--muted); cursor: pointer; display: inline-flex; padding: 1px; }
.att-chip button:hover { color: var(--danger); }
.att-chip .icon { width: 12px; height: 12px; }
.att-chip.quote-chip { border-style: dashed; }
.att-chip.quote-chip .att-name { font-style: italic; color: var(--muted); }

/* Floating "Quote" button over a text selection inside an assistant answer. */
.quote-pop {
  position: fixed; z-index: 45;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--card);
  color: var(--ink); font-size: 12px; cursor: pointer;
  box-shadow: var(--shadow-lg); white-space: nowrap;
}
.quote-pop .icon { width: 12px; height: 12px; }
.quote-pop:hover { border-color: var(--accent); color: var(--accent-ink); }
.composer-bar { display: flex; align-items: center; gap: 6px; }
.composer-bar .spacer { flex: 1; min-width: 4px; }
.model-label, .mode-label, .focus-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.model-btn, .mode-btn { min-width: 0; max-width: 220px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 11px; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 12px; white-space: nowrap;
}
.chip-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.chip-btn .icon { width: 13px; height: 13px; }
.chip-btn.on { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.chip-btn select, .model-select {
  border: 0; background: transparent; color: inherit; font: inherit; font-size: 12px;
  max-width: 180px; outline: none; cursor: pointer;
}
.model-btn .model-label { color: var(--ink); font-size: 12px; }
.chip-btn:disabled, .model-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.send-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 0;
  background: var(--accent); color: var(--on-accent); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.send-btn:hover:not(:disabled) { background: var(--accent-ink); }
.send-btn:disabled { background: var(--border-strong); color: var(--muted); cursor: not-allowed; }
.send-btn.stop { background: var(--danger); }
.composer-note { font-size: 11px; color: var(--faint); padding: 0 2px; }

.slash-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: var(--card); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; padding: 4px;
}
.slash-menu.model-menu {
  right: auto; width: max-content; min-width: 108px; max-height: none; overflow: visible;
}
.slash-item {
  display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.slash-item:hover, .slash-item.sel { background: var(--accent-soft); }
.slash-item .cmd-name { font-family: var(--mono); font-size: 12.5px; color: var(--accent-ink); }
.slash-item .cmd-desc { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-wrap { position: relative; }

/* ---------- Chat ---------- */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroller { flex: 1; min-height: 0; overflow-y: auto; }
.chat-inner { max-width: var(--chat-max); margin: 0 auto; padding: 20px 24px 16px; }
/* Zero-height anchor pinned to the scroller's visible bottom edge; the jump
   button floats above the message list without occupying layout space. */
.jump-anchor { position: sticky; bottom: 0; height: 0; z-index: 30; }
.jump-btn {
  position: absolute; right: 18px; bottom: 14px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--card);
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg);
}
.jump-btn[hidden] { display: none; }
.jump-btn:hover { color: var(--ink); border-color: var(--accent); }
.jump-btn .icon { width: 16px; height: 16px; }
[data-width="wide"] { --chat-max: 1080px; }
.composer-slot.docked {
  flex: none; padding: 10px 24px 14px; max-width: calc(var(--chat-max) + 48px);
  width: 100%; margin: 0 auto;
}
.load-earlier-wrap { display: flex; justify-content: center; padding: 4px 0 14px; }

.msg { display: flex; gap: 14px; margin: 0 0 22px; content-visibility: auto; contain-intrinsic-size: auto 120px; }
/* Citation popups must escape content-visibility's paint containment. This is
   set as soon as citations render (including mid-stream), rather than only on
   hover, because toggling containment can nudge complex Markdown layouts. */
.msg.has-citations { content-visibility: visible; }
.msg-mark { flex: none; width: 26px; display: flex; flex-direction: column; align-items: center; padding-top: 3px; }
.msg-mark .m-sigma {
  width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center;
  font-family: var(--serif); font-size: 14px; color: var(--accent);
  border: 1px solid var(--border-strong); background: var(--card);
}
.msg-mark .m-user { color: var(--muted); }
.msg-body { flex: 1; min-width: 0; }
.msg-role { font-size: 11px; color: var(--faint); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }

.msg.user { justify-content: flex-end; }
.msg.user .msg-body {
  flex: none; max-width: 78%;
  background: var(--rail); border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px; padding: 10px 14px;
}
.msg.user .msg-text { white-space: pre-wrap; overflow-wrap: break-word; }
.msg.user .msg-quote {
  white-space: normal; overflow-wrap: break-word;
  border-left: 2px solid var(--border-strong); border-radius: 0 7px 7px 0;
  background: var(--card-soft); color: var(--muted); font-style: italic;
  padding: 6px 10px; margin: 0 0 8px; font-size: 12.5px;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.msg.user .msg-att { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg.user.editing .msg-body { flex: 1; max-width: none; }
.msg .edit-actions { display: flex; gap: 8px; margin-top: 8px; justify-content: flex-end; }

.msg.assistant .msg-text { overflow-wrap: break-word; }
.msg-streaming { white-space: pre-wrap; }
.msg-streaming.md { white-space: normal; }
.msg-cursor { display: inline-block; width: 8px; height: 1.1em; background: var(--accent); vertical-align: text-bottom; margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.msg-actions { display: flex; gap: 2px; margin-top: 8px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 26px; height: 26px; }
.msg-actions .icon { width: 14px; height: 14px; }
.msg-status { font-size: 11.5px; color: var(--warn); margin-top: 6px; }
.msg-status.error { color: var(--danger); }
.msg-usage { font-size: 11px; color: var(--faint); margin-top: 6px; }

.reasoning {
  margin: 1px 0 11px; color: var(--muted);
}
.reasoning summary {
  width: fit-content; max-width: 100%; padding: 4px 7px 4px 5px;
  border-radius: 7px; cursor: pointer; font-size: 11.5px; line-height: 1.3;
  color: var(--faint); display: flex; align-items: center; gap: 5px;
  list-style: none; transition: color .15s ease, background .15s ease;
}
.reasoning summary:hover, .reasoning summary:focus-visible {
  color: var(--muted); background: var(--card-soft); outline: none;
}
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning summary .icon { width: 12px; height: 12px; flex: none; }
.reasoning summary > .icon:first-child { opacity: .72; }
.reasoning .reasoning-body {
  margin: 5px 0 0 6px; padding: 2px 0 2px 12px;
  border-left: 1px solid var(--border); font-size: 12.5px;
  color: var(--muted); white-space: pre-wrap;
}
.reasoning summary .r-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reasoning summary .r-chev {
  transform: rotate(-90deg); transition: transform .15s ease; opacity: .65;
}
.reasoning[open] summary .r-chev { transform: rotate(0deg); }
/* Live activity trace: thinking, preamble, tool calls and plan in stream
   order — folds into the same block once the answer lands. */
.trace-scroll-wrap { position: relative; }
.trace-body { max-height: 320px; overflow: auto; }
.trace-jump {
  position: absolute; z-index: 3; left: 50%; bottom: 10px;
  width: 30px; height: 30px; padding: 0; transform: translateX(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--card); color: var(--muted); box-shadow: var(--shadow);
  cursor: pointer;
}
.trace-jump[hidden] { display: none; }
.trace-jump:hover { color: var(--ink); border-color: var(--accent); }
.trace-jump .icon { width: 14px; height: 14px; }
.trace-note {
  padding: 7px 9px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
  border-left: 2px solid var(--border);
  background: var(--card-soft);
  border-radius: 0 6px 6px 0;
}
.trace-note + .trace-note { margin-top: 6px; }
.trace-note.md > :first-child { margin-top: 0; }
.trace-note.md > :last-child { margin-bottom: 0; }
.trace-note.md p, .trace-note.md ul, .trace-note.md ol,
.trace-note.md pre, .trace-note.md blockquote { margin-top: 5px; margin-bottom: 5px; }
.trace-note.md .katex-display { margin: 7px 0; overflow-x: auto; overflow-y: hidden; }
.trace-item .toolcard, .trace-item .plan-card { margin: 6px 0; }
.trace-item .plan-card { padding: 6px 10px; }

.toolcard {
  border: 1px solid var(--border); border-radius: 10px; margin: 4px 0;
  background: var(--card-soft); overflow: hidden; font-size: 12.5px;
}
/* Collapsed tool calls read as compact clickable boxes inside the trace. */
.toolcard summary {
  padding: 6px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px; list-style: none;
}
.toolcard summary::-webkit-details-marker { display: none; }
.toolcard .t-status { margin-left: auto; font-size: 11px; color: var(--muted); }
.toolcard .t-status[data-s="completed"] { color: var(--ok); }
.toolcard .t-status[data-s="failed"], .toolcard .t-status[data-s="error"] { color: var(--danger); }
.toolcard .t-status[data-s="in_progress"], .toolcard .t-status[data-s="pending"] { color: var(--warn); }
.toolcard .icon { width: 14px; height: 14px; color: var(--muted); }
.toolcard-body { border-top: 1px solid var(--border); padding: 8px 12px; }
.toolcard-body pre {
  margin: 6px 0; padding: 8px 10px; background: var(--code-bg); border-radius: 8px;
  font-family: var(--mono); font-size: 11.5px; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}
.tool-diff { display: grid; gap: 4px; }
.diff-old, .diff-new {
  font-family: var(--mono); font-size: 11.5px; padding: 6px 10px; border-radius: 8px;
  white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: auto;
}
.diff-old { background: rgba(179, 64, 46, 0.09); border-left: 3px solid var(--danger); }
.diff-new { background: rgba(74, 138, 86, 0.1); border-left: 3px solid var(--ok); }
/* Tool calls with nothing to show inside are flat chips, not expandable. */
.toolcard-flat summary { cursor: default; }

/* Trailing "Sources:" link lists render as their own expandable box. */
.sources-box {
  margin: 7px 0 3px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card-soft); overflow: hidden; font-size: 12px;
}
.sources-box summary {
  padding: 5px 9px; cursor: pointer; font-size: 11px; color: var(--muted);
  display: flex; align-items: center; gap: 5px; list-style: none;
}
.sources-box summary::-webkit-details-marker { display: none; }
.sources-box summary .icon { width: 11px; height: 11px; }
.sources-box[open] summary { border-bottom: 1px solid var(--border); }
.sources-box .sources-list { padding: 3px 10px 7px; }
.sources-box ul, .sources-box ol { margin: 4px 0; padding-left: 18px; }
.sources-box li { margin: 2px 0; }
.sources-box a { color: var(--accent); overflow-wrap: anywhere; }
.sources-box .source-favicon {
  width: 12px; height: 12px; margin-right: 5px; vertical-align: -1px;
  border-radius: 2px;
}

/* Numeric citation markers resolve into inline chips next to the cited
   sentence: first source name, "+N" for extras, hover popup lists all links. */
.md .cite {
  position: relative; display: inline-flex; margin-left: 1px;
  vertical-align: -2px; white-space: nowrap; font: normal 400 10px/1 var(--sans);
}
.md .cite-chip {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-width: 17px; height: 17px; padding: 0 3px; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 5px;
  background: var(--card-soft); color: var(--muted); text-decoration: none; white-space: nowrap;
}
.md .cite-chip:hover { border-color: var(--border-strong); color: var(--ink); }
.md .cite-chip .icon, .md .cite-favicon { width: 10px; height: 10px; flex: none; }
.md .cite-favicon { position: absolute; object-fit: contain; background: var(--card-soft); }
.md .cite-name {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.md .cite-more { margin-left: 10px; color: var(--faint); font-size: 8px; }
.md .cite-pop {
  /* Fixed so it never contributes to any scrollable overflow area — JS sets
     top/left in viewport coordinates on hover/focus. */
  position: fixed; top: 0; left: 0; z-index: 40;
  display: none; min-width: min(180px, calc(100vw - 16px)); max-width: min(300px, calc(100vw - 16px)); padding: 5px;
  flex-direction: column; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg);
}
/* The scrolling item list lives in an inner wrapper: a scroll container clips
   its own pseudo elements, which would cut the hover-bridge strips below. */
.md .cite-pop-list {
  display: flex; flex-direction: column; max-height: 260px; overflow-y: auto;
}
/* Invisible strips spanning the gap between chip and popup — they belong to
   the popup element, so the cursor can cross without dropping :hover. */
.md .cite-pop::before, .md .cite-pop::after {
  content: ''; position: absolute; left: 0; right: 0; height: 8px;
}
.md .cite-pop::before { bottom: 100%; }
.md .cite-pop::after { top: 100%; }
.md .cite:hover .cite-pop, .md .cite:focus-within .cite-pop { display: flex; }
.md .cite-pop-item {
  display: flex; flex-direction: column; gap: 1px; padding: 6px 8px;
  border-radius: 7px; font-size: 12px; color: var(--ink); text-decoration: none;
}
.md .cite-pop-item:hover { background: var(--card-soft); }
.md .cite-pop-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md .cite-pop-favicon {
  width: 12px; height: 12px; margin-right: 5px; vertical-align: -1.5px;
  border-radius: 2px;
}
.md .cite-pop-host { font-size: 11px; color: var(--muted); }

.plan-card { border: 1px solid var(--border); border-radius: 10px; background: var(--card-soft); margin: 8px 0; padding: 8px 12px; }
.plan-card .plan-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }
.plan-item { display: flex; gap: 8px; font-size: 12.5px; padding: 3px 0; align-items: baseline; }
.plan-item .p-status { flex: none; color: var(--faint); width: 14px; text-align: center; }
.plan-item[data-s="completed"] .p-status { color: var(--ok); }
.plan-item[data-s="in_progress"] .p-status { color: var(--warn); }

.perm-card {
  border: 1.5px solid var(--warn); border-radius: 14px; background: var(--card);
  padding: 14px 16px; margin: 10px 0; box-shadow: var(--shadow);
}
.perm-card .perm-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; }
.perm-card .perm-head .icon { color: var(--warn); }
.perm-card .perm-desc { font-size: 12.5px; color: var(--muted); margin: 8px 0; }
.perm-card .perm-detail {
  font-family: var(--mono); font-size: 11.5px; background: var(--code-bg);
  border-radius: 8px; padding: 8px 10px; margin: 8px 0; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 220px; overflow-y: auto;
}
.perm-card .perm-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.perm-opt {
  border: 1px solid var(--border-strong); border-radius: 9px; padding: 7px 13px;
  background: var(--card-soft); cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.perm-opt:hover { border-color: var(--accent); }
.perm-opt.kind-allow_once, .perm-opt.kind-allow_always { color: var(--ok); }
.perm-opt.kind-reject_once, .perm-opt.kind-reject_always { color: var(--danger); }

.sources { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.sources a { color: var(--accent-ink); font-size: 12.5px; }

/* markdown body */
.md p { margin: 0 0 10px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 18px 0 8px; line-height: 1.3; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.08em; }
.md h5, .md h6 { font-size: 0.92em; }
.md ul, .md ol { margin: 10px 0; padding-left: 24px; }
.md ul { list-style: disc; }
.md ol { list-style: decimal; }
.md li { margin: 4px 0; }
/* marked wraps loose list items in <p> — without this each item inherits the
   10px paragraph gap and the list falls apart visually. */
.md li > p { margin: 0 0 4px; }
.md li > p:last-child { margin-bottom: 0; }
.md li > ul, .md li > ol { margin: 4px 0 2px; }
.md li::marker { color: var(--muted); }
.md blockquote {
  margin: 10px 0; padding: 4px 14px; border-left: 3px solid var(--border-strong);
  color: var(--muted);
}
.md code {
  font-family: var(--mono); font-size: 0.88em; background: var(--code-bg);
  padding: 1.5px 5px; border-radius: 5px;
}
.md table {
  border-collapse: collapse; margin: 10px 0; font-size: 13px;
  display: block; max-width: 100%; overflow-x: auto;
}
.md th, .md td { border: 1px solid var(--border-strong); padding: 5px 10px; }
.md th { background: var(--card-soft); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.md a { color: var(--accent-ink); }

.codeblock { margin: 10px 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.codeblock-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px; background: var(--card-soft); border-bottom: 1px solid var(--border);
}
.codeblock-lang { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.codeblock-actions { display: flex; gap: 4px; }
.codeblock-btn {
  border: 0; background: none; color: var(--muted); font-size: 11px; cursor: pointer;
  padding: 2px 7px; border-radius: 6px;
}
.codeblock-btn:hover { color: var(--ink); background: var(--accent-soft); }
.codeblock pre {
  margin: 0; padding: 12px 14px; overflow-x: auto; background: var(--code-bg);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
}
[data-wrap="wrap"] .codeblock pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.codeblock code { font-family: inherit; background: none; padding: 0; }

/* highlight.js token colors mapped onto the Sigma palette. */
.hljs-comment, .hljs-quote { color: var(--faint); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-meta .hljs-keyword, .hljs-template-tag { color: var(--accent-ink); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: var(--ok); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet { color: var(--warn); }
.hljs-title, .hljs-title.function_, .hljs-title.class_, .hljs-section { color: var(--accent); }
.hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-tag { color: var(--accent-ink); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-type { color: var(--warn); }
.hljs-built_in, .hljs-builtin-name { color: var(--accent); }
.hljs-comment *, .hljs-quote * { color: inherit; }
.hljs-deletion { color: var(--danger); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }
.hljs-link { color: var(--accent-ink); text-decoration: underline; }
.math-display { display: block; margin: 10px 0; overflow-x: auto; }

/* ---------- Statusbar ---------- */
.statusbar {
  flex: none; display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 7px 16px; font-size: 10px; letter-spacing: 0.18em; color: var(--faint);
  border-top: 1px solid var(--border);
}
.status-sep { letter-spacing: 0; }

/* ---------- Drawer ---------- */
.drawer {
  width: 340px; flex: none; border-left: 1px solid var(--border); background: var(--rail);
  display: flex; flex-direction: column; z-index: 20;
}
.drawer-tabs { display: flex; align-items: center; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.drawer-tab {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
}
.drawer-tab[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.drawer-close { margin-left: auto; }
.drawer-pane { flex: 1; overflow-y: auto; padding: 14px; font-size: 12.5px; }
.drawer-pane h3 { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); margin: 14px 0 6px; }
.drawer-pane h3:first-child { margin-top: 0; }
.ctx-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.ctx-row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
.ctx-row .k { color: var(--muted); }
.ctx-row .v { text-align: right; overflow-wrap: anywhere; }
.ctx-file {
  border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; margin: 6px 0;
  background: var(--card-soft);
}
.ctx-file .f-name { font-family: var(--mono); font-size: 11.5px; font-weight: 600; }
.ctx-file .f-preview {
  margin-top: 5px; font-family: var(--mono); font-size: 11px; color: var(--muted);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 140px; overflow-y: auto;
}
.act-item { border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; margin: 6px 0; background: var(--card-soft); }
.act-item .a-head { display: flex; gap: 7px; align-items: center; font-size: 12px; }
.act-item .a-status { margin-left: auto; color: var(--muted); font-size: 11px; }

/* ---------- Dialogs ---------- */
.dlg {
  border: 1px solid var(--border-strong); border-radius: 16px; background: var(--paper);
  color: var(--ink); padding: 0; box-shadow: var(--shadow-lg); max-width: min(92vw, 480px);
}
.dlg::backdrop { background: rgba(20, 20, 18, 0.4); }
.dlg-card { padding: 20px; }
.dlg-title { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.dlg-body { margin: 0 0 8px; color: var(--muted); font-size: 13.5px; white-space: pre-wrap; }
.dlg-label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 5px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-wide { max-width: min(94vw, 720px); width: 720px; }
.dlg-palette { max-width: min(94vw, 560px); width: 560px; margin-top: 12vh; align-self: flex-start; }

.text-input, .dlg textarea.text-input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 9px;
  background: var(--card); padding: 8px 11px; font-size: 13.5px; outline: none;
}
.text-input:focus { border-color: var(--accent); }
textarea.text-input { resize: vertical; min-height: 90px; font-family: inherit; line-height: 1.5; }
select.text-input { cursor: pointer; }

.ghost-btn {
  border: 1px solid var(--border-strong); background: transparent; border-radius: 9px;
  padding: 7px 14px; cursor: pointer; font-size: 13px; color: var(--ink);
}
.ghost-btn:hover { border-color: var(--accent); }
.primary-btn {
  border: 0; background: var(--accent); color: var(--on-accent); border-radius: 9px;
  padding: 7px 14px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.primary-btn:hover { background: var(--accent-ink); }
.primary-btn.danger { background: var(--danger); }
.ghost-btn:disabled, .primary-btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* settings dialog */
.settings-wrap { display: flex; min-height: 420px; }
.settings-nav {
  width: 160px; flex: none; border-right: 1px solid var(--border); padding: 14px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.settings-nav button {
  border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 8px;
  cursor: pointer; font-size: 13px; color: var(--muted);
}
.settings-nav button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 500; }
.settings-nav button:hover { color: var(--ink); }
.settings-pane { flex: 1; padding: 18px 20px; overflow-y: auto; max-height: 70vh; }
.settings-pane h2 { margin: 0 0 4px; font-size: 16px; }
.settings-pane .pane-sub { color: var(--muted); font-size: 12px; margin: 0 0 16px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: 0; }
.set-row .set-label { font-size: 13px; }
.set-row .set-label small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.set-row .set-ctl { flex: none; max-width: 260px; }
.set-row .set-ctl .text-input { font-size: 12.5px; padding: 6px 9px; }
.set-note { font-size: 11.5px; color: var(--muted); background: var(--card-soft); border: 1px solid var(--border); border-radius: 9px; padding: 8px 11px; margin: 10px 0; line-height: 1.5; }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong);
  transition: background 0.15s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.dir-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.dir-chip {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px;
  border: 1px solid var(--border); border-radius: 7px; padding: 3px 8px; background: var(--card-soft);
}
.dir-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); display: inline-flex; padding: 0; }
.dir-chip .icon { width: 11px; height: 11px; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.opt-row .opt-name { color: var(--muted); }

/* palette */
.palette-inner { padding: 10px; }
.palette-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--border); background: transparent;
  padding: 10px 8px 12px; font-size: 14.5px; outline: none;
}
.palette-list { max-height: 46vh; overflow-y: auto; padding: 6px 0 2px; }
.palette-item {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none;
  text-align: left; padding: 9px 10px; border-radius: 9px; cursor: pointer; font-size: 13.5px;
}
.palette-item .icon { width: 15px; height: 15px; color: var(--muted); }
.palette-item:hover, .palette-item.sel { background: var(--accent-soft); }
.palette-item .p-sub { margin-left: auto; font-size: 11.5px; color: var(--faint); }
.palette-empty { color: var(--muted); font-size: 13px; padding: 14px 10px; }
.palette-group { font-size: 10px; letter-spacing: 0.12em; color: var(--faint); text-transform: uppercase; padding: 10px 10px 3px; }

/* toasts */
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--card); border: 1px solid var(--border-strong); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow-lg);
  max-width: 340px; animation: toast-in 0.2s ease-out;
}
.toast-error { border-left-color: var(--danger); }
.toast-out { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* workspace + artifacts */
.workdir-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; margin-bottom: 8px;
  border: 1px dashed var(--border); border-radius: 12px;
  color: var(--muted); font-size: 12.5px;
}
.crumb-folder { margin-left: 4px; }
.ctx-path { font-family: var(--mono); font-size: 11px; overflow-wrap: anywhere; }
.artifact-img {
  display: block; max-width: 100%; max-height: 480px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 10px; margin: 8px 0;
  cursor: zoom-in; background: var(--card);
}
.svg-figure { border-top: 1px solid var(--border); padding: 10px 12px; }
.svg-preview {
  display: block; max-width: 100%; max-height: 480px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.svg-toggle { margin-top: 8px; }
.svg-src-hidden { display: none; }
.svg-unavailable { color: var(--muted); font-size: 12px; }
.msg .md table, .data-table {
  border-collapse: collapse; margin: 10px 0; font-size: 13px; max-width: 100%;
}
.msg .md th, .msg .md td, .data-table th, .data-table td {
  border: 1px solid var(--border); padding: 5px 10px; text-align: left; vertical-align: top;
}
.msg .md th, .data-table th { background: var(--card); font-weight: 600; }
.table-wrap { overflow-x: auto; max-width: 100%; }
.results-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.results-head h3 { margin: 0; }
.results-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.result-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 10px;
  display: flex; flex-direction: column; gap: 6px; background: var(--card);
}
.result-thumb {
  width: 100%; max-height: 140px; object-fit: contain; border-radius: 8px;
  background: var(--bg);
}
.result-ph {
  display: flex; align-items: center; justify-content: center; height: 72px;
  color: var(--muted);
}
.result-ph .icon { width: 26px; height: 26px; }
.result-name {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.result-meta { font-size: 11px; color: var(--faint); }
.result-actions { display: flex; gap: 6px; }
.result-actions .ghost-btn { padding: 4px 10px; font-size: 12px; }
.art-dl { text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.art-dl .icon { width: 13px; height: 13px; }
.art-viewer { display: flex; flex-direction: column; min-height: 0; max-height: 82vh; }
.art-viewer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.art-viewer-name { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }
.art-viewer-actions { display: flex; align-items: center; gap: 8px; }
.art-viewer-body {
  padding: 14px 16px; overflow: auto; min-height: 120px;
}
.art-full { display: block; max-width: 100%; max-height: 64vh; object-fit: contain; margin: 0 auto; }
.art-frame { display: block; width: 100%; height: 64vh; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
/* A generated HTML artifact is a whole app/page. Use nearly the full browser
   viewport so canvas and fixed-size layouts are not clipped by the generic
   720px document-preview dialog. */
.dlg.art-html-dialog {
  width: 96vw; max-width: 96vw; height: 92vh; max-height: 92vh;
}
.art-viewer-html { height: 100%; max-height: none; }
.art-viewer-html .art-viewer-body {
  display: flex; flex: 1; min-height: 0; padding: 0; overflow: hidden;
}
.art-viewer-html .art-frame {
  flex: 1; width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0;
}
.art-text {
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap;
  overflow-wrap: anywhere; margin: 0; max-height: 60vh; overflow: auto;
}
.folder-card { display: flex; flex-direction: column; gap: 8px; min-height: 320px; }
.folder-bar { display: flex; gap: 8px; align-items: center; }
.folder-bar .text-input { flex: 1; }
.folder-list {
  border: 1px solid var(--border); border-radius: 10px; overflow-y: auto;
  max-height: 300px; min-height: 140px; padding: 4px;
}
.folder-recent { max-height: 120px; min-height: 0; margin-bottom: 4px; }
.folder-name { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; text-align: left; }

/* responsive */
@media (max-width: 900px) {
  .rail {
    position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%);
    transition: transform 0.2s ease; box-shadow: var(--shadow-lg);
  }
  .rail.open { transform: translateX(0); }
  .icon-btn.rail-toggle { display: inline-flex; }
  .icon-btn.rail-close { display: inline-flex; }
  .drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 92vw); box-shadow: var(--shadow-lg); }
  .landing-title { font-size: 32px; }
  .chat-inner { padding: 14px 14px 10px; }
  .composer-slot.docked { padding: 8px 12px 10px; }
  .msg.user .msg-body { max-width: 88%; }
  .composer-bar { flex-wrap: wrap; }
  .composer-bar .send-btn { margin-left: auto; }
  .chip-btn .chip-label { display: none; }
  .chip-btn { padding: 5px 9px; }
  .model-btn, .mode-btn { max-width: 130px; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 10px 12px; }
  .settings-wrap { flex-direction: column; min-height: 0; }
  .settings-nav {
    width: 100%; flex-direction: row; overflow-x: auto; border-right: 0;
    border-bottom: 1px solid var(--border); padding: 8px; gap: 4px;
  }
  .settings-nav button { white-space: nowrap; }
  .set-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .set-row .set-ctl { max-width: 100%; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
[data-motion="reduce"] *, [data-motion="reduce"] *::before, [data-motion="reduce"] *::after {
  animation-duration: 0.001s !important; transition-duration: 0.001s !important;
}

/* ---- Projects ---- */
.thread-group-projects { display: flex; align-items: center; justify-content: space-between; padding-right: 4px; }
.group-add {
  border: 0; background: transparent; color: var(--faint); cursor: pointer;
  padding: 2px; border-radius: 5px; display: inline-flex;
}
.group-add:hover { color: var(--ink); background: var(--card); }
.group-add .icon { width: 12px; height: 12px; }
.threads-empty-projects { padding: 4px 10px 10px; font-size: 11.5px; }
.project-row {
  display: flex; align-items: center; gap: 4px; width: 100%;
  border-radius: 8px; padding: 4px; color: var(--ink); font-size: 13px;
}
.project-row:hover { background: var(--card); }
.project-row .p-open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: inherit; font: inherit; text-align: left;
  padding: 4px; border-radius: 6px; cursor: pointer;
}
.project-row .p-icon { color: var(--accent); display: inline-flex; }
.project-row .p-icon .icon { width: 13px; height: 13px; }
.project-row .p-count { color: var(--faint); font-size: 11px; }
.project-row > button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 3px; border-radius: 5px; display: none;
}
.project-row:hover > button, .project-row:focus-within > button { display: inline-flex; }
.project-row > button:hover { color: var(--ink); background: var(--rail); }
.project-row > button .icon { width: 13px; height: 13px; }
.thread-item.in-project { padding-left: 22px; }

/* Drag & drop project assignment */
.thread-item[draggable="true"] { cursor: grab; }
.thread-item.dragging { opacity: 0.45; }
#thread-list.drag-active .project-row,
#thread-list.drag-active .chats-zone {
  outline: 1px dashed var(--border-strong);
  outline-offset: -1px;
  border-radius: 8px;
}
.project-row.drop-hover, .thread-item.drop-hover {
  background: var(--accent-soft, var(--card));
  box-shadow: inset 0 0 0 1px var(--accent);
}
.chats-zone.drop-hover {
  outline: 1px dashed var(--accent) !important;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.chats-zone { min-height: 24px; }

.project-page { flex: 1; min-height: 0; overflow-y: auto; }
.project-content { max-width: var(--chat-max); margin: 0 auto; padding: 28px 28px 60px; }
.project-content h2 { margin: 0; font-size: 22px; }
.project-content h3 { margin: 26px 0 8px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.proj-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.proj-head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.proj-instructions {
  width: 100%; resize: vertical; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 8px; background: var(--card);
  color: var(--ink); font: inherit; font-size: 13.5px; padding: 10px 12px;
}
.proj-instructions:focus { outline: none; border-color: var(--accent); }
.proj-instructions + .ghost-btn { margin-top: 8px; }
.proj-files, .proj-chats { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; }
.proj-file, .proj-chat {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--card);
}
.proj-file .pf-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); text-decoration: none; font-size: 13.5px; }
.proj-file .pf-name:hover { text-decoration: underline; }
.proj-file .pf-size { color: var(--faint); font-size: 11.5px; flex-shrink: 0; }
.proj-chat .pc-open {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13.5px;
  text-align: left; cursor: pointer; padding: 0;
}
.proj-chat .pc-open:hover { color: var(--accent); }
.proj-file .icon-btn, .proj-chat .icon-btn { color: var(--muted); }
.proj-file .icon-btn:hover, .proj-chat .icon-btn:hover { color: var(--ink); }
.ghost-btn.danger:hover { border-color: var(--danger, #c0392b); color: var(--danger, #c0392b); }

.pop-menu {
  z-index: 60; min-width: 160px; padding: 4px;
  background: var(--card); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35); display: flex; flex-direction: column;
}
.pop-menu button {
  border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13px;
  text-align: left; padding: 7px 10px; border-radius: 6px; cursor: pointer;
}
.pop-menu button:hover { background: var(--card); }
.pop-menu button.checked { color: var(--accent); }

.extension-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 12px 0; }
.extension-card textarea { width: 100%; resize: vertical; font: 12px/1.6 var(--mono); }
.extension-card > button { margin-top: 8px; }
.skill-install { display: flex; gap: 8px; align-items: center; margin: 10px 0 4px; flex-wrap: wrap; }
.skill-install .text-input { flex: 1; min-width: 200px; }
.skill-desc { margin: 8px 0 0; font-size: 12.5px; color: var(--ink); }
.skill-meta { margin: 4px 0 0; font-size: 11.5px; color: var(--muted); }
.skill-actions { display: flex; gap: 8px; margin-top: 10px; }
.skill-actions .ghost-btn { margin-top: 0; }
.skill-editor { margin-top: 10px; }
.skill-editor input.text-input { width: 100%; margin-bottom: 8px; }
.skill-editor textarea { width: 100%; resize: vertical; font: 12px/1.6 var(--mono); }
.skill-editor .dlg-actions { margin-top: 8px; justify-content: flex-end; }
