/* Foreman design system. Source of truth: /DESIGN.md (DESIGN.md wins on drift).
   Dark is the primary mode; light is a designed sibling, not an inversion. */

/* ---------- Fonts (self-hosted, OFL) ---------- */
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("fonts/atkinson-hyperlegible-next.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Martian Mono";
  src: url("fonts/martian-mono.woff2") format("woff2");
  font-weight: 100 800; font-stretch: 75% 112.5%; font-style: normal; font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;
  --font-body: "Atkinson Hyperlegible Next", "Segoe UI", sans-serif;
  --font-mono: "Martian Mono", "Cascadia Mono", Consolas, ui-monospace, monospace;
  --mono-stretch: 80%;

  /* type: ratio 1.2 (minor third), base 14px; mono steps are set ~1px smaller because Martian runs large */
  --t-micro: 11px;  --t-meta: 12px;  --t-body: 14px;
  --t-lead: 17px;   --t-h2: 20px;    --t-h1: 24px;  --t-readout: 29px;
  --m-micro: 10.5px; --m-meta: 11.5px; --m-body: 12.5px;

  /* spacing: 4px base */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  /* shape: two radii, defined edges, no shadows */
  --r-1: 2px;  /* strips, chips, fields, cells */
  --r-2: 4px;  /* buttons, inputs, plates */
  --rail: 3px; /* rack rail width (the logo's stem) */
  --pull: 16px; /* how far a strip that needs you sticks out of the rack */

  /* motion */
  --dur-1: 120ms; --dur-2: 180ms; --dur-3: 240ms; --dur-sheet: 320ms;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);

  /* colour: dark (primary) */
  --bg: oklch(0.175 0.006 70);          /* #12100e  the rack */
  --surface: oklch(0.215 0.007 70);     /* #1c1916  a strip */
  --surface-2: oklch(0.255 0.008 70);   /* #25221f  raised: header strip, popover */
  --surface-3: oklch(0.295 0.009 70);   /* #302c28  hover on raised */
  --border: oklch(0.33 0.009 70);       /* #383530  field rules */
  --border-strong: oklch(0.44 0.011 70);/* #57524c  strip edge, rail */
  --control: oklch(0.56 0.012 75);      /* #79746d  input/button outline, >= 3:1 */
  --fg: oklch(0.93 0.010 85);           /* #ebe7e0 */
  --muted: oklch(0.72 0.012 80);        /* #a9a49c */
  --faint: oklch(0.56 0.012 75);        /* #79746d  non-text only */

  --accent: oklch(0.84 0.085 82);       /* #e6c68a  strip buff */
  --accent-hover: oklch(0.88 0.075 85); /* #eed49f */
  --accent-fg: oklch(0.21 0.02 70);     /* #1e170e */
  --accent-ink: var(--accent);          /* buff used as text */
  --accent-wash: oklch(0.255 0.03 80);  /* #2a2112  pulled strip ground */
  --accent-mark: var(--accent);

  --working: oklch(0.76 0.075 225);     /* #7bbcd5 */
  --working-wash: oklch(0.25 0.025 225);
  --done: oklch(0.78 0.12 150);         /* #7ccd8e */
  --done-wash: oklch(0.25 0.03 150);
  --blocked: oklch(0.77 0.13 55);       /* #f39d5e */
  --blocked-wash: oklch(0.26 0.035 55);
  --error: oklch(0.71 0.16 25);         /* #f5746d */
  --error-wash: oklch(0.25 0.045 25);
  --waiting: var(--muted);
  --waiting-wash: var(--surface-2);

  --focus: var(--accent);
}

