/* ============================================================
   Claude Sessions — "Ink & Ember"
   Editorial-terminal aesthetic: warm espresso ink, ember accent,
   typeset transcript instead of generic chat bubbles.
   ============================================================ */

:root {
  --bg:        #1c1b18;   /* warm charcoal page (Claude-like, less brown) */
  --ink:       #242320;   /* panels / sidebar */
  --ink-2:     #2d2b27;   /* raised: sheet, inputs, chips */
  --ink-3:     #37342f;   /* hover / active chip */
  --line:      #3a3832;
  --line-soft: #2f2d28;

  --text:      #ece9e2;
  --text-dim:  #b3ab9d;
  --muted:     #8a8273;
  --text-strong: #fbf9f5;   /* bolded prose — brighter than body */

  --ember:     #e2703a;
  --ember-lt:  #f0945f;
  --ember-dk:  #c25a2b;
  --gold:      #cdab68;
  --accent-blue: #6ea8fe;

  --user-bg:   #2c281f;
  --user-line: #473f29;

  /* surfaces & structural fills (abstracted so light mode can remap them) */
  --surface:       #201e1b;   /* card base: tool / ask / think / fold */
  --surface-2:     #191714;   /* deeper inset: tool body, code, tables */
  --surface-soft:  #201e1b99; /* faint card (think / fold) over the page */
  --surface-hover: #262320;   /* row / header hover */
  --page-grad:     #1f1d1a;   /* body bottom gradient stop */
  --th-bg:         #1a1815;   /* table header */
  --code-text:     #e5ddcc;   /* code inside prose */
  --row-hover:     #ffffff06; /* faint hover tint on table rows */
  --ask-grad-top:  #262320;   /* ask-card gradient top */
  --sel-bg:        #2f241a;   /* ember-tinted selected option bg */

  /* shadows + modal/sheet scrim */
  --shadow-1: #00000033;
  --shadow-2: #00000088;
  --shadow-3: #000000bb;
  --overlay:  #00000088;

  /* semantic accents (danger red, ok green) */
  --danger:            #d8503a;
  --danger-hover:      #e0664f;
  --danger-strong:     #df5030;
  --danger-strong-hov: #c4421f;
  --danger-text:       #df7c66;
  --danger-text-lt:    #f0b8a4;
  --danger-tname:      #e58a6e;
  --danger-border:     #7c3a26;
  --danger-soft:       #df503018;
  --err-bg:            #2a1610;
  --ok:                #7d9a5c;

  --radius:    14px;
  --radius-sm: 9px;

  --font-display: serif;       /* browser default serif (headings, logo, greetings) */
  --font-body:    sans-serif;  /* browser default sans (UI / body text) */
  --font-mono:    monospace;   /* browser default monospace (code, ids, labels) */
}

/* ============================================================
   Light mode — warm "paper & ember" remap. Applied when the resolved
   theme is light; the inline <head> script + setTheme() set
   <html data-theme="light|dark"> (resolving "system" via matchMedia),
   so no @media duplication is needed. Every value overrides a :root
   token so all components flip together.
   ============================================================ */
:root[data-theme="light"] {
    --bg:        #faf8f2;   /* clean warm paper (Claude-like cream) */
    --ink:       #fffefb;   /* panels / sidebar — near-white */
    --ink-2:     #f3f0e7;   /* raised: sheet, inputs, chips */
    --ink-3:     #e9e4d7;   /* hover / active chip */
    --line:      #e4dfd0;
    --line-soft: #efebe0;

    --text:      #282520;   /* espresso ink */
    --text-dim:  #615849;
    --muted:     #8c8270;
    --text-strong: #181510; /* bolded prose — darker than body */

    --ember:     #c4571f;   /* darker ember reads on light */
    --ember-lt:  #ab4a18;   /* link / hover text → darker, not lighter */
    --ember-dk:  #a4451a;
    --gold:      #927226;   /* readable mustard for labels */
    --accent-blue: #2563c9; /* stronger blue for contrast */

    --user-bg:   #fbe7d4;   /* warm peach user bubble */
    --user-line: #e6b187;   /* peach border */

    --surface:       #fffefb;
    --surface-2:     #f4f1e8;
    --surface-soft:  #fffefbb3;
    --surface-hover: #f0ece0;
    --page-grad:     #f4f1e8;
    --th-bg:         #f0ece0;
    --code-text:     #4a4030;
    --row-hover:     #00000008;
    --ask-grad-top:  #fff8ef;
    --sel-bg:        #fbe4d3;

    --shadow-1: #0000000d;
    --shadow-2: #00000016;
    --shadow-3: #00000022;
    --overlay:  #0000003d;

    --danger:            #c33c1f;
    --danger-hover:      #a82f17;
    --danger-strong:     #c63619;
    --danger-strong-hov: #a82f17;
    --danger-text:       #b23a1d;
    --danger-text-lt:    #9a2e15;
    --danger-tname:      #a83c1d;
    --danger-border:     #e6b2a2;
    --danger-soft:       #c33c1f18;
    --err-bg:            #fbe4dc;
    --ok:                #5e7d3e;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* --- atmosphere: grain + warm glow --- */
.grain {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none; opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.glow {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(620px 480px at 16% -8%, #e2703a18, transparent 70%),
    radial-gradient(720px 560px at 100% 110%, #cdab6810, transparent 70%);
}

/* 100dvh tracks the *visible* viewport (excludes mobile browser chrome / keyboard),
   so the composer never gets pushed under the URL bar. 100vh is the fallback. */
#app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; }

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar {
  width: 296px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--ink) 0%, var(--page-grad) 100%);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow: hidden; transition: width .22s ease; /* desktop collapse animates width */
}

/* Sidebar collapse (desktop) — like the mobile drawer, but reflows instead of overlaying. */
#sidebar-collapse-btn {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 7px; transition: all .15s;
}
#sidebar-collapse-btn:hover { color: var(--text); background: var(--ink-2); }
#sidebar-collapse-btn svg { width: 18px; height: 18px; }
.sidebar-expand {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 45;
  width: 34px; height: 34px; align-items: center; justify-content: center;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 10px; color: var(--text-dim); cursor: pointer; transition: all .15s;
}
.sidebar-expand:hover { color: var(--text); border-color: var(--gold); }
.sidebar-expand svg { width: 20px; height: 20px; }
@media (min-width: 769px) {
  html.sidebar-collapsed #sidebar { width: 0; min-width: 0; border-right: none; }
  html.sidebar-collapsed .sidebar-expand { display: flex; }
  /* clear the floating expand button so it doesn't overlap top-left titles */
  html.sidebar-collapsed #chat-head { padding-left: 60px; }
  html.sidebar-collapsed .files-panel { padding-left: 60px; }
}
@media (max-width: 768px) { #sidebar-collapse-btn, .sidebar-expand { display: none !important; } }

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 22px 18px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand .brand-mark { display: none; } /* sidebar wordmark only — hide the icon */
.brand-mark { display: inline-flex; color: var(--ember); filter: drop-shadow(0 0 10px #e2703a55); }
.brand-mark .brand-logo { width: 20px; height: 20px; display: block; }
.brand-logo { width: 1em; height: 1em; }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-name { font-family: var(--font-display); font-size: 20px; font-weight: 500; letter-spacing: .01em; }
.brand-sub  { font-family: var(--font-mono); font-size: 10px; letter-spacing: .32em; text-transform: uppercase; color: var(--gold); margin-top: 4px; }

#new-btn {
  width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--ink-2); color: var(--text-dim);
  font-size: 20px; display: grid; place-items: center; line-height: 0;
  transition: all .18s ease;
}
#new-btn:hover { background: var(--ember); border-color: var(--ember); color: #fff; transform: rotate(90deg); box-shadow: 0 4px 16px #e2703a55; }

.list-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .28em;
  text-transform: uppercase; color: var(--muted);
  padding: 4px 24px 10px;
}

#session-list { list-style: none; margin: 0; padding: 0 12px 16px; overflow-y: auto; flex: 1; }
#session-list::-webkit-scrollbar { width: 7px; }
#session-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.session-item {
  position: relative; padding: 13px 14px 13px 16px; border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 3px; border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease;
}
/* Entrance plays only on items first seen (initial load / a newly created
   session), not on every re-render — so the list doesn't flash on updates. */
