/* okxdesk - dark trading-desk terminal. No framework, no external fonts (works offline). */
:root {
  color-scheme: dark;   /* dark scrollbars and native form-control chrome */
  --bg: #0b0e13; --bg2: #10141b; --panel: #131821; --panel2: #18202b; --line: #232c3a; --line2: #2e394a; --line-soft: #1a212c;
  /* --mute >= 4.5:1 on every surface (panel2 4.76, panel 5.16, bg 5.61) */
  --fg: #d8dee9; --fg2: #9aa6b8; --mute: #7f8b9f;
  --green: #22c55e; --green-d: #14532d; --red: #ef4444; --red-d: #5b1717; --amber: #f59e0b; --amber-d: #4d3606;
  /* solid red fills carrying white text (HALT, LIVE): 4.83:1 / hover 6.47:1 */
  --red-strong: #dc2626; --red-stronger: #b91c1c; --red-fg: #ffd6d6; --amber-ink: #1a1200;
  --blue: #38bdf8; --blue-d: #0c3b52; --blue-fg: #cfeeff; --violet: #a78bfa; --cyan: #2dd4bf;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 6px;
  --gut: 12px;     /* one outer margin / gutter for topbar, banners, status bar, pages and the terminal grid */
  --ctl-h: 26px;   /* rendered height of a standard input / select */
}
@media (max-width: 899px) { :root { --gut: 8px; } }
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 13px/1.45 var(--sans); display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--blue); }
code { font-family: var(--mono); background: var(--panel2); padding: 1px 4px; border-radius: 3px; }
h2 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--fg2); margin: 0 0 8px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; }
h3 { margin: 0 0 8px; font-size: 14px; }
.muted { color: var(--mute); } .small { font-size: 11px; } .r { text-align: right; } .grow { flex: 1; }
.pos { color: var(--green); } .neg { color: var(--red); } .warn-t { color: var(--amber); }
.error { color: var(--red); min-height: 1em; margin: 6px 0 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------------------------------------------------------------- buttons / inputs */
.btn { font: 600 12px var(--sans); color: var(--fg); background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--r); padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: var(--fg2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 3px 8px; font-size: 11px; }
.btn.primary { background: var(--blue-d); border-color: var(--blue); color: #e6f6ff; }
.btn.ghost { background: transparent; }
.btn.danger { border-color: var(--red); color: var(--red-fg); background: transparent; }
.btn.halt { background: var(--red-strong); border-color: #ff7b7b; color: #fff; letter-spacing: .1em; padding: 8px 18px; font-size: 13px; box-shadow: 0 0 0 1px #000, 0 0 12px rgba(239, 68, 68, .35); }
.btn.halt:hover { background: var(--red-stronger); }
.btn.resume { background: var(--green-d); border-color: var(--green); color: #dcfce7; letter-spacing: .1em; padding: 8px 18px; font-size: 13px; }
input, select, textarea { font: 12px var(--mono); color: var(--fg); background: var(--bg2); border: 1px solid var(--line2); border-radius: 4px; padding: 5px 7px; }
input:focus, select:focus { border-color: var(--blue); outline: none; }
input.bad, select.bad { border-color: var(--red); background: #1d0f12; }
input[type=checkbox] { accent-color: var(--blue); width: 15px; height: 15px; }
label { color: var(--fg2); }

/* ---------------------------------------------------------------- top bar */
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px var(--gut); background: var(--bg2); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 10; }
.brand { font: 700 15px var(--mono); letter-spacing: .04em; white-space: nowrap; }
.brand-mark { color: var(--blue); }
.mode-badge { font: 800 15px var(--mono); letter-spacing: .15em; padding: 4px 14px; border-radius: var(--r); border: 2px solid; }
.mode-badge.demo { color: var(--green); border-color: var(--green); background: rgba(34, 197, 94, .08); }
.mode-badge.live { color: #fff; border-color: #ff8a8a; background: var(--red-strong); animation: pulse 1.6s infinite; }
.mode-badge.mock { color: var(--amber-ink); border-color: #fcd34d; background: var(--amber); font-size: 12px; letter-spacing: .06em; white-space: nowrap; }
@keyframes pulse { 50% { box-shadow: 0 0 16px rgba(239, 68, 68, .8); } }
.kpis { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; min-width: 0; }
.kpi { display: flex; flex-direction: column; min-width: 60px; position: relative; }
.kpi-l { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); }
.kpi-v { font: 600 14px var(--mono); white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.spark { position: absolute; left: 100%; top: 4px; margin-left: 6px; }
.kpi:first-child { margin-right: 96px; }
.tabs { display: flex; gap: 2px; margin-left: auto; }   /* tabs + HALT + sign-out always pinned right */
.tabs a { color: var(--fg2); text-decoration: none; padding: 6px 10px; border-radius: var(--r); font-weight: 600; }
.tabs a:hover { color: var(--fg); background: var(--panel2); }
.tabs a.active { color: var(--fg); background: var(--panel2); box-shadow: inset 0 -2px 0 var(--blue); }
.banner { padding: 8px var(--gut); background: var(--amber-d); color: #ffe7b3; border-bottom: 1px solid var(--amber); font-weight: 600; }
.banner.halted { background: var(--red-d); color: var(--red-fg); border-color: var(--red); }
.banner.mock { background: #3b2a04; color: #fde68a; border-color: var(--amber); font-weight: 600; }
.banner.mock::before { content: "MOCK"; font: 800 11px var(--mono); letter-spacing: .1em; background: var(--amber); color: var(--amber-ink); border-radius: 3px; padding: 1px 6px; margin-right: 8px; }

/* ---------------------------------------------------------------- dots */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--mute); flex: none; }
.dot.ok, .dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.working { background: var(--blue); box-shadow: 0 0 6px var(--blue); animation: blink 1s infinite; }
.dot.warn { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.dot.error, .dot.bad { background: var(--red); box-shadow: 0 0 6px var(--red); }
.dot.idle, .dot.off { background: #3a4557; }
.dot.halted { background: var(--red); border-radius: 2px; box-shadow: 0 0 0 2px rgba(239, 68, 68, .35); }
.dot.stopped { background: transparent; border: 2px solid var(--mute); }
.agent.st-halted .agent-act { color: #fca5a5; } .agent.st-stopped { opacity: .6; }
@keyframes blink { 50% { opacity: .35; } }

/* ---------------------------------------------------------------- terminal grid */
/* The shell (topbar, banners, status bar) is fixed to the viewport; every .view scrolls inside itself.
   >= 1281px: three columns filling the viewport; rows 1-2 size to the agents/pipeline content first and the
   watchlist/equity row takes the rest. 900-1280: two columns, trades + equity below; < 900: one column.
   Below 1281 the terminal grid is content-sized and scrolls inside its view (rows never squeeze a panel).
   Panels never overlap: each scrolls inside itself. */
.view { flex: 1; min-height: 0; }
.terminal { display: grid; gap: var(--gut); padding: var(--gut); min-height: 0;
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr) minmax(280px, 340px);
  grid-template-rows: auto auto minmax(180px, 1fr);
  grid-template-areas: "rail log trades" "pipe log trades" "watch log equity"; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 0; min-width: 0;
  display: flex; flex-direction: column; overflow: hidden; }
.panel > h2, .panel > .log-head { flex: none; }
.rail { grid-area: rail; } .pipeline-panel { grid-area: pipe; } .watch { grid-area: watch; }
.log-panel { grid-area: log; } .trades-panel { grid-area: trades; } .equity-panel { grid-area: equity; }
.agent-rail, .cards, .watch .table-wrap { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.eng-state { margin-left: auto; font: 700 10px var(--mono); letter-spacing: .06em; color: var(--blue); text-transform: none; }
.eng-state.halted { color: var(--red); }
@media (min-width: 1281px) {
  body { height: 100vh; }
  .terminal { min-height: 560px; }
  /* open-trade cards scroll inside their panel and never size the rail/pipeline rows */
  .cards { contain: size; }
}

.agent-rail { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.agent-rail > li { flex: none; }
.agent { display: grid; grid-template-columns: 12px 78px 1fr; grid-template-rows: auto auto; column-gap: 6px; padding: 4px 6px; border-radius: 4px; align-items: center; }
.agent:hover { background: var(--panel2); }
.agent .dot { grid-row: 1 / span 2; }
.agent-name { font-weight: 600; font-size: 12px; }
.agent-model { justify-self: end; font: 10px var(--mono); padding: 0 5px; border-radius: 3px; border: 1px solid var(--line2); color: var(--fg2); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-model.llm { color: var(--violet); border-color: #4c3d80; }
.agent-act { grid-column: 2 / span 2; font: 11px var(--mono); color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pipeline { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.stage { background: var(--bg2); border: 1px solid var(--line); border-radius: 4px; min-height: 64px; padding: 4px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.stage-h { font: 700 10px var(--mono); letter-spacing: .06em; color: var(--mute); text-align: center; }
.stage.busy { border-color: var(--blue-d); }
.stage.busy .stage-h { color: var(--blue); }
.chip-sym { font: 600 10px var(--mono); background: var(--blue-d); color: var(--blue-fg); border-radius: 3px; padding: 1px 3px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: background .4s; }
.chip-sym.fresh { background: var(--blue); color: #001018; }

.table-wrap { overflow: auto; min-height: 0; }
table.grid { width: 100%; border-collapse: collapse; font: 11.5px var(--mono); }
table.grid th { text-align: left; color: var(--mute); font: 600 10px var(--sans); text-transform: uppercase; letter-spacing: .06em; padding: 4px 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); white-space: nowrap; }
table.grid td { padding: 3px 6px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
/* numeric columns: header and values share one right edge (beats the th/td defaults above) */
table.grid th.r, table.grid td.r { text-align: right; font-variant-numeric: tabular-nums; }
/* free-text cells wrap, but never below a readable measure: the table scrolls inside .table-wrap instead */
table.grid td.wrap { white-space: normal; min-width: 24ch; overflow-wrap: anywhere; }
table.grid tr:hover td { background: var(--panel2); }
.mark { font: 700 10px var(--mono); padding: 0 5px; border-radius: 3px; }
.mark.pass { background: var(--green-d); color: #bbf7d0; } .mark.skip { background: #2a2f38; color: var(--fg2); } .mark.watching { background: var(--blue-d); color: var(--blue-fg); }
.why { color: var(--mute); font-size: 11px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }

/* ---------------------------------------------------------------- decision log */
.log-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.log-head h2 { margin: 0; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.chip { font: 600 10px var(--mono); padding: 2px 6px; border-radius: 10px; border: 1px solid var(--line2); background: transparent; color: var(--mute); cursor: pointer; }
.chip.on { color: var(--fg); background: var(--panel2); border-color: var(--fg2); }
.log { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; font: 12px/1.55 var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 0; min-height: 200px; }
/* reason and meta both shrink (ellipsis) so a line never scrolls the log sideways; size/notional truncates first */
.ln { display: grid; grid-template-columns: 62px 84px 92px minmax(0, 1fr) fit-content(40%); gap: 8px; padding: 0 8px; white-space: nowrap; }
.ln:hover { background: var(--panel); }
.ln .t { color: var(--mute); } .ln .s { color: var(--fg); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ln .why { max-width: none; color: var(--fg2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.ln .meta { color: var(--mute); font-size: 11px; display: flex; gap: 8px; justify-content: flex-end; min-width: 0; overflow: hidden; }
.ln .meta > * { flex: none; }
.ln .meta > :first-child { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ln .meta .who { color: var(--mute); }
.ln .a { font-weight: 700; }
.tone-go { color: var(--green); }
.tone-exit { color: var(--cyan); }
.tone-mute { color: var(--mute); }
.tone-stop { color: #fb923c; }
.tone-adj { color: #facc15; }
.tone-llm { color: var(--violet); }
.tone-neutral { color: var(--fg2); }
.tone-alarm { color: #fff; background: var(--red); border-radius: 3px; padding: 0 3px; }
.ln .a { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.ln.violation { box-shadow: inset 3px 0 0 var(--red); }
.ln.lvl-warn .why { color: var(--amber); }
.ln.lvl-error { background: rgba(239, 68, 68, .08); } .ln.lvl-error .why { color: #fca5a5; }
.ln.new { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: rgba(56, 189, 248, .18); } }

/* ---------------------------------------------------------------- trade cards */
.cards { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-left: 3px solid var(--mute); border-radius: 6px; padding: 8px 10px; font: 11.5px var(--mono); }
.card.up { border-left-color: var(--green); } .card.down { border-left-color: var(--red); }
.card-h { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.card-sym { font: 700 14px var(--mono); }
.card-pnl { font: 700 14px var(--mono); }
.kv { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 1px 8px; }
.kv .k { color: var(--mute); } .kv .v { text-align: right; }
.card-why { margin-top: 5px; color: var(--fg2); font-family: var(--sans); white-space: normal; }
.card-foot { margin-top: 4px; display: flex; justify-content: space-between; color: var(--mute); font-size: 11px; }
.empty { color: var(--mute); font-style: italic; padding: 8px 0; }

/* ---------------------------------------------------------------- charts */
.equity-chart { width: 100%; flex: 1 1 auto; min-height: 100px; }   /* fits the 180px minimum watch/equity row */
.eq-foot { display: flex; justify-content: space-between; margin-top: 4px; }
.chart-line { fill: none; stroke-width: 1.6; } .chart-line.up { stroke: var(--green); } .chart-line.down { stroke: var(--red); }
.chart-area { stroke: none; } .chart-area.up { fill: rgba(34, 197, 94, .08); } .chart-area.down { fill: rgba(239, 68, 68, .08); }
.chart-base { stroke: var(--fg2); stroke-dasharray: 3 3; stroke-width: 1; opacity: .6; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--mute); font: 10px var(--mono); }
.chart-empty { fill: var(--mute); font: 11px var(--sans); }
.chart-dot.up { fill: var(--green); } .chart-dot.down { fill: var(--red); }

/* ---------------------------------------------------------------- status bar */
.statusbar { display: flex; gap: 16px; align-items: center; padding: 5px var(--gut); background: var(--bg2); border-top: 1px solid var(--line); font: 11px var(--mono); color: var(--fg2); flex-wrap: wrap; position: sticky; bottom: 0; }
.statusbar b { color: var(--fg); font-weight: 600; }
.statusbar .dd { display: inline-flex; align-items: center; gap: 5px; }
.bar { display: inline-block; width: 70px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--green); transition: width .4s; }
.bar > span.warn { background: var(--amber); } .bar > span.bad { background: var(--red); }
.llm-spend { display: inline-flex; gap: 10px; }

/* ---------------------------------------------------------------- pages: settings / trades / audit */
.page, .settings { padding: var(--gut); overflow: auto; }
/* no bottom padding: the docked Apply bar sits flush on the status bar, nothing scrolls visibly beneath it */
.settings { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 16px; align-items: start; padding-bottom: 0; }
/* sticky offsets are relative to the .settings scroller (not the window) */
.snav { position: sticky; top: 0; display: flex; flex-direction: column; gap: 2px; }
.snav a { color: var(--fg2); text-decoration: none; padding: 5px 9px; border-radius: 4px; }
.snav a:hover { background: var(--panel2); color: var(--fg); }
.sform { display: flex; flex-direction: column; gap: 14px; max-width: 1100px; }
.sec { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.sec h3 { display: flex; justify-content: space-between; align-items: baseline; }
.sec .sub { margin: 12px 0 6px; font: 600 11px var(--sans); color: var(--fg2); text-transform: uppercase; letter-spacing: .06em; border-top: 1px solid var(--line); padding-top: 10px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 6px 18px; }
/* first row is always one control tall, so checkbox rows share the label line of input/select rows */
.field { display: grid; grid-template-columns: 1fr 150px; grid-template-rows: minmax(var(--ctl-h), auto); gap: 2px 10px; align-items: center; padding: 3px 0; }
.field > label { font: 12px var(--mono); color: var(--fg); overflow: hidden; text-overflow: ellipsis; }
.field input:not([type=checkbox]), .field select { width: 100%; }
.field .hint { grid-column: 1 / span 2; font-size: 11px; color: var(--mute); display: flex; gap: 8px; flex-wrap: wrap; }
.field .ferr { grid-column: 1 / span 2; color: var(--red); font-size: 11px; }
.tag { font: 700 10px var(--mono); padding: 0 4px; border-radius: 3px; border: 1px solid var(--line2); }
.tag.ceil { color: var(--amber); border-color: #6b4d10; } .tag.restart { color: #f0abfc; border-color: #6b2f74; } .tag.hot { color: var(--cyan); border-color: #135e55; }
.field.wide { grid-column: 1 / -1; grid-template-columns: 1fr 2fr; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 12px; grid-column: 1 / span 2; }
.checks label { display: inline-flex; gap: 4px; align-items: center; font: 11px var(--mono); }
.secret-row { display: grid; grid-template-columns: 190px 120px 1fr auto auto; gap: 8px; align-items: center; padding: 4px 0; font: 12px var(--mono); }
.secret-row .st { color: var(--mute); } .secret-row .st.set { color: var(--green); }
.applybar { position: sticky; bottom: 0; background: var(--bg2); border: 1px solid var(--line2); border-bottom: 0; border-radius: 8px 8px 0 0; padding: 10px 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; z-index: 5; }
.applybar .msg { flex: 1; font: 12px var(--mono); }
.result { background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 10px 14px; font: 12px var(--mono); }
.result li { margin: 2px 0; }
.gate { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font: 12px var(--mono); margin: 8px 0; }
.warnbox { border: 1px solid var(--amber); background: rgba(245, 158, 11, .08); color: #fde7b0; border-radius: 6px; padding: 8px 10px; margin: 8px 0; }
.verdict { border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; border: 1px solid var(--line2); background: var(--panel); }
.verdict.pass { border-color: var(--green); } .verdict.fail { border-color: var(--red); }
.stats { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 12px; }
.stats div { display: flex; flex-direction: column; } .stats b { font: 600 16px var(--mono); }
/* Trades / Audit: header blocks keep their size, the table takes the rest of the view and scrolls inside itself */
.page { display: flex; flex-direction: column; }
.page > * { flex: none; }
.page > .table-wrap { flex: 0 1 auto; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }

/* ---------------------------------------------------------------- dialog / toasts / login */
dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--line2); border-radius: 10px; padding: 0; max-width: 440px; width: 92vw; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.dialog label { display: flex; flex-direction: column; gap: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 16px; bottom: 44px; display: flex; flex-direction: column; gap: 6px; z-index: 50; }
.toast { background: var(--panel2); border: 1px solid var(--line2); border-left: 3px solid var(--blue); padding: 8px 12px; border-radius: 6px; max-width: 420px; box-shadow: 0 4px 16px rgba(0, 0, 0, .4); }
.toast.error { border-left-color: var(--red); } .toast.ok { border-left-color: var(--green); }
.login-page { align-items: center; justify-content: center; }
.login-box { width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px; margin: auto; }
.login-box form { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.login-box label { display: flex; flex-direction: column; gap: 4px; }
.login-box input, .login-box .btn { padding: 8px; font-size: 13px; line-height: 1.25; }   /* inputs and button share one height */

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  /* content-sized rows in a view that scrolls itself: a definite view height can no longer squeeze a panel */
  .terminal { overflow-y: auto; overscroll-behavior: contain; align-content: start;
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
    grid-template-rows: repeat(4, max-content);
    grid-template-areas: "rail log" "pipe log" "watch log" "trades equity"; }
  /* 9 agent rows: size to content, never an inner scroll in practice */
  .rail { max-height: 560px; }
  .watch { min-height: 220px; max-height: 360px; }
  .watch .table-wrap { min-height: 150px; }
  .log-panel { min-height: 340px; }
  /* flex-basis 0: the log fills whatever height the three spanned rows give it (it never stretches the rows) */
  .log { flex: 1 1 0; min-height: 280px; max-height: none; }
  .trades-panel { max-height: 440px; min-height: 140px; }
  .equity-panel { min-height: 240px; max-height: 440px; }
  .kpis { order: 10; flex-basis: 100%; }
  /* watchlist: compress columns instead of scrolling sideways */
  .watch table.grid { table-layout: fixed; font-size: 11px; }
  .watch table.grid th, .watch table.grid td { padding: 3px 4px; overflow: hidden; text-overflow: ellipsis; }
  .watch table.grid th:nth-child(1) { width: 28%; } .watch table.grid th:nth-child(2) { width: 24%; }
  .watch table.grid th:nth-child(3) { width: 16%; } .watch table.grid th:nth-child(4) { width: 16%; } .watch table.grid th:nth-child(5) { width: 16%; }
}
/* the two-column watchlist sits in a ~300px column: drop 24h vol there */
@media (min-width: 900px) and (max-width: 1280px) {
  .watch table.grid th:nth-child(4), .watch table.grid td:nth-child(4) { display: none; }
  .watch table.grid th:nth-child(1) { width: 32%; } .watch table.grid th:nth-child(2) { width: 28%; }
  .watch table.grid th:nth-child(3) { width: 18%; } .watch table.grid th:nth-child(5) { width: 22%; }
}
@media (max-width: 599px) {
  .watch table.grid th:nth-child(4), .watch table.grid td:nth-child(4) { display: none; }
  .watch table.grid th:nth-child(1) { width: 32%; } .watch table.grid th:nth-child(2) { width: 28%; }
  .watch table.grid th:nth-child(3) { width: 18%; } .watch table.grid th:nth-child(5) { width: 22%; }
}
@media (max-width: 899px) {
  .topbar { gap: 8px 10px; }
  #halt-btn { margin-left: auto; }   /* tabs wrap to their own row here: keep HALT pinned right */
  .terminal { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-rows: max-content;
    grid-template-areas: "rail" "pipe" "log" "trades" "equity" "watch"; }
  .log-panel { min-height: 340px; }
  .log { flex: 1 1 auto; min-height: 300px; max-height: 60vh; }
  .trades-panel { max-height: 420px; min-height: 120px; }
  .equity-panel { min-height: 220px; max-height: 320px; }
  .watch { min-height: 220px; max-height: 340px; }
  .settings { grid-template-columns: 1fr; } .snav { display: none; }
  .ln { grid-template-columns: 58px 72px 80px minmax(0, 1fr); } .ln .meta { display: none; }
  .kpis { gap: 10px 16px; }
  .kpi:first-child { margin-right: 0; } .spark { display: none; }
  .tabs { order: 11; flex-basis: 100%; overflow-x: auto; }
  .statusbar { gap: 6px 12px; }
}