/* light mode: explicit choice only. Dark is the default even when the OS prefers light (dark-first decision). */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: oklch(0.955 0.004 75); --surface: oklch(0.995 0.002 80); --surface-2: oklch(0.975 0.003 75); --surface-3: oklch(0.945 0.004 75);
  --border: oklch(0.87 0.006 75); --border-strong: oklch(0.73 0.009 75); --control: oklch(0.60 0.010 70);
  --fg: oklch(0.22 0.010 70); --muted: oklch(0.47 0.012 70); --faint: oklch(0.62 0.010 70);
  --accent: oklch(0.86 0.085 82); --accent-hover: oklch(0.82 0.09 80); --accent-fg: oklch(0.22 0.02 70);
  --accent-ink: oklch(0.47 0.09 68); --accent-wash: oklch(0.95 0.03 85); --accent-mark: oklch(0.64 0.12 72);
  --working: oklch(0.48 0.09 235); --working-wash: oklch(0.95 0.02 235);
  --done: oklch(0.48 0.11 150); --done-wash: oklch(0.95 0.03 150);
  --blocked: oklch(0.53 0.13 50); --blocked-wash: oklch(0.95 0.03 55);
  --error: oklch(0.51 0.18 27); --error-wash: oklch(0.95 0.025 25);
  --focus: oklch(0.47 0.09 68);
}
.theme-switching * { transition: none !important; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 400 var(--t-body)/1.5 var(--font-body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent); color: var(--accent-fg); }
.mono, code, kbd {
  font-family: var(--font-mono); font-stretch: var(--mono-stretch);
  font-size: var(--m-body); font-weight: 450; letter-spacing: -0.01em;
}
code { color: var(--fg); }
.num { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-body); text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.label {
  font-family: var(--font-mono); font-stretch: var(--mono-stretch);
  font-size: var(--m-micro); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus { outline: none; }
:focus-visible { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--focus); border-radius: var(--r-1); }
.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: butt; stroke-linejoin: miter; vertical-align: -3px; }
.ico-fill { fill: currentColor; stroke: none; }

/* Links: fg text, rule underline, arrow glyph for direction. Buff is reserved for "needs you" and the primary action. */
.link { color: var(--fg); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.link:hover { text-decoration-color: var(--fg); }
.link .arr { font-family: var(--font-mono); font-size: 0.85em; color: var(--muted); margin-left: 2px; text-decoration: none; display: inline-block; }

/* ---------- Shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 52px; display: flex; align-items: center; gap: var(--s-6);
  padding: 0 var(--s-6); background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--fg); height: 40px; }
.brand svg.mark { width: 24px; height: 24px; }
.brand svg.word { height: 20px; width: auto; }
.nav { display: flex; gap: 2px; height: 100%; }
.nav a {
  display: flex; align-items: center; gap: 8px; padding: 0 var(--s-3); height: 100%;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500;
}
.nav a:hover { color: var(--fg); }
.nav a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--fg); }
.nav .count { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); color: var(--muted); }
.nav .count.need { color: var(--accent-fg); background: var(--accent); padding: 1px 5px; border-radius: var(--r-1); font-weight: 600; }
.topbar .spacer { flex: 1; }
.hub { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); color: var(--muted); }
.hub .lamp { width: 8px; height: 8px; background: var(--done); border-radius: 1px; }
.hub.offline .lamp { background: transparent; box-shadow: inset 0 0 0 1.5px var(--blocked); }
.hub.offline { color: var(--blocked); }
.iconbtn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: var(--r-2);
  border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer;
}
.iconbtn:hover { color: var(--fg); background: var(--surface); border-color: var(--border); }
.iconbtn:active { background: var(--surface-2); }
.who { font-size: var(--t-meta); color: var(--muted); }

/* accounts strip: one field per account, rules between, like a strip */
.quota { display: flex; align-items: stretch; min-height: 34px; padding: 0 var(--s-6); border-bottom: 1px solid var(--border); background: color-mix(in oklch, var(--surface) 55%, var(--bg)); overflow-x: auto; scrollbar-width: none; font-size: var(--t-meta); }
.quota .q-label { align-self: center; padding-right: var(--s-4); white-space: nowrap; }
.q-acc { display: flex; align-items: center; gap: 10px; padding: 0 var(--s-4); border-left: 1px solid var(--border); white-space: nowrap; color: var(--fg); }
.q-acc:hover { background: var(--surface); }
.q-name { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-meta); font-weight: 600; }
.q-m { display: inline-flex; align-items: center; gap: 5px; }
.q-k { color: var(--muted); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); }
.q-m .bar { width: 36px; height: 4px; background: var(--border); border-radius: 1px; overflow: hidden; display: inline-block; }
.q-m .bar i { display: block; height: 100%; background: var(--muted); }
.q-m[data-lvl="low"] .bar i { background: var(--blocked); }
.q-m[data-lvl="spent"] .bar i { background: var(--error); }
.q-m .mono { font-size: var(--m-micro); }
.q-v { font-size: var(--m-meta); }
.q-sub { color: var(--muted); font-size: 11.5px; }
.q-acc .st { font-size: 10.5px; }
.q-tail { align-self: center; margin-left: auto; padding-left: var(--s-4); white-space: nowrap; font-size: var(--t-meta); }
.offline-banner {
  display: none; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-6);
  background: var(--blocked-wash); color: var(--fg); border-bottom: 1px solid var(--border); font-size: var(--t-meta);
}
.offline-banner b { color: var(--blocked); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); letter-spacing: .06em; }
body.is-offline .offline-banner { display: flex; }
body.is-offline .live-only { opacity: .55; }

