/* ════════════════════════════════════════════════════════════════════
   Stan Chat — StanAI premium chat UI.
   See ./DESIGN.md. Inherits /brand/tokens.css. Built to out-feel the field:
   full-width bubble-free assistant prose, a proud tool timeline, one accent,
   depth from blur + hairlines, motion on the house spring.
   ════════════════════════════════════════════════════════════════════ */

/* ── Local theme vars (premium reading surfaces over the shared tokens) ── */
:root {
  --canvas:      var(--bg);          /* conversation backdrop */
  --rail-w:      34px;               /* avatar rail width */
  --col-max:     740px;              /* reading column on wide screens */
  --halo:        rgba(255,59,92,0.28);
  --blur:        saturate(180%) blur(22px);
}
:root[data-theme="dark"],
:root:not([data-theme="light"]) {
  /* dark gets a true near-black canvas, not the card grey */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --canvas: #000000; --halo: rgba(255,78,106,0.30); }
}
:root[data-theme="dark"] { --canvas: #000000; --halo: rgba(255,78,106,0.30); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--canvas); color: var(--text-primary);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:active { opacity: .7; }

/* ════════ Auth ════════════════════════════════════════════════════ */
#auth-screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 30px; padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  background:
    radial-gradient(120% 80% at 50% -10%, var(--accent-dim) 0%, transparent 55%),
    var(--canvas);
}
.auth-hero { text-align: center; }
.auth-logo {
  width: 76px; height: 76px; margin: 0 auto 18px; border-radius: 24px;
  background: var(--gradient-accent); color: #fff; font-size: 38px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 14px 40px var(--halo);
  animation: orbBob 4.5s ease-in-out infinite;
}
.auth-title { font-family: var(--font-display); font-size: 34px; font-weight: 800; letter-spacing: -0.025em; }
.auth-title span {
  background: var(--gradient-wordmark); -webkit-background-clip: text;
  background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-subtitle { color: var(--text-dim); margin: 8px 0 0; font-size: 15px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--r-2xl);
  padding: 22px; box-shadow: var(--shadow-md);
}
.auth-input-wrap { margin-bottom: 12px; }
#token-input {
  width: 100%; padding: 14px 16px; font-size: 16px;
  background: var(--bg-input); border: 1.5px solid var(--border);
  border-radius: var(--r-md); color: var(--text-primary); outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
#token-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); }
#token-submit {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 700;
  background: var(--accent); color: #fff; border: none; border-radius: var(--r-md);
  transition: transform var(--dur-fast), background var(--dur-fast);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
#token-submit:active { background: var(--accent-press); transform: scale(0.98); }
.auth-passkey-btn {
  width: 100%; margin-top: 10px; padding: 13px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 15px; font-weight: 700; color: var(--text-primary);
  background: var(--bg-input); border: 1.5px solid var(--border); border-radius: var(--r-md);
  transition: transform var(--dur-fast), border-color var(--dur-fast);
}
.auth-passkey-btn svg { width: 19px; height: 19px; color: var(--accent); }
.auth-passkey-btn:active { transform: scale(0.98); border-color: var(--accent); }
.auth-passkey-btn[disabled] { opacity: 0.55; }
.auth-error { color: var(--red); font-size: 13px; text-align: center; margin: 12px 0 0; }
.auth-hint { color: var(--text-dim); font-size: 12px; text-align: center; margin: 14px 0 0; line-height: 1.5; }

/* ════════ App frame ═══════════════════════════════════════════════ */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--canvas); }

#topbar {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; padding-top: calc(7px + var(--safe-top));
  background: var(--bg-card); /* fallback if color-mix unsupported */
  background: color-mix(in srgb, var(--bg-card) 78%, transparent);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 5; flex-shrink: 0;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-md); border: none;
  background: transparent; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background var(--dur-fast), transform var(--dur-fast);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--bg-secondary); transform: scale(0.92); }
.icon-btn.bolt { color: var(--accent); }
.icon-btn.bolt svg { width: 20px; height: 20px; }
.topbar-title { flex: 1; min-width: 0; text-align: center; }
.topbar-name {
  font-family: var(--font-display); font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-sub {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 11.5px; color: var(--text-dim); margin-top: 1px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); flex-shrink: 0; transition: background var(--dur-normal); }
.status-dot.idle { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.status-dot.thinking { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.status-dot.exited { background: var(--amber); }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.35;transform:scale(.6)} }

/* ════════ Thread (the reading column) ════════════════════════════ */
#thread {
  flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  overflow-anchor: none;   /* we manage bottom-follow ourselves; let the browser not fight it */
  padding: 18px 0 26px;
  display: flex; flex-direction: column; gap: 22px;
}
/* centre the column on wide screens, gutter on phone */
.turn, .empty-state {
  width: 100%; max-width: var(--col-max); margin-left: auto; margin-right: auto;
  padding-left: 16px; padding-right: 16px;
}

.turn { display: grid; grid-template-columns: var(--rail-w) 1fr; gap: 10px; animation: rise var(--dur-normal) var(--ease); }
@keyframes rise { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }

.turn-avatar { width: var(--rail-w); display: flex; justify-content: center; }
.orb-mini {
  width: 28px; height: 28px; border-radius: 9px; flex-shrink: 0;
  background: var(--gradient-accent); color: #fff; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px var(--halo);
}
/* Live Stan face on the "is typing" bubble — he's working, not a static dot */
.turn-avatar.stan { width: var(--rail-w); }
.turn-avatar.stan img {
  width: 30px; height: 30px; object-fit: contain; flex-shrink: 0;
  filter: drop-shadow(0 3px 7px var(--halo));
  animation: stanThink 1.5s ease-in-out infinite; transform-origin: 50% 100%;
}
@keyframes stanThink { 0%,100%{transform:translateY(0) rotate(-3deg)} 50%{transform:translateY(-3px) rotate(3deg)} }
@media (prefers-reduced-motion: reduce) { .turn-avatar.stan img { animation: none; } }
.turn-body { min-width: 0; padding-top: 2px; }
.turn-author {
  font-family: var(--font-display); font-size: 11px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim);
  margin-bottom: 4px;
}

/* ── Machine stamp ── every message says which box it ran on (Pi vs NUC). */
.turn-machine {
  display: inline-flex; align-items: center; gap: 3px;
  margin-left: 6px; padding: 1px 7px; border-radius: var(--r-pill);
  background: var(--bg-secondary); color: var(--text-dim);
  font-family: var(--font-display); font-size: 10px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: none; vertical-align: middle;
}
.turn-machine[data-machine="pi"]  { background: var(--amber-bg); color: var(--amber); }
.turn-machine-row { display: flex; justify-content: flex-end; margin-top: 3px; }
.turn-machine-row .turn-machine { margin-left: 0; }
.sys-pill .turn-machine { background: transparent; opacity: .7; }
.drawer-note { color: var(--text-dim); font-size: 12px; padding: 10px 4px 2px; }

/* ── Assistant prose ── */
.prose { font-size: 15.5px; line-height: 1.62; color: var(--text-secondary); word-wrap: break-word; overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 10px; }
.prose strong { color: var(--text-primary); font-weight: 700; }
.prose em { font-style: italic; }
.prose a { border-bottom: 1px solid var(--accent-border); }
.prose .md-h { color: var(--text-primary); font-family: var(--font-display); line-height: 1.3; margin: 16px 0 8px; letter-spacing: -0.01em; }
.prose .md-h1 { font-size: 20px; font-weight: 800; }
.prose .md-h2 { font-size: 18px; font-weight: 700; }
.prose .md-h3 { font-size: 16px; font-weight: 700; }
.prose .md-list { margin: 6px 0 12px; padding-left: 22px; }
.prose .md-list li { margin: 3px 0; }
.prose blockquote {
  margin: 8px 0 12px; padding: 4px 0 4px 14px;
  border-left: 3px solid var(--accent-border); color: var(--text-dim);
}
.prose .md-hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.prose code.inline {
  background: var(--bg-secondary); padding: 1.5px 6px; border-radius: 6px;
  font-family: var(--font-mono); font-size: 0.86em; color: var(--text-primary);
}