.session-item.enter { animation: card-in .4s cubic-bezier(.2,.7,.3,1) backwards; }
@keyframes card-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.session-item::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%) scaleY(0);
  width: 3px; height: 60%; background: var(--ember); border-radius: 3px;
  transition: transform .2s ease;
}
.session-item:hover { background: var(--ink-2); }
.session-item.active { background: var(--ink-2); border-color: var(--line); }
.session-item.active::before { transform: translateY(-50%) scaleY(1); }

.session-item .s-title {
  font-size: 14px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 20px;
}
.session-item .s-meta { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.session-item .s-id {
  font-family: var(--font-mono); font-size: 11px; color: var(--gold); opacity: .8;
}
.session-item .s-time { font-size: 11px; color: var(--muted); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 #7d9a5c00; flex-shrink: 0; }
.dot.running { background: var(--ember); animation: live 1.3s ease-in-out infinite; }
@keyframes live {
  0%,100% { box-shadow: 0 0 0 0 #e2703a88; }
  50%     { box-shadow: 0 0 0 5px #e2703a00; }
}

.session-item .del {
  position: absolute; right: 9px; top: 11px; opacity: 0;
  width: 22px; height: 22px; border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 13px; border-radius: 6px; transition: all .15s;
}
.session-item:hover .del { opacity: 1; }
.session-item .del:hover { color: var(--ember); background: var(--ink-3); }

code {
  font-family: var(--font-mono); font-size: .86em;
  background: var(--ink-3); color: var(--gold);
  padding: 1.5px 6px; border-radius: 5px; border: 1px solid var(--line-soft);
}

/* ============================================================
   Main column
   ============================================================ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* hamburger + drawer backdrop — desktop hides them, mobile media query shows them */
.menu-btn { display: none; }
.drawer-backdrop { display: none; }

#chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 32px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg), transparent); backdrop-filter: blur(4px);
}
/* Home/empty state has no title — drop the bare header bar (desktop; mobile keeps it for the menu button). */
#main.no-session #chat-head { display: none; }
#chat-title {
  font-family: var(--font-display); font-size: 22px; font-weight: 500;
  letter-spacing: .005em; line-height: 1.2;
  max-width: 60ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#chat-title.editable { cursor: text; }
#chat-title.editable:hover { text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 4px; }
.title-edit {
  font-family: var(--font-display); font-size: 22px; font-weight: 500; letter-spacing: .005em;
  width: min(60ch, 100%); color: var(--text); background: var(--ink-3);
  border: 1px solid var(--gold); border-radius: 8px; padding: 2px 8px; outline: none;
}
#chat-sub { font-family: var(--font-mono); font-size: 11.5px; color: var(--gold); opacity: .75; margin-top: 5px; }
#chat-sub:empty { display: none; }

.head-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

/* composer model+effort trigger — opens the bottom sheet */
.model-trigger {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text);
  background: var(--ink); border: 1px solid var(--line); border-radius: 100px;
  padding: 6px 12px; cursor: pointer; transition: border-color .15s;
}
.model-trigger:hover { border-color: var(--gold); }
.model-trigger .mt-effort {
  color: var(--ember-lt); padding-left: 7px; border-left: 1px solid var(--line);
}
.model-trigger .mt-chev { color: var(--gold); opacity: .8; }

/* ---- bottom sheet (model → effort drilldown) ---- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center;
  background: var(--overlay); backdrop-filter: blur(2px);
  animation: sheet-fade .18s ease;
}
.sheet-overlay.hidden { display: none; }
@keyframes sheet-fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: relative; width: 100%; max-width: 460px; max-height: 82vh; overflow: hidden;
  background: var(--ink-2); border: 1px solid var(--line); border-bottom: none;
  border-radius: 18px 18px 0 0; box-shadow: 0 -10px 40px var(--shadow-3);
  padding: 6px 0 max(14px, env(safe-area-inset-bottom));
  animation: sheet-up .24s cubic-bezier(.22,1,.36,1);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Desktop: render the sheet as an anchored dropdown (no dim, no slide-up). */
@media (min-width: 769px) {
  .sheet-overlay.popover { display: block; background: none; backdrop-filter: none; animation: none; }
  .sheet-overlay.popover .sheet {
    position: fixed; width: 300px; max-width: 300px; max-height: 64vh;
    border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 16px 44px var(--shadow-3); padding: 6px 0 8px;
    animation: popover-in .14s ease;
  }
  .sheet-overlay.popover .sheet-grip { display: none; }
  .sheet-overlay.popover .sheet-panel { max-height: calc(64vh - 24px); }
}
@keyframes popover-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.sheet-grip { width: 38px; height: 4px; border-radius: 4px; background: var(--line); margin: 6px auto 4px; }
/* the two panels share the same box; data-panel decides which shows */
.sheet-panel { display: none; flex-direction: column; max-height: calc(82vh - 24px); }
.sheet[data-panel="model"]  .panel-model  { display: flex; }
.sheet[data-panel="effort"] .panel-effort { display: flex; }
.sheet-head {
  position: relative; display: flex; align-items: center; justify-content: center;
  padding: 10px 12px 12px; min-height: 24px;
}
.sheet-title { font-family: var(--font-display); font-size: 17px; font-weight: 600; color: var(--text); }
.sheet-icon-btn {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: var(--ink-3); color: var(--text-dim); cursor: pointer; transition: all .15s;
}
.sheet-icon-btn:hover { background: var(--line); color: var(--text); }
.sheet-list { overflow-y: auto; padding: 0 10px; }
.sheet-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 12px; border: none; background: none; cursor: pointer;
  border-radius: 12px; transition: background .14s; font: inherit;
}
.sheet-row:hover { background: var(--ink-3); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.row-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.row-sub.unsupported { color: var(--ember-dk); }
.row-badge {
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 600; letter-spacing: .04em;
  color: var(--text-dim); background: var(--ink-3); border: 1px solid var(--line);
  padding: 2px 7px; border-radius: 100px; text-transform: none;
}
.row-check { width: 22px; flex-shrink: 0; color: var(--accent-blue); opacity: 0; }
.row-check svg { width: 22px; height: 22px; display: block; }
.sheet-row.opt.selected .row-title,
.sheet-row.opt.selected .row-sub { color: var(--accent-blue); }
.sheet-row.opt.selected .row-check { opacity: 1; }
.sheet-sep { height: 1px; background: var(--line); margin: 6px 18px; }
.sheet-drill .row-chev { color: var(--muted); flex-shrink: 0; }
.sheet-note { padding: 14px 14px 6px; color: var(--muted); font-size: 13px; }
/* thinking toggle switch */
.row-switch {
  flex-shrink: 0; width: 42px; height: 25px; border-radius: 100px;
  background: var(--ink-3); border: 1px solid var(--line); position: relative; transition: all .18s;
}
.row-switch-knob {
  position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%;
  background: var(--text-dim); transition: all .18s;
}
.sheet-toggle.on .row-switch { background: var(--accent-blue); border-color: var(--accent-blue); }
.sheet-toggle.on .row-switch-knob { left: 19px; background: #fff; }

.head-status {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-dim); padding: 6px 13px; border: 1px solid var(--line); border-radius: 100px; background: var(--ink);
}
.head-status .status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.head-status.busy .status-dot { background: var(--ember); animation: live 1.3s infinite; }
.head-status.busy { color: var(--ember-lt); border-color: var(--ember-dk); }
.hidden { display: none !important; }

/* ============================================================
   Messages — typeset transcript
   ============================================================ */
#messages {
  flex: 1; overflow-y: auto; padding: 34px 0 28px;
  display: flex; flex-direction: column; gap: 26px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 10px; }
#messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; border: 2px solid var(--bg); }

.load-earlier {
  align-self: center; cursor: pointer; flex: none;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 100px;
  color: var(--text-dim); font-family: var(--font-body); font-size: 12.5px; font-weight: 500;
  padding: 7px 16px; transition: border-color .15s, color .15s;
}
.load-earlier:hover { border-color: var(--gold); color: var(--text); }

.msg, .tool, .thinking-live, .banner-error { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 32px; }

.role-tag {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .24em;
  text-transform: uppercase; margin-bottom: 9px; display: flex; align-items: center; gap: 8px;
}
.role-tag::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line), transparent); }