.tabbar { display: none; }

main.page { flex: 1; width: 100%; max-width: 1560px; margin: 0 auto; padding: var(--s-6) var(--s-6) var(--s-12); }
.page-head { display: flex; align-items: baseline; gap: var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-6); }
.page-head h1 { font-size: var(--t-h1); font-weight: 650; letter-spacing: -0.01em; line-height: 1.15; }
.page-head .sub { color: var(--muted); font-size: var(--t-meta); }
.page-head .tools { margin-left: auto; display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }

.cols { display: grid; grid-template-columns: minmax(0, 8fr) minmax(0, 4fr); gap: var(--s-10) var(--s-8); align-items: start; }
.stack-v > * + * { margin-top: var(--s-10); }

/* readout: the one number that matters, not a triptych */
.readout { display: flex; align-items: baseline; gap: var(--s-3); }
.readout .n { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--t-readout); font-weight: 600; line-height: 1; color: var(--accent-ink); }
.readout .t { font-size: var(--t-lead); font-weight: 600; }
.readout .s { color: var(--muted); font-size: var(--t-meta); }

/* ---------- Bay (the rack) ---------- */
.bay { position: relative; padding-left: calc(var(--rail) + var(--s-3)); }
.bay::before { /* the rack rail: the logo's stem */
  content: ""; position: absolute; left: 0; top: 4px; bottom: 0; width: var(--rail); background: var(--border-strong); border-radius: 1px;
}
.bay.needs::before { background: var(--accent-mark); }
.bay-head { display: flex; align-items: baseline; gap: var(--s-3); margin-bottom: var(--s-3); min-height: 24px; flex-wrap: wrap; }
.bay-head h2 { font-size: var(--t-body); font-weight: 650; letter-spacing: 0; }
.bay-head .n { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-meta); color: var(--muted); }
.bay-head .hint { color: var(--muted); font-size: var(--t-meta); }
.bay-head .end { margin-left: auto; display: flex; gap: var(--s-2); align-items: center; }
.rack { display: flex; flex-direction: column; gap: var(--s-1); padding-right: var(--pull); }