/* code block */
.codeblock {
  margin: 10px 0; border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--border); background: var(--bg-console);
}
.code-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.code-lang { font-family: var(--font-mono); font-size: 11px; color: #9aa; text-transform: lowercase; letter-spacing: .02em; }
.codeblock .copy {
  font-size: 11px; padding: 3px 10px; border-radius: 6px; border: none;
  background: rgba(255,255,255,0.10); color: #fff; font-weight: 600;
  transition: background var(--dur-fast);
}
.codeblock .copy:active { background: var(--accent); }
.codeblock pre {
  margin: 0; padding: 12px; overflow-x: auto;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; color: var(--text-on-dark);
}
.codeblock pre code { font-family: inherit; }

.streaming-caret {
  display: inline-block; width: 7px; height: 15px; vertical-align: text-bottom;
  background: var(--accent); margin-left: 2px; border-radius: 1px;
  animation: blink 1s step-start infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Typing bubble (Stan is typing, before the first token) ── */
.turn.typing .turn-body { padding-top: 2px; }
.typing-dots { display: inline-flex; gap: 5px; padding: 6px 0; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .85; animation: thinkPulse 1.2s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: .16s; }
.typing-dots i:nth-child(3) { animation-delay: .32s; }

/* live token counter while a turn is building */
.meta-cost.live { color: var(--accent); font-weight: 600; }

/* ── User turn (right bubble) ── */
.turn.user { grid-template-columns: 1fr; justify-items: end; }
.user-msg {
  max-width: 85%; padding: 10px 15px; border-radius: 20px 20px 6px 20px;
  background: var(--accent); color: #fff;
  font-size: 15.5px; line-height: 1.5; font-weight: 450;
  word-wrap: break-word; overflow-wrap: anywhere;
  box-shadow: 0 4px 14px var(--halo);
}
/* Links/code inside the accent bubble must stay readable — not accent-on-accent */
.user-msg a { color: #fff; text-decoration: underline; text-underline-offset: 2px; border-bottom: none; }
.user-msg a:active { opacity: .75; }
.user-msg code { background: rgba(255,255,255,.18); color: #fff; }

/* ── Thinking ── */
.turn.thinking .think { display: flex; align-items: center; gap: 9px; padding-top: 4px; color: var(--text-dim); font-size: 13.5px; font-style: italic; }
.think-dots { display: inline-flex; gap: 4px; }
.think-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: thinkPulse 1.2s ease-in-out infinite; }
.think-dots i:nth-child(2) { animation-delay: .18s; }
.think-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes thinkPulse { 0%,80%,100%{opacity:.25;transform:scale(.7)} 40%{opacity:1;transform:scale(1)} }

/* ── System pill ── */
.turn.system { grid-template-columns: 1fr; justify-items: center; }
.sys-pill {
  background: var(--bg-secondary); color: var(--text-dim); border-radius: var(--r-pill);
  font-size: 12px; padding: 5px 13px; text-align: center; max-width: 92%;
}
.turn.system.warn .sys-pill { background: var(--amber-bg); color: var(--amber); }
.turn.system.error .sys-pill { background: var(--red-bg); color: var(--red); }

/* ════════ Tool timeline card ═════════════════════════════════════ */
.turn.tool .turn-avatar { align-items: flex-start; }
.turn.tool .turn-avatar::before {
  content: ''; width: 2px; height: 100%; min-height: 22px;
  background: var(--border); border-radius: 1px; margin-top: 4px;
}
.tool-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); overflow: hidden;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.tool-card:active { box-shadow: var(--shadow-xs); }
.tool-head { display: flex; align-items: center; gap: 10px; padding: 9px 11px; }
.tool-badge {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 14px; font-weight: 700; color: #fff;
}
.tool-info { flex: 1; min-width: 0; }
.tool-name { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.tool-sum {
  font-size: 12px; color: var(--text-dim); font-family: var(--font-mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px;
}
.tool-dur { font-size: 10.5px; color: var(--text-dim); font-family: var(--font-mono); flex-shrink: 0; }
.tool-state { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--text-dim); }
.tool-state.ok { background: var(--green); }
.tool-state.err { background: var(--red); }
.tool-state.run { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.tool-chevron { color: var(--text-dim); font-size: 15px; transition: transform var(--dur-fast); flex-shrink: 0; line-height: 1; }
.tool-card.open .tool-chevron { transform: rotate(90deg); }
.tool-body { display: none; border-top: 1px solid var(--border); }
.tool-card.open .tool-body { display: block; animation: rise var(--dur-fast) var(--ease); }
.tool-body .tool-input {
  padding: 9px 11px; font-family: var(--font-mono); font-size: 11.5px;
  color: var(--text-secondary); background: var(--bg-secondary);
  white-space: pre-wrap; word-break: break-word;
}
.tool-body pre.tool-out {
  margin: 0; padding: 11px; background: var(--bg-console); color: var(--text-on-dark);
  font-family: var(--font-mono); font-size: 12px; line-height: 1.45;
  max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
/* Tappable file paths inside tool output → copy on tap. */
.tool-out .tool-path {
  color: var(--accent); text-decoration: underline; text-underline-offset: 2px;
  cursor: pointer; word-break: break-all;
}
.tool-out .tool-path:active { opacity: .6; }

/* ── Chat ⇄ terminal bridge: "Send to terminal" buttons ── */
.code-bar .code-lang { margin-right: auto; }   /* group the buttons to the right */
.term-send {
  font-size: 11px; padding: 3px 10px; border-radius: 6px; border: none;
  background: rgba(61,214,140,0.16); color: var(--green, #3DD68C); font-weight: 700;
  white-space: nowrap; transition: background var(--dur-fast);
}
.code-bar .term-send { margin-right: 8px; }
.term-send:active { background: var(--green, #3DD68C); color: #04210f; }
.tool-actions { padding: 8px 11px; background: var(--bg-secondary); }
.tool-actions .term-send { width: 100%; padding: 7px; }

/* ── Inline diff viewer (Edit / MultiEdit / Write) ──────────────────────────
   Additions in the accent, deletions muted — single accent, no glows. */
.tool-diff-wrap { font-family: var(--font-mono); font-size: 11.5px; }
.diff-head { display: flex; align-items: center; gap: 10px; padding: 7px 11px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); }
.diff-file { flex: 1; min-width: 0; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.diff-stat { display: flex; gap: 8px; font-weight: 700; flex-shrink: 0; }
.diff-stat .d-plus { color: var(--accent); }
.diff-stat .d-minus { color: var(--text-dim); }
.diff-copy { flex-shrink: 0; font-size: 10.5px; padding: 3px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-secondary); font-weight: 600; transition: background var(--dur-fast); }
.diff-copy:active { background: var(--bg-secondary); }
.tool-diff { max-height: 340px; overflow: auto; background: var(--bg-card); }
.d-line { display: flex; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.d-gut { flex: 0 0 18px; text-align: center; color: var(--text-dim); user-select: none; }
.d-txt { flex: 1; min-width: 0; padding-right: 8px; }
.d-add { background: var(--accent-dim); }
.d-add .d-gut { color: var(--accent); font-weight: 700; }
.d-add .d-txt { color: var(--text-primary); }
.d-del { background: var(--bg-secondary); }
.d-del .d-txt { color: var(--text-dim); text-decoration: line-through; text-decoration-color: var(--border-mid); }
.d-ctx .d-txt { color: var(--text-secondary); }
.diff-more { padding: 6px 11px; color: var(--text-dim); font-size: 11px; background: var(--bg-secondary); }

/* ── Liveness hairlines (no glows; respect reduced-motion) ──────────────────*/
.tool-head { position: relative; }
.tool-card:has(.tool-state.run) .tool-head::after {
  content: ''; position: absolute; left: 0; bottom: 0; height: 2px; width: 38%;
  background: var(--accent); border-radius: 2px; animation: tool-prog 1.2s ease-in-out infinite;
}
@keyframes tool-prog { 0% { transform: translateX(-100%); } 100% { transform: translateX(360%); } }

#topbar { position: relative; }
#topbar:has(.status-dot.thinking)::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 42% 100%; background-repeat: no-repeat; animation: hdr-prog 1.3s linear infinite;
}
@keyframes hdr-prog { 0% { background-position: -42% 0; } 100% { background-position: 142% 0; } }

@media (prefers-reduced-motion: reduce) {
  .tool-card:has(.tool-state.run) .tool-head::after { animation: none; width: 100%; opacity: .35; }
  #topbar:has(.status-dot.thinking)::after { animation: none; background: var(--accent); opacity: .4; }
}

/* ── Plan tracker (pinned checklist from TodoWrite) ─────────────────────────*/
.plan-tracker {
  position: sticky; top: 0; z-index: 5; margin: 0 0 14px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs); overflow: hidden;
}
.plan-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; }
.plan-title { font-weight: 700; font-size: 13px; color: var(--text-primary); }
.plan-count { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
.plan-tracker.all-done .plan-count { color: var(--green); }
.plan-toggle { margin-left: auto; border: none; background: none; color: var(--text-dim); font-size: 12px; line-height: 1; transition: transform var(--dur-fast); }
.plan-tracker.collapsed .plan-toggle { transform: rotate(-90deg); }
.plan-tracker.collapsed .plan-body { display: none; }
.plan-body { padding: 2px 12px 11px; display: flex; flex-direction: column; gap: 8px; }
.plan-item { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; line-height: 1.4; }
.plan-dot { flex: 0 0 14px; width: 14px; height: 14px; margin-top: 1px; border-radius: 50%; border: 2px solid var(--border-mid); position: relative; transition: border-color var(--dur-normal), background var(--dur-normal); }
.plan-item.active .plan-dot { border-color: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.plan-item.done .plan-dot { border-color: var(--green); background: var(--green); animation: none; }
.plan-item.done .plan-dot::after { content: ''; position: absolute; left: 4px; top: 0.5px; width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.plan-text { color: var(--text-secondary); }
.plan-item.active .plan-text { color: var(--text-primary); font-weight: 600; }
.plan-item.done .plan-text { color: var(--text-dim); text-decoration: line-through; text-decoration-color: var(--border-mid); }

/* ── Turn-complete flash on the final message ───────────────────────────────*/
@keyframes turn-done-flash { 0% { background: var(--accent-dim); } 100% { background: transparent; } }
.turn.turn-done { animation: turn-done-flash .9s ease-out; border-radius: var(--r-md); }

@media (prefers-reduced-motion: reduce) {
  .plan-item.active .plan-dot { animation: none; }
  .turn.turn-done { animation: none; }
}

/* ── Message actions (copy / retry-from-here) ───────────────────────────────*/
.turn-acts { display: flex; gap: 6px; margin-top: 6px; opacity: .5; transition: opacity .15s ease; }
.turn:hover .turn-acts, .turn:active .turn-acts, .turn-acts:active { opacity: 1; }
.turn.user .turn-acts { justify-content: flex-end; }
.msg-act { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-dim); font-size: 13px; line-height: 1; display: grid; place-items: center; transition: background var(--dur-fast), color var(--dur-fast), transform .1s ease; }
.msg-act:active { transform: scale(.9); background: var(--bg-secondary); color: var(--accent); }

/* ── Diff revert button ─────────────────────────────────────────────────────*/
.diff-revert { flex-shrink: 0; font-size: 10.5px; padding: 3px 9px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-secondary); font-weight: 600; transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast); }
.diff-revert[data-armed="1"] { border-color: var(--accent); color: var(--accent); }
.diff-revert.done { color: var(--green); border-color: var(--green); }
.diff-revert:disabled { opacity: .6; }

/* ── Context-used chips (which files Stan touched this turn) ─────────────────*/
.ctx-card { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 9px; }
.ctx-head { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 7px; }
.ctx-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ctx-chip { font-family: var(--font-mono); font-size: 11px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text-secondary); white-space: nowrap; max-width: 200px; overflow: hidden; text-overflow: ellipsis; transition: border-color var(--dur-fast), color var(--dur-fast); }
.ctx-chip:active { border-color: var(--accent-border); color: var(--accent); }

/* ── Cost cap over-limit ────────────────────────────────────────────────────*/
.meta-cost.over-cap { color: var(--red); font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  .msg-act:active, .ctx-chip:active { transform: none; }
}

/* ════════════════════════════════════════════════════════════════════════
   Glow pass — accent halos on what's alive (new DESIGN.md: glow with intent).
   rgba fallbacks so glow renders even before tokens.css loads.
   ════════════════════════════════════════════════════════════════════════ */
.status-dot.thinking { box-shadow: 0 0 11px var(--glow-accent, rgba(255,59,92,.42)), 0 0 0 3px var(--accent-dim); }
.tool-state.run { box-shadow: 0 0 8px var(--glow-accent, rgba(255,59,92,.42)); }
.streaming-caret { box-shadow: 0 0 7px var(--glow-accent, rgba(255,59,92,.42)); }
#send-btn { box-shadow: 0 4px 16px var(--glow-accent-soft, rgba(255,59,92,.22)); }
#send-btn:not(:disabled):active, #send-btn.stop { box-shadow: 0 0 0 4px var(--accent-dim), 0 6px 22px var(--glow-accent, rgba(255,59,92,.42)); }
.orb-mini { box-shadow: 0 3px 12px var(--halo, rgba(255,59,92,.3)), 0 0 15px var(--glow-accent-soft, rgba(255,59,92,.22)); }
.user-msg { box-shadow: 0 2px 16px var(--glow-accent-soft, rgba(255,59,92,.22)); }
.plan-item.active .plan-dot { box-shadow: 0 0 9px var(--glow-accent, rgba(255,59,92,.42)); }
.diff-revert.done { box-shadow: 0 0 8px rgba(52,199,89,.4); }

/* ════════════════════════════════════════════════════════════════════════
   Motion pass v2 — more life everywhere (glow-era). Decorative; all disabled
   under prefers-reduced-motion at the bottom.
   ════════════════════════════════════════════════════════════════════════ */
/* Running tool cards breathe a soft accent glow */
@keyframes tool-breathe { 0%,100% { box-shadow: 0 0 0 rgba(255,59,92,0); } 50% { box-shadow: 0 0 16px var(--glow-accent-soft, rgba(255,59,92,.3)); } }
.tool-card:has(.tool-state.run) { animation: tool-breathe 1.8s ease-in-out infinite; }
/* Streaming caret breathes */
@keyframes caret-glow { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.streaming-caret { animation: caret-glow 1s ease-in-out infinite; }
/* Tool finishes → status dot pops in */
@keyframes state-pop { 0% { transform: scale(0); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }
.tool-state.ok, .tool-state.err { animation: state-pop .34s var(--ease); }
/* User bubble springs in */
@keyframes bubble-pop { 0% { opacity: 0; transform: translateY(8px) scale(.96); } 60% { transform: translateY(0) scale(1.012); } 100% { opacity: 1; transform: none; } }
.turn.user .user-msg { animation: bubble-pop .34s var(--ease); }
/* Plan tracker slides in, items cascade */
@keyframes plan-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.plan-tracker { animation: plan-in .3s var(--ease); }
.plan-item { animation: plan-in .3s var(--ease) both; }
.plan-item:nth-child(2){animation-delay:.05s} .plan-item:nth-child(3){animation-delay:.1s} .plan-item:nth-child(4){animation-delay:.15s} .plan-item:nth-child(5){animation-delay:.2s} .plan-item:nth-child(n+6){animation-delay:.24s}
/* Diff lines reveal when the card opens */
@keyframes diff-line-in { from { opacity: 0; transform: translateX(-5px); } to { opacity: 1; transform: none; } }
.tool-card.open .tool-diff .d-line { animation: diff-line-in .26s ease both; }
/* Context chips cascade */
@keyframes chip-in { from { opacity: 0; transform: translateY(5px) scale(.95); } to { opacity: 1; transform: none; } }
.ctx-chip { animation: chip-in .3s var(--ease) both; }
.ctx-chip:nth-child(2){animation-delay:.05s} .ctx-chip:nth-child(3){animation-delay:.1s} .ctx-chip:nth-child(4){animation-delay:.15s} .ctx-chip:nth-child(n+5){animation-delay:.18s}
/* System pills pop */
@keyframes pill-pop { from { opacity: 0; transform: translateY(4px) scale(.96); } to { opacity: 1; transform: none; } }
.sys-pill { animation: pill-pop .26s var(--ease); }
/* Tool badge press */
.tool-badge { transition: transform .12s ease; }
.tool-head:active .tool-badge { transform: scale(.9); }
/* Stop button pulses while Stan works */
@keyframes send-breathe { 0%,100% { box-shadow: 0 0 0 4px var(--accent-dim), 0 6px 18px var(--glow-accent-soft, rgba(255,59,92,.25)); } 50% { box-shadow: 0 0 0 4px var(--accent-dim), 0 6px 26px var(--glow-accent, rgba(255,59,92,.5)); } }
#send-btn.stop { animation: send-breathe 1.3s ease-in-out infinite; }

@media (prefers-reduced-motion: reduce) {
  .tool-card:has(.tool-state.run), .streaming-caret, .tool-state.ok, .tool-state.err, .turn.user .user-msg,
  .plan-tracker, .plan-item, .tool-card.open .tool-diff .d-line, .ctx-chip, .sys-pill, #send-btn.stop { animation: none !important; }
}

/* ── New chat controls: read-aloud active state + pinned chats ──────────────*/
.msg-speak.on { color: var(--accent); background: var(--accent-dim); box-shadow: 0 0 8px var(--glow-accent, rgba(255,59,92,.4)); }
.sess-pin { flex-shrink: 0; background: none; border: none; color: var(--text-dim); font-size: 14px; line-height: 1; padding: 4px 5px; cursor: pointer; transition: color var(--dur-fast), transform .1s ease; }
.sess-pin.on { color: var(--accent); text-shadow: 0 0 7px var(--glow-accent-soft, rgba(255,59,92,.4)); }
.sess-pin:active { transform: scale(.85); }
.sess-section-h.pin .sess-count { color: var(--accent); }

/* ════════ Empty state ════════════════════════════════════════════ */
.empty-state { margin: auto; text-align: center; padding: 30px 24px; max-width: 380px; }
/* Living Stan — the welcome mascot is a little stage: aura + sparkles behind,
   a floating/breathing/blinking cat, a weight-selling ground shadow, and pose
   swaps (peek → wake → idle → nap) driven from JS. Not a static image any more. */
.empty-orb {
  position: relative; width: 172px; height: 172px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
}
/* Gradient-tile fallback, shown only if the art 404s (JS adds .no-art) */
.empty-orb .orb-fallback {
  display: none; width: 72px; height: 72px; border-radius: 22px;
  background: var(--gradient-accent); color: #fff; font-size: 34px;
  align-items: center; justify-content: center; box-shadow: 0 14px 38px var(--halo);
  animation: stanFloat 4.5s ease-in-out infinite;
}
.empty-orb.no-art > :not(.orb-fallback) { display: none; }
.empty-orb.no-art .orb-fallback { display: flex; }

/* Aura — soft brand glow breathing behind Stan */
.stan-aura {
  position: absolute; width: 158px; height: 158px; border-radius: 50%;
  background: radial-gradient(circle at 50% 46%, var(--halo) 0%,
              color-mix(in srgb, var(--accent) 16%, transparent) 40%, transparent 72%);
  filter: blur(5px); animation: auraPulse 4.6s ease-in-out infinite;
}
/* Sparkles — tiny accent motes drifting up around him */
.stan-sparkles { position: absolute; inset: 0; pointer-events: none; }
.stan-sparkles i {
  position: absolute; width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); opacity: 0; box-shadow: 0 0 8px var(--accent);
  animation: stanSparkle 3.8s ease-in-out infinite;
}
.stan-sparkles i:nth-child(1) { left: 15%; top: 32%; animation-delay: 0s; }
.stan-sparkles i:nth-child(2) { left: 83%; top: 27%; animation-delay: .95s; }
.stan-sparkles i:nth-child(3) { left: 79%; top: 63%; animation-delay: 1.9s; }
.stan-sparkles i:nth-child(4) { left: 21%; top: 65%; animation-delay: 2.7s; }

/* Float + breathe nested so the two transforms compose without clashing */
.stan-float   { animation: stanFloat 4.6s ease-in-out infinite; }
.stan-breathe { animation: stanBreathe 3.4s ease-in-out infinite; transform-origin: 50% 100%; }
.empty-stan {
  display: block; width: 134px; height: 134px; object-fit: contain; user-select: none;
  filter: drop-shadow(0 14px 22px var(--halo));
  animation: stanBlink 5.4s ease-in-out infinite; transform-origin: 50% 62%;
}
/* Ground shadow pulses opposite the bob → sells the float */
.stan-shadow {
  position: absolute; bottom: 8px; width: 98px; height: 15px; border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0,0,0,.30) 0%, transparent 72%);
  animation: stanShadow 4.6s ease-in-out infinite;
}
/* Napping — slow the breath, dim the aura, kill sparkles, float a Zzz */
.empty-orb.napping .stan-float    { animation-duration: 6.6s; }
.empty-orb.napping .stan-breathe  { animation-duration: 5s; }
.empty-orb.napping .empty-stan    { animation: none; }
.empty-orb.napping .stan-aura     { opacity: .45; }
.empty-orb.napping .stan-sparkles { opacity: 0; }
.empty-orb.napping::after {
  content: 'z Z z'; position: absolute; top: 8px; right: 26px;
  font-family: var(--font-display); font-weight: 800; font-size: 13px; letter-spacing: 2px;
  color: var(--accent); opacity: .85; animation: stanZzz 2.6s ease-in-out infinite;
}
/* Just woke / first peek — a springy pop */
.empty-orb.wake .stan-breathe { animation: stanWake .6s cubic-bezier(0.16,1,0.3,1); }

@keyframes stanFloat   { 0%,100%{transform:translateY(0) rotate(-1.2deg)} 50%{transform:translateY(-9px) rotate(1.2deg)} }
@keyframes stanBreathe { 0%,100%{transform:scale(1,1)} 50%{transform:scale(1.04,.965)} }
@keyframes stanBlink   { 0%,45%,53%,100%{transform:scaleY(1)} 49%{transform:scaleY(.84)} }
@keyframes auraPulse   { 0%,100%{transform:scale(.92);opacity:.55} 50%{transform:scale(1.08);opacity:.95} }
@keyframes stanSparkle { 0%,100%{opacity:0;transform:translateY(5px) scale(.5)} 45%{opacity:1;transform:translateY(-7px) scale(1)} }
@keyframes stanShadow  { 0%,100%{transform:scale(1);opacity:.85} 50%{transform:scale(.78);opacity:.5} }
@keyframes stanZzz     { 0%,100%{opacity:.2;transform:translateY(2px)} 50%{opacity:.9;transform:translateY(-4px)} }
@keyframes stanWake    { 0%{transform:scale(.62) translateY(10px)} 60%{transform:scale(1.09)} 100%{transform:scale(1)} }
@media (prefers-reduced-motion: reduce) {
  .stan-float,.stan-breathe,.empty-stan,.stan-aura,.stan-sparkles i,.stan-shadow,.orb-fallback { animation: none !important; }
}
.empty-title { font-family: var(--font-display); font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.empty-sub { color: var(--text-dim); font-size: 14.5px; margin-top: 9px; line-height: 1.55; }
.empty-actions { margin-top: 22px; display: flex; justify-content: center; }
.empty-auto {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--gradient-accent); color: #fff; border: none;
  border-radius: var(--r-pill); padding: 13px 24px; font-size: 15px; font-weight: 700;
  box-shadow: 0 8px 22px var(--halo);
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
}
.empty-auto:active { transform: scale(0.95); box-shadow: 0 4px 14px var(--halo); }
.empty-hint { font-size: 12px; color: var(--text-dim); margin-top: 12px; }
.empty-hint code {
  font-family: var(--font-mono); background: var(--bg-secondary);
  padding: 1.5px 7px; border-radius: 5px; color: var(--accent);
}
.empty-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.empty-chip {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary);
  border-radius: var(--r-pill); padding: 9px 15px; font-size: 13px;
  transition: border-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}
.empty-chip:active { border-color: var(--accent); color: var(--accent); transform: scale(0.96); }

/* ════════ Tap-to-pick choices ════════════════════════════════════ */
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.choice-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary);
  border-radius: var(--r-pill); padding: 8px 14px 8px 8px; font-size: 13.5px; text-align: left;
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast);
}
.choice-chip .choice-n {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-dim); color: var(--accent);
  font-family: var(--font-display); font-size: 12px; font-weight: 800;
}
.choice-chip .choice-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice-chip:active {
  border-color: var(--accent); color: var(--accent); background: var(--accent-dim); transform: scale(0.97);
}

