
/* ════════════════════════════════════════════════════════════════════════════
   babel · telemetry console
   ────────────────────────────────────────────────────────────────────────────
   A single-user instrument panel for the babel proxy. Design language:
     • IBM Plex Sans (UI) · IBM Plex Mono (all data, tabular-nums) ·
       Instrument Serif (wordmark + hero figures)
     • graphite canvas, one restrained teal accent, tinted status semantics
       (green healthy / amber paused / red dead) as soft-bg + saturated-fg,
       never solid blocks except the destructive badge
     • hairline cards, right slide-over detail drawer, live 1-second
       countdown ticks (data polled slowly), thin progress bars w/ time pin
   Both themes; dark-first, auto via prefers-color-scheme unless overridden.
═══════════════════════════════════════════════════════════════════════════ */

:root {
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --font-serif: 'Instrument Serif', Georgia, serif;
  --radius: 10px;
  --radius-lg: 14px;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --dur: 220ms;
  --sidebar-w: 232px;
  color-scheme: dark;
}
/* Dark is the default palette. It applies to data-theme="dark" AND to
   data-theme="auto" when the OS is in dark mode (the common case). */
:root[data-theme="dark"],
:root[data-theme="auto"] {
  --bg:        #0e1115;
  --bg-elev:   #151a20;
  --surface:   #1a2028;
  --surface-2: #212a33;
  --border:   #2a333e;
  --border-soft:#222b35;
  --hair:      #232c36;
  --fg:        #e6ebf1;
  --fg-muted:  #93a1b2;
  --fg-faint:  #7b8a9c;
  --accent:    #2dd4bf;
  --accent-ink:#0b1f1c;
  --accent-soft:#0e2a26;
  --ok:        #34d399;
  --ok-soft:   #0e2a22;
  --warn:      #fbbf24;
  --warn-soft: #2a2110;
  --err:       #f87171;
  --err-soft:  #2a1614;
  --on-err:    #1a0c0c;
  --shadow:    0 1px 0 rgba(255,255,255,.03), 0 8px 24px rgba(0,0,0,.35);
  --grid:      rgba(255,255,255,.025);
  color-scheme: dark;
}
/* Explicit light. */
:root[data-theme="light"] {
  --bg:        #f6f5f1;
  --bg-elev:   #fbfaf6;
  --surface:   #ffffff;
  --surface-2: #f1efe9;
  --border:    #e2ddd1;
  --border-soft:#ece8de;
  --hair:      #ebe6da;
  --fg:        #1c1f24;
  --fg-muted:  #5c6470;
  --fg-faint:  #6b7280;
  --accent:    #0d9488;
  --accent-ink:#ffffff;
  --accent-soft:#dcefe9;
  --ok:        #059669;
  --ok-soft:   #d8f3e6;
  --warn:      #b45309;
  --warn-soft: #fbe9c9;
  --err:       #dc2626;
  --err-soft:  #fde2e2;
  --on-err:    #ffffff;
  --shadow:    0 1px 0 rgba(0,0,0,.02), 0 8px 24px rgba(60,55,40,.08);
  --grid:      rgba(0,0,0,.025);
  color-scheme: light;
}
/* Auto + OS in light mode → switch to the light palette. */
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] { color-scheme: light;
    --bg:#f6f5f1;--bg-elev:#fbfaf6;--surface:#ffffff;--surface-2:#f1efe9;
    --border:#e2ddd1;--border-soft:#ece8de;--hair:#ebe6da;--fg:#1c1f24;
    --fg-muted:#5c6470;--fg-faint:#6b7280;--accent:#0d9488;--accent-ink:#fff;
    --accent-soft:#dcefe9;--ok:#059669;--ok-soft:#d8f3e6;--warn:#b45309;
    --warn-soft:#fbe9c9;--err:#dc2626;--err-soft:#fde2e2;--on-err:#fff;
    --shadow:0 1px 0 rgba(0,0,0,.02),0 8px 24px rgba(60,55,40,.08);--grid:rgba(0,0,0,.025);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* mobile: kill the blue flash on tap, let horizontal scrolls happen inside
     wrappers (not the whole page), and stop iOS rubber-band on the body. */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  background-image:
    radial-gradient(1200px 600px at 80% -10%, var(--accent-soft), transparent 60%),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100% 100%, 44px 44px, 44px 44px;
}
/* inputs at <16px trigger iOS auto-zoom on focus; floor the editable font size.
   These specific selectors (.field input, .gate-card input, #reqQ) set their
   own font-size, so they have to be re-floored on mobile too. */