/* ---------- Strip ---------- */
.strip {
  position: relative; display: grid; grid-template-columns: var(--cols, 104px 112px minmax(0, 1fr) auto); align-items: stretch;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-1);
  min-height: 52px; transition: transform var(--dur-2) var(--ease-out);
}
.strip > .f { padding: 7px var(--s-3); border-left: 1px solid var(--border); min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.strip > .f:first-child { border-left: 0; }
.strip > .f.act { flex-direction: row; align-items: center; gap: var(--s-2); justify-content: flex-end; }
.strip .title { font-weight: 550; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.strip .title a:hover { text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.strip .meta { color: var(--muted); font-size: var(--t-meta); display: flex; gap: 6px 10px; flex-wrap: wrap; align-items: center; min-width: 0; }
.strip .meta .mono { font-size: var(--m-meta); }
.strip .call { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-body); font-weight: 600; white-space: nowrap; }
.strip .call-sub { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip:hover { border-color: var(--border-strong); }

/* pulled: the strip slides out of the rack toward you. Position + buff + word, never colour alone. */
.strip.pulled { transform: translateX(var(--pull)); background: var(--accent-wash); border-color: color-mix(in oklch, var(--accent-mark) 55%, var(--border)); }
.strip.pulled > .f { border-left-color: color-mix(in oklch, var(--accent-mark) 30%, var(--border)); }
.strip.filed { background: transparent; }
.strip.filed .title { font-weight: 500; }

/* designator cell: status glyph + state word, as a whole field (not a side border) */
.desig {
  display: flex !important; flex-direction: row !important; align-items: center !important; justify-content: flex-start !important; gap: 7px !important;
  font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--s-c, var(--muted)); background: transparent; border-radius: 1px 0 0 1px; line-height: 1.2;
}
/* only "needs you" fills its designator; every other state is glyph + word on the strip ground (calm) */
.desig[data-s="needs"] { background: var(--accent); }
.desig .g { width: 12px; height: 12px; flex: none; }
.desig small { display: block; font-size: 10px; font-weight: 500; letter-spacing: 0.02em; text-transform: none; color: var(--muted); margin-top: 2px; }
[data-s="working"] { --s-c: var(--working); --s-w: var(--working-wash); }
[data-s="waiting"] { --s-c: var(--waiting); --s-w: transparent; }
[data-s="needs"]   { --s-c: var(--accent-fg); --s-w: var(--accent); }
[data-s="done"]    { --s-c: var(--done); --s-w: var(--done-wash); }
[data-s="blocked"] { --s-c: var(--blocked); --s-w: var(--blocked-wash); }
[data-s="crashed"] { --s-c: var(--error); --s-w: var(--error-wash); }
[data-s="hung"]    { --s-c: var(--blocked); --s-w: var(--blocked-wash); }
[data-s="ready"]   { --s-c: var(--done); --s-w: var(--done-wash); }
[data-s="fail"]    { --s-c: var(--error); --s-w: var(--error-wash); }
[data-s="review"]  { --s-c: var(--fg); --s-w: transparent; }
[data-s="conflict"]{ --s-c: var(--blocked); --s-w: var(--blocked-wash); }
[data-s="draft"]   { --s-c: var(--muted); --s-w: transparent; }
[data-s="running"] { --s-c: var(--working); --s-w: transparent; }
[data-s="merged"]  { --s-c: var(--done); --s-w: transparent; }
[data-s="closed"]  { --s-c: var(--muted); --s-w: transparent; }
[data-s="queued"]  { --s-c: var(--muted); --s-w: transparent; }
[data-s="escalated"] { --s-c: var(--fg); --s-w: transparent; }
[data-s="todo"]    { --s-c: var(--muted); --s-w: transparent; }
[data-s="progress"]{ --s-c: var(--working); --s-w: transparent; }
[data-s="overdue"] { --s-c: var(--error); --s-w: var(--error-wash); }
/* on the needs designator inside a pulled strip the buff is a full fill with dark ink */
.desig[data-s="needs"] small { color: var(--accent-fg); opacity: .8; }

/* status glyph inline (markers, agent refs, timeline) */
.st { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; color: var(--s-c, var(--muted)); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.st .g { width: 12px; height: 12px; flex: none; }
.st[data-s="needs"] { color: var(--accent-ink); }
.st .plain { text-transform: none; letter-spacing: 0; font-weight: 450; color: var(--muted); }

/* markers row on PR strips: fixed order, glyph + word, never colour alone */
.markers { display: flex; gap: 4px 12px; flex-wrap: wrap; align-items: center; }
.markers .st { font-size: 10.5px; }

/* agent reference field: links to the agent page */
.agent-ref { display: flex; flex-direction: column; gap: 2px; min-width: 0; color: var(--fg); }
.agent-ref:hover .st { text-decoration: underline; text-underline-offset: 3px; }
.agent-ref .act-line { font-size: var(--t-meta); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-ref .act-line code { font-size: var(--m-micro); color: var(--fg); }
.agent-none { color: var(--muted); font-size: var(--t-meta); }

/* spawn: tier picker joined to the Start agent button */
.spawn { display: inline-flex; align-items: stretch; }
.spawn .select { height: 28px; width: auto; padding: 0 6px; font-size: var(--t-meta); border-radius: var(--r-2) 0 0 var(--r-2); border-right: 0; background: var(--bg); }
.spawn .btn { border-radius: 0 var(--r-2) var(--r-2) 0; }
@media (max-width: 760px) { .spawn .select { height: 36px; font-size: 15px; } }

/* tier + actual model, and per-account use */
.tier { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); font-weight: 600; white-space: nowrap; }
.tier b { border: 1px solid var(--border-strong); border-radius: var(--r-1); padding: 0 5px; font-weight: 600; }
.tier .g { width: 10px; height: 10px; }
.model { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.use { display: grid; grid-template-columns: auto auto; gap: 1px 8px; justify-content: start; font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); }
.use span:nth-child(odd) { color: var(--muted); }
.use span:nth-child(even) { text-align: right; }

/* ---------- Merge pile (stack) ---------- */
.pile { border: 1px solid var(--border); border-radius: var(--r-2); background: color-mix(in oklch, var(--surface) 40%, var(--bg)); padding: var(--s-3); margin-right: var(--pull); }
.pile + .pile, .pile + .rack, .rack + .pile { margin-top: var(--s-4); }
.pile-head { display: flex; align-items: baseline; gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-3); }
.pile-head .name { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-body); font-weight: 600; }
.pile-head .meta { color: var(--muted); font-size: var(--t-meta); }
.pile-head .end { margin-left: auto; }
.pile .rack { padding-right: 0; }
.pile .rack { --cols: 34px 112px 84px minmax(0,1fr) 200px 150px; }
.pile .pos { align-items: center !important; font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-body); font-weight: 650; color: var(--muted); padding: 0 !important; }
.pile .pos small { font-size: 9.5px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }
.pile-foot { display: flex; gap: var(--s-3); align-items: center; margin-top: var(--s-2); color: var(--muted); font-size: var(--t-meta); }
.pile-foot .mono { font-size: var(--m-meta); }