/* ════════ Jump-to-latest ═════════════════════════════════════════ */
#jump-btn {
  position: absolute; left: 50%; transform: translateX(-50%) translateY(8px);
  bottom: calc(var(--composer-h, 132px) + 12px); z-index: 6;
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg-card); /* fallback if color-mix unsupported */
  background: color-mix(in srgb, var(--bg-card) 86%, transparent);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  color: var(--text-secondary); box-shadow: var(--shadow-md);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity var(--dur-normal), transform var(--dur-normal);
}
#jump-btn svg { width: 20px; height: 20px; }
#jump-btn.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }

/* ════════ Composer (floating dock) ═══════════════════════════════ */
#composer {
  flex-shrink: 0;
  background: var(--bg-card); /* fallback if color-mix unsupported */
  background: color-mix(in srgb, var(--bg-card) 82%, transparent);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-top: 1px solid var(--border);
  padding: 9px 12px; padding-bottom: calc(9px + var(--safe-bottom));
}
#composer-inner { max-width: var(--col-max); margin: 0 auto; }
/* Wraps on narrow screens. Six items (dir/mode/model/box/plan/cost) overflow a
   phone width, and the plan pill is last — without wrap it is pushed off the
   right edge with nothing to scroll. */
#composer-meta { display: flex; align-items: center; gap: 8px; padding: 0 2px 8px; flex-wrap: wrap; }
.meta-chip, .meta-usage, .meta-cost { flex: 0 0 auto; }
.meta-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 5px 11px; font-size: 12px; color: var(--text-secondary);
  transition: border-color var(--dur-fast);
}
.meta-chip:active { border-color: var(--accent); }
.meta-chip-k { color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.meta-cost { font-size: 11px; color: var(--text-dim); font-family: var(--font-mono); }

/* ── Claude Max-plan usage pill (composer) ───────────────────────── */
.meta-usage {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 4px 9px 4px 8px; cursor: pointer;
  transition: border-color var(--dur-fast);
}
.meta-usage:active { transform: scale(.96); }
.meta-usage[hidden] { display: none; }
.meta-usage .mu-k { font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); font-weight: 700; }
.meta-usage .mu-track { width: 38px; height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.meta-usage .mu-track i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .4s ease; }
.meta-usage .mu-pct { font-size: 11px; font-family: var(--font-mono); color: var(--text-secondary); min-width: 26px; text-align: right; }
.meta-usage.warn { border-color: var(--amber); }
.meta-usage.warn .mu-track i { background: var(--amber); }
.meta-usage.crit { border-color: var(--red); }
.meta-usage.crit .mu-track i { background: var(--red); }
.meta-usage.crit .mu-pct { color: var(--red); }