input, select, textarea { font-size: 16px; }
.field input, .field select, .gate-card input, #reqQ { font-size: 16px; }
@media (min-width: 721px) {
  input, select, textarea { font-size: 14px; }
  .field input, .field select, .gate-card input, #reqQ { font-size: .85rem; }
}
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--fg-muted); }
.faint { color: var(--fg-faint); }
.serif { font-family: var(--font-serif); font-weight: 400; letter-spacing: -.01em; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* ── Gate ─────────────────────────────────────────────────────────────────── */
#gate {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 100;
}
.gate-card {
  width: min(380px, 92vw); padding: 2.4rem 2rem 2rem; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  animation: rise .5s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.gate-card .mark { font-family: var(--font-serif); font-size: 2rem; line-height: 1; }
.gate-card .mark .dot { color: var(--accent); }
.gate-card .tagline { color: var(--fg-muted); font-size: .82rem; margin: .3rem 0 1.6rem; letter-spacing: .02em; }
.gate-card label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); margin-bottom: .4rem; }
.gate-card input {
  width: 100%; padding: .6rem .7rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); font-family: var(--font-mono); font-size: .85rem;
}
.gate-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.gate-card button {
  width: 100%; margin-top: .8rem; padding: .6rem; background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: var(--radius); font-weight: 600; font-size: .85rem;
  transition: transform var(--dur) var(--ease), filter var(--dur);
}
.gate-card button:hover { filter: brightness(1.08); }
.gate-msg { margin-top: .7rem; font-size: .78rem; min-height: 1rem; }
.gate-msg.err { color: var(--err); }

/* ── App shell ────────────────────────────────────────────────────────────── */
#app { display: none; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
#app.show { display: grid; }
aside {
  border-right: 1px solid var(--border); background: var(--bg-elev); padding: 1.4rem 0 1rem;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 1.2rem .8rem; border-bottom: 1px solid var(--hair); margin-bottom: .8rem; }
