/* QuantDesk — night-desk palette for long screen sessions. Colour carries
   meaning only: green = up/allowed/passing, red = down/blocked/failing,
   brass = caution/waiting, blue = the thing you can act on. */
:root {
  color-scheme: dark;
  --paper: #0D131A;
  --panel: #141C25;
  --panel-2: #1B2531;
  --rail: #090E14;
  --ink: #E3EAF0;
  --ink-2: #8C9DAD;
  --line: #253242;
  --go: #26A17B;
  --go-wash: rgba(38, 161, 123, .15);
  --wait: #D4A13D;
  --wait-wash: rgba(212, 161, 61, .14);
  --stop: #E2554F;
  --stop-wash: rgba(226, 85, 79, .15);
  --act: #5B8DEF;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-cond: "IBM Plex Sans Condensed", "IBM Plex Sans", system-ui, sans-serif;
  --r-sm: 4px;
  --r-md: 10px;
  --space: 1rem;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.5 var(--font); font-feature-settings: "tnum" 1;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .75rem; max-width: 68ch; }
a { color: var(--act); }
small, .muted { color: var(--ink-2); }
:focus-visible { outline: 3px solid var(--act); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--panel); padding: .5rem 1rem; z-index: 10; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100vh; }
.nav { background: var(--rail); color: var(--ink-2); border-bottom: 1px solid var(--line); padding: .35rem .5rem; padding-top: max(.35rem, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 5; display: flex; flex-direction: row; align-items: center; min-width: 0; }
.brand { display: flex; align-items: center; padding: 0 .9rem 0 .25rem; flex: none; text-decoration: none; }
.brand img { display: block; height: auto; }
.brand .brand-full { width: 166px; }
.brand .brand-mark { display: none; width: 30px; }
.nav ul { list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column; justify-content: start; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; }
.nav ul::-webkit-scrollbar { display: none; }
.nav a { display: block; padding: .4rem .7rem; border-radius: var(--r-sm); color: inherit; text-decoration: none; font-weight: 500; font-size: .92rem; white-space: nowrap; }
.nav a:hover { background: var(--panel-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--act); }
.nav-foot { margin: 0 0 0 auto; padding: 0 .5rem; font-size: .85rem; color: #A9B6C0; white-space: nowrap; flex: none; }
main { padding: 2rem clamp(1rem, 3vw, 2.5rem) 4rem; max-width: 1180px; width: 100%; min-width: 0; margin: 0 auto; }
.panel, .grid > * { min-width: 0; }
main:focus { outline: none; }

/* ---------- building blocks */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-md); padding: 1.25rem; }
.stack > * + * { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.lede { font-size: 1.1rem; color: var(--ink-2); }
.big { font: 600 2.25rem/1.1 var(--font-cond); letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--go); } .down { color: var(--stop); }