/* ── Plan-usage drawer breakdown ─────────────────────────────────── */
.usage-plan { display: flex; align-items: center; gap: 8px; margin: 2px 2px 14px; }
.usage-plan-badge {
  font-size: 12px; font-weight: 800; letter-spacing: .02em; color: var(--accent);
  background: var(--accent-dim); border: 1px solid var(--accent); border-radius: var(--r-pill); padding: 4px 12px;
}
.usage-stale { font-size: 11px; color: var(--text-dim); }
.ubar { margin: 0 2px 16px; }
.ubar-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.ubar-label { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.ubar-pct { font-size: 14px; font-family: var(--font-mono); color: var(--text-primary); font-weight: 700; }
.ubar-track { height: 9px; border-radius: 5px; background: var(--border); overflow: hidden; }
.ubar-track i { display: block; height: 100%; border-radius: 5px; background: var(--accent); transition: width .5s ease; }
.ubar-reset { margin-top: 5px; font-size: 11px; color: var(--text-dim); font-family: var(--font-mono); }
.ubar.warn .ubar-track i { background: var(--amber); }
.ubar.warn .ubar-pct { color: var(--amber); }
.ubar.crit .ubar-track i { background: var(--red); }
.ubar.crit .ubar-pct { color: var(--red); }
#composer-row {
  position: relative; isolation: isolate;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input); border: 1.5px solid var(--border);
  border-radius: 22px; padding: 5px 5px 5px 6px;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