/* user — right-aligned ember card */
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  max-width: 80%; background: var(--user-bg); border: 1px solid var(--user-line);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 13px 17px; line-height: 1.62; white-space: pre-wrap; word-break: break-word;
  color: var(--text); box-shadow: 0 2px 14px var(--shadow-1);
}
.msg.user .role-tag { color: var(--ember); justify-content: flex-end; align-self: flex-end; }
.msg.user .role-tag::after { display: none; }
.msg.user .role-tag::before { content: ""; width: 26px; height: 1px; background: linear-gradient(90deg, transparent, var(--ember-dk)); }
/* CLI-injected context turn (e.g. image size note) — agent's own user message,
   NOT something the human sent. Muted dashed inset so it's never read as "You". */
.meta-note {
  align-self: stretch; max-width: 100%; /* fill the turn column so the line can clamp (turn-body is align-items:flex-start) */
  display: flex; align-items: baseline; gap: 9px; margin: 5px 0;
  padding: 7px 12px; border-radius: 8px; cursor: pointer; overflow: hidden;
  background: var(--surface-soft); border: 1px dashed var(--line);
  font-family: var(--font-mono); font-size: 11.5px; color: var(--muted);
  transition: border-color .14s;
}
.meta-note:hover { border-color: var(--muted); }
.meta-note-tag {
  flex: none; font-size: 9px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px;
}
/* Collapsed: a single clamped line; click toggles `.expanded` to reveal it all. */
.meta-note-text { flex: 1; min-width: 0; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta-note.expanded .meta-note-text { white-space: pre-wrap; word-break: break-word; overflow: visible; }
.meta-note-toggle { flex: none; font-size: 10px; color: var(--muted); transition: transform .15s; align-self: center; }
.meta-note.expanded .meta-note-toggle { transform: rotate(90deg); }
/* Queued message (typed while a turn is running) */
.msg.user.queued .role-tag { color: var(--muted); }
.msg.user.queued .role-tag::before { background: linear-gradient(90deg, transparent, var(--line)); }
.msg.user.queued .bubble {
  background: none; border-style: dashed; border-color: var(--line); color: var(--text-dim);
  box-shadow: none; display: flex; align-items: center; gap: 10px;
}
.q-del {
  flex: none; background: none; border: none; cursor: pointer; color: var(--muted);
  display: inline-flex; padding: 2px; border-radius: 5px; transition: color .15s, background .15s;
}
.q-del:hover { color: var(--text); background: var(--ink-3); }
.q-del .ic { width: 13px; height: 13px; }

/* assistant — one "turn" under a single label: text + tools share an ember rule */
.msg.assistant .role-tag { color: var(--gold); }
.turn-body {
  border-left: 2px solid var(--ember-dk); padding-left: 18px;
  display: flex; flex-direction: column; gap: 12px; align-items: flex-start;
}
.turn-text { line-height: 1.74; color: var(--text); word-break: break-word; align-self: stretch; }
.turn-text > *:first-child { margin-top: 0; }
.turn-text > *:last-child { margin-bottom: 0; }
.turn-text.think { font-style: italic; color: var(--text-dim); font-size: 14px; }
.turn-text.live-text { white-space: pre-wrap; }

.turn-working { display: flex; align-items: center; gap: 9px; color: var(--ember-lt); }
.turn-working .caret { width: 9px; height: 18px; background: var(--ember); animation: caret 1s steps(2) infinite; border-radius: 1px; }
.turn-working .tl-text { font-family: var(--font-mono); font-size: 12px; letter-spacing: .12em; }
.turn-working .tl-text::after { content: ""; animation: dots 1.4s steps(4,end) infinite; }

/* markdown inside assistant text */
.turn-text p { margin: 0 0 .85em; }
.turn-text h1, .turn-text h2, .turn-text h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.3; margin: 1.1em 0 .5em; }
.turn-text h1 { font-size: 1.45em; } .turn-text h2 { font-size: 1.28em; } .turn-text h3 { font-size: 1.12em; }
.turn-text ul, .turn-text ol { margin: .5em 0 .9em; padding-left: 1.4em; }
.turn-text li { margin: .3em 0; }
.turn-text a { color: var(--ember-lt); text-decoration: none; border-bottom: 1px solid #f0945f55; }
.turn-text a:hover { border-bottom-color: var(--ember-lt); }
.turn-text strong { color: var(--text-strong); font-weight: 600; }
.turn-text em { font-style: italic; color: var(--text); }
.turn-text blockquote { margin: .7em 0; padding: 2px 0 2px 14px; border-left: 2px solid var(--line); color: var(--text-dim); font-style: italic; }
.turn-text pre {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; overflow-x: auto; margin: .8em 0; font-size: 13px; line-height: 1.6;
}
.turn-text pre code { background: none; border: none; padding: 0; color: var(--code-text); font-size: 13px; }
.turn-text :not(pre) > code { color: var(--gold); }
/* clickable workspace-file path (chat inline code + tool-card summary) */
code.fpath { cursor: pointer; color: var(--ember-lt); text-decoration: underline; text-decoration-color: #f0945f66; text-underline-offset: 2px; }
code.fpath:hover { text-decoration-color: var(--ember-lt); }
.tool-head .tsummary.fpath { color: var(--ember-lt); cursor: pointer; text-decoration: underline; text-decoration-color: #f0945f55; text-underline-offset: 2px; }
.tool-head .tsummary.fpath:hover { text-decoration-color: var(--ember-lt); }
.turn-text hr { border: none; border-top: 1px solid var(--line); margin: 1.2em 0; }

/* markdown tables */
.turn-text .table-wrap {
  overflow-x: auto; margin: .85em 0;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2);
}
.turn-text table { border-collapse: collapse; width: 100%; font-size: 13.5px; line-height: 1.55; }
.turn-text th, .turn-text td {
  padding: 8px 13px; border-bottom: 1px solid var(--line-soft);
  text-align: left; vertical-align: top;
}
.turn-text th + th, .turn-text td + td { border-left: 1px solid var(--line-soft); }
.turn-text thead th {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--gold); background: var(--th-bg);
  font-weight: 500; white-space: nowrap;
}
.turn-text tbody tr:last-child td { border-bottom: none; }
.turn-text tbody tr:hover td { background: var(--row-hover); }

/* thinking (transcript) */
.msg.think .role-tag { color: var(--muted); }
.msg.think .bubble {
  border-left: 2px dashed var(--line); padding-left: 18px;
  font-style: italic; color: var(--text-dim); line-height: 1.7; font-size: 14px;
}

/* tool calls — one slim collapsible card per tool, nested inside the turn */
.tool-card {
  border: 1px solid var(--line-soft); border-radius: 9px; background: var(--surface);
  overflow: hidden; font-family: var(--font-mono); width: fit-content; max-width: 100%;
}
.tool-card.error { border-color: var(--danger-border); }
.tool-head {
  display: flex; align-items: center; gap: 9px; padding: 6px 12px; cursor: pointer;
  font-size: 12px; color: var(--text-dim); user-select: none; line-height: 1;
}
.tool-head:hover { background: var(--surface-hover); }
.tool-head .tdot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.tool-head .tdot.ok  { background: var(--gold); }
.tool-head .tdot.err { background: var(--ember); }
.tool-head .tname { color: var(--gold); font-weight: 500; flex-shrink: 0; }
.tool-card.error .tname { color: var(--danger-tname); }
.tool-head .tsummary {
  min-width: 0; max-width: 52ch; flex: 0 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); font-size: 11.5px;
}
.tool-head .chev { margin-left: 4px; transition: transform .2s; color: var(--muted); font-size: 10px; }
.tool-card.open .chev { transform: rotate(90deg); }

.tool-body { display: none; border-top: 1px solid var(--line-soft); background: var(--surface-2); }
.tool-card.open .tool-body { display: block; }
.tsec { padding: 8px 12px; }
.tsec + .tsec { border-top: 1px solid var(--line-soft); }
.tsec-label {
  font-size: 9.5px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 5px;
}
.tsec pre {
  margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 11.5px;
  line-height: 1.55; color: var(--text-dim); max-height: 300px; overflow: auto;
}

