/*
 * Hercules Back Office — the console surface.
 *
 * `packages/ui/src/tokens.css` positions the two client-facing front ends as "the terminal,
 * softened", and the dealing terminal as the unsoftened one. This is the third position and it is
 * between them: the admin portal is an INSTRUMENT — dense enough that a compliance officer can
 * see a queue, a balance and a restriction without scrolling, warm enough that they can sit in
 * front of it for eight hours. So the type scale is 13px rather than the terminal's 11 or the
 * portal's 15, radii are 6px rather than 0 or 12, and the accent is the product blue rather than
 * the dealer's amber.
 *
 * THE TOKENS ARE COPIED, NOT IMPORTED, and that is deliberate. `@import` costs a second round
 * trip before first paint on a screen that opens onto a sign-in form, and the CSP forbids the
 * inline style tag that would avoid it. The values below are the same values; the two files are
 * bound by convention and by the comment you are reading.
 *
 * COLOUR CARRIES MEANING AND NOTHING ELSE CARRIES IT. Green is money arriving or a control
 * passing, red is money leaving or a control failing, amber is a deadline. The accent marks
 * structure — the active nav item, a focus ring, a section rule — and never appears inside a
 * number, because the instant an accent starts appearing in the numbers the eye stops being able
 * to scan a column.
 *
 * EVERY NUMERAL IS TABULAR. `font-variant-numeric: tabular-nums` on every cell holding a figure,
 * so the decimal point sits in the same place from row to row. A wandering decimal point in a
 * balance column is the fastest way to misread a balance.
 */

:root {
  --bg: #0B0F14;
  --surface: #111823;
  --raised: #18212E;
  --sunken: #070A0E;
  --overlay: rgba(3, 6, 10, .74);

  --line: #243040;
  --line-strong: #35455A;
  --line-subtle: #1A2430;

  --text: #E8EDF4;
  --dim: #A7B4C6;
  --muted: #6E7E93;
  --inverse: #0B0F14;

  --accent: #3D7BFF;
  --accent-hover: #5C92FF;
  --accent-wash: #132441;

  --pos: #2FC08A;  --pos-wash: #0E2A22;
  --neg: #FF5C6C;  --neg-wash: #33161C;
  --warn: #F5A524; --warn-wash: #2E2210;
  --info: #4FB6E8; --info-wash: #0F2733;
  --neutral: #8494A8; --neutral-wash: #182029;

  --focus: #7EA8FF;

  --s1: 2px; --s2: 4px; --s3: 6px; --s4: 8px; --s5: 12px;
  --s6: 16px; --s7: 20px; --s8: 24px; --s9: 32px; --s10: 40px;

  --r-xs: 4px; --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-full: 9999px;

  --ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --nav-w: 244px;
  --head-h: 52px;

  --elev-1: 0 0 0 1px var(--line);
  --elev-2: 0 0 0 1px var(--line), 0 8px 24px rgba(0, 0, 0, .45);
  --elev-3: 0 0 0 1px var(--line), 0 24px 64px rgba(0, 0, 0, .6);

  --fast: 120ms cubic-bezier(.2, 0, .38, .9);
  --base: 200ms cubic-bezier(.2, 0, .38, .9);

  color-scheme: dark;
}