.brand .mark { font-family: var(--font-serif); font-size: 1.7rem; line-height: 1; }
.brand .mark .dot { color: var(--accent); }
.brand .ver { font-family: var(--font-mono); font-size: .66rem; color: var(--fg-faint); letter-spacing: .04em; margin-top: .2rem; }
.nav-group { padding: .4rem .6rem; }
.nav-label { font-size: .66rem; text-transform: uppercase; letter-spacing: .1em; color: var(--fg-faint); padding: .5rem .6rem .3rem; }
.nav-item {
  display: flex; align-items: center; gap: .6rem; padding: .42rem .6rem; border-radius: var(--radius);
  color: var(--fg-muted); font-size: .85rem; border: none; background: transparent; width: 100%; text-align: left;
  transition: background var(--dur), color var(--dur);
}
.nav-item:hover { background: var(--surface); color: var(--fg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item .ic { width: 16px; height: 16px; opacity: .8; flex: 0 0 16px; }
.nav-item .ic svg { width: 16px; height: 16px; }
.nav-spacer { flex: 1; }
.nav-foot { padding: .6rem .8rem; border-top: 1px solid var(--hair); }
.theme-toggle { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px; }
.theme-toggle button { flex: 1; padding: .3rem; font-size: .72rem; background: transparent; border: none; border-radius: 7px; color: var(--fg-muted); }
.theme-toggle button.active { background: var(--surface-2); color: var(--fg); }

main { min-width: 0; }
/* ── Status pills (now in the sidebar foot) + the floating mobile ☰ ─────── */
.nav-status { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .6rem; }
.nav-status .pill { display: flex; align-items: center; gap: .35rem; font-family: var(--font-mono); font-size: .66rem; padding: .2rem .5rem; border-radius: 20px; background: var(--surface-2); color: var(--fg-muted); }
.nav-status .pill .led { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 6px var(--ok); animation: pulse 2.4s ease-in-out infinite; flex: 0 0 7px; }
@keyframes pulse { 50% { opacity: .4; } }
.nav-status .pill .led.down { background: var(--err); box-shadow: 0 0 6px var(--err); }
/* floating ☰ — mobile only (the sidebar collapses off-screen on phones).
   Declared here with display:none; the mobile @media block below switches it
   to display:inline-flex. Desktop never shows it (sidebar is always visible). */
#navToggle { display: none; align-items: center; justify-content: center; position: fixed; top: max(.7rem, env(safe-area-inset-top)); left: max(.7rem, env(safe-area-inset-left)); z-index: 40; width: 40px; height: 40px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); font-size: 1rem; color: var(--fg); box-shadow: var(--shadow); }
#navToggle:hover { border-color: var(--accent); }

.view { padding: 1.6rem; max-width: 1180px; padding-left: max(1.6rem, env(safe-area-inset-left)); padding-right: max(1.6rem, env(safe-area-inset-right)); }
.view-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.view-head h2 { font-family: var(--font-serif); font-size: 1.6rem; margin: 0; font-weight: 400; }
.view-head .sub { color: var(--fg-muted); font-size: .82rem; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 .7rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; color: var(--fg-faint); font-weight: 600; }
.card .card-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
/* horizontal-scroll wrappers around tables: sticky header stays labeled while
   swiping the wide table sideways on a phone. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x > table { min-width: 36rem; }
.scroll-x > table thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; box-shadow: inset 0 -1px 0 var(--border); }

.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
/* cards inside a grid rely on the grid gap for spacing — their own
   margin-bottom would otherwise DOUBLE the gap (grid gap + card margin),
   making vertical gaps ~2× the horizontal ones (looked "off" on mobile). */
.grid > .card { margin-bottom: 0; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
/* On tablet/mobile, 2-up grids (g2) and 3-up (g3) collapse to one column,
   but the 4-stat-card row (g4 — pulse overview + stats totals) goes 2×2:
   four compact stat cards fit comfortably two-per-row on a phone, instead of
   stacking into four tall single-column rows. */
@media (max-width: 880px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, 1fr); }
}

.stat { display: flex; flex-direction: column; gap: .2rem; }
.stat .num { font-family: var(--font-serif); font-size: 2.1rem; line-height: 1; }
.stat .lbl { font-family: var(--font-mono); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); }

/* ── Status badges ────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .5rem; border-radius: 6px; font-size: .7rem; font-family: var(--font-mono); font-weight: 500; letter-spacing: .02em; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.healthy { background: var(--ok-soft); color: var(--ok); }
.badge.paused  { background: var(--warn-soft); color: var(--warn); }
.badge.dead    { background: var(--err); color: var(--on-err); }
.badge.err     { background: var(--err-soft); color: var(--err); }
.badge.ok      { background: var(--ok-soft); color: var(--ok); }
.badge.warn    { background: var(--warn-soft); color: var(--warn); }
.badge.neutral { background: var(--surface-2); color: var(--fg-muted); }
.badge.accent  { background: var(--accent-soft); color: var(--accent); }
/* thin countdown badge — its text is refreshed in place each tick (no per-second
   DOM rebuild), so the ↻ read stays a quiet inline label instead of a flashy
   badge that pops every second. Less tall than the status badges. */
.badge.cd { padding: .04rem .42rem; font-size: .64rem; line-height: 1.15; }
.http { font-family: var(--font-mono); font-size: .72rem; padding: .1rem .4rem; border-radius: 5px; }
.http.s2 { background: var(--ok-soft); color: var(--ok); }
.http.s4 { background: var(--warn-soft); color: var(--warn); }
.http.s5 { background: var(--err-soft); color: var(--err); }
.http.s0 { background: var(--surface-2); color: var(--fg-faint); }
/* In-flight (not-yet-finalized) request — teal/accent, distinct from error.
   The status text is "—" until finalize; the color says "live", not "failed". */