/* AskUserQuestion — interactive choice card (single/multi select + Other) */
.ask-card {
  align-self: stretch; max-width: 640px; overflow: hidden;
  border: 1px solid var(--ember-dk); border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--ask-grad-top), var(--surface));
  box-shadow: 0 2px 18px var(--shadow-1);
}
.ask-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.ask-badge {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: #fff; background: var(--ember); padding: 3px 8px; border-radius: 100px; flex-shrink: 0;
}
.ask-badge.done { background: var(--muted); }
.ask-title { font-size: 13px; color: var(--text-dim); }
.ask-groups { padding: 6px 14px 4px; }
.ask-q { padding: 10px 0; }
.ask-q + .ask-q { border-top: 1px solid var(--line-soft); }
.ask-q-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ask-chip {
  font-size: 11px; font-weight: 600; color: var(--gold);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px;
}
.ask-mode { font-family: var(--font-mono); font-size: 10px; color: var(--muted); }
.ask-question { font-size: 14.5px; color: var(--text); line-height: 1.5; margin-bottom: 9px; }
.ask-options { display: flex; flex-direction: column; gap: 7px; }
.ask-opt {
  display: flex; align-items: flex-start; gap: 10px; text-align: left; width: 100%;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--ink); color: var(--text); cursor: pointer; transition: all .14s; font: inherit;
}
.ask-opt:hover { border-color: var(--ember-dk); background: var(--ink-2); }
.ask-opt.selected { border-color: var(--ember); background: var(--sel-bg); box-shadow: 0 0 0 1px var(--ember) inset; }
.ask-mark {
  flex-shrink: 0; width: 16px; height: 16px; margin-top: 2px;
  border: 1.5px solid var(--muted); position: relative; transition: all .14s;
}
.ask-mark.single { border-radius: 50%; }
.ask-mark.multi { border-radius: 4px; }
.ask-opt.selected .ask-mark { border-color: var(--ember); background: var(--ember); }
.ask-opt.selected .ask-mark::after {
  content: ""; position: absolute; inset: 0; margin: auto;
}
.ask-opt.selected .ask-mark.single::after { width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.ask-opt.selected .ask-mark.multi::after {
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.ask-opt-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ask-opt-label { font-size: 13.5px; font-weight: 500; }
.ask-opt-desc { font-size: 12px; color: var(--text-dim); line-height: 1.45; }
.ask-other-input {
  margin-top: 7px; width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--ink); color: var(--text); font: inherit; font-size: 13.5px;
}
.ask-other-input:focus { outline: none; border-color: var(--ember); }
.ask-foot { padding: 4px 14px 14px; }
.ask-submit {
  width: 100%; padding: 10px; border: none; border-radius: var(--radius-sm);
  background: var(--ember); color: #fff; font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all .14s;
}
.ask-submit:hover { background: var(--ember-lt); box-shadow: 0 4px 16px #e2703a55; }
.ask-card.locked { border-color: var(--line); opacity: .82; }
.ask-card.locked .ask-opt { cursor: default; }
.ask-card.locked .ask-opt:not(.selected) { opacity: .5; }
.ask-card.locked .ask-opt.selected { border-color: var(--muted); box-shadow: 0 0 0 1px var(--muted) inset; background: var(--ink-2); }
.ask-card.locked .ask-opt.selected .ask-mark { border-color: var(--muted); background: var(--muted); }

/* thinking — collapsed-by-default card; expands to the full italic monologue */
.think-card {
  align-self: stretch; overflow: hidden;
  border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-soft);
}
.think-head {
  display: flex; align-items: center; gap: 9px; padding: 6px 12px;
  cursor: pointer; user-select: none; line-height: 1;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
}
.think-head:hover { background: var(--surface-hover); }
.think-icon { color: var(--gold); opacity: .65; font-size: 12px; }
.think-label { letter-spacing: .2em; text-transform: uppercase; flex-shrink: 0; }
.think-preview {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-body); font-style: italic; font-size: 12px; opacity: .85;
}
.think-card .chev { transition: transform .2s; color: var(--muted); font-size: 10px; flex-shrink: 0; }
.think-card.open .chev { transform: rotate(90deg); }
.think-body {
  display: none; padding: 11px 14px 13px; border-top: 1px dashed var(--line-soft);
  font-style: italic; color: var(--text-dim); font-size: 13.5px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
}
.think-card.open .think-body { display: block; }
.think-card.live-think { border-color: var(--user-line); }
.live-think .think-head { cursor: default; }
.think-dots { font-family: var(--font-mono); font-size: 11px; color: var(--ember-lt); }
.think-dots::after { content: ""; animation: dots 1.4s steps(4,end) infinite; }

/* folded fallback — the CLI's auto-reject ramble after an ask card, hidden by default */
.fold-card {
  align-self: stretch; overflow: hidden;
  border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-soft);
}
.fold-head {
  display: flex; align-items: center; gap: 9px; padding: 6px 12px;
  cursor: pointer; user-select: none; line-height: 1;
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
}
.fold-head:hover { background: var(--surface-hover); }
.fold-icon { color: var(--gold); opacity: .5; font-size: 12px; }
.fold-label { letter-spacing: .12em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fold-card .chev { transition: transform .2s; color: var(--muted); font-size: 10px; flex-shrink: 0; }
.fold-card.open .chev { transform: rotate(90deg); }
.fold-body {
  display: none; padding: 10px 14px 12px; border-top: 1px dashed var(--line-soft);
  color: var(--text-dim); font-size: 13px; line-height: 1.65; word-break: break-word;
}
.fold-card.open .fold-body { display: block; }
.fold-body p:first-child { margin-top: 0; }
.fold-body p:last-child { margin-bottom: 0; }

/* inline caret on the live streaming bubble */
.caret-inline {
  display: inline-block; width: 8px; height: 1.05em; margin-left: 2px;
  background: var(--ember); border-radius: 1px; vertical-align: text-bottom;
  animation: caret 1s steps(2) infinite;
}
.msg.streaming .bubble { white-space: pre-wrap; }

/* live thinking indicator */
.thinking-live { display: flex; align-items: center; gap: 11px; color: var(--ember-lt); }
.thinking-live .caret { width: 9px; height: 18px; background: var(--ember); animation: caret 1s steps(2) infinite; border-radius: 1px; }
@keyframes caret { 0%,100% { opacity: 1; } 50% { opacity: .15; } }
.thinking-live .tl-text { font-family: var(--font-mono); font-size: 12.5px; letter-spacing: .06em; }
.thinking-live .tl-text::after { content: ""; animation: dots 1.4s steps(4,end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "·"; } 50% { content: "··"; } 75% { content: "···"; } }

.banner-error {
  background: var(--err-bg); border: 1px solid var(--danger-border); color: var(--danger-text-lt);
  padding: 12px 16px; border-radius: 10px; font-size: 13.5px; line-height: 1.5;
  display: flex; gap: 10px;
}
.banner-error::before { content: "⚠"; color: var(--ember); }

/* Entrance animation plays only on a session's first paint (.first-load),
   so live event updates re-render without replaying it (no flicker). */
#messages.first-load .msg { animation: msg-in .35s cubic-bezier(.2,.7,.3,1) backwards; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* empty state */
.empty-state { margin: auto; text-align: center; max-width: 420px; padding: 0 32px; }
.empty-mark { color: var(--ember); filter: drop-shadow(0 0 22px #e2703a55); margin-bottom: 18px; }
.empty-mark .brand-logo { width: 40px; height: 40px; }
.empty-state h2 { font-family: var(--font-display); font-weight: 500; font-size: 28px; margin: 0 0 14px; letter-spacing: .01em; }
.empty-state p { color: var(--text-dim); line-height: 1.75; margin: 0 0 26px; font-size: 14.5px; }

/* Centered loader shown while a session's transcript streams in. */
.chat-loading {
  margin: auto; display: flex; flex-direction: column; align-items: center; gap: 14px;
  color: var(--muted); font-size: 13px;
}
.chat-spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--ember);
  animation: chat-spin .7s linear infinite;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

/* No-session hero (logo + greeting) — sits just above the centered composer */
.hero { text-align: center; padding: 0 24px; }
.hero-mark { color: var(--ember); filter: drop-shadow(0 0 30px #e2703a66); margin-bottom: 22px; }
.hero-mark .brand-logo { width: 52px; height: 52px; }
.hero h2 {
  font-family: var(--font-display); font-weight: 500; font-size: 40px;
  margin: 0 auto; max-width: 18ch; line-height: 1.15; letter-spacing: -.01em;
}

/* Empty-state layout: header stays on top; the hero + composer are centered as
   a group. #messages grows and pins the hero to its bottom (just above the
   composer); the ::after spacer of equal flex balances it to vertical center. */
#main.no-session #messages {
  flex: 1 1 0; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end; padding: 0 0 22px;
}
#main.no-session::after { content: ''; flex: 1 1 0; }

/* ============================================================
   Composer
   ============================================================ */
#composer { padding: 0 32px 26px; position: relative; }
/* Floating "scroll to latest" — anchored just above the composer, fades in when
   the message list is scrolled up off the bottom. */
.scroll-bottom {
  position: absolute; top: -48px; left: 50%; transform: translateX(-50%) translateY(6px);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; z-index: 6;
  display: grid; place-items: center;
  background: var(--ink-2); color: var(--text-dim);
  border: 1px solid var(--line); box-shadow: 0 6px 22px var(--shadow-2);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease, color .14s, border-color .14s;
}
.scroll-bottom.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.scroll-bottom:hover { color: var(--text); border-color: var(--gold); }
.scroll-bottom svg { width: 17px; height: 17px; }
.composer-shell {
  max-width: 760px; margin: 0 auto;
  background: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px 10px; transition: border-color .2s, box-shadow .2s;
}
.composer-shell:focus-within { border-color: var(--ember-dk); box-shadow: 0 0 0 4px #e2703a18, 0 8px 30px var(--shadow-1); }

#input {
  width: 100%; resize: none; background: none; border: none; outline: none;
  color: var(--text); font-family: var(--font-body); font-size: 15px; line-height: 1.6;
  max-height: 200px; overflow-y: auto;
}
#input::placeholder { color: var(--muted); }
#input:disabled { opacity: .45; }

.composer-foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
/* Attach + model trigger share one pill style so the controls read as a set. */
.composer-foot .model-trigger {
  height: 32px; font-size: 12px; padding: 0 12px; border-radius: 9px;
  background-color: var(--ink-3);
}
.composer-foot #send-btn { margin-left: auto; }
#send-btn {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  font-family: var(--font-body); font-weight: 600; font-size: 14px;
  background: var(--ember); color: #fff; border: none; padding: 9px 18px; border-radius: 10px;
  transition: all .18s; box-shadow: 0 4px 16px #e2703a33;
}
#send-btn svg { transition: transform .18s; }
#send-btn:not(:disabled):hover { background: var(--ember-lt); box-shadow: 0 6px 22px #e2703a55; }
#send-btn:not(:disabled):hover svg { transform: translateX(3px); }
#send-btn:disabled { background: var(--ink-3); color: var(--muted); box-shadow: none; cursor: not-allowed; }
/* Loading: spinner only (no label) while a new session is being created from
   the empty state. Keep the ember fill even though the button is disabled. */
#send-btn.loading, #send-btn.loading:disabled {
  background: var(--ember); color: #fff; box-shadow: 0 4px 16px #e2703a33; cursor: default; padding: 9px 18px;
}
#send-btn .btn-spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: chat-spin .7s linear infinite;
}
#send-btn.stop { background: var(--danger); box-shadow: 0 4px 16px #d8503a44; }
#send-btn.stop:hover { background: var(--danger-hover); }
#send-btn.stop:hover svg { transform: none; }