/* ---------- Buttons ---------- */
.btn {
  --b-bg: transparent; --b-fg: var(--fg); --b-bd: var(--control);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 32px; padding: 0 var(--s-3);
  border-radius: var(--r-2); border: 1px solid var(--b-bd); background: var(--b-bg); color: var(--b-fg);
  font-weight: 600; font-size: var(--t-body); line-height: 1; white-space: nowrap; cursor: pointer; user-select: none;
  transition: background-color var(--dur-1) var(--ease-out), transform var(--dur-1) var(--ease-out);
}
.btn:hover { --b-bg: var(--surface-2); --b-bd: var(--muted); }
.btn:active { transform: scale(0.97); --b-bg: var(--surface-3); }
.btn .ico { width: 14px; height: 14px; vertical-align: 0; }
.btn-primary { --b-bg: var(--accent); --b-fg: var(--accent-fg); --b-bd: var(--accent); }
.btn-primary:hover { --b-bg: var(--accent-hover); --b-bd: var(--accent-hover); }
.btn-primary:active { --b-bg: var(--accent); }
.btn-strip { --b-fg: var(--accent-ink); --b-bd: color-mix(in oklch, var(--accent-mark) 70%, transparent); }
.btn-strip:hover { --b-bg: color-mix(in oklch, var(--accent) 14%, transparent); --b-bd: var(--accent-mark); }
.btn-quiet { --b-bd: transparent; --b-fg: var(--muted); padding: 0 var(--s-2); }
.btn-quiet:hover { --b-fg: var(--fg); --b-bd: transparent; --b-bg: var(--surface-2); }
.btn-danger { --b-bg: var(--error); --b-fg: oklch(0.99 0 0); --b-bd: var(--error); }
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--t-meta); }
.btn-lg { height: 44px; padding: 0 var(--s-5); font-size: 15px; }
.btn:disabled, .btn[aria-disabled="true"] { --b-bg: transparent; --b-fg: var(--faint); --b-bd: var(--border); cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"] .spin { display: inline-block; }
.spin { display: none; width: 12px; height: 12px; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* segmented control (radio based, instant apply) */
.seg { display: inline-flex; border: 1px solid var(--control); border-radius: var(--r-2); padding: 2px; gap: 2px; background: var(--bg); flex-wrap: wrap; }
.seg label { position: relative; display: inline-flex; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r-1); color: var(--muted); font-size: var(--t-meta); font-weight: 600; white-space: nowrap; cursor: pointer; }
.seg label:hover span { color: var(--fg); background: var(--surface-2); }
.seg input:checked + span { background: var(--fg); color: var(--bg); }
.seg input:focus-visible + span { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--focus); }
.seg input:disabled + span { color: var(--faint); cursor: not-allowed; }
.seg .n { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); opacity: .8; }