.http.sOngoing { background: var(--accent-soft); color: var(--accent); }

/* ── Tables ───────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th { text-align: left; padding: .5rem .5rem; font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); font-weight: 600; border-bottom: 1px solid var(--border); }
td { padding: .5rem .5rem; border-bottom: 1px solid var(--hair); vertical-align: top; }
tbody tr { transition: background var(--dur); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.flagged { box-shadow: inset 2px 0 0 var(--warn); }
/* Hot-row coloring: only rows with > 20000 total tokens (in+out+cache_read+
   cache_write) get a background, driven by cache efficiency — cache% < 40 red,
   < 80 yellow. Sparse-context rows stay uncolored. The flagged left-border still
   applies on top (it's a separate declaration). */
tbody tr.row-hot-red { background: var(--err-soft); }
tbody tr.row-hot-red:hover { background: color-mix(in srgb, var(--err-soft) 70%, var(--surface-2)); }
tbody tr.row-hot-yellow { background: var(--warn-soft); }
tbody tr.row-hot-yellow:hover { background: color-mix(in srgb, var(--warn-soft) 70%, var(--surface-2)); }
/* Route badges — themed by inbound path. Messages/Count are Anthropic-orange;
   Chat is neutral white; Responses is royal-blue; unknown is gray. */
.tag.route-messages { color: #fff; background: #d97757; }       /* Anthropic orange */
.tag.route-count    { color: #fff; background: #d97757; }
.tag.route-chat     { color: #1a1a1a; background: #e8e8e8; }    /* white */
.tag.route-responses{ color: #fff; background: #2453ff; }        /* royal blue */
.tag.route-unknown  { color: #888; background: #3a3a3a; }        /* gray */
.tnum { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tmono { font-family: var(--font-mono); font-size: .76rem; }
/* agent column label: an optional local svg/png icon and/or an alias (emoji or
   short text) configured per agent_id in config.agentLabels. The full agent_id
   is kept as the hover title; rows with no configured label fall back to the raw
   agent_id. Used in the requests table + compact view. */
.agent-lbl { display: inline-flex; align-items: center; gap: .22rem; }
.agent-ic { width: 14px; height: 14px; vertical-align: middle; }
.agent-alias { font-family: var(--font-sans); }
/* clickable rows need a fat-enough tap target on touch */
tbody tr.clickable td { padding-top: .6rem; padding-bottom: .6rem; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.field { margin-bottom: .7rem; }
.field label { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-faint); margin-bottom: .25rem; }
.field input, .field select {
  width: 100%; padding: .4rem .5rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .85rem;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input.locked { background: var(--surface-2); color: var(--fg-muted); cursor: not-allowed; }
.row-acts { white-space: nowrap; text-align: right; }
.row-acts .btn + .btn { margin-left: .3rem; }
.btn { padding: .4rem .7rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); font-size: .78rem; color: var(--fg); transition: background var(--dur), border-color var(--dur); }
.btn:hover { background: var(--surface); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--border)); }
.btn.danger:hover { background: var(--err-soft); }
.btn.small { padding: .25rem .45rem; font-size: .72rem; }
/* comfortable touch target — buttons are tappable on phones */
.btn { min-height: 36px; }
.btn.small { min-height: 30px; }
.row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1; min-width: 8rem; }

/* ── Progress / usage bar ─────────────────────────────────────────────────── */
.bar { position: relative; height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.err > i { background: var(--err); }
.bar .pin { position: absolute; top: -2px; width: 2px; height: 9px; background: var(--fg-faint); border-radius: 1px; }

/* ── Per-token rate-limit windows (pulse) ─────────────────────────────────── */
.rl-token { padding: .5rem 0; border-bottom: 1px solid var(--hair); }
.rl-token:last-child { border-bottom: none; }
.rl-token .rl-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .35rem; }
.rl-token .rl-head .lbl { font-weight: 600; }
.rl-windows { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .5rem .9rem; }
.rl-win { min-width: 0; }
.rl-win .rl-meta { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--font-mono); font-size: .7rem; margin-bottom: .15rem; }
.rl-win .rl-meta .pct { font-weight: 600; }
.rl-win .rl-meta .pct.lo { color: var(--ok); }
.rl-win .rl-meta .pct.mid { color: var(--warn); }
.rl-win .rl-meta .pct.hi { color: var(--err); }
.rl-win .rl-bar { height: 6px; }
.rl-win .rl-count { font-family: var(--font-mono); font-size: .66rem; color: var(--fg-faint); margin-top: .1rem; }
/* cooldown chip shares the paused-badge look (soft warn bg + saturated warn fg
   + a status dot, via .badge.paused on the element). It carries the model +
   window name only — no live ↻ countdown (the window-level countdown next to
   each quota bar still ticks). A modifier hook, not a standalone style. */
.cooldown { gap: .25rem; }
.cooldown .cd-win { color: var(--fg-faint); font-weight: 400; }

/* ── Model-status wall (pulse) ────────────────────────────────────────────── */
.wall { display: flex; flex-wrap: wrap; gap: 2px; }
.wall .bar-req { width: 6px; height: 24px; border-radius: 2px; background: var(--surface-2); transition: transform var(--dur); }
/* usage-chart legend */
.chart-legend { display: flex; gap: 1rem; margin-bottom: .4rem; }
.chart-legend .leg { display: inline-flex; align-items: center; gap: .35rem; font-family: var(--font-mono); font-size: .66rem; color: var(--fg-muted); }
.chart-legend .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-legend .sw.teal { background: var(--accent); opacity: .85; }
.chart-legend .sw.amber { background: var(--warn); opacity: .6; }
/* chart x-axis: start + end (space-between, never overlaps on mobile); a single
   mid-tick for desktop scale, hidden on phones where it would crowd. */
.chart-axis { display: flex; justify-content: space-between; font-size: .66rem; color: var(--fg-faint); margin-top: .5rem; }
.chart-axis .chart-mid { color: var(--fg-faint); opacity: .7; }
@media (max-width: 720px) { .chart-axis .chart-mid { display: none; } }
.wall .bar-req:hover { transform: scaleY(1.15); }
.wall .bar-req.s2 { background: var(--ok); }
.wall .bar-req.s4 { background: var(--warn); }
.wall .bar-req.s5 { background: var(--err); }
/* In-flight (not-yet-finalized) request — distinct from error: teal/accent,
   not red. An ongoing request is live, not failed. */
.wall .bar-req.sOngoing { background: var(--accent); }
/* s0 = a status that matched no bucket (e.g. 3xx) — neutral, not an error. */
.wall .bar-req.s0 { background: var(--surface-2); }
.wall .bar-req.sX { background: var(--surface-2); }

/* ── Slide-over detail drawer ─────────────────────────────────────────────── */
#drawer { position: fixed; inset: 0; z-index: 50; display: none; }
#drawer.open { display: block; }
#drawer .backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(2px); animation: fade .2s var(--ease) both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#drawer .panel {
  /* +30% width (640→832px); clamped to 96vw so wide desktops still see margin. */
  position: absolute; right: 0; top: 0; height: 100%; width: min(832px, 96vw);
  background: var(--bg-elev); border-left: 1px solid var(--border); box-shadow: -16px 0 40px rgba(0,0,0,.4);
  display: flex; flex-direction: column; animation: slide .28s var(--ease) both; overflow: hidden;
}
@keyframes slide { from { transform: translateX(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .7rem; min-height: 56px; }
.drawer-head .x { margin-left: auto; background: transparent; border: none; color: var(--fg-muted); font-size: 1.2rem; padding: .2rem .5rem; border-radius: 6px; }
.drawer-head .x:hover { background: var(--surface); color: var(--fg); }
.drawer-head .http { font-family: var(--font-mono); font-size: .9rem; padding: .15rem .45rem; border-radius: 6px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 1.2rem; }
.drawer-body h4 { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); margin: 1.2rem 0 .5rem; font-weight: 600; display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.drawer-body h4:first-child { margin-top: 0; }
.drawer-body h4 .h-sub { font-weight: 400; text-transform: none; letter-spacing: 0; font-size: .7rem; color: var(--fg-faint); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; font-size: .82rem; }
.kv dt { color: var(--fg-muted); }
.kv dd { margin: 0; font-family: var(--font-mono); min-width: 0; word-break: break-all; }
.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(108px, 1fr)); gap: .5rem; }
.pre {
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: .8rem; font-family: var(--font-mono); font-size: .72rem; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
  max-height: 280px; overflow: auto; margin: 0; box-sizing: border-box; width: 100%; max-width: 100%;
}
/* "this turn" — the readable transcript of one request (user input + response). */
.turn-wrap { display: flex; flex-direction: column; gap: .6rem; }
.turn-msg { border: 1px solid var(--border-soft); border-radius: var(--radius); overflow: hidden; }
.turn-msg .turn-role { font-family: var(--font-mono); font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-faint); padding: .35rem .8rem; background: var(--surface-2); border-bottom: 1px solid var(--border-soft); }
.turn-msg .pre { border: none; border-radius: 0; max-height: 320px; }
.turn-user .turn-role { color: var(--accent); }
.turn-assistant .turn-role { color: var(--ok); }
.turn-thinking .turn-role { color: var(--warn); }
.turn-thinking .pre { color: var(--fg-muted); font-style: italic; }
.turn-tool .turn-role { color: var(--accent); }
.turn-tool .pre { white-space: pre-wrap; }
.collapsible > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: .4rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-muted); }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary .chev { transition: transform var(--dur); }
.collapsible[open] > summary .chev { transform: rotate(90deg); }
.collapsible > .pre { margin-top: .5rem; }