/*
 * Light. The console is used at a desk with a window behind it as often as in a dealing room, and
 * an operator who has to squint at a dark screen at 10 a.m. turns the brightness up and then
 * cannot read it at 6 p.m. Redefines tokens only — no component below names a raw colour.
 */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F6F8FB; --surface: #FFFFFF; --raised: #FFFFFF; --sunken: #EEF2F7;
    --overlay: rgba(14, 22, 32, .45);
    --line: #D8E0EA; --line-strong: #B4C1D2; --line-subtle: #E7ECF3;
    --text: #0E1620; --dim: #455467; --muted: #6B7C91; --inverse: #FFFFFF;
    --accent: #1F5FE0; --accent-hover: #1A52C4; --accent-wash: #E8F0FF;
    --pos: #0F7A54; --pos-wash: #E3F6EE;
    --neg: #C42A3A; --neg-wash: #FDE9EB;
    --warn: #9A6100; --warn-wash: #FFF3DC;
    --info: #1D6E92; --info-wash: #E4F4FB;
    --neutral: #5C6B7E; --neutral-wash: #EDF1F6;
    --elev-1: 0 0 0 1px var(--line), 0 1px 2px rgba(14, 22, 32, .06);
    --elev-2: 0 0 0 1px var(--line), 0 4px 12px rgba(14, 22, 32, .1);
    --elev-3: 0 0 0 1px var(--line), 0 16px 48px rgba(14, 22, 32, .16);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F6F8FB; --surface: #FFFFFF; --raised: #FFFFFF; --sunken: #EEF2F7;
  --overlay: rgba(14, 22, 32, .45);
  --line: #D8E0EA; --line-strong: #B4C1D2; --line-subtle: #E7ECF3;
  --text: #0E1620; --dim: #455467; --muted: #6B7C91; --inverse: #FFFFFF;
  --accent: #1F5FE0; --accent-hover: #1A52C4; --accent-wash: #E8F0FF;
  --pos: #0F7A54; --pos-wash: #E3F6EE;
  --neg: #C42A3A; --neg-wash: #FDE9EB;
  --warn: #9A6100; --warn-wash: #FFF3DC;
  --info: #1D6E92; --info-wash: #E4F4FB;
  --neutral: #5C6B7E; --neutral-wash: #EDF1F6;
  --elev-1: 0 0 0 1px var(--line), 0 1px 2px rgba(14, 22, 32, .06);
  --elev-2: 0 0 0 1px var(--line), 0 4px 12px rgba(14, 22, 32, .1);
  --elev-3: 0 0 0 1px var(--line), 0 16px 48px rgba(14, 22, 32, .16);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 400 13px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: var(--r-full); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }

/* ── Sign in ───────────────────────────────────────────────────────────────── */

#gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-wash), transparent 60%),
    var(--bg);
}
#gate[hidden] { display: none; }

.gate-card {
  width: min(400px, calc(100vw - 32px));
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-3);
  padding: var(--s9);
}
.gate-mark {
  display: flex; align-items: center; gap: var(--s4);
  font-weight: 650; letter-spacing: -.01em; font-size: 16px;
  margin-bottom: var(--s2);
}
.gate-mark .dot {
  width: 10px; height: 10px; border-radius: var(--r-full);
  background: var(--accent); box-shadow: 0 0 0 4px var(--accent-wash);
}
.gate-sub { color: var(--muted); font-size: 12px; margin-bottom: var(--s8); }
.gate-card label { display: block; font-size: 12px; color: var(--dim); margin: var(--s6) 0 var(--s3); }
.gate-card input {
  width: 100%; height: 40px; padding: 0 var(--s5);
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--r-sm); color: var(--text);
}
.gate-card input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-wash); }
.gate-card button {
  width: 100%; height: 40px; margin-top: var(--s7);
  background: var(--accent); color: #fff; border: 0; border-radius: var(--r-sm);
  font-weight: 600; transition: background var(--fast);
}
.gate-card button:hover { background: var(--accent-hover); }
.gate-card button:disabled { opacity: .55; cursor: not-allowed; }
.gate-err {
  margin-top: var(--s6); padding: var(--s4) var(--s5);
  background: var(--neg-wash); color: var(--neg);
  border-radius: var(--r-sm); font-size: 12px;
}
.gate-err[hidden] { display: none; }
.gate-note { margin-top: var(--s7); font-size: 11px; color: var(--muted); line-height: 1.6; }

/* ── Shell ─────────────────────────────────────────────────────────────────── */

#shell { display: grid; grid-template-columns: var(--nav-w) 1fr; height: 100vh; }
#shell[hidden] { display: none; }