/* filter chips (toggle buttons) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r-1);
  border: 1px solid var(--border-strong); background: transparent; color: var(--muted); font-size: var(--t-meta); font-weight: 600; cursor: pointer;
}
.chip:hover { color: var(--fg); border-color: var(--control); }
.chip[aria-pressed="true"] { color: var(--bg); background: var(--fg); border-color: var(--fg); }
.chip .n { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .flabel { font-weight: 600; font-size: var(--t-meta); }
.field .help { color: var(--muted); font-size: var(--t-meta); }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 var(--s-3); background: var(--bg); color: var(--fg);
  border: 1px solid var(--control); border-radius: var(--r-2); font-size: 15px;
}
.textarea { height: auto; min-height: 96px; padding: 10px var(--s-3); line-height: 1.5; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--muted); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); border-radius: var(--r-2); }
.input[aria-invalid="true"] { border-color: var(--error); }
.input:disabled, .select:disabled { color: var(--faint); border-color: var(--border); background: transparent; }
.err { display: flex; gap: 6px; align-items: flex-start; color: var(--error); font-size: var(--t-meta); font-weight: 600; }
.err .g { width: 12px; height: 12px; margin-top: 2px; flex: none; }
.input-affix { position: relative; }
.input-affix .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-affix .input { padding-left: 38px; }
.input-affix kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
kbd { font-size: var(--m-micro); color: var(--muted); border: 1px solid var(--border-strong); border-radius: var(--r-1); padding: 1px 5px; }

/* ---------- Plates, key-values, tables ---------- */
.plate { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-2); }
.plate-head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--border); }
.plate-head h2, .plate-head h3 { font-size: var(--t-body); font-weight: 650; }
.plate-head .end { margin-left: auto; display: flex; gap: var(--s-2); align-items: center; }
.plate-body { padding: var(--s-4); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s-4); font-size: var(--t-meta); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.kv dd.l { text-align: left; }
table.t { width: 100%; border-collapse: collapse; font-size: var(--t-meta); }
.t th { text-align: left; font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 var(--s-3) var(--s-2); border-bottom: 1px solid var(--border); }
.t td { padding: 9px var(--s-3); border-bottom: 1px solid var(--border); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t .r { text-align: right; }

/* meter: cost against budget (value also printed) */
.meter { display: flex; align-items: center; gap: 8px; }
.meter .bar { flex: 1; height: 4px; background: var(--border); border-radius: 1px; overflow: hidden; min-width: 40px; }
.meter .bar i { display: block; height: 100%; background: var(--muted); }
.meter.hot .bar i { background: var(--blocked); }

/* empty / loading / error */
.empty { border: 1px dashed var(--border-strong); border-radius: var(--r-1); padding: var(--s-4); color: var(--muted); font-size: var(--t-meta); display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.empty b { color: var(--fg); font-weight: 600; }
.skel { background: linear-gradient(90deg, var(--surface) 0 40%, var(--surface-2) 50%, var(--surface) 60% 100%); background-size: 300% 100%; animation: skel 1.4s linear infinite; border-radius: var(--r-1); }
@keyframes skel { from { background-position: 100% 0; } to { background-position: 0 0; } }
.error-line { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; padding: var(--s-3) var(--s-4); border: 1px solid var(--error); border-radius: var(--r-1); background: var(--error-wash); font-size: var(--t-meta); }
.error-line .st { color: var(--error); }

/* ---------- Timeline ---------- */
.tl { list-style: none; margin: 0; padding: 0; position: relative; }
.tl li { position: relative; display: grid; grid-template-columns: 58px 16px 1fr; gap: 0 var(--s-2); padding-bottom: var(--s-4); }
.tl li::before { content: ""; position: absolute; left: calc(58px + var(--s-2) + 7px); top: 16px; bottom: 0; width: 1px; background: var(--border-strong); }
.tl li:last-child::before { display: none; }
.tl time { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); color: var(--muted); text-align: right; padding-top: 2px; }
.tl .g { width: 12px; height: 12px; margin: 3px 2px 0; color: var(--s-c, var(--muted)); position: relative; z-index: 1; background: var(--surface); }
.tl .what { font-size: var(--t-meta); line-height: 1.45; }
.tl .what .st { margin-right: 6px; }
.tl .what .d { color: var(--muted); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); margin-left: 6px; }