/* Attachments — paperclip button + pending file/image chips */
.attach-btn {
  display: flex; align-items: center; justify-content: center; flex: none;
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer;
  background: var(--ink-3); border: 1px solid var(--line); color: var(--text-dim);
  transition: border-color .16s, color .16s;
}
.attach-btn:hover:not(:disabled) { border-color: var(--gold); color: var(--text); }
.attach-btn:disabled { opacity: .4; cursor: not-allowed; }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.attach-chip {
  display: flex; align-items: center; gap: 7px; max-width: 220px;
  background: var(--ink-3); border: 1px solid var(--line); border-radius: 9px;
  padding: 5px 7px 5px 6px; font-size: 12px; color: var(--text-dim);
}
.attach-chip img { width: 30px; height: 30px; object-fit: cover; border-radius: 5px; flex: none; }
.attach-chip .ax-ic { font-size: 15px; line-height: 1; flex: none; }
.attach-chip .ax-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .ax-del {
  margin-left: 1px; flex: none; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 12px; line-height: 1; padding: 2px 3px; border-radius: 5px;
}
.attach-chip .ax-del:hover { color: var(--text); background: var(--ink-2); }

.composer-shell.drag { border-color: var(--ember-dk); box-shadow: 0 0 0 4px #e2703a22; }

/* ============================================================
   File manager
   ============================================================ */
.files-nav {
  display: flex; align-items: center; gap: 11px; box-sizing: border-box; width: calc(100% - 24px);
  margin: 1px 12px; padding: 8px 11px; cursor: pointer; position: relative;
  background: transparent; border: none; border-radius: 9px;
  color: var(--text-dim); font-family: var(--font-body); font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s;
}
.files-nav:first-of-type { margin-top: 6px; }
.side-divider { height: 1px; background: var(--line); margin: 10px 16px 4px; }
.files-nav svg { color: var(--muted); transition: color .15s; flex: none; }
.files-nav:hover { background: var(--ink-2); color: var(--text); }
.files-nav:hover svg { color: var(--gold); }
.files-nav.active { background: #e2703a16; color: var(--text); }
.files-nav.active svg { color: var(--ember); }
/* left accent on the active nav item, matching the session-item rail */
.files-nav.active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 56%; background: var(--ember); border-radius: 3px;
}

/* The panel takes over the chat body when files mode is on. */
#main.files-mode #messages,
#main.files-mode #composer { display: none; }
.files-panel { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; padding: 18px 32px 26px; }
.files-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding-bottom: 14px; margin-bottom: 6px; border-bottom: 1px solid var(--line);
}
.files-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-family: var(--font-mono); font-size: 12.5px; min-width: 0; }
.files-crumbs .crumb { color: var(--text-dim); cursor: pointer; padding: 2px 5px; border-radius: 5px; }
.files-crumbs .crumb:hover { background: var(--ink-3); color: var(--text); }
.files-crumbs .crumb.curr { color: var(--gold); cursor: default; }
.files-crumbs .sep { color: var(--muted); }
.files-actions { display: flex; gap: 8px; margin-left: auto; }
.fbtn {
  cursor: pointer; font-family: var(--font-body); font-size: 12.5px; font-weight: 500;
  background: var(--ink-3); border: 1px solid var(--line); color: var(--text-dim);
  padding: 6px 12px; border-radius: 8px; transition: all .16s;
}
.fbtn:hover { border-color: var(--gold); color: var(--text); }
.fbtn.primary { background: var(--ember); border-color: transparent; color: #fff; }
.fbtn.primary:hover { background: var(--ember-lt); }

/* Thin indeterminate bar for silent refreshes — keeps the list visible instead
   of blanking it to a full "Loading…" state. */
.files-progress { position: relative; height: 2px; flex: 0 0 auto; margin: -7px 0 7px; overflow: hidden; }
.files-progress::after {
  content: ''; position: absolute; top: 0; left: 0; height: 100%; width: 35%;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  border-radius: 2px; opacity: 0; transform: translateX(-120%);
}
.files-progress.active::after { opacity: 1; animation: files-sweep 1.05s ease-in-out infinite; }
@keyframes files-sweep {
  0%   { transform: translateX(-120%); }
  100% { transform: translateX(400%); }
}

.files-list { flex: 1 1 0; overflow-y: auto; }
.frow {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px;
  border: 1px solid transparent; transition: background .12s, border-color .12s; cursor: pointer;
}
.frow:hover { background: var(--ink-2); border-color: var(--line); }
.frow .fic { width: 18px; text-align: center; flex: none; color: var(--muted); }
.frow.dir .fic { color: var(--gold); }
.frow .fname {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; color: var(--text);
}
.frow.dir .fname { cursor: pointer; font-weight: 500; }
.frow.dir .fname:hover { color: var(--gold); }
.frow .fsize { flex: none; font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); width: 78px; text-align: right; }
.frow .fkebab {
  flex: none; cursor: pointer; background: none; border: none; border-radius: 7px;
  color: var(--muted); padding: 4px 6px; transition: background .12s, color .12s;
  display: inline-flex; align-items: center;
}
.frow .fkebab:hover { background: var(--ink-3); color: var(--text); }
.frow .fkebab .ic { width: 18px; height: 18px; }
/* files are clickable to preview/edit */
.frow.file .fname, .frow.file .fic { cursor: pointer; }
.frow.file .fname:hover { color: var(--ember-lt); }