/* transcript (session-detail): idle-gap divider + long-text truncation. Reuses
   the .turn-msg/.turn-role/.pre + .collapsible primitives; these few rules are
   the only transcript-specific additions. */
.tgap { text-align: center; color: var(--fg-faint); font-family: var(--font-mono); font-size: .8rem; letter-spacing: .3em; padding: .6rem 0; user-select: none; }
.trunc > summary { cursor: pointer; list-style: none; font-family: var(--font-mono); font-size: .72rem; color: var(--fg-muted); padding: .6rem .8rem; word-break: break-word; }
.trunc > summary::-webkit-details-marker { display: none; }
.trunc > summary .more { color: var(--accent); white-space: nowrap; margin-left: .25rem; }
.trunc[open] > summary .more { display: none; }
.trunc > .pre { border: none; border-radius: 0; margin: 0 .8rem .6rem; }

/* ── Session timeline ─────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 1.2rem; }
.timeline::before { content: ''; position: absolute; left: 4px; top: 4px; bottom: 4px; width: 1px; background: var(--border); }
.tl-item { position: relative; padding: .5rem 0 .8rem; }
.tl-item::before { content: ''; position: absolute; left: -1.12rem; top: .65rem; width: 9px; height: 9px; border-radius: 50%; background: var(--surface); border: 2px solid var(--fg-faint); }
.tl-item.ok::before { border-color: var(--ok); }
.tl-item.err::before { border-color: var(--err); }
.tl-item .tl-meta { font-family: var(--font-mono); font-size: .72rem; color: var(--fg-muted); display: flex; gap: .7rem; flex-wrap: wrap; }
.tl-item .tl-body { font-size: .8rem; margin-top: .15rem; }

.empty { color: var(--fg-faint); padding: 2rem; text-align: center; font-size: .85rem; }
.loading { color: var(--fg-faint); font-size: .8rem; }
.tag { display: inline-block; padding: .1rem .4rem; border-radius: 5px; background: var(--surface-2); color: var(--fg-muted); font-family: var(--font-mono); font-size: .68rem; margin-right: .25rem; }
.spin { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .9rem; font-size: .8rem; box-shadow: var(--shadow); z-index: 80; animation: rise .3s var(--ease) both; }
.toast.err { border-color: var(--err); color: var(--err); }

/* ☰ mobile-nav toggle (hidden on desktop). Declared BEFORE the mobile media
   query so the media query's `display: inline-flex` can override this
   `display: none` (same specificity → source order decides; if this sat after
   the @media block it would win and hide the button on mobile, making the
   sidebar unreachable — the v3.12.0 bug). */
