:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #14202b; --muted: #5f6f7e; --line: #dde3e9;
  --accent: #1f6feb; --good: #13854e; --bad: #c62828; --warn: #b26a00; --paper: #6b4fd8; --live: #c62828;
  --good-bg: #e3f4ea; --bad-bg: #fbe7e7; --warn-bg: #fff3dc; --chip: #eef2f6;
  --radius: 14px; --tabs-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720; --card: #17212c; --ink: #e6edf3; --muted: #93a2b1; --line: #263342;
    --accent: #58a6ff; --good: #3fb97a; --bad: #f2645f; --warn: #e3a33b;
    --good-bg: #143326; --bad-bg: #3a1a1c; --warn-bg: #3a2c12; --chip: #213040;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1720; --card: #17212c; --ink: #e6edf3; --muted: #93a2b1; --line: #263342;
  --accent: #58a6ff; --good: #3fb97a; --bad: #f2645f; --warn: #e3a33b;
  --good-bg: #143326; --bad-bg: #3a1a1c; --warn-bg: #3a2c12; --chip: #213040;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--card); border-bottom: 1px solid var(--line);
}
.title { font-weight: 650; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.badge { font-weight: 800; letter-spacing: .06em; font-size: 12px; padding: 4px 9px; border-radius: 999px; color: #fff; background: var(--muted); }
.badge.PAPER { background: var(--paper); }
.badge.LIVE { background: var(--live); }
.badge.big { font-size: 22px; padding: 8px 18px; }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; }
.pad { padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--ink); margin: 2px 4px 2px 0; }
.chip.PASS, .chip.open, .chip.ok, .chip.positive { background: var(--good-bg); color: var(--good); }
.chip.BLOCK, .chip.skip, .chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.coin_flip, .chip.unproven, .chip.warn, .chip.pre-open { background: var(--warn-bg); color: var(--warn); }
.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-weight: 550; }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.good { background: var(--good-bg); color: var(--good); }
.meter { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.meter > div { height: 100%; background: var(--accent); width: 0; }
.meter.hot > div { background: var(--bad); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.tap { display: block; color: inherit; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 6px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
button, .btn {
  font: inherit; font-weight: 650; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  background: var(--chip); color: var(--ink); min-height: 46px;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-good { background: var(--good); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); min-height: 44px;
}
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.chart { height: 300px; margin: 0 -6px; }
.fan svg { width: 100%; height: auto; display: block; }
.countdown { font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; text-align: center; padding: 8px 0 10px; font-size: 11px; color: var(--muted); }
.tabs a .ico { display: block; font-size: 19px; line-height: 1.3; }
.tabs a.on { color: var(--accent); font-weight: 650; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + 14px + env(safe-area-inset-bottom)); z-index: 9;
  background: var(--ink); color: var(--bg); padding: 12px 14px; border-radius: 12px; font-weight: 550;
}
.toast.bad { background: var(--bad); color: #fff; }
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; }
.sheet {
  background: var(--card); width: 100%; max-width: 760px; margin: 0 auto; border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.login { max-width: 380px; margin: 8vh auto 0; }
.rule { display: flex; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.rule:first-child { border-top: 0; }
.rule .mark { font-weight: 800; width: 48px; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 3px; vertical-align: middle; margin-right: 4px; }
.l-vwap { background: #f0a020; } .l-ema { background: #8a63d2; } .l-or { background: #7f8c99; }
.l-entry { background: #1f6feb; } .l-stop { background: #c62828; } .l-target { background: #13854e; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
pre.code { white-space: pre-wrap; font-size: 12px; background: var(--chip); padding: 10px; border-radius: 10px; }
@media (min-width: 640px) {
  .grid3 { grid-template-columns: repeat(3, 1fr); }
  .chart { height: 380px; }
}

/* --- wide pages: Command center, Pipeline, Watch, Trades, Strategy --- */
body.wide main { max-width: 1480px; }
.center { text-align: center; }
.right { text-align: right; }
.grow { flex: 1; min-width: 120px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.linkbtn { background: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 600; }
.iconbtn { background: transparent; color: var(--muted); min-height: 0; padding: 4px 8px; border-radius: 8px; font-size: 15px; line-height: 1; }
.iconbtn:hover { background: var(--chip); color: var(--ink); }
.small-btn { min-height: 0; padding: 6px 12px; font-size: 13px; margin-top: 6px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; margin: 8px 12px 0 0; }
.check input { width: auto; min-height: 0; }
.seg { display: inline-flex; gap: 2px; background: var(--chip); border-radius: 9px; padding: 2px; }
.seg button { min-height: 0; padding: 4px 10px; font-size: 12px; border-radius: 7px; background: transparent; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--accent); }
input.sym { width: 190px; min-height: 0; padding: 6px 10px; font-size: 13px; }
.strip { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; font-size: 13px; }
.strip .chip { margin: 0 4px 0 0; }
.meter.mini { height: 5px; margin-top: 3px; }
.dots { display: inline-flex; gap: 10px; font-size: 12px; color: var(--muted); }
.dot::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; background: var(--muted); }
.dot.ok::before { background: var(--good); }
.dot.bad::before { background: var(--bad); }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { padding: 7px 4px; border-top: 1px solid var(--line); }
.rows li:first-child { border-top: 0; }
.rows li.tap:hover, .pipe-row:hover, .tile:hover { background: var(--chip); }
.rows li.sel, .pipe-row.sel { background: var(--warn-bg); border-radius: 8px; }
.cols2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 12px; align-items: start; }
.filters4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
table.trades tr.tap { cursor: pointer; }
table.trades tr.tap:hover { background: var(--chip); }

/* Command center grid */
.desk { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-width: 0; }
.panel > header { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 6px 8px 6px 10px; border-bottom: 1px solid var(--line); }
.panel .ptitle { font-weight: 650; font-size: 13px; }
.panel .tools { flex: 1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.panel .grip { cursor: grab; color: var(--muted); user-select: none; padding: 0 2px; display: none; }
.panel .body { padding: 8px 10px; overflow: auto; max-height: 440px; }
/* enlarged panel: a full-screen popup over a dimmed page */
.panel.max { position: fixed; inset: 16px; z-index: 40; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.panel.max .body { flex: 1; max-height: none; overflow: auto; }
.panel.max .grip { display: none; }
.panel.tall .body { max-height: none; overflow: visible; }
.maxbg { position: fixed; inset: 0; z-index: 39; background: rgba(0, 0, 0, .55); }
body.modal-open { overflow: hidden; }
.panel.dragging { opacity: .45; }
.panel.drop { outline: 2px dashed var(--accent); outline-offset: 2px; }
.deskchart { height: 360px; }
.panel.max .deskchart { height: calc(100vh - 130px); }
.panel .body .deskchart { margin: 0 -4px; }
.eqchart { height: 200px; }
.panel.max .eqchart { height: calc(100vh - 170px); }
.stat .v { font-size: 18px; }

/* Pipeline */
.steps { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin: 8px 0; }
.step { border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font-size: 11px; color: var(--muted); min-width: 0; overflow: hidden; }
.step .n { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps.big .step { font-size: 12px; padding: 6px 8px; }
.steps.big .step .t { white-space: normal; }
.step.done { border-color: var(--good); color: var(--good); }
.step.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.step.stopped { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.step.warn { border-color: var(--warn); color: var(--warn); }
.pipe-focus { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 6px; }
.pipechart { height: 300px; }
.wwn { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
.pipe-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 12px; }
.pipe-row { padding: 8px 6px; border-top: 1px solid var(--line); }
.console { max-height: 420px; overflow: auto; font-size: 12px; }
.logline { padding: 3px 0; border-top: 1px dashed var(--line); }
.logline .ev { font-weight: 700; }

/* Watch tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; outline: none; }
.tile:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.tile.has-signal { border-color: var(--warn); }
.tile.has-ticket { border-color: var(--accent); }
.tile .px { font-size: 18px; font-weight: 650; }
.tile .art svg { width: 100%; height: 64px; display: block; margin: 4px 0; }
.tile .chip { font-size: 11px; padding: 1px 6px; }

/* Trades replay, Strategy */
.replaybar { margin-top: 8px; }
.replaybar input[type=range] { min-height: 0; padding: 0; }
.flow { padding-left: 20px; margin: 0; font-size: 14px; }
.flow li { margin: 6px 0; }
.setup { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 8px; }
.setup.on { border-color: var(--good); }
.rules2 { columns: 1; padding-left: 18px; margin: 0; }
.rules2 li { margin: 4px 0; break-inside: avoid; }

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tabs { position: sticky; top: 49px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); justify-content: center; gap: 4px; padding: 0; }
  .tabs a { flex: 0 0 auto; padding: 10px 18px; font-size: 14px; display: flex; gap: 6px; align-items: center; }
  .tabs a .ico { display: inline; font-size: 15px; }
  .tabs a.on { box-shadow: inset 0 -2px 0 var(--accent); }
  .toast { left: auto; right: 20px; bottom: 20px; max-width: 440px; }
  .desk { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panel.span2 { grid-column: span 2; }
  .panel.tall { grid-row: span 2; }
  .panel .grip { display: inline; }
  .deskchart { height: 520px; }
  .cols2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pipe-focus { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
  .pipe-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .rules2 { columns: 2; }
}
@media (max-width: 899px) {
  .tabs a { font-size: 10px; }
  .steps { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  input.sym { width: 140px; }
}

.quotes li { padding: 6px 4px; font-size: 13px; }
.checklist { list-style: none; padding: 0; margin: 8px 0 12px; font-size: 14px; }
.checklist li { padding: 4px 0; color: var(--muted); }
.checklist li.good { color: var(--good); }
.seg.big button { padding: 6px 16px; font-size: 13px; font-weight: 750; cursor: default; }
.seg.big button.on { color: var(--paper); }
.seg.big button.on.live { color: #fff; background: var(--live); }
@media (max-width: 899px) { .panel.max { inset: 0; border-radius: 0; } }
.rows li.row { display: flex; }
.tabs[hidden] { display: none !important; }

/* chart + watchlist in one panel */
.chartwrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.wl { border-top: 1px solid var(--line); padding-top: 8px; min-width: 0; }
.wlhead { flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.wl .rows { max-height: 320px; overflow: auto; }
@media (min-width: 900px) {
  .chartwrap { grid-template-columns: minmax(0, 1fr) 270px; }
  .wl { border-top: 0; border-left: 1px solid var(--line); padding: 0 0 0 10px; }
  .wl .rows { max-height: 470px; }
  .panel.max .wl .rows { max-height: calc(100vh - 150px); }
}
.wl .rows li.sel { background: color-mix(in srgb, var(--accent) 18%, transparent); box-shadow: inset 3px 0 0 var(--accent); border-radius: 6px; }
.panel .ptitle .num { font-weight: 600; }