.btn { font: 600 .95rem var(--font); border-radius: var(--r-sm); border: 1px solid var(--act); background: var(--act); color: #fff; padding: .6rem 1rem; cursor: pointer; min-height: 44px; }
.btn:hover { filter: brightness(1.15); }
.btn.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.go { background: var(--go); border-color: var(--go); }
.btn.stop { background: var(--stop); border-color: var(--stop); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

.tag { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: var(--panel-2); color: var(--ink-2); }
.tag.go { background: var(--go-wash); color: var(--go); }
.tag.wait { background: var(--wait-wash); color: var(--wait); }
.tag.stop { background: var(--stop-wash); color: var(--stop); }

.callout { border-left: 4px solid var(--wait); background: var(--wait-wash); padding: .85rem 1rem; border-radius: var(--r-sm); }
.callout.stop { border-color: var(--stop); background: var(--stop-wash); }
.callout.go { border-color: var(--go); background: var(--go-wash); }
.empty { text-align: left; padding: 1.5rem; border: 1px dashed var(--line); border-radius: var(--r-md); color: var(--ink-2); }

/* ---------- gauges (risk used) */
.gauge { display: grid; gap: .35rem; }
.gauge .bar { height: 10px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.gauge .fill { height: 100%; background: var(--go); }
.gauge .fill.wait { background: var(--wait); } .gauge .fill.stop { background: var(--stop); }

/* ---------- the stage track: the one bold element */
.track { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin: .75rem 0 1rem; }
.track span { position: relative; padding: .5rem .25rem 0; font: 600 .85rem var(--font-cond); color: var(--ink-2); border-top: 6px solid var(--line); }
.track span.done { border-top-color: var(--go); color: var(--go); }
.track span.here { border-top-color: var(--ink); color: var(--ink); }
.track.retired span { border-top-color: var(--line); color: var(--ink-2); text-decoration: line-through; }

/* ---------- gate checklist */
.gates { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.gates li { background: var(--panel-2) !important; display: grid; grid-template-columns: 28px 1fr; gap: .6rem; align-items: start; padding: .65rem .75rem; border-radius: var(--r-sm); background: var(--paper); }
.gates .mark { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: var(--paper); background: var(--ink-2); font-size: .85rem; }
.gates .pass .mark { background: var(--go); } .gates .fail .mark { background: var(--stop); }
.gates .detail { font-size: .9rem; color: var(--ink-2); }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 600; color: var(--ink-2); font-size: .85rem; }
td.r, th.r { text-align: right; }

/* ---------- forms */
label { display: grid; gap: .3rem; font-weight: 500; font-size: .95rem; }
input, select { font: inherit; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); color: var(--ink); min-height: 44px; width: 100%; }
.form-grid { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); }
.seg { display: inline-grid; grid-auto-flow: column; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { font: 600 1rem var(--font); border: 0; padding: .6rem 1.2rem; background: var(--paper); color: var(--ink-2); cursor: pointer; min-height: 44px; }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--act); }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
.seg button[aria-pressed="true"].buy { background: var(--go); color: #fff; }
.seg button[aria-pressed="true"].sell { background: var(--stop); color: #fff; }
.switch { display: flex; align-items: center; gap: 1rem; }

/* ---------- chart */
.chart { width: 100%; height: 220px; display: block; }
.chart path.line { fill: none; stroke: var(--act); stroke-width: 1.6; }
.chart line.base { stroke: var(--line); stroke-dasharray: 4 4; }
.chart text { font: 12px var(--font); fill: var(--ink-2); }

#toast { position: fixed; bottom: 1rem; right: 1rem; max-width: min(420px, calc(100vw - 2rem)); z-index: 20; }
#toast .t { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); padding: .8rem 1rem; border-radius: var(--r-sm); margin-top: .5rem; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
#toast .t.err { background: var(--stop); color: #fff; border-color: var(--stop); }
#banner:empty { display: none; }
#banner { margin-bottom: 1rem; }

/* ---------- mobile: nav becomes a scrolling top bar */
@media (max-width: 820px) {
  .brand { padding: 0 .5rem 0 .25rem; }
  .brand .brand-full { display: none; }
  .brand .brand-mark { display: block; }
  .nav a { padding: .5rem .7rem; }
  .nav-foot { display: none; }
  main { padding: 1.25rem 1rem 5rem; }
  h1 { font-size: 1.45rem; }
  .big { font-size: 1.85rem; }
  .track span { font-size: .75rem; }
  td, th { padding: .5rem .45rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* =================================================================== terminal */
body.terminal main { max-width: none; padding: 0; }
body.terminal #banner { margin: .5rem; }

.term { display: grid; gap: 1px; background: var(--line); height: calc(100vh - 49px); min-height: 640px;
  grid-template-columns: 250px minmax(0, 1fr) 300px; grid-template-rows: auto minmax(0, 1fr) 240px;
  grid-template-areas: "cmd cmd cmd" "watch chart ticket" "bottom bottom ticket"; }
.term > * { background: var(--panel); min-width: 0; min-height: 0; }
.t-cmd { grid-area: cmd; display: flex; gap: .5rem; align-items: center; padding: .4rem .6rem; }
.t-cmd input { font: 500 .95rem var(--font); min-height: 36px; background: var(--paper); flex: 1; }
.t-cmd kbd { font: .75rem var(--font); color: var(--ink-2); border: 1px solid var(--line); border-radius: 3px; padding: 0 .3rem; }
.t-watch { grid-area: watch; overflow-y: auto; }
.t-chart { grid-area: chart; display: flex; flex-direction: column; }
.t-ticket { grid-area: ticket; overflow-y: auto; padding: .75rem; }
.t-bottom { grid-area: bottom; display: flex; flex-direction: column; }
.t-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .45rem .6rem; border-bottom: 1px solid var(--line); font-size: .85rem; color: var(--ink-2); }
.t-head strong { color: var(--ink); font-size: .95rem; }

.wl { list-style: none; margin: 0; padding: 0; }
.wl button { all: unset; box-sizing: border-box; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; column-gap: .5rem; width: 100%; padding: .5rem .6rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.wl button:hover { background: var(--panel-2); }
.wl button[aria-current="true"] { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--act); }
.wl button:focus-visible { outline: 2px solid var(--act); outline-offset: -2px; }
.wl .sym { font-weight: 600; }
.wl .nm { font-size: .78rem; color: var(--ink-2); }
.wl .px { text-align: right; font-variant-numeric: tabular-nums; }
.wl .ch { text-align: right; font-size: .8rem; font-variant-numeric: tabular-nums; }
.wl svg { grid-column: 1 / -1; width: 100%; height: 22px; margin-top: .25rem; }
.wl svg polyline { fill: none; stroke-width: 1.2; }

.c-tools { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; padding: .4rem .6rem; border-bottom: 1px solid var(--line); }
.c-tools .grp { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; max-width: 100%; }
/* on narrow screens the indicator buttons scroll sideways instead of being cut off */
.c-tools .grp { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.c-tools .grp::-webkit-scrollbar { display: none; }
.c-tools .grp > button { flex: none; }
.c-tools .grp button { font: 500 .8rem var(--font); background: transparent; color: var(--ink-2); border: 0; border-right: 1px solid var(--line); padding: .3rem .55rem; cursor: pointer; min-height: 30px; }
.c-tools .grp button:last-child { border-right: 0; }
.c-tools .grp button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); }
.c-tools select { min-height: 30px; padding: .2rem .4rem; font-size: .8rem; width: auto; background: var(--paper); }
.c-legend { padding: .35rem .6rem; font-size: .8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; display: flex; flex-wrap: wrap; gap: .25rem .9rem; }
.c-legend b { color: var(--ink); font-weight: 600; }
.c-area { position: relative; flex: 1; min-height: 260px; }
.c-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--ink-2); padding: 1rem; }
.c-credit { position: absolute; left: .6rem; top: .3rem; font-size: .7rem; color: var(--ink-2); z-index: 2; }
.c-credit a { color: inherit; }