/* ---------- Transcript ---------- */
.tx { font-size: var(--t-meta); line-height: 1.55; }
.tx .msg { display: grid; grid-template-columns: 76px minmax(0,1fr); gap: var(--s-3); padding: 10px var(--s-4); border-bottom: 1px solid var(--border); }
.tx .who { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding-top: 2px; }
.tx .who time { display: block; font-weight: 400; letter-spacing: 0; margin-top: 2px; }
.tx .msg.me .who { color: var(--accent-ink); }
.tx .msg.me { background: color-mix(in oklch, var(--accent-wash) 60%, transparent); }
.tx .body p + p { margin-top: 6px; }
.tx .tool { border: 1px solid var(--border); border-radius: var(--r-1); background: var(--bg); }
.tx .tool-h { display: flex; gap: var(--s-2); align-items: center; padding: 6px 10px; font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); }
.tx .tool-h .end { margin-left: auto; color: var(--muted); }
.tx .tool pre { margin: 0; padding: 8px 10px; border-top: 1px solid var(--border); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: 11px; line-height: 1.6; color: var(--muted); overflow-x: auto; white-space: pre; }
.tx .tool pre .ok { color: var(--done); } .tx .tool pre .bad { color: var(--error); }
.tx .live { display: flex; gap: var(--s-2); align-items: center; padding: 10px var(--s-4); color: var(--muted); font-size: var(--t-meta); }
.tx .new { animation: in var(--dur-2) var(--ease-out); }
@keyframes in { from { opacity: 0; transform: translateY(4px); } }

/* ---------- Settings rows ---------- */
.set { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-2) var(--s-6); align-items: center; padding: var(--s-4) 0; border-bottom: 1px solid var(--border); }
.set:last-child { border-bottom: 0; }
.set h3 { font-size: var(--t-body); font-weight: 650; }
.set p { color: var(--muted); font-size: var(--t-meta); margin-top: 2px; max-width: 60ch; }
.set .ctl { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.ack { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); color: var(--muted); display: inline-flex; gap: 6px; align-items: center; min-height: 14px; }
.ack .g { width: 10px; height: 10px; color: var(--done); }
.ack.pending { color: var(--working); }

.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--control); border-radius: var(--r-2); height: 34px; }
.stepper button { width: 34px; background: none; border: 0; color: var(--fg); cursor: pointer; font-family: var(--font-mono); font-size: 14px; }
.stepper button:hover { background: var(--surface-2); }
.stepper input { width: 52px; text-align: center; border: 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border); background: var(--bg); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-body); }

/* search hit highlight */
mark { background: var(--accent-wash); color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent-mark); padding: 0 1px; }