/* (the #navToggle base rule now lives up with the status-pills section, and
   is declared before this @media block so the override below works.) */

/* mobile: collapse sidebar into an overlay drawer toggled from the floating ☰ */
@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  aside {
    display: none; position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); height: 100vh; height: 100dvh; z-index: 30;
    box-shadow: 0 0 40px rgba(0,0,0,.4); padding-top: max(1.4rem, env(safe-area-inset-top));
    padding-bottom: env(safe-area-inset-bottom);
  }
  #app.nav-open aside { display: flex; }
  #app.nav-open::before { content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 25; }
  /* the floating ☰ shows on mobile only (its base rule sets display:none) */
  #navToggle { display: inline-flex; }
  /* when the sidebar is open, hide the ☰ so it doesn't overlap the close-on-backdrop tap target */
  #app.nav-open #navToggle { display: none; }
  /* tighten view + card padding on phones (was 1.6rem / 1.1-1.2rem) */
  .view { padding: 1rem; }
  .view-head { margin-bottom: .9rem; padding-left: 3rem; } /* clear the floating ☰ (40px + 8px) */
  .view-head h2 { font-size: 1.4rem; }
  .card { padding: .9rem; margin-bottom: .9rem; }
  /* filter rows stack full-width; the search input owns its own line */
  .row { flex-direction: column; align-items: stretch; gap: .5rem; }
  .row .grow { width: 100%; min-width: 0; }
  .row .btn, .row > select { width: 100%; }
  /* detail drawer: near-full-screen on phones, slid from the right */
  #drawer .panel { width: 100vw; box-shadow: -10px 0 30px rgba(0,0,0,.5); }
  .drawer-head { padding: .8rem .9rem; padding-right: max(.9rem, env(safe-area-inset-right)); }
  .drawer-body { padding: .9rem; padding-bottom: max(.9rem, env(safe-area-inset-bottom)); }
  /* the kv grid in the drawer + usage grid breathe */
  .kv { grid-template-columns: auto 1fr; }
  /* gate card: don't overflow on small phones; respect the notch */
  #gate { padding: 1rem; padding-top: max(1rem, env(safe-area-inset-top)); }
  .gate-card { width: 100%; max-width: 22rem; padding: 1.4rem 1.2rem; }
  /* the pricing form row is wide — let it wrap to a single column on phones */
  #priceForm .row { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
  #priceForm .row .field { flex: 1 1 7rem; }
  /* toasts clear the home indicator */
  .toast { bottom: max(1.2rem, env(safe-area-inset-bottom)); left: 1rem; right: 1rem; transform: none; max-width: 30rem; margin: 0 auto; }
}
/* very small phones: shrink view padding further so the wall/tables get room */
@media (max-width: 400px) {
  .view { padding: .7rem; }
  .card { padding: .8rem; }
  .view-head h2 { font-size: 1.25rem; }
  .stat .num { font-size: 1.7rem; }
}

/* compact inline window-tab strip (pulse view head) — a mini horizontal bar */
.win-tabs { display: inline-flex; gap: .25rem; margin-left: auto; }
.win-tabs .win-tab { padding: .2rem .5rem; font-size: .72rem; min-height: 0; }

/* keyboard focus — visible ring on every interactive element (only via
   keyboard, not mouse: :focus-visible) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button:focus-visible, .nav-item:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