/* ---- file preview / editor modal ---- */
.preview-overlay {
  position: fixed; inset: 0; z-index: 220; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--overlay); backdrop-filter: blur(2px); animation: modal-fade .14s ease;
}
.preview-card {
  display: flex; flex-direction: column; width: 100%; max-width: 900px; height: 80vh; max-height: 860px;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 70px var(--shadow-3);
}
.pv-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; flex: none;
  border-bottom: 1px solid var(--line);
}
.pv-head .pv-ic { color: var(--gold); flex: none; display: inline-flex; }
.pv-head .pv-ic .ic { width: 17px; height: 17px; }
.pv-name {
  font-family: var(--font-mono); font-size: 13.5px; color: var(--text); font-weight: 500;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pv-meta { flex: 1; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.pv-close {
  flex: none; cursor: pointer; background: none; border: none; border-radius: 7px;
  color: var(--muted); padding: 5px; display: inline-flex; transition: background .12s, color .12s;
}
.pv-close:hover { background: var(--ink-3); color: var(--text); }
.pv-close .ic { width: 18px; height: 18px; }
.pv-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pv-editor {
  flex: 1; width: 100%; resize: none; border: none; outline: none; padding: 14px 16px;
  background: var(--surface-2); color: var(--text); tab-size: 2;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.6; white-space: pre;
}
/* markdown Edit/Preview toggle */
.pv-tabs {
  flex: none; display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--ink-2);
}
.pv-tab {
  cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: none; border: 1px solid transparent; border-radius: 7px; padding: 5px 14px; transition: all .14s;
}
.pv-tab:hover { color: var(--text); }
.pv-tab.active { color: var(--ember-lt); background: var(--ink-3); border-color: var(--line); }
.pv-content { flex: 1; min-height: 0; display: flex; }
.pv-content .pv-editor { flex: 1; }
.pv-render {
  flex: 1; overflow: auto; padding: 18px 22px; background: var(--surface-2);
  font-size: 15px; /* match chat prose; .turn-text supplies the rest */
}
.pv-frame { flex: 1; width: 100%; border: none; background: #fff; } /* iframe renders its own page; white canvas */
/* image preview — contained & centered; checkerboard shows transparency */
.pv-image {
  flex: 1; min-height: 0; width: 100%; object-fit: contain; padding: 18px; box-sizing: border-box;
  background-color: var(--surface-2);
  background-image:
    linear-gradient(45deg, #00000014 25%, transparent 25%, transparent 75%, #00000014 75%),
    linear-gradient(45deg, #00000014 25%, transparent 25%, transparent 75%, #00000014 75%);
  background-size: 22px 22px; background-position: 0 0, 11px 11px;
}
.pv-loading, .pv-msg { margin: auto; padding: 28px; color: var(--muted); font-size: 14px; text-align: center; }
.pv-dl {
  display: block; margin: 0 auto 28px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  background: var(--ember); color: #fff; border: none; padding: 9px 18px; border-radius: 10px;
}
.pv-dl:hover { background: var(--ember-lt); }
.pv-foot {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; flex: none;
  border-top: 1px solid var(--line);
}
.pv-status { flex: 1; font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.pv-status.dirty { color: var(--gold); }
.pv-status.ok { color: var(--ok); }
.pv-status.err { color: var(--danger-text); }
.pv-save {
  flex: none; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
  background: var(--ember); color: #fff; border: none; padding: 8px 20px; border-radius: 9px;
  transition: background .14s;
}
.pv-save:hover:not(:disabled) { background: var(--ember-lt); }
.pv-save:disabled { opacity: .45; cursor: default; }

.file-menu {
  position: fixed; z-index: 60; min-width: 178px; padding: 5px;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: 0 14px 38px var(--shadow-2); animation: fmenu-in .12s ease;
}
@keyframes fmenu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.file-menu .fmi {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer; border-radius: 7px;
  color: var(--text-dim); font-family: var(--font-body); font-size: 13px; padding: 8px 10px;
  transition: background .12s, color .12s;
}
.file-menu .fmi:hover { background: var(--ink-3); color: var(--text); }
.file-menu .fmi .ic { width: 15px; height: 15px; flex: none; }
.file-menu .fmi.danger { color: var(--danger-text); }
.file-menu .fmi.danger:hover { background: var(--danger-soft); color: var(--danger-text-lt); }

/* ============================================================
   Confirm modal (replaces native confirm())
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px;
  background: var(--overlay); backdrop-filter: blur(2px); animation: modal-fade .14s ease;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  width: min(420px, 100%); background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 16px; padding: 22px 22px 18px; box-shadow: 0 24px 70px var(--shadow-3);
  animation: modal-pop .16s cubic-bezier(.2, .7, .3, 1);
}
@keyframes modal-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-title { font-family: var(--font-display); font-size: 19px; font-weight: 500; color: var(--text); margin-bottom: 9px; }
.modal-msg { font-size: 14px; line-height: 1.55; color: var(--text-dim); }
.modal-detail {
  margin-top: 10px; padding: 8px 11px; border-radius: 8px; background: var(--ink);
  border: 1px solid var(--line); font-family: var(--font-mono); font-size: 12px;
  color: var(--gold); word-break: break-all;
}
.modal-input {
  width: 100%; margin-top: 14px; box-sizing: border-box;
  font-family: var(--font-body); font-size: 14px; color: var(--text);
  background: var(--ink); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 12px; outline: none; transition: border-color .15s;
}
.modal-input:focus { border-color: var(--gold); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.fbtn .caret { width: 12px; height: 12px; opacity: .7; margin-left: -1px; }
.modal-btn {
  cursor: pointer; font-family: var(--font-body); font-size: 13.5px; font-weight: 600;
  padding: 9px 18px; border-radius: 10px; border: 1px solid var(--line); transition: all .15s;
}
.modal-btn.cancel { background: var(--ink-3); color: var(--text-dim); }
.modal-btn.cancel:hover { color: var(--text); border-color: var(--gold); }
.modal-btn.confirm { background: var(--ember); border-color: transparent; color: #fff; box-shadow: 0 4px 16px #e2703a33; }
.modal-btn.confirm:hover { background: var(--ember-lt); }
.modal-btn.confirm.danger { background: var(--danger); box-shadow: 0 4px 16px #d8503a44; }
.modal-btn.confirm.danger:hover { background: var(--danger-hover); }
.modal-btn:disabled { opacity: .6; cursor: default; }

/* modal form (e.g. create-account dialog) */
.modal-form { margin-top: 16px; }
.modal-field { display: block; margin-bottom: 12px; }
.modal-field > span {
  display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px;
}
.modal-field > input {
  width: 100%; box-sizing: border-box; background: var(--ink); border: 1px solid var(--line);
  border-radius: 9px; outline: none; color: var(--text); font-family: var(--font-body);
  font-size: 14px; padding: 10px 12px; transition: border-color .15s;
}
.modal-field > input:focus { border-color: var(--ember-dk); }
.modal-field > input:-webkit-autofill,
.modal-field > input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text); caret-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--ink) inset; transition: background-color 9999s ease 0s;
}
.modal-err { min-height: 16px; font-size: 12.5px; color: var(--danger-text); }
.modal-form .modal-actions { margin-top: 14px; }

/* ============================================================
   Spend quota — sidebar usage meter
   ============================================================ */
.sidebar-foot .foot-row { display: flex; align-items: center; justify-content: space-between; }
.usage-meter { min-width: 0; }
.usage-meter .um-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.usage-meter .um-label { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.usage-meter .um-val { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
.usage-meter .um-bar { height: 5px; border-radius: 3px; background: var(--ink-3); overflow: hidden; }
.usage-meter .um-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--ember)); border-radius: 3px; transition: width .3s ease; }
.usage-meter.over .um-bar > span { background: var(--danger); }
.usage-meter .um-note { margin-top: 6px; font-size: 10.5px; color: var(--danger-text); }

/* ============================================================
   Admin — quota management panel
   ============================================================ */
.admin-title { font-family: var(--font-display); font-size: 17px; color: var(--text); }
.admin-title .admin-sub { font-family: var(--font-body); font-size: 12px; color: var(--muted); margin-left: 10px; }

/* ---- Usage stats panel ---- */
.stats-wrap { display: flex; flex-direction: column; gap: 20px; padding-bottom: 10px; }
.stat-quota { background: var(--ink-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat-quota-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--text-dim); }
.stat-quota-head span:last-child { font-family: var(--font-mono); color: var(--text); }
.stat-quota-bar { height: 7px; border-radius: 4px; background: var(--ink-3); overflow: hidden; margin: 9px 0 7px; }
.stat-quota-fill { height: 100%; background: var(--gold); border-radius: 4px; transition: width .3s; }
.stat-quota.over .stat-quota-fill { background: var(--danger); }
.stat-sub { font-size: 11.5px; color: var(--muted); }

.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card { background: var(--ink-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 15px; }
.stat-card-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-cost { font-family: var(--font-display); font-size: 26px; font-weight: 500; color: var(--gold); margin: 6px 0 2px; }
.stat-toks { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }

.stat-section-title { font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: -8px; }
.stat-chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding: 6px 2px 0; background: var(--ink-2); border: 1px solid var(--line); border-radius: 12px; }
.stat-bar { flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; }
.stat-bar-fill { width: 100%; background: var(--gold); border-radius: 3px 3px 0 0; opacity: .85; transition: height .3s; }
.stat-bar:hover .stat-bar-fill { opacity: 1; background: var(--ember-lt); }
.stat-chart-axis { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); margin-top: -14px; padding: 0 4px; }