/* mock-only control (not part of the product UI) */
.mock-ctl { position: fixed; left: 12px; bottom: 12px; z-index: 50; display: flex; gap: 6px; align-items: center; padding: 6px 8px; border: 1px dashed var(--control); border-radius: var(--r-2); background: var(--bg); font-size: 11px; color: var(--muted); }
.mock-ctl select { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-1); color: var(--fg); font-size: 11px; height: 24px; }
body.no-mock .mock-ctl { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  .nav a .lbl-long { display: none; }
  .who { display: none; }
}
@media (max-width: 760px) {
  :root { --pull: 10px; --t-body: 15px; }
  .topbar { height: 48px; padding: 0 var(--s-4); gap: var(--s-3); }
  .topbar .nav, .topbar .who, .topbar .themebtn { display: none; }
  .brand svg.word { display: none; }
  .topbar .ptitle { display: block; font-weight: 650; font-size: 16px; }
  main.page { padding: var(--s-4) var(--s-4) calc(80px + env(safe-area-inset-bottom)); }
  /* accounts strip: one field per account, rules between, like a strip */
.quota { display: flex; align-items: stretch; min-height: 34px; padding: 0 var(--s-6); border-bottom: 1px solid var(--border); background: color-mix(in oklch, var(--surface) 55%, var(--bg)); overflow-x: auto; scrollbar-width: none; font-size: var(--t-meta); }
.quota .q-label { align-self: center; padding-right: var(--s-4); white-space: nowrap; }
.q-acc { display: flex; align-items: center; gap: 10px; padding: 0 var(--s-4); border-left: 1px solid var(--border); white-space: nowrap; color: var(--fg); }
.q-acc:hover { background: var(--surface); }
.q-name { font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-meta); font-weight: 600; }
.q-m { display: inline-flex; align-items: center; gap: 5px; }
.q-k { color: var(--muted); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: var(--m-micro); }
.q-m .bar { width: 36px; height: 4px; background: var(--border); border-radius: 1px; overflow: hidden; display: inline-block; }
.q-m .bar i { display: block; height: 100%; background: var(--muted); }
.q-m[data-lvl="low"] .bar i { background: var(--blocked); }
.q-m[data-lvl="spent"] .bar i { background: var(--error); }
.q-m .mono { font-size: var(--m-micro); }
.q-v { font-size: var(--m-meta); }
.q-sub { color: var(--muted); font-size: 11.5px; }
.q-acc .st { font-size: 10.5px; }
.q-tail { align-self: center; margin-left: auto; padding-left: var(--s-4); white-space: nowrap; font-size: var(--t-meta); }
.offline-banner { padding: var(--s-2) var(--s-4); }
  .page-head { margin-bottom: var(--s-4); }
  .page-head h1 { font-size: var(--t-h2); }
  .page-head .tools { margin-left: 0; width: 100%; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--bg); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 58px; color: var(--muted); font-size: 11px; font-weight: 600; position: relative; }
  .tabbar a .ico { width: 20px; height: 20px; }
  .tabbar a[aria-current="page"] { color: var(--fg); }
  .tabbar a[aria-current="page"]::before { content: ""; position: absolute; top: -1px; left: 25%; right: 25%; height: 2px; background: var(--fg); }
  .tabbar .badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 16px; padding: 0 4px; border-radius: var(--r-1); background: var(--accent); color: var(--accent-fg); font-family: var(--font-mono); font-stretch: var(--mono-stretch); font-size: 10px; font-weight: 700; display: grid; place-items: center; }
  .bay { padding-left: calc(var(--rail) + var(--s-2)); }

  /* strips reflow into a three-row card: designator+callsign / title / fields+action */
  .strip, .pile .strip { grid-template-columns: minmax(0, 1fr) auto; grid-auto-flow: row; }
  .strip > .f { border-left: 0; padding: 4px var(--s-3); }
  .strip > .desig { grid-column: 1 / -1; padding: 6px var(--s-3) !important; border-radius: 1px 1px 0 0; border-bottom: 1px solid var(--border); }
  .strip > .f.callf { grid-column: 1 / -1; flex-direction: row; align-items: baseline; justify-content: flex-start; gap: 8px; padding-top: 8px; }
  .strip > .f.main, .strip > .f.side { grid-column: 1 / -1; }
  .strip > .f.main { padding-top: 2px; }
  .strip > .f.act { grid-column: 1 / -1; justify-content: flex-start; padding-top: 6px; }
  .strip > .f:last-child { padding-bottom: 10px; }
  .strip > .f.hide-m { display: none; }
  .strip .title { -webkit-line-clamp: 3; }
  .btn { height: 40px; }
  .btn-sm { height: 36px; }
  .pile { padding: var(--s-2); }
  .pile .pos { display: none !important; }
  .pile .strip .desig .posm { display: inline; }
  .set { grid-template-columns: minmax(0, 1fr); }
  .set .ctl { align-items: flex-start; }
  .seg span { height: 34px; }
  .chip { height: 34px; }
  .tx .msg { grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 10px var(--s-3); }
  .tx .who time { display: inline; margin-left: 6px; }
  .mock-ctl { bottom: 70px; }
  .pile-head .end { margin-left: 0; flex-basis: 100%; }
  .page-head h1.vh-m { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .page-head .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .page-head .seg span { padding: 0 8px; }
  .iconbtn { width: 40px; height: 40px; }
  .pile-head .end .st, .agent-ref .st { white-space: normal; flex-wrap: wrap; }
}
.ptitle { display: none; }
.posm { display: none; font-weight: 500; color: inherit; opacity: .85; margin-left: auto; letter-spacing: 0.02em; }

@media (prefers-reduced-motion: reduce) {
  .strip { transition: none; }
  .tx .new { animation: fadeonly var(--dur-1) linear; }
  @keyframes fadeonly { from { opacity: 0; } }
  .skel, .spin { animation-duration: 3s; }
  .btn:active { transform: none; }
}
