:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ee;
  --border: #e2e2de;
  --text: #191919;
  --text-2: #5f5f5f;
  --text-3: #8a8a8a;
  --accent: #1b64be;
  --accent-ink: #ffffff;
  --good: #0a7d24;
  --good-bg: #e5f5e8;
  --warn: #9a6200;
  --warn-bg: #fdf1d8;
  --bad: #c62f30;
  --bad-bg: #fde8e8;
  --info-bg: #e7f0fc;
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --series-4: #f2a600;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121212;
    --surface: #191919;
    --surface-2: #222222;
    --border: #2e2e2e;
    --text: #efefef;
    --text-2: #a8a8a8;
    --text-3: #7a7a7a;
    --accent: #519ced;
    --accent-ink: #0b0b0b;
    --good: #3cc35a;
    --good-bg: #13301b;
    --warn: #e0a83a;
    --warn-bg: #35280c;
    --bad: #ef6b6b;
    --bad-bg: #3a1717;
    --info-bg: #15263c;
    --series-1: #338ced;
    --series-2: #e76624;
    --series-3: #00a888;
    --series-4: #d28e05;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212; --surface: #191919; --surface-2: #222222; --border: #2e2e2e;
  --text: #efefef; --text-2: #a8a8a8; --text-3: #7a7a7a; --accent: #519ced; --accent-ink: #0b0b0b;
  --good: #3cc35a; --good-bg: #13301b; --warn: #e0a83a; --warn-bg: #35280c; --bad: #ef6b6b; --bad-bg: #3a1717;
  --info-bg: #15263c; --series-1: #338ced; --series-2: #e76624; --series-3: #00a888; --series-4: #d28e05; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px; height: 56px;
  display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-lg { font-size: 24px; margin-bottom: 6px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px; flex: none;
  background:
    radial-gradient(circle at 30% 30%, var(--series-1) 0 22%, transparent 23%),
    radial-gradient(circle at 70% 30%, var(--series-2) 0 22%, transparent 23%),
    radial-gradient(circle at 30% 70%, var(--series-3) 0 22%, transparent 23%),
    radial-gradient(circle at 70% 70%, var(--series-4) 0 22%, transparent 23%), var(--surface-2);
}
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a {
  color: var(--text-2); text-decoration: none; padding: 7px 12px; border-radius: 8px; font-weight: 550; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.queue-pill { font-size: 13px; color: var(--text-2); white-space: nowrap; }

main.page { max-width: 1200px; margin: 0 auto; padding: 24px 16px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card + .card, .stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid > .card, .seat-grid > .card { margin-top: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Forms */
label { display: block; font-weight: 550; font-size: 14px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; margin-top: 6px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 140px; line-height: 1.5; }
.inline-select { width: auto; margin: 0; padding: 6px 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: auto; margin: 0; accent-color: var(--accent); }
.form-error { color: var(--bad); min-height: 1.5em; margin: 8px 0; font-size: 14px; }

.btn {
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.btn-ghost { border-color: transparent; background: transparent; }

/* Seat picker */
.seat-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.seat-option {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer; background: var(--surface);
}
.seat-option:has(input:checked) { border-color: var(--accent); background: var(--info-bg); }
.seat-option input { width: auto; margin: 3px 0 0; accent-color: var(--accent); }
.seat-option .seat-name { font-weight: 600; }
.seat-option select { margin-top: 6px; padding: 4px 6px; font-size: 13px; }
.seat-option input.model-input { width: 100%; margin: 6px 0 2px; padding: 4px 6px; font-size: 13px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.s-claude-cli { background: var(--series-1); }
.s-codex { background: var(--series-2); }
.s-antigravity { background: var(--series-3); }
.s-grok-cli { background: var(--series-4); }

/* Pills */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-good { background: var(--good-bg); color: var(--good); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-info { background: var(--info-bg); color: var(--accent); }
.pill-run::before { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* Run view */
.question { white-space: pre-wrap; margin: 10px 0 0; max-height: 220px; overflow: auto; }
.stages { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.stage { font-size: 13px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-3); }
.stage.on { color: var(--text); border-color: var(--text-3); }
.stage.done { color: var(--good); border-color: var(--good); }
.seat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 16px; margin-top: 16px; }
.seat-card { display: flex; flex-direction: column; min-width: 0; }
.seat-card header { padding: 14px 16px 10px; min-width: 0; border-bottom: 1px solid var(--border); }
.seat-card .meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-top: 6px; }
.seat-card .body { padding: 12px 16px 16px; min-width: 0; }
.log {
  font-family: var(--mono); font-size: 12px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px;
  max-height: 140px; overflow: auto; white-space: pre-wrap; word-break: break-word; color: var(--text-2); margin: 0;
}
.answer { overflow-wrap: anywhere; }
.answer.collapsed { max-height: 360px; overflow: hidden; mask-image: linear-gradient(to bottom, #000 75%, transparent); }
.synthesis-card { border-color: var(--accent); }
.spread { display: flex; flex-wrap: wrap; gap: 2px 12px; justify-content: space-between; margin-top: 8px; padding: 6px 10px;
  background: var(--surface-2); border-radius: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.run-tabs { display: flex; gap: 4px; margin: 10px 0 -11px; overflow-x: auto; scrollbar-width: none; }
.run-tab { font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border: 1px solid var(--border); border-bottom: 0;
  border-radius: 8px 8px 0 0; background: var(--surface-2); color: var(--text-2); cursor: pointer; white-space: nowrap; }
.run-tab.on { background: var(--surface); color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.run-tab.bad .muted { color: var(--bad); }
.run-tab:disabled { cursor: default; opacity: .6; }
.synthesis-card > header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
details { margin-top: 10px; }
details > summary { cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 600; }
details pre { margin: 8px 0 0; }
.error-box { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 8px 10px; font-size: 13px; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md pre { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; }
.md blockquote { margin-left: 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-2); }
.md h1, .md h2, .md h3 { margin: 1em 0 .4em; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.r, table.data th.r { text-align: right; }
table.data tr.link { cursor: pointer; }
table.data tr.link:hover td { background: var(--surface-2); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 560px; }

/* Stat tiles */
.tile { padding: 16px 18px; }
.tile .label { font-size: 13px; color: var(--text-2); font-weight: 550; }
.tile .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }

/* Chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .grid line { stroke: var(--border); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.12);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; min-width: 160px; z-index: 5;
}
.tooltip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; }

/* Logins */
.login-seat header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; margin: 12px 0; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Modal terminal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: min(920px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.modal .term-host { background: #0d0d0d; padding: 8px; height: 420px; flex: none; }
.term-links { display: flex; align-items: center; gap: 8px; padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--info-bg); }
.term-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-input { display: flex; gap: 8px; padding: 10px 18px; border-top: 1px solid var(--border); }
.term-input input { margin: 0; font-family: var(--mono); font-size: 13px; }

.notice { background: var(--info-bg); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.notice-warn { background: var(--warn-bg); color: var(--warn); }
.empty { text-align: center; padding: 40px 16px; color: var(--text-2); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); }

/* Sign-in page */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card form { margin-top: 18px; display: grid; gap: 12px; }

/* The submit row of a long form stays on screen while the form scrolls (on every width; it only sticks
   while the form's end is below the fold). */
.form-actions {
  position: sticky; bottom: 0; z-index: 5; margin: 16px -18px -18px; padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
}
.form-actions .form-error { margin: 0 0 6px; min-height: 0; }
.form-actions .form-error:empty { display: none; }
@media (hover: none) { .kbd-hint { display: none; } }

@media (max-width: 640px) {
  /* Top bar: brand + sign-out on one row, all five tabs on a full-width row below, so none hides off-screen. */
  .topbar-inner { flex-wrap: wrap; height: auto; gap: 0 10px; padding: 6px 12px 0; }
  .brand { height: 36px; }
  .brand span:last-child { display: none; }
  .topbar-right { margin-left: auto; }
  .nav { order: 3; flex: 1 0 100%; gap: 0; margin: 0 -4px; }
  .nav a { flex: 1 1 auto; text-align: center; padding: 9px 6px 10px; border-radius: 8px 8px 0 0; }
  .nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .queue-pill { display: none; }

  main.page { padding: 16px 16px 48px; }
  h1 { font-size: 20px; }
  .page-head { margin-bottom: 12px; }
  .card-pad { padding: 14px; }
  .form-actions { margin: 14px -14px -14px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .form-actions .row-between { flex-wrap: nowrap; }
  .form-actions .btn-primary { flex: 1 0 auto; justify-content: center; padding: 12px 16px; font-size: 15px; }
  #ask-estimate { flex: 0 1 auto; min-width: 0; }
  textarea { min-height: 110px; }
  /* 16px keeps iOS Safari from zooming into a field on focus. */
  input, select, textarea, .seat-option select, .seat-option input.model-input { font-size: 16px; }
  .btn-sm { padding: 7px 12px; }

  /* Checkbox hints wrap onto their own line under the label instead of squeezing it. */
  .check { flex-wrap: wrap; row-gap: 0; }
  .check .hint { flex-basis: 100%; padding-left: 21px; }

  .seat-picker { gap: 8px; }
  .seat-option { padding: 10px; }
  .seat-grid, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile .value { font-size: 22px; }
  .modal .term-host { height: 340px; }

  /* Run lists: each run as a card, question on top at full width, details on one line under it. */
  table.runs thead { display: none; }
  table.runs, table.runs tbody { display: block; }
  table.runs tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 12px 10px; border-bottom: 1px solid var(--border); }
  table.runs tr:last-child { border-bottom: 0; }
  table.runs td { display: block; padding: 0; border: 0; font-size: 13px; color: var(--text-2); }
  table.runs td.c-q { order: -1; flex: 1 0 100%; font-size: 15px; color: var(--text); }
  table.runs td.c-status { order: 0; }
  table.runs td.c-seats { margin-left: auto; order: 9; }
  table.runs td.c-tokens::after { content: " tok"; }
  table.runs .clamp { max-width: none; }
}