.stat-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.stat-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.stat-table th { text-align: right; font-weight: 500; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stat-table th:first-child { text-align: left; }
.stat-table td { text-align: right; font-family: var(--font-mono); color: var(--text-dim); padding: 8px 12px; border-bottom: 1px solid var(--ink-3); }
.stat-table td:first-child { text-align: left; font-family: var(--font-body); color: var(--text); }
.stat-table tr:last-child td { border-bottom: none; }
.stat-table-empty { text-align: center !important; color: var(--muted); padding: 18px !important; }
.stat-since { font-size: 11.5px; color: var(--muted); text-align: center; }

@media (max-width: 720px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
.admin-create {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 2px 16px; margin-bottom: 4px; border-bottom: 1px solid var(--line);
}
.admin-create input {
  background: var(--ink); border: 1px solid var(--line); border-radius: 8px; outline: none;
  color: var(--text); font-family: var(--font-body); font-size: 13px; padding: 8px 11px;
}
.admin-create input:focus { border-color: var(--ember-dk); }
.admin-create input:-webkit-autofill,
.admin-create input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text); caret-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--ink) inset;
  transition: background-color 9999s ease 0s;
}
.admin-create #ac-username { width: 180px; }
.admin-create #ac-password { width: 175px; }
.admin-create .fbtn { font-size: 13px; padding: 8px 14px; }
.ac-msg { font-size: 12.5px; }
.ac-msg.ok { color: var(--ok); }
.ac-msg.err { color: var(--danger-text); }

/* server status card (admin dashboard) */
.admin-sys { padding: 6px 2px 14px; border-bottom: 1px solid var(--line); }
.admin-sys:empty { display: none; }
.sys-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }
.sys-tile { background: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; }
.sys-tile .st-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.sys-tile .st-val { font-family: var(--font-display); font-size: 19px; color: var(--text); margin-top: 3px; line-height: 1.2; }
.sys-tile .st-val .st-of { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.sys-tile .st-bar { height: 5px; border-radius: 3px; background: var(--ink-3); overflow: hidden; margin: 9px 0 6px; }
.sys-tile .st-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--ember)); transition: width .4s ease; }
.sys-tile .st-bar.warn > span { background: linear-gradient(90deg, var(--ember), #e8a33d); }
.sys-tile .st-bar.danger > span { background: var(--danger); }
.sys-tile .st-sub { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.sys-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 10px; }

/* port previews */
.admin-create #pc-port { width: 150px; }
.ports-hint { padding: 4px 12px 14px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.ports-hint code { font-family: var(--font-mono); font-size: 11.5px; color: var(--gold); background: var(--ink-3); padding: 1px 5px; border-radius: 5px; }
.port-row {
  display: flex; align-items: center; gap: 14px; padding: 13px 12px; border-bottom: 1px solid var(--line);
}
.port-row .pr-main { flex: 1 1 auto; min-width: 0; }
.port-row .pr-top { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.port-row .pr-port { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--ember-lt); flex: none; }
.port-row .pr-url {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-dim); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-bottom: 1px solid #f0945f33;
}
.port-row .pr-url:hover { color: var(--ember-lt); border-bottom-color: var(--ember-lt); }
.port-row .pr-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-top: 5px; }
.port-row .pr-actions { flex: none; display: flex; gap: 6px; }
.port-row .pr-copy, .port-row .pr-revoke {
  cursor: pointer; font: inherit; font-size: 12.5px; font-weight: 600; padding: 7px 13px; border-radius: 8px;
  background: none; border: 1px solid var(--line); color: var(--text-dim); transition: all .14s;
}
.port-row .pr-copy:hover { border-color: var(--gold); color: var(--text); }
.port-row .pr-revoke { border-color: var(--danger-border); color: var(--danger-text); }
.port-row .pr-revoke:hover:not(:disabled) { background: var(--danger-soft); }
.port-row .pr-revoke:disabled { opacity: .5; cursor: default; }
@media (max-width: 768px) {
  .port-row { flex-wrap: wrap; }
  .port-row .pr-actions { width: 100%; }
}
.admin-row {
  display: flex; align-items: center; gap: 18px; padding: 14px 12px;
  border-bottom: 1px solid var(--line);
}
.admin-row .ar-main { flex: 1 1 auto; min-width: 0; }
.admin-row .ar-name { font-size: 14px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.admin-row .ar-badge { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; }
.admin-row .ar-bar { height: 5px; border-radius: 3px; background: var(--ink-3); overflow: hidden; margin: 8px 0 5px; max-width: 380px; }
.admin-row .ar-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--ember)); }
.admin-row .ar-bar.over > span { background: var(--danger); }
.admin-row .ar-used { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }
.admin-row .ar-edit { flex: none; display: flex; align-items: center; gap: 6px; }
.admin-row .ar-cur { color: var(--muted); font-family: var(--font-mono); font-size: 13px; }
.admin-row .ar-input {
  width: 84px; background: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-family: var(--font-mono); font-size: 13px; padding: 7px 9px; outline: none;
}
.admin-row .ar-input:focus { border-color: var(--ember-dk); }
.admin-row .ar-save {
  cursor: pointer; font-family: var(--font-body); font-size: 12.5px; font-weight: 600;
  background: var(--ember); border: none; color: #fff; padding: 7px 14px; border-radius: 8px; transition: all .15s;
}
.admin-row .ar-save:hover:not(:disabled) { background: var(--ember-lt); }
.admin-row .ar-save:disabled { opacity: .6; cursor: default; }
.admin-row .ar-ban {
  cursor: pointer; font-family: var(--font-body); font-size: 12.5px; font-weight: 600;
  background: none; border: 1px solid var(--danger-border); color: var(--danger-text); padding: 7px 13px; border-radius: 8px;
  margin-right: 4px; transition: all .15s;
}
.admin-row .ar-ban:hover:not(:disabled) { background: var(--danger-soft); }
.admin-row .ar-ban.on { border-color: var(--line); color: var(--ok); }
.admin-row .ar-ban.on:hover { background: #7d9a5c1a; }
.admin-row .ar-del {
  cursor: pointer; font-family: var(--font-body); font-size: 12.5px; font-weight: 600;
  background: var(--danger-strong); border: 1px solid var(--danger-strong); color: #fff; padding: 7px 13px; border-radius: 8px;
  margin-right: 4px; transition: all .15s;
}
.admin-row .ar-del:hover:not(:disabled) { background: var(--danger-strong-hov); border-color: var(--danger-strong-hov); }
.admin-row .ar-del:disabled { opacity: .6; cursor: default; }
.admin-row .ar-badge.ban { color: var(--danger-text); border-color: var(--danger-border); }
.admin-row.disabled .ar-main { opacity: .5; }
.files-empty { color: var(--muted); font-size: 13px; padding: 24px 10px; text-align: center; }
.files-loading { color: var(--muted); font-size: 13px; padding: 24px 10px; }

/* ============================================================
   Inline icons (Lucide, stroke-based) — sized per context
   ============================================================ */
.ic { flex: none; display: inline-block; vertical-align: middle; }
.frow .fic { display: flex; align-items: center; justify-content: center; }
.frow .fic .ic { width: 18px; height: 18px; }
.frow .fact { display: inline-flex; align-items: center; gap: 5px; }
.frow .fact .ic { width: 13px; height: 13px; }
.think-icon { display: inline-flex; align-items: center; }
.think-icon .ic { width: 13px; height: 13px; }
.attach-chip .ax-ic { display: inline-flex; align-items: center; color: var(--muted); }
.attach-chip .ax-ic .ic { width: 16px; height: 16px; }
.attach-chip .ax-del { display: inline-flex; align-items: center; justify-content: center; }
.attach-chip .ax-del .ic { width: 12px; height: 12px; }
.session-item .del { display: flex; align-items: center; justify-content: center; }
.session-item .del .ic { width: 14px; height: 14px; }
.fbtn { display: inline-flex; align-items: center; gap: 6px; }
.fbtn svg { width: 14px; height: 14px; }
.fbtn.icon-only { padding: 7px 9px; }
#new-btn svg { width: 18px; height: 18px; }

/* ============================================================
   Mobile — sidebar becomes a slide-in drawer; chat goes full width
   ============================================================ */
@media (max-width: 768px) {
  /* file preview goes full-screen on mobile */
  .preview-overlay { padding: 0; }
  .preview-card { max-width: 100%; height: 100%; max-height: none; border: none; border-radius: 0; }
  .pv-editor { font-size: 14px; }

  /* sidebar -> off-canvas drawer */
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 84vw; max-width: 320px;
    z-index: 50; transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.2,.7,.3,1);
    box-shadow: 0 0 50px var(--shadow-3);
  }
  #sidebar.open { transform: translateX(0); }

  .drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 40; background: var(--overlay);
    opacity: 0; pointer-events: none; transition: opacity .26s;
  }
  .drawer-backdrop.show { opacity: 1; pointer-events: auto; }

  /* hamburger */
  .menu-btn {
    display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0;
    background: var(--ink-2); border: 1px solid var(--line); border-radius: 10px;
    color: var(--text-dim); cursor: pointer;
  }
  .menu-btn:active { background: var(--ink-3); }

  /* header */
  #chat-head { padding: 11px 14px; gap: 10px; }
  #main.no-session #chat-head { display: flex; } /* keep on mobile for the menu button */
  .head-left { flex: 1; min-width: 0; }
  #chat-title { font-size: 16px; max-width: 100%; }
  #chat-sub { display: none; }
  .head-right { gap: 7px; }
  .model-trigger { font-size: 11px; padding: 0 10px; }
  .sheet { max-width: 100%; }
  .head-status { padding: 6px; gap: 0; }
  .head-status .status-text { display: none; }

  /* messages + composer — tighter gutters */
  #messages { padding: 18px 0 20px; gap: 18px; }
  .msg, .thinking-live, .banner-error { padding: 0 16px; }
  #composer { padding: 0 14px 16px; }
  .composer-shell { padding: 10px 12px 9px; }
  #input { font-size: 16px; } /* >=16px avoids iOS zoom-on-focus */

  .empty-state h2 { font-size: 24px; }
  .empty-state p { font-size: 14px; }
  .hero h2 { font-size: 30px; }
  .hero-mark .brand-logo { width: 46px; height: 46px; }

  /* user bubbles can use more width on a narrow screen */
  .msg.user .bubble { max-width: 88%; }
}