/* Calm focus glow — a soft, static accent halo. No animated rainbow and no
   constant motion: gentle on the eyes, just a quiet lift on focus/typing. */
#composer-row::before {
  content: ''; position: absolute; inset: -2px; border-radius: 24px; z-index: -1;
  background: var(--accent); filter: blur(10px); opacity: 0;
  transition: opacity .3s ease;
}
#composer-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
#composer-row:focus-within::before { opacity: .12; }
#composer-row.typing::before { opacity: .18; }
#prompt {
  flex: 1; resize: none; border: none; background: transparent;
  padding: 8px 8px; font-size: 16px; font-family: inherit; line-height: 1.4;
  color: var(--text-primary); outline: none; max-height: 140px;
}
#prompt::placeholder { color: var(--text-dim); }
#send-btn {
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
  transition: opacity var(--dur-fast), transform var(--dur-fast), background var(--dur-fast);
}
#send-btn svg { width: 20px; height: 20px; }
#send-btn:active { transform: scale(0.9); background: var(--accent-press); }
#send-btn:disabled { opacity: 0.35; transform: none; }

/* ════════ Drawer ═════════════════════════════════════════════════ */
/* Above .stan-screen (60) and #stan-nav (120) — the drawer can be opened
   from a Stan Shell screen (e.g. You → All settings) that stays visible
   underneath, so it must always win the stack, not just inside #app. */
#drawer { position: fixed; inset: 0; z-index: 130; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: fade var(--dur-normal) ease; }
@keyframes fade { from{opacity:0} to{opacity:1} }
.drawer-panel {
  position: absolute; bottom: 0; left: 0; right: 0; max-height: 84vh;
  width: 100%; max-width: 560px; margin: 0 auto;
  background: var(--bg-card); border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  border-top: 1px solid var(--border); display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom); box-shadow: var(--shadow-sheet);
  animation: sheetUp var(--dur-slow) var(--ease);
}
@keyframes sheetUp { from{transform:translateY(100%)} to{transform:none} }
.drawer-panel::before { content: ''; width: 38px; height: 4px; border-radius: 2px; background: var(--border-mid); position: absolute; top: 8px; left: 50%; transform: translateX(-50%); }
.drawer-head { display: flex; align-items: center; padding: 20px 18px 12px; flex-shrink: 0; }
.drawer-head span { font-family: var(--font-display); font-size: 19px; font-weight: 800; letter-spacing: -0.01em; flex: 1; }
.text-btn { background: none; border: none; color: var(--accent); font-size: 15px; font-weight: 600; padding: 6px 4px; }
#drawer-body { overflow-y: auto; padding: 0 14px 18px; }

.sess-row {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  border-radius: var(--r-md); background: var(--bg-secondary); margin-bottom: 8px;
  transition: background var(--dur-fast), transform var(--dur-fast);
}
.sess-row:active { background: var(--accent-dim); transform: scale(0.99); }
.sess-icon {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0; background: var(--gradient-accent);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 17px;
  box-shadow: 0 3px 10px var(--halo);
}
.sess-info { flex: 1; min-width: 0; }
.sess-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-meta { font-size: 12px; color: var(--text-dim); font-family: var(--font-mono); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-del { background: none; border: none; color: var(--text-dim); padding: 8px; font-size: 16px; flex-shrink: 0; }
.sess-del:active { color: var(--red); }

.drawer-section-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; margin: 16px 4px 8px; font-weight: 700; }
.opt-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  background: var(--bg-secondary); border: 1.5px solid var(--border); border-radius: var(--r-md);
  padding: 10px 15px; font-size: 14px; color: var(--text-secondary); min-height: 44px;
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
.opt.sel { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); font-weight: 600; }
.drawer-cta {
  width: 100%; margin-top: 20px; padding: 15px; border: none; border-radius: var(--r-md);
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
  transition: background var(--dur-fast), transform var(--dur-fast);
}
.drawer-cta:active { background: var(--accent-press); transform: scale(0.99); }
.mode-note { font-size: 12.5px; color: var(--text-dim); margin: 10px 4px 0; line-height: 1.5; }

/* ── Mode sheet — a focused live permission switcher (NOT the new-chat flow).
   Claude/ChatGPT-menu styling: rich rows, title + what-it-does, live check. ── */