.tk .seg { width: 100%; grid-auto-columns: 1fr; }
.tk label { font-size: .85rem; }
.tk input, .tk select { min-height: 38px; padding: .35rem .5rem; }
.tk .two { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.tk .res { font-size: .85rem; }
.tk .res ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.ladder { margin-top: .75rem; border: 1px solid var(--line); border-radius: var(--r-sm); font-size: .8rem; font-variant-numeric: tabular-nums; }
.ladder .lh, .ladder button { display: grid; grid-template-columns: 1fr 1.2fr 1fr; align-items: center; }
.ladder .lh { color: var(--ink-2); padding: .3rem .4rem; border-bottom: 1px solid var(--line); }
.ladder button { all: unset; box-sizing: border-box; display: grid; grid-template-columns: 1fr 1.2fr 1fr; width: 100%; padding: .12rem .4rem; cursor: pointer; border-bottom: 1px solid rgba(37,50,66,.5); }
.ladder button:hover { background: var(--panel-2); }
.ladder button:focus-visible { outline: 2px solid var(--act); outline-offset: -2px; }
.ladder .p { text-align: center; }
.ladder .at { background: rgba(91,141,239,.18); }
.ladder .tag-l { font-size: .7rem; color: var(--ink-2); }
.ladder .ent { color: var(--act); } .ladder .stp { color: var(--stop); } .ladder .tgt { color: var(--go); }

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { font: 500 .85rem var(--font); background: transparent; color: var(--ink-2); border: 0; padding: .55rem .8rem; cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--act); }
.tab-body { flex: 1; overflow: auto; }
.tab-body table { font-size: .85rem; }
.tab-body th, .tab-body td { padding: .4rem .6rem; }
.tab-body .empty { margin: .75rem; padding: 1rem; }
.mini-chart { height: 100%; min-height: 200px; }

.explain-note { display: none; font-size: .78rem; color: var(--ink-2); padding: .3rem .6rem; border-bottom: 1px dashed var(--line); background: rgba(91,141,239,.06); }
body.explain .explain-note { display: block; }

@media (max-width: 1100px) {
  .term { height: auto; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto auto auto auto;
    grid-template-areas: "cmd cmd" "watch watch" "chart ticket" "bottom bottom"; }
  .t-watch { overflow-x: auto; }
  .t-watch .wl { display: flex; }
  .t-watch .wl li { min-width: 175px; border-right: 1px solid var(--line); }
  .t-watch .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .c-area { flex: none; height: 420px; }
  .t-bottom { min-height: 300px; }
}
@media (max-width: 760px) {
  .c-area { height: 360px; }
  .term { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto auto;
    grid-template-areas: "cmd" "watch" "chart" "ticket" "bottom"; }
  .t-cmd kbd { display: none; }
}