/* ============================================================
   Auth gate + sidebar user footer (multi-user)
   ============================================================ */
.auth-overlay {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: var(--bg); padding: 24px;
}
.auth-overlay.hidden { display: none; }
.auth-loading { display: grid; place-items: center; }
.auth-loading.hidden { display: none; }
.auth-loading-mark { color: var(--ember); filter: drop-shadow(0 0 26px #e2703a66); animation: logo-pulse 1.25s ease-in-out infinite; }
.auth-loading-mark .brand-logo { width: 52px; height: 52px; display: block; }
@keyframes logo-pulse { 0%,100% { opacity: .35; transform: scale(.9); } 50% { opacity: 1; transform: scale(1); } }
.auth-card {
  width: 100%; max-width: 380px; background: var(--ink); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 28px; box-shadow: 0 24px 70px var(--shadow-3);
}
.auth-brand { display: flex; align-items: center; gap: 11px; justify-content: center; }
.auth-brand .brand-mark .brand-logo { width: 24px; height: 24px; }
.auth-title { font-family: var(--font-display); font-size: 24px; font-weight: 500; }
.auth-tagline { text-align: center; color: var(--text-dim); font-size: 13px; margin: 10px 0 22px; }
.auth-tabs { display: flex; gap: 6px; background: var(--ink-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.auth-tab {
  flex: 1; padding: 8px; border: none; background: none; color: var(--text-dim);
  font-family: var(--font-body); font-size: 13.5px; font-weight: 600; border-radius: 7px; cursor: pointer; transition: all .15s;
}
.auth-tab.active { background: var(--ember); color: #fff; box-shadow: 0 4px 14px #e2703a44; }
#auth-form { display: flex; flex-direction: column; gap: 11px; }
#auth-form input {
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; color: var(--text); font-family: var(--font-body); font-size: 14px;
}
#auth-form input:focus { outline: none; border-color: var(--ember-dk); box-shadow: 0 0 0 3px #e2703a18; }
/* Mask Chrome's white autofill background so it matches the dark theme. */
#auth-form input:-webkit-autofill,
#auth-form input:-webkit-autofill:hover,
#auth-form input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text); caret-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--ink-2) inset;
  transition: background-color 9999s ease 0s;
}
#auth-submit {
  margin-top: 4px; background: var(--ember); color: #fff; border: none; border-radius: 10px;
  padding: 12px; font-family: var(--font-body); font-size: 14.5px; font-weight: 600; cursor: pointer;
  box-shadow: 0 6px 20px #e2703a44; transition: all .15s;
}
#auth-submit:hover { background: var(--ember-lt); }
#auth-submit:disabled { opacity: .55; cursor: not-allowed; }
.auth-error { color: var(--danger-text-lt); background: var(--err-bg); border: 1px solid var(--danger-border); border-radius: 8px; padding: 9px 12px; font-size: 12.5px; }
.auth-error.hidden { display: none; }

.sidebar-foot {
  margin-top: auto; display: flex; flex-direction: column; align-items: stretch;
  gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line);
}
.user-chip { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }
.user-name { font-family: var(--font-mono); font-size: 12.5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn {
  flex-shrink: 0; background: var(--ink-2); border: 1px solid var(--line); color: var(--text-dim);
  font-size: 12px; padding: 5px 11px; border-radius: 8px; cursor: pointer; transition: all .15s;
}
.logout-btn:hover { color: var(--ember); border-color: var(--ember-dk); }

/* Settings gear in the footer */
.icon-btn {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
  background: var(--ink-2); border: 1px solid var(--line); color: var(--text-dim); transition: all .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--gold); }

/* Settings popup */
.settings-menu {
  position: fixed; z-index: 120; min-width: 210px; padding: 8px;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 40px var(--shadow-3); animation: fmenu-in .12s ease;
}
.settings-menu .sm-section { padding: 4px 6px 8px; }
.settings-menu .sm-label { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.settings-menu .sm-seg { display: flex; gap: 4px; background: var(--ink-3); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.settings-menu .sm-seg-btn {
  flex: 1; cursor: pointer; background: none; border: none; border-radius: 6px;
  color: var(--text-dim); font-family: var(--font-body); font-size: 12px; font-weight: 500; padding: 6px 4px; transition: all .14s;
}
.settings-menu .sm-seg-btn:hover { color: var(--text); }
.settings-menu .sm-seg-btn.on { background: var(--ember); color: #fff; }
.settings-menu .sm-divider { height: 1px; background: var(--line); margin: 4px 0; }
.settings-menu .sm-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer; border-radius: 8px;
  color: var(--text-dim); font-family: var(--font-body); font-size: 13px; padding: 9px 8px; transition: background .12s, color .12s;
}
.settings-menu .sm-item:hover { background: var(--ink-3); color: var(--text); }
.settings-menu .sm-item .ic { width: 15px; height: 15px; flex: none; }
.settings-menu .sm-item.danger { color: var(--danger-text); }
.settings-menu .sm-item.danger:hover { background: var(--danger-soft); color: var(--danger-hover); }

/* Change-password modal form */
.cp-form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.cp-input {
  background: var(--ink); border: 1px solid var(--line); border-radius: 9px; outline: none;
  color: var(--text); font-family: var(--font-body); font-size: 14px; padding: 11px 13px;
}
.cp-input:focus { border-color: var(--ember-dk); box-shadow: 0 0 0 3px var(--danger-soft); }
.cp-input:-webkit-autofill, .cp-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text); caret-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--ink) inset; transition: background-color 9999s ease 0s;
}
.cp-error { color: var(--danger-text); background: var(--err-bg); border: 1px solid var(--danger-border); border-radius: 8px; padding: 8px 11px; font-size: 12.5px; }
.cp-error.hidden { display: none; }
.cp-form .modal-actions { margin-top: 4px; }