.mode-list { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.mode-opt {
  display: flex; align-items: flex-start; gap: 12px; text-align: left; width: 100%;
  background: var(--bg-secondary); border: 1.5px solid var(--border); border-radius: var(--r-md);
  padding: 13px 15px; transition: border-color var(--dur-fast), background var(--dur-fast);
}
.mode-opt:active { transform: scale(0.99); }
.mode-opt.sel { border-color: var(--accent); background: var(--accent-dim); }
.mode-opt-tick {
  flex-shrink: 0; width: 22px; height: 22px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--border); display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; transition: background var(--dur-fast), border-color var(--dur-fast);
}
.mode-opt.sel .mode-opt-tick { background: var(--accent); border-color: var(--accent); }
.mode-opt-text { min-width: 0; }
.mode-opt-h { display: block; font-size: 15px; font-weight: 700; color: var(--text-primary); }
.mode-opt.sel .mode-opt-h { color: var(--accent); }
.mode-opt-note { display: block; font-size: 12.5px; color: var(--text-dim); margin-top: 3px; line-height: 1.45; }

/* ════════ Attachments ════════════════════════════════════════════ */
#attach-btn {
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 50%;
  background: transparent; color: var(--text-dim); display: flex; align-items: center; justify-content: center;
  transition: color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast);
}
#attach-btn svg { width: 20px; height: 20px; }
#attach-btn:active { transform: scale(0.9); background: var(--bg-secondary); color: var(--accent); }

/* ── Voice dictation (mic) ───────────────────────────────────────── */
#mic-btn {
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 50%;
  background: transparent; color: var(--text-dim); display: flex; align-items: center; justify-content: center;
  transition: color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast);
}
#mic-btn[hidden] { display: none; }
#mic-btn svg { width: 20px; height: 20px; }
#mic-btn:active { transform: scale(0.9); color: var(--accent); }
#mic-btn.recording { color: #fff; background: var(--red); animation: micPulse 1.1s ease-in-out infinite; }
#mic-btn.busy { color: var(--accent); }
#mic-btn.busy svg { animation: spin 0.9s linear infinite; }
@keyframes micPulse { 0%,100% { box-shadow: 0 0 0 0 var(--red-bg); } 50% { box-shadow: 0 0 0 7px transparent; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Slash palette ────────────────────────────────────────────────── */
#slash-menu { display: none; margin: 0 2px 8px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-md); }
#slash-menu.show { display: block; }
.slash-row { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left; padding: 9px 13px; background: none; border: none; border-bottom: 1px solid var(--border); }
.slash-row:last-child { border-bottom: none; }
.slash-row:active { background: var(--accent-dim); }
.slash-row code { color: var(--accent); font-family: var(--font-mono); font-size: 13px; font-weight: 600; }
.slash-row span { color: var(--text-dim); font-size: 12.5px; }

/* ── System command card (help / models) ─────────────────────────── */
.sys-card { max-width: var(--col-max); margin: 0 auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 14px; }
.cmd-help-h { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); margin-bottom: 9px; }
.cmd-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; align-items: baseline; }
.cmd-row code { color: var(--accent); font-family: var(--font-mono); font-size: 13px; white-space: nowrap; }
.cmd-row span { color: var(--text-secondary); font-size: 13px; text-align: right; }

/* ── /remote-control — QR + link to open this chat elsewhere ──────── */
.rc-qr { background: #fff; border-radius: var(--r-sm); padding: 10px; width: min(220px, 62%); margin: 2px auto 10px; }
.rc-qr svg { display: block; width: 100%; height: auto; }
.rc-none { padding: 40px 0; text-align: center; color: var(--text-dim); font-size: 13px; }
.rc-url { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); word-break: break-all; text-align: center; margin-bottom: 10px; }
.rc-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.rc-toggle input { accent-color: var(--accent); }
.rc-note { font-size: 12px; color: var(--text-dim); line-height: 1.45; margin: 6px 0 10px; }
.rc-actions { display: flex; gap: 8px; }
.rc-btn { flex: 1; padding: 9px 12px; border-radius: var(--r-sm); border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.rc-btn:active { background: var(--bg-card); }

/* ── /pet — ASCII Stan mascot ─────────────────────────────────────── */
.stan-pet {
  position: absolute; left: 14px; bottom: 138px; z-index: 40;
  padding: 7px 9px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--accent); box-shadow: var(--shadow-md);
  animation: petBob 3.6s ease-in-out infinite;
}
.stan-pet:active { transform: scale(.92); }
.pet-face, .pet-big { font-family: var(--font-mono); margin: 0; line-height: 1.05; white-space: pre; }
.pet-face { font-size: 10px; }
@keyframes petBob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
.pet-pop {
  position: absolute; left: 14px; bottom: 196px; z-index: 41; width: min(280px, calc(100vw - 28px));
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sheet); padding: 14px; text-align: center;
}
.pet-big { font-size: 12px; color: var(--accent); margin-bottom: 8px; }
.pet-mood { font-size: 13px; color: var(--text-secondary); font-style: italic; margin-bottom: 12px; }
.pet-btw { display: flex; gap: 7px; }
.pet-btw input { flex: 1; min-width: 0; padding: 9px 11px; font-size: 14px; font-family: inherit; background: var(--bg-input); border: 1.5px solid var(--border); border-radius: var(--r-md); color: var(--text-primary); outline: none; }
.pet-btw input:focus { border-color: var(--accent); }
.pet-btw button { flex: 0 0 auto; padding: 0 14px; border: none; border-radius: var(--r-md); background: var(--accent); color: #fff; font-weight: 700; }
.pet-x { margin-top: 10px; background: none; border: none; color: var(--text-dim); font-size: 12px; }

#attach-tray { display: none; flex-wrap: wrap; gap: 8px; padding: 0 2px 8px; }
#attach-tray.show { display: flex; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px; position: relative;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 6px 9px; font-size: 12.5px; color: var(--text-secondary);
  max-width: 180px;
}
.att-chip.img { padding: 0; overflow: visible; border: none; background: none; }
.att-chip.img img { width: 52px; height: 52px; object-fit: cover; border-radius: var(--r-md); border: 1px solid var(--border); display: block; }
.att-ico { font-size: 14px; }
.att-nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-x {
  position: absolute; top: -7px; right: -7px; width: 19px; height: 19px; border-radius: 50%;
  background: var(--text-primary); color: var(--canvas); border: 2px solid var(--canvas);
  font-size: 10px; line-height: 1; display: flex; align-items: center; justify-content: center; padding: 0;
}

/* attachments echoed in the user's turn */
.user-atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.user-att-img { width: 140px; max-width: 60vw; border-radius: var(--r-md); border: 1px solid var(--border); display: block; }
.user-att-file {
  font-size: 12.5px; color: var(--text-secondary); background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px 10px; font-family: var(--font-mono);
}

/* ════════ Fleet ══════════════════════════════════════════════════ */
/* z-index 145, not 45 — reachable from the Tools .stan-screen (60), which
   must not be left on top of it. Same reasoning as #drawer above. */
#fleet {
  position: fixed; inset: 0; z-index: 145; background: var(--canvas);
  display: flex; flex-direction: column; animation: rise var(--dur-normal) var(--ease);
}
.fleet-head {
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
  padding: calc(14px + var(--safe-top)) 16px 12px;
  background: var(--bg-card); background: color-mix(in srgb, var(--bg-card) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}
.fleet-title { font-family: var(--font-display); font-size: 22px; font-weight: 800; letter-spacing: -0.02em; flex: 1; }
#fleet-body { flex: 1; overflow-y: auto; padding: 16px 14px calc(24px + var(--safe-bottom)); max-width: var(--col-max); width: 100%; margin: 0 auto; }

.fan-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-xl);
  padding: 16px; margin-bottom: 8px;
}
.fan-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin-bottom: 12px; }
.fan-prompt {
  width: 100%; resize: none; border: 1.5px solid var(--border); background: var(--bg-input);
  border-radius: var(--r-md); padding: 10px 12px; font-size: 15px; font-family: inherit; line-height: 1.45;
  color: var(--text-primary); outline: none; transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.fan-prompt:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); }
.fan-prompt::placeholder { color: var(--text-dim); }
.fan-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; margin: 14px 2px 8px; }
.fan-dirs, .fan-modes { display: flex; flex-wrap: wrap; gap: 8px; }
.fan-dir, .fan-mode {
  border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text-secondary);
  border-radius: var(--r-pill); padding: 7px 13px; font-size: 13px; min-height: 36px;
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
.fan-dir.sel, .fan-mode.sel { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); font-weight: 600; }
.fan-card .drawer-cta { margin-top: 16px; }