nav {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.brand {
  height: var(--head-h);
  display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s6);
  border-bottom: 1px solid var(--line);
  font-weight: 650; letter-spacing: -.01em;
  flex: 0 0 auto;
}
.brand .dot { width: 8px; height: 8px; border-radius: var(--r-full); background: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.brand small { margin-left: auto; font-weight: 500; font-size: 10px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }

.nav-scroll { flex: 1 1 auto; overflow-y: auto; padding: var(--s5) var(--s4) var(--s8); }
.nav-group { margin-bottom: var(--s6); }
.nav-group > h6 {
  margin: 0 0 var(--s3); padding: 0 var(--s5);
  font-size: 10px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.nav-item {
  display: flex; align-items: center; gap: var(--s5);
  padding: 7px var(--s5); margin-bottom: 1px;
  border-radius: var(--r-sm); color: var(--dim);
  font-size: 12.5px; cursor: pointer;
  transition: background var(--fast), color var(--fast);
  border: 0; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--accent-wash); color: var(--text); font-weight: 550; }
.nav-item .ico { width: 16px; text-align: center; opacity: .85; flex: 0 0 auto; }
.nav-item .count {
  margin-left: auto; font-size: 10px; padding: 1px 6px;
  border-radius: var(--r-full); background: var(--raised); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.nav-item[aria-current="page"] .count { background: var(--accent); color: #fff; }
.nav-item .count.hot { background: var(--neg); color: #fff; }

.nav-foot {
  flex: 0 0 auto; border-top: 1px solid var(--line);
  padding: var(--s5) var(--s6); font-size: 11px; color: var(--muted);
  display: grid; gap: var(--s2);
}
.nav-foot b { color: var(--dim); font-weight: 550; }
/* A class rather than a style attribute: `style-src 'self'` blocks inline style attributes, so a
   `style="margin-top:6px"` in the markup silently does nothing and the console reports a CSP
   violation nobody reads. */
.nav-actions { margin-top: var(--s3); }

/* ── Main ──────────────────────────────────────────────────────────────────── */

main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

header.bar {
  height: var(--head-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s5);
  padding: 0 var(--s8);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
header.bar h1 { margin: 0; font-size: 15px; font-weight: 620; letter-spacing: -.01em; }
header.bar .blurb {
  color: var(--muted); font-size: 11.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 46ch;
}
header.bar .spacer { margin-left: auto; }

.pulse {
  display: flex; align-items: center; gap: var(--s5);
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.pulse .k { color: var(--dim); }
.pulse .live { display: inline-flex; align-items: center; gap: 5px; }
.pulse .live::before {
  content: ""; width: 6px; height: 6px; border-radius: var(--r-full);
  background: var(--pos); animation: beat 2s ease-in-out infinite;
}
.pulse .live.stale::before { background: var(--neg); animation: none; }
@keyframes beat { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.content { flex: 1 1 auto; overflow-y: auto; padding: var(--s8); }
.content > * + * { margin-top: var(--s7); }

/* ── Banners ───────────────────────────────────────────────────────────────── */

.banner {
  display: flex; align-items: flex-start; gap: var(--s5);
  padding: var(--s5) var(--s6);
  border-radius: var(--r-md); font-size: 12.5px;
  border: 1px solid transparent;
}
.banner .b-body { flex: 1 1 auto; }
.banner strong { display: block; margin-bottom: 2px; font-weight: 600; }
.banner.warn { background: var(--warn-wash); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--text); }
.banner.neg  { background: var(--neg-wash);  border-color: color-mix(in srgb, var(--neg) 35%, transparent); color: var(--text); }
.banner.info { background: var(--info-wash); border-color: color-mix(in srgb, var(--info) 35%, transparent); color: var(--text); }
.banner.pos  { background: var(--pos-wash);  border-color: color-mix(in srgb, var(--pos) 35%, transparent); color: var(--text); }
.banner .ico { font-size: 15px; line-height: 1.2; }

/* The elevation bar. Deliberately loud: an operator must never forget they are elevated. */
#elevation {
  flex: 0 0 auto;
  background: var(--neg); color: #fff;
  padding: var(--s3) var(--s8);
  font-size: 12px; font-weight: 550;
  display: flex; align-items: center; gap: var(--s5);
}
#elevation[hidden] { display: none; }
#elevation button {
  margin-left: auto; background: rgba(255, 255, 255, .18); color: #fff;
  border: 0; border-radius: var(--r-sm); padding: 3px 10px; font-size: 11px;
}

/* ── Cards and grids ───────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--elev-1);
  overflow: hidden;
}
.card > h3 {
  margin: 0; padding: var(--s5) var(--s6);
  font-size: 12px; font-weight: 600; letter-spacing: .02em;
  border-bottom: 1px solid var(--line-subtle);
  display: flex; align-items: center; gap: var(--s4);
}
.card > h3 .sub { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: auto; }
.card > .body { padding: var(--s6); }
.card > .body > * + * { margin-top: var(--s5); }
.card .note { color: var(--muted); font-size: 11.5px; line-height: 1.6; }

.grid { display: grid; gap: var(--s6); }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
@media (max-width: 1400px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .grid.c3, .grid.c2 { grid-template-columns: minmax(0, 1fr); } }

/* ── Stat tiles ────────────────────────────────────────────────────────────── */

.tile {
  background: var(--surface); border-radius: var(--r-md);
  box-shadow: var(--elev-1); padding: var(--s6);
  display: flex; flex-direction: column; gap: var(--s2);
  min-width: 0;
}
.tile .k { font-size: 10.5px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tile .v {
  font-size: 22px; font-weight: 600; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis;
}
.tile .m { font-size: 11px; color: var(--muted); }
.tile.pos .v { color: var(--pos); }
.tile.neg .v { color: var(--neg); }
.tile.warn .v { color: var(--warn); }
.tile.accent { box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent); }

/* ── Tables ────────────────────────────────────────────────────────────────── */

.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-weight: 600; font-size: 10.5px;
  letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  padding: var(--s4) var(--s5);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td {
  padding: 7px var(--s5);
  border-bottom: 1px solid var(--line-subtle);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--raised); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 11.5px; }
td.mono, th.mono { font-family: var(--mono); font-size: 11px; }
td.wrap { white-space: normal; max-width: 46ch; }
/* The same constraint as a standalone utility. Without it a long description inside a cell — the
   command blurb on the console page — sets the column width and pushes the action column past the
   right edge of the viewport. */
.wrap { white-space: normal; max-width: 52ch; }
.empty { padding: var(--s9); text-align: center; color: var(--muted); font-size: 12px; }

/* ── Badges ────────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: var(--r-full);
  font-size: 10.5px; font-weight: 550; letter-spacing: .01em;
  white-space: nowrap;
  background: var(--neutral-wash); color: var(--dim);
}
.badge.pos { background: var(--pos-wash); color: var(--pos); }
.badge.neg { background: var(--neg-wash); color: var(--neg); }
.badge.warn { background: var(--warn-wash); color: var(--warn); }
.badge.info { background: var(--info-wash); color: var(--info); }
.badge.accent { background: var(--accent-wash); color: var(--accent); }
.badge + .badge { margin-left: 4px; }

.chip {
  display: inline-block; padding: 1px 6px; border-radius: var(--r-xs);
  background: var(--sunken); border: 1px solid var(--line-subtle);
  font-family: var(--mono); font-size: 10.5px; color: var(--dim);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s3);
  height: 30px; padding: 0 var(--s5);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--raised); color: var(--text);
  font-size: 12px; font-weight: 520;
  transition: background var(--fast), border-color var(--fast), opacity var(--fast);
  white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--neg); border-color: var(--neg); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn.ghost:hover { background: var(--raised); color: var(--text); }
.btn.sm { height: 24px; padding: 0 var(--s4); font-size: 11px; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s4); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */

.field { display: grid; gap: var(--s3); margin-bottom: var(--s6); }
.field > label { font-size: 11.5px; font-weight: 550; color: var(--dim); }
.field > label .req { color: var(--neg); margin-left: 3px; }
.field .help { font-size: 11px; color: var(--muted); line-height: 1.55; }
.field .err { font-size: 11px; color: var(--neg); }
.field input[type="text"], .field input[type="number"], .field input[type="password"],
.field select, .field textarea {
  width: 100%; padding: 7px var(--s5);
  background: var(--sunken); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-family: inherit;
}
.field input.mono, .field textarea.mono { font-family: var(--mono); font-size: 11.5px; }
.field textarea { min-height: 76px; resize: vertical; line-height: 1.55; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash);
}
.field input:invalid { border-color: var(--neg); }
.field .row { display: flex; align-items: center; gap: var(--s4); }
.switch { display: inline-flex; align-items: center; gap: var(--s4); cursor: pointer; font-size: 12px; }
.switch input { appearance: none; width: 34px; height: 19px; border-radius: var(--r-full);
  background: var(--line); position: relative; transition: background var(--fast); cursor: pointer; }
.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: var(--r-full); background: var(--text);
  transition: transform var(--fast);
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(15px); background: #fff; }

.search {
  display: flex; align-items: center; gap: var(--s4);
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 0 var(--s5); height: 30px;
  min-width: 240px;
}
.search input { border: 0; background: none; outline: none; width: 100%; font-size: 12px; }
.search .ico { color: var(--muted); }

/* ── Parameter rows ────────────────────────────────────────────────────────── */

.param {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(200px, .75fr) auto;
  gap: var(--s6); align-items: start;
  padding: var(--s6);
  border-bottom: 1px solid var(--line-subtle);
}
.param:last-child { border-bottom: 0; }
.param:hover { background: color-mix(in srgb, var(--raised) 55%, transparent); }
.param .p-name { font-size: 12.5px; font-weight: 550; display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.param .p-help { font-size: 11.5px; color: var(--muted); line-height: 1.6; margin-top: var(--s2); }
.param .p-src {
  font-family: var(--mono); font-size: 10px; color: var(--muted);
  margin-top: var(--s3); opacity: .8;
}
.param .p-edit { display: grid; gap: var(--s3); }
.param .p-edit input, .param .p-edit select {
  width: 100%; padding: 6px var(--s4);
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--r-sm); font-family: var(--mono); font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.param .p-edit input:focus, .param .p-edit select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash);
}
.param .p-edit input:disabled { opacity: .6; cursor: not-allowed; }
.param .p-unit { font-size: 10.5px; color: var(--muted); }
.param .p-act { display: flex; align-items: center; gap: var(--s3); padding-top: 2px; }
.param.dirty { background: var(--accent-wash); }
.param.ro { opacity: .82; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */

.modal-bg {
  position: fixed; inset: 0; z-index: 60;
  background: var(--overlay);
  display: grid; place-items: center;
  padding: var(--s8);
  backdrop-filter: blur(2px);
}
.modal-bg[hidden] { display: none; }
.modal {
  width: min(640px, 100%); max-height: calc(100vh - 96px);
  background: var(--surface); border-radius: var(--r-lg);
  box-shadow: var(--elev-3);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal.wide { width: min(940px, 100%); }
.modal > header {
  padding: var(--s6) var(--s7); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s5);
}
.modal > header h2 { margin: 0; font-size: 14px; font-weight: 620; }
.modal > header .x { margin-left: auto; }
.modal > .m-body { padding: var(--s7); overflow-y: auto; flex: 1 1 auto; }
.modal > .m-body > .blurb { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 0 0 var(--s7); }
.modal > footer {
  padding: var(--s5) var(--s7); border-top: 1px solid var(--line);
  display: flex; gap: var(--s4); justify-content: flex-end; align-items: center;
}
.modal > footer .left { margin-right: auto; font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: var(--s2); border-bottom: 1px solid var(--line); margin-bottom: var(--s6); flex-wrap: wrap; }
.tab {
  padding: var(--s4) var(--s5); border: 0; background: none;
  color: var(--muted); font-size: 12px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color var(--fast), border-color var(--fast);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 550; }

/* ── Toasts ────────────────────────────────────────────────────────────────── */

#toasts {
  position: fixed; right: var(--s8); bottom: var(--s8); z-index: 90;
  display: flex; flex-direction: column; gap: var(--s4);
  max-width: 400px;
}
.toast {
  background: var(--raised); border-radius: var(--r-md);
  box-shadow: var(--elev-2); padding: var(--s5) var(--s6);
  font-size: 12px; line-height: 1.55;
  border-left: 3px solid var(--neutral);
  animation: slide var(--base);
}
.toast.pos { border-left-color: var(--pos); }
.toast.neg { border-left-color: var(--neg); }
.toast.warn { border-left-color: var(--warn); }
.toast strong { display: block; margin-bottom: 2px; }
.toast .hint { color: var(--muted); font-size: 11.5px; margin-top: var(--s3); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Misc ──────────────────────────────────────────────────────────────────── */

.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--s3) var(--s6); font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

pre.json {
  margin: 0; padding: var(--s5);
  background: var(--sunken); border: 1px solid var(--line-subtle);
  border-radius: var(--r-sm);
  font-family: var(--mono); font-size: 11px; line-height: 1.55;
  overflow-x: auto; max-height: 340px; white-space: pre-wrap; word-break: break-word;
}

.meter { height: 5px; border-radius: var(--r-full); background: var(--line-subtle); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: var(--r-full); }
.meter.pos > span { background: var(--pos); }
.meter.warn > span { background: var(--warn); }
.meter.neg > span { background: var(--neg); }

.spinner {
  width: 14px; height: 14px; border-radius: var(--r-full);
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hr { height: 1px; background: var(--line-subtle); border: 0; margin: var(--s6) 0; }
.muted { color: var(--muted); }
.pos-t { color: var(--pos); }
.neg-t { color: var(--neg); }
.warn-t { color: var(--warn); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); }
.small { font-size: 11px; }
.stack { display: grid; gap: var(--s5); }
.inline { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