.fleet-grid-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; margin: 22px 4px 10px; }
#fleet-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.fleet-empty { color: var(--text-dim); font-size: 13.5px; text-align: center; padding: 28px 12px; }
.fleet-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 13px 14px; transition: border-color var(--dur-fast), transform var(--dur-fast);
}
.fleet-card:active { transform: scale(0.99); border-color: var(--accent); }
.fleet-card-top { display: flex; align-items: center; gap: 10px; }
.fleet-orb { color: var(--accent); font-size: 17px; flex-shrink: 0; }
.fleet-card-id { flex: 1; min-width: 0; }
.fleet-card-name { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-card-meta { font-size: 12px; color: var(--text-dim); font-family: var(--font-mono); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fleet-del { background: none; border: none; color: var(--text-dim); padding: 4px 6px; font-size: 14px; flex-shrink: 0; }
.fleet-del:active { color: var(--red); }
.fleet-card-last {
  font-size: 13px; color: var(--text-secondary); line-height: 1.45; margin-top: 9px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.fleet-card-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 9px; font-size: 11px; color: var(--text-dim); font-family: var(--font-mono); }

/* ════════ Markdown tables ════════════════════════════════════════ */
.prose .md-tablewrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 12px 0;
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.prose .md-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.prose .md-table th, .prose .md-table td {
  padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap; vertical-align: top;
}
.prose .md-table th { background: var(--bg-secondary); color: var(--text-primary); font-weight: 700; font-size: 12.5px; }
.prose .md-table td { color: var(--text-secondary); }
.prose .md-table tr:last-child td { border-bottom: none; }
.prose .md-table code.inline { white-space: normal; }

/* ── Task-list checkboxes (- [ ] / - [x]) ── */
.prose .checklist { list-style: none; padding-left: 2px; margin: 6px 0 12px; }
.prose .checklist li { margin: 4px 0; }
.prose .md-task { display: flex; align-items: flex-start; gap: 9px; }
.prose .md-check {
  width: 17px; height: 17px; border-radius: 5px; flex-shrink: 0; margin-top: 1px;
  border: 1.5px solid var(--border-mid); position: relative;
}
.prose .md-task.done .md-check { background: var(--green); border-color: var(--green); }
.prose .md-task.done .md-check::after { content: '✓'; position: absolute; inset: 0; color: #fff; font-size: 11px; line-height: 16px; text-align: center; }
.prose .md-task.done > span { color: var(--text-dim); text-decoration: line-through; }

/* ════════ Send-button states (Stop while working · dim while empty) ═ */
#send-btn.stop { background: var(--accent); }
#send-btn.stop:active { background: var(--accent-press); }
#send-btn.stop svg { width: 22px; height: 22px; }
#send-btn.send-idle { opacity: 0.4; }

/* ════════ Drawer theme toggle ════════════════════════════════════ */
.drawer-head .icon-sm {
  width: 36px; height: 36px; border-radius: 10px; border: none; flex-shrink: 0;
  background: var(--bg-secondary); color: var(--text-secondary); margin-right: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}
.drawer-head .icon-sm svg { width: 19px; height: 19px; }
.drawer-head .icon-sm:active { transform: scale(0.9); background: var(--accent-dim); color: var(--accent); }

/* ════════ Chats drawer — search · sections · previews ════════════ */
.sess-search-wrap { padding: 4px 2px 10px; position: sticky; top: 0; z-index: 1; background: var(--bg-card); }
.sess-search {
  width: 100%; padding: 11px 14px; font-size: 15px; font-family: inherit;
  background: var(--bg-input); border: 1.5px solid var(--border); border-radius: var(--r-md);
  color: var(--text-primary); outline: none; transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.sess-search:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim); }
.sess-search::placeholder { color: var(--text-dim); }

.sess-section-h {
  display: flex; align-items: center; gap: 8px; margin: 14px 4px 9px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim);
}
.sess-section-h::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.sess-section-h.live::before { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.sess-section-h.off::before { background: var(--text-dim); }
.sess-count {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bg-secondary); color: var(--text-dim);
  font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.sess-clear { margin-left: auto; background: none; border: none; color: var(--accent); font-size: 12.5px; font-weight: 600; padding: 4px 2px; text-transform: none; letter-spacing: 0; }
.sess-clear:active { opacity: .6; }
.sess-clear:disabled { color: var(--text-dim); }

.sess-icon.off { background: var(--bg-secondary); color: var(--text-dim); box-shadow: none; }
.sess-dir { color: var(--text-dim); font-weight: 400; }
.sess-meta .status-dot { display: inline-block; vertical-align: middle; margin-right: 6px; }
.sess-prev {
  font-size: 12px; color: var(--text-secondary); margin-top: 4px; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sess-row.cur { border: 1.5px solid var(--accent); background: var(--accent-dim); }
.sess-row.cur .sess-icon { box-shadow: 0 0 0 2px var(--accent-dim); }

/* Keyword tags — OpenClaw-style chips under each chat title */
.sess-kw { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.kw-tag {
  background: var(--bg-secondary); color: var(--text-dim);
  font-size: 11px; padding: 2px 7px; border-radius: 8px;
  font-family: var(--font-mono); letter-spacing: 0.01em;
}

/* full-width / destructive option buttons in the Settings sheet */
.opt.wide { width: 100%; justify-content: center; display: flex; }
.opt.danger { color: var(--red); border-color: var(--red-bg); }
.opt.danger:active { background: var(--red-bg); }
.opt.danger:disabled { opacity: .5; }

/* Passkey (Face ID) list — Settings → Face ID sign-in */
.passkey-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 14px; margin-bottom: 8px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--r-md);
  font-size: 14px; color: var(--text-primary);
}
.passkey-del { font-size: 13px; font-weight: 600; color: var(--red); background: none; border: none; padding: 4px 6px; }
.passkey-del:active { opacity: .6; }
.passkey-del:disabled { opacity: .4; }

/* Notification category toggles (Settings → Notify me about) */
.notif-cats { display: flex; flex-direction: column; gap: 8px; }
.notif-cats .drawer-section-label { margin-top: 16px; }
.notif-cat {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left; padding: 11px 44px 11px 14px; position: relative; min-height: 52px; justify-content: center;
}
.notif-cat .notif-cat-l { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.notif-cat .notif-cat-d { font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.notif-cat.sel { border-color: var(--accent); background: var(--accent-dim); }
.notif-cat.sel .notif-cat-l { color: var(--accent); }
.notif-cat::after {
  content: ''; position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.notif-cat.sel::after {
  border-color: var(--accent); background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-size: 13px; background-position: center; background-repeat: no-repeat;
}

/* ════════ Wide screens ═══════════════════════════════════════════ */
@media (min-width: 760px) {
  .empty-chips { max-width: 460px; margin-left: auto; margin-right: auto; }
  #fleet-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Pi Terminal ─────────────────────────────────────────────────────────────
   Full xterm shell inside StanChat (replaces the separate Stan CLI app). */
#terminal {
  position: fixed; inset: 0; z-index: 146; background: #0E0C15;
  display: flex; flex-direction: column; animation: rise var(--dur-normal) var(--ease);
}
.term-head {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding: calc(10px + var(--safe-top)) 10px 10px;
  background: color-mix(in srgb, #14111d 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.term-head .icon-btn { color: #E8E6F0; }
.term-head-title {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px; color: #B9B6C8;
}
#term-session-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#terminal .status-dot.connected   { background: #3DD68C; box-shadow: 0 0 0 3px rgba(61,214,140,.18); }
#terminal .status-dot.reconnecting { background: #F5A623; animation: pulse 1.1s ease-in-out infinite; }
#terminal .status-dot.offline     { background: #F2503F; }

/* Project switcher — taps open a shell straight in that repo (?cwd=) */
#term-projects {
  flex-shrink: 0; display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none;
  padding: 9px 10px; border-bottom: 1px solid rgba(255,255,255,0.06);
  background: #110e19;
}
#term-projects::-webkit-scrollbar { display: none; }
.term-proj {
  flex-shrink: 0; border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.04);
  color: #C9C6D6; border-radius: var(--r-pill); padding: 6px 13px; font-size: 12.5px;
  font-weight: 600; white-space: nowrap; min-height: 32px;
  transition: border-color var(--dur-fast), color var(--dur-fast), background var(--dur-fast);
}
.term-proj.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

#terminal-container { flex: 1; min-height: 0; padding: 6px 8px 0; overflow: hidden; }
#terminal-container .xterm { height: 100%; }
#terminal-container .xterm-viewport::-webkit-scrollbar { width: 6px; }
#terminal-container .xterm-viewport::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }

/* Mobile key bar */
#term-keybar {
  flex-shrink: 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: #14111d; border-top: 1px solid rgba(255,255,255,0.08);
}
#term-keybar::-webkit-scrollbar { display: none; }
.term-key {
  flex-shrink: 0; min-width: 38px; height: 38px; padding: 0 11px;
  border: 1px solid rgba(255,255,255,0.14); background: rgba(255,255,255,0.05);
  color: #E8E6F0; border-radius: 9px; font-size: 14px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  display: flex; align-items: center; justify-content: center;
}
.term-key:active { background: rgba(255,255,255,0.14); transform: scale(0.94); }
.term-key.primary { border-color: var(--accent); color: #fff; background: var(--accent); font-weight: 700; min-width: 44px; }
.term-key.primary:active { background: var(--accent-press); }
.term-key.on { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.term-key.macro { font-size: 12px; color: #9D9AB0; font-family: var(--font-ui); }
.term-key-sep { flex-shrink: 0; width: 1px; height: 24px; background: rgba(255,255,255,0.14); align-self: center; margin: 0 3px; }

#term-pill {
  position: absolute; top: calc(58px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  background: rgba(245,166,35,0.92); color: #1C1929; font-size: 12px; font-weight: 700;
  padding: 5px 13px; border-radius: var(--r-pill); display: none; z-index: 2;
}

/* Shell-sessions bottom sheet */
.term-sheet { position: fixed; inset: 0; z-index: 47; background: rgba(0,0,0,0.5); display: flex; align-items: flex-end; }
.term-sheet-panel {
  width: 100%; max-height: 70vh; background: var(--bg-card); border-radius: 20px 20px 0 0;
  padding: 8px 14px calc(16px + var(--safe-bottom)); overflow-y: auto;
  animation: rise var(--dur-normal) var(--ease);
}
.term-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 2px 12px; font-weight: 700; color: var(--text-primary); }
.term-sheet-empty { color: var(--text-dim); font-size: 13.5px; text-align: center; padding: 24px 12px; }
.term-sess-row { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.term-sess-row.active { opacity: .72; }
.term-sess-info { flex: 1; min-width: 0; }
.term-sess-name { font-size: 14.5px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-sess-meta { font-size: 11.5px; color: var(--text-dim); font-family: "JetBrains Mono", ui-monospace, monospace; margin-top: 2px; }
.term-sess-actions { display: flex; gap: 6px; flex-shrink: 0; }
#terminal .top-bar-action, .term-sheet .top-bar-action {
  border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text-secondary);
  border-radius: var(--r-pill); padding: 6px 13px; font-size: 12.5px; font-weight: 600; min-height: 34px;
}
.term-sheet .top-bar-action.primary { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.term-sheet .top-bar-action.danger { border-color: rgba(242,80,63,.4); color: #F2503F; }
.term-sheet .top-bar-action:disabled { opacity: .45; }

/* Paste overlay (clipboard fallback for iOS/restricted browsers) */
.term-paste-panel { max-height: 50vh; }
.term-paste-panel textarea {
  width: 100%; min-height: 120px; resize: vertical;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--text-primary);
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13.5px;
  padding: 12px; margin-bottom: 10px; outline: none;
}
.term-paste-panel textarea:focus { border-color: var(--accent); }
.term-paste-panel .top-bar-action.primary { width: 100%; display: flex; align-items: center; justify-content: center; }

/* Clipboard keybar buttons — slight accent */
.term-key.clip { border-color: rgba(65,215,255,0.3); color: #41D7FF; }

/* ── Flipper × Pi tab ─────────────────────────────────────────────────────── */
#flipper { position: fixed; inset: 0; z-index: 46; background: var(--canvas); display: flex; flex-direction: column; animation: rise var(--dur-normal) var(--ease); }
#flipper-body { flex: 1; overflow-y: auto; padding: 14px 14px calc(24px + var(--safe-bottom)); max-width: var(--col-max); width: 100%; margin: 0 auto; }
.fl-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-xl); padding: 14px; margin-bottom: 10px; }
.fl-k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); font-weight: 700; margin-bottom: 4px; }
.fl-v { font-size: 16px; font-weight: 700; color: var(--text-primary); word-break: break-word; }
.fl-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 4px; word-break: break-word; }
.fl-row { display: flex; align-items: center; justify-content: space-between; }
.fl-badge { font-size: 12.5px; font-weight: 700; color: var(--text-dim); }
.fl-badge.on { color: var(--green); }
.fl-bar { height: 10px; background: var(--bg-secondary); border-radius: 999px; overflow: hidden; margin: 12px 0 8px; }
.fl-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .5s ease; }
.fl-stats { font-size: 12.5px; color: var(--text-secondary); font-family: "JetBrains Mono", ui-monospace, monospace; }
.fl-found { border-color: var(--green); background: color-mix(in srgb, var(--green) 10%, transparent); }
.fl-cap { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.fl-cap + .fl-cap, .fl-k + .fl-cap { border-top: 1px solid var(--border); }
.fl-cap-info { min-width: 0; flex: 1; }
.fl-crack { flex-shrink: 0; border: 1px solid var(--accent); color: var(--accent); background: var(--accent-dim); border-radius: var(--r-pill); padding: 8px 14px; font-size: 13px; font-weight: 700; }
.fl-crack:disabled { opacity: .55; }
.fl-foot { text-align: center; font-size: 11.5px; color: var(--text-dim); margin-top: 16px; }

/* ── Pi Monitor ── */
#pi-monitor { position: fixed; inset: 0; background: var(--bg); z-index: 50; display: flex; flex-direction: column; }
#pi-body { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.pi-loading { text-align: center; color: var(--text-dim); padding: 40px 0; }
.pi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 520px; margin: 0 auto; }
.pi-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-card); padding: 14px; }
.pi-card.pi-warn { border-color: var(--yellow, #FF9500); }
.pi-card.pi-crit { border-color: var(--red, #FF3B30); background: color-mix(in srgb, var(--red, #FF3B30) 6%, var(--bg-card)); }
.pi-card-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); margin-bottom: 4px; }
.pi-card-value { font-size: 28px; font-weight: 700; font-family: "JetBrains Mono", ui-monospace, monospace; }
.pi-card-value.pi-small { font-size: 16px; }
.pi-card-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.pi-bar { height: 4px; background: var(--bg-secondary); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.pi-bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s ease; }
.pi-bar-fill.warn { background: #FF9500; }
.pi-bar-fill.crit { background: #FF3B30; }
.pi-link { background: none; border: none; color: var(--accent); font-size: 12px; padding: 4px 0; cursor: pointer; }

/* ── Clipboard Sync Panel ── */
.clip-panel { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg-card); border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; padding: 16px; z-index: 60; max-height: 60vh; overflow-y: auto; box-shadow: 0 -4px 24px rgba(0,0,0,.2); }
.clip-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-weight: 700; }
.clip-section { margin-bottom: 16px; }
.clip-section-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); margin-bottom: 6px; }
.clip-panel textarea { width: 100%; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--r-card); padding: 10px; color: var(--text); font-size: 14px; font-family: inherit; resize: none; }
.clip-remote { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--r-card); padding: 10px; font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 120px; overflow-y: auto; }
.clip-empty { color: var(--text-dim); font-style: italic; }

/* ── Snippets ── */
.snippet-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.snippet-chip { font-size: 12px !important; }
.snippet-pick { text-align: left; }

/* Model picker — descriptions */
.model-opt {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  padding: 8px 12px;
}
.model-opt .model-name {
  font-weight: 600;
  font-size: 0.92em;
}
.model-opt .model-desc {
  font-size: 0.72em;
  opacity: 0.6;
  line-height: 1.3;
  white-space: normal;
}
.model-grid {
  grid-template-columns: 1fr !important;
}
