/* "crossover" console — NAVY FINAL (operator-approved 2026-08-06, samples_v2/sample_11)
   + THEME TOGGLE (operator-approved 2026-08-07, samples/th_01): token-driven dark/bright.
   BRIGHT (default) = the SOFTENED set; DARK redefines ONLY the tokens under
   [data-theme=dark]; the navy sidebar is the brand anchor and never flips. Every
   component styles through the tokens — the only literal colors below live in the
   sidebar/top-bar blocks (theme-invariant) and white-on-blue accents. Corner rounding
   follows the OLD dashboard's ruling: 8px cards/panels · 6px small controls · 4px bar
   tracks · 999px pills. */
:root {
  color-scheme: light;
  /* ground — the SOFTENED bright set (operator-locked 2026-08-07; cards one step
     softer again in the §T8 retune — page ground deliberately unchanged) */
  --bg: #e2e7ee;
  --card: #f4f7fa;
  --hover: #eef1f5;
  --border: #d5dde8;
  --border2: #cfd8e4;
  --sidebar: #0b2540;   /* brand anchor — identical in BOTH themes (never redefined) */
  /* ink — today's navy-final literals, unchanged */
  --text: #26324b;
  --muted: #5a6b84;
  --dim: #98a4b3;
  --label: #8492a6;
  /* state */
  --blue: #1f7cff;      /* accent — constant across themes (never redefined) */
  --green: #37c384;
  --red: #e04c4c;
  --amber: #c77d0a;     /* mock-locked (th_01) — supersedes the pre-theme value */
  /* derived surfaces (bright side = the pre-theme literals) */
  --shadow: 0 1px 4px rgba(15, 34, 58, .06);
  --shadow-sm: 0 1px 3px rgba(15, 34, 58, .05);
  --shadow-pop: 0 8px 24px rgba(15, 34, 58, .18);
  --shadow-sheet: 0 -8px 24px rgba(15, 34, 58, .18);
  --tint-blue: #e8f1ff;
  --tint-blue-border: #d8e6fb;
  --tint-red: #fdecec;
  --tint-amber: #fdf3e2;
  --row-hover: #f7fafd;
  --row-sel: #f0f6ff;
  --diary-ink: #1c2536;   /* §T8 ④: near-black first-person lines (pair, both blocks) */
  --dot-off: #c2ccd8;
  --calc-rule: #1c1e2b;
  --warn-border: #ecdcbf;
  --green-fill: rgba(55, 195, 132, .55);
  --red-fill: rgba(224, 76, 76, .55);
  --blue-fill: rgba(31, 124, 255, .55);   /* blue family — constant across themes */
  --amber-fill: rgba(192, 127, 10, .5);
  --red-bg: rgba(224, 76, 76, .15);
  --amber-bg: rgba(192, 127, 10, .15);
  --red-bg-faint: rgba(224, 76, 76, .08);
  --amber-bg-faint: rgba(192, 127, 10, .07);
}
/* DARK — the lifted set (operator-locked 2026-08-07). ONLY tokens change here; the
   sidebar + accent blue are deliberately absent (theme-invariant by decree) — and
   since the §T8 retune so are GREEN + RED: one pair everywhere, inherited from
   :root (the lifted dark pair is RETIRED, values recorded in the plan). */
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #141e2e;
  --card: #1e2a3c;
  --hover: #263650;
  --border: #2e405a;
  --border2: #2e405a;
  --text: #dde5ef;
  --muted: #9dacc2;
  --dim: #74869e;
  --label: #8b9ab2;
  --amber: #e0a34a;
  --shadow: 0 1px 4px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
  --shadow-pop: 0 8px 24px rgba(0, 0, 0, .5);
  --shadow-sheet: 0 -8px 24px rgba(0, 0, 0, .5);
  --tint-blue: #203a5c;
  --tint-blue-border: #2a4a74;
  --tint-red: #3a2733;
  --tint-amber: #3c3222;
  --row-hover: #232f44;
  --row-sel: #1f3554;
  --diary-ink: #eef3f9;   /* §T8 ④: near-white first-person lines */
  --dot-off: #4a5c76;
  --calc-rule: #2e405a;
  --warn-border: #5c4a26;
  /* §T8 ⑤: green/red fills + banner bg now INHERIT the bright rgba of the constant
     pair; only the faint red keeps its stronger dark alpha (T8-D2) */
  --amber-fill: rgba(224, 163, 74, .5);
  --amber-bg: rgba(224, 163, 74, .15);
  --red-bg-faint: rgba(224, 76, 76, .12);
  --amber-bg-faint: rgba(224, 163, 74, .1);
}

* { box-sizing: border-box; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0; background: var(--bg); color: var(--text); min-height: 100vh;
  transition: background .25s, color .25s;   /* the toggle's soft flip (mock th_01) */
}
main { padding: 24px 28px; min-width: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { font-size: 1.05rem; margin: 0.8rem 0 0.4rem; }
.muted { color: var(--label); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
/* card surfaces cross-fade with the theme flip (no layout motion) */
.card, .acc, .tile, .diary, .pos-card, .showbar, .badge, .themebtn {
  transition: background-color .25s, border-color .25s;
}

/* ===== the navy sidebar shell ===== */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
aside {
  background: var(--sidebar);
  padding: 22px 18px; display: flex; flex-direction: column; gap: 4px;
}
aside .brand { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; }
.lgmark {
  width: 34px; height: 34px; border-radius: 6px; background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .18); display: grid; place-items: center;
}
.lgmark svg { transform: scale(.62); }
.brand b.wm { font-weight: 350; letter-spacing: .05em; font-size: 17px; color: #fff; }
/* nav items: line icon + label; the ACTIVE item is a full-bleed accent bar
   (negative margins run it edge to edge, exactly the reference's trick) */
aside nav a {
  display: flex; align-items: center; gap: 12px; margin: 0 -18px;
  padding: 10px 18px 10px 26px; color: #a9bcd4; text-decoration: none; font-size: 13.5px;
}
aside nav a svg { flex: none; opacity: .85; }
aside nav a:hover { text-decoration: none; color: #fff; }
aside nav a.on { background: var(--blue); color: #fff; font-weight: 600; }
aside nav a.off { opacity: .45; cursor: default; pointer-events: none; }
aside .note {
  margin-top: auto; font-size: 11px; color: #7f93ad; line-height: 1.5;
  border-top: 1px solid rgba(255, 255, 255, .12); padding-top: 12px;
}

/* status pills top-right of the content — states keep today's semantics */
.mainhead { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.badges { margin-left: auto; display: flex; gap: 8px; }
.badge {
  font-size: 12px; padding: 5px 12px; border-radius: 999px; font-weight: 600;
  background: var(--card); border: 1px solid var(--border2); color: var(--muted);
  box-shadow: var(--shadow-sm);
}
.badge.ok::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); margin-right: 6px;
}
.badge.stale   { color: var(--amber); border-color: var(--amber); }
.badge.halted  { color: var(--red); border-color: var(--red); }
.badge.waiting { color: var(--label); }
/* the theme pill (mock th_01): moon "Dark" in bright, sun "Bright" in dark */
.themebtn {
  cursor: pointer; font: inherit; font-size: 12px; display: flex; align-items: center;
  gap: 6px; padding: 5px 12px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--border2); color: var(--muted);
}
.themebtn svg { display: block; }

/* ===== MOBILE TOP BAR (§A, operator-approved 2026-08-06, mock mo_01) =====
   Below 880px the sidebar becomes a slim sticky navy top bar: compact brand, then the
   nav as ONE horizontal swipeable row (icon above label, active = white + inset blue
   underline, no pill). EVERYTHING mobile lives INSIDE this one block — that containment
   IS the desktop-untouched proof, pinned mechanically in the test suite. At >=880px the
   desktop sidebar renders byte-identically. (This block SUBSUMES the old crude 820px
   shell collapse — the full-screen navy wall on the operator's iPhone screenshot.) */
@media (max-width: 880px) {
  .app { display: block; }
  aside {
    position: sticky; top: 0; z-index: 10; padding: 10px 14px 0; gap: 0;
    box-shadow: 0 2px 8px rgba(11, 37, 64, .25);
  }
  aside .brand { margin-bottom: 8px; }
  .lgmark { width: 28px; height: 28px; }
  .lgmark svg { transform: scale(.5); }
  .brand b.wm { font-size: 15.5px; }
  aside nav {
    display: flex; flex-direction: row; overflow-x: auto; margin: 0 -14px;
    padding: 0 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  aside nav::-webkit-scrollbar { display: none; }
  aside nav a {
    flex-direction: column; gap: 3px; margin: 0; padding: 6px 12px 9px;
    font-size: 10.5px; border-radius: 0; white-space: nowrap;
  }
  aside nav a.on {
    background: none; color: #fff; font-weight: 600;
    box-shadow: inset 0 -2.5px 0 #1f7cff;
  }
  aside .note { display: none; }
  main { padding: 14px 12px; }
  .cards { gap: 10px; }
  /* §C (operator rule 2026-08-07): on the phone, idle subs from Sub3 onward vanish —
     Main (child 1) + Sub1 + Sub2 always show, active or idle; an ACTIVE later sub
     always shows (no .idle class -> can never match). The server still renders every
     card (display-only); desktop shows all, exactly as today. Scales to any sub count. */
  .accrow .acc.account.idle:nth-child(n+4) { display: none; }
}

/* cards */
/* 0.6rem everywhere: between cards AND between sections (operator: same space) */
.cards { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.6rem; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 0.6rem 0.9rem; box-shadow: var(--shadow);
}
.card .v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.card.placeholder { width: 100%; padding: 1.1rem; }

/* tables */
table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; }
th, td {
  border: 1px solid var(--border); padding: 0.35rem 0.5rem; text-align: right;
  font-size: 0.85rem; font-variant-numeric: tabular-nums;
}
th { background: var(--card); color: var(--label); font-weight: 600; }
td:first-child, th:first-child { text-align: left; }

/* phone-first: stack the cards full-width on small screens */
@media (max-width: 700px) {
  .cards { flex-direction: column; }
  .card { width: 100%; }
  .nav-links a { margin-right: 0.6rem; font-size: 0.9rem; }
}

/* live chart card (D3) */
.chart-card { width: 100%; padding: 0.4rem; margin-bottom: 0.6rem; }
#live-chart { height: 400px; }

/* Live page (D3 Part C) */
.banner-alert {
  width: 100%; background: var(--red-bg); border: 1px solid var(--red);
  color: var(--red); font-weight: 700; border-radius: 8px; padding: 0.6rem 0.9rem;
  margin: 0.5rem 0;
}
/* FIX-I: the liq WARNING banner is AMBER — red stays reserved for orphan/HALT */
.banner-warn {
  width: 100%; background: var(--amber-bg); border: 1px solid var(--amber);
  color: var(--amber); font-weight: 700; border-radius: 8px; padding: 0.6rem 0.9rem;
  margin: 0.5rem 0;
}
/* the safety chips stay LOUD: tinted backgrounds, state-colored ink/border */
.pill.liq-risk { color: var(--amber); border-color: var(--amber); background: var(--tint-amber); }
/* FIX-J: level 2 — liq at/inside the SL */
.pill.liq-critical { color: var(--red); border-color: var(--red); background: var(--tint-red); }
/* FIX-K: no stop resting — the repair is not sticking */
.pill.no-sl { color: var(--red); border-color: var(--red); background: var(--tint-red); }
.green { color: var(--green); }
.red { color: var(--red); }
.amber { color: var(--amber); }
.blue { color: var(--blue); }
.center { text-align: center; }
.section-head { text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.8rem; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.green { background: var(--green); }
.dot.gray { background: var(--label); }
.pill {
  background: var(--tint-blue); border: 1px solid var(--tint-blue-border); border-radius: 999px;
  padding: 0.1rem 0.6rem; font-weight: 700; font-size: 0.8rem; color: var(--blue);
}
/* ===== Analytics (bento rebuild 2026-08-06, an_03b): head pills, showbar, bento ===== */
.an-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.an-head h1 { font-size: 18px; font-weight: 650; margin: 0; }
.pills {
  display: flex; gap: 4px; background: var(--card); border: 1px solid var(--border2);
  border-radius: 8px; padding: 3px;
}
.pills a { padding: 5px 13px; border-radius: 6px; font-size: 12.5px; color: var(--muted);
  text-decoration: none; }
.pills a:hover { text-decoration: none; }
.pills a.on { background: var(--blue); color: #fff; font-weight: 600; }
.showbar {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  padding: 10px 16px; margin-bottom: 14px; flex-wrap: wrap;
}
.showbar .lbl { font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--label); font-weight: 600; }
.spill { font-size: 11.5px; padding: 4px 11px; border-radius: 999px; background: var(--tint-blue);
  color: var(--blue); font-weight: 600; }
.apill { font-size: 10.5px; padding: 3px 9px; border-radius: 999px; background: var(--blue);
  color: #fff; font-weight: 700; }
.showbar-hint { font-size: 12px; color: var(--label); margin-left: auto; }
.bento { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 15px 17px;
}
.tile h2 { font-size: 11.5px; letter-spacing: .14em; color: var(--label); margin: 0 0 12px;
  text-transform: uppercase; font-weight: 600; }
.t-eq { grid-column: span 3; grid-row: span 2; }
.t-eq #equity-chart { min-height: 280px; }
.t-stat label { font-size: 11.5px; color: var(--label); }
.t-stat .v { display: block; font-size: 20px; font-weight: 750; margin-top: 3px; }
.t-stat .v.sm { font-size: 14px; }
.t-stat .s { display: block; font-size: 11px; color: var(--dim); margin-top: 1px; }
.t-full { grid-column: span 4; }
table.combos th { cursor: default; }
table.combos td { cursor: pointer; border: none; border-bottom: 1px solid var(--bg); }
table.combos tbody tr:hover td { background: var(--row-hover); }
table.combos tr.sel td { background: var(--row-sel); }
table.combos tr.sel td:first-child { border-left: 3px solid var(--blue); font-weight: 600;
  color: var(--text); }
table.combos .rowlink { color: inherit; }
table.combos .rowlink:hover { text-decoration: none; }
.pre-d1-note { font-size: 11.5px; margin-top: 8px; }
@media (max-width: 900px) {
  .bento { grid-template-columns: 1fr 1fr; }
  .t-eq, .t-full { grid-column: span 2; }
}

/* ===== Live page (navy final 2026-08-06): panels, cards, twin half-tracks ===== */
/* two-column: content + the diary rail (stacks below on narrow) */
.mainwrap { display: grid; grid-template-columns: 1fr 280px; gap: 20px; align-items: start; }
@media (max-width: 1020px) { .mainwrap { grid-template-columns: 1fr; } .diary { position: static; } }

/* uniform vertical account cards (main + subs) */
.accrow {
  /* 200px minimum (navy reference): long money rows like "Next trade capital
     $84,484.00" must never clip inside a card */
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px; margin-bottom: 16px;
}
.acc {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
/* §T8 ③ (+20%, Live acc cards ONLY): nm 12.5->15px, kv2/kv 11.5->13.8px — taller
   cards accepted by decree, padding deliberately NOT tightened to compensate */
.acc .nm { font-size: 15px; font-weight: 700; display: flex; align-items: center;
  text-transform: capitalize; }
.acc .nm i { font-style: normal; color: var(--green); margin-right: 5px; }
.acc .nm i.off { color: var(--dot-off); }
.acc .kv2 { display: flex; justify-content: space-between; font-size: 13.8px;
  color: var(--label); padding: 1px 0; white-space: nowrap; gap: 8px; }
.acc .kv2 b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.acc .kv2 b.v { color: var(--green); }
.acc .kv2 b.v.neg { color: var(--red); }
/* the merged Main card spans tall; amber = risk, green = deployable */
.acc.cap { grid-row: span 2; }
.acc.cap .nm i { color: var(--label); }
.capkvs { display: grid; grid-template-columns: 1fr; gap: 1px; margin-top: 5px; }
.acc.cap .kv { display: flex; justify-content: space-between; font-size: 13.8px;
  padding: 2px 0; color: var(--label); white-space: nowrap; gap: 8px; }
.acc.cap .kv b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.acc.cap .kv b.g { color: var(--green); }
.acc.cap .kv b.a { color: var(--amber); }
/* IDLE = no position on that sub (count-driven, NEVER balance-driven) */
.acc.idle { opacity: .6; }
.acc.idle .nm, .acc.idle .kv2 b { color: var(--dim); }

/* position panels */
.pos-card { width: 100%; margin: 0 0 14px; padding: 16px 18px; border-radius: 8px;
  box-shadow: var(--shadow); }
.pos-head { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
/* §T10: the panel joins the acc-card type family — the LONG/SHORT header sits at
   the card-name size/weight (15px/700), the grid rows at the kv-row size (13.8px);
   grid columns, bar labels and every color role unchanged */
.pos-head .side { font-size: 15px; font-weight: 700; letter-spacing: .05em; }
.pos-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px 16px;
  font-size: 13.8px; color: var(--label);
}
.pos-grid b { color: var(--text); margin-left: 5px; font-weight: 600;
  font-variant-numeric: tabular-nums; }
.pos-grid b.green { color: var(--green); }
.pos-grid b.red { color: var(--red); }
.pos-grid b.amber { color: var(--amber); }
@media (max-width: 820px) { .pos-grid { grid-template-columns: 1fr 1fr; } }

/* TWIN HALF-TRACKS (navy final, replaces the centered bar): the 6px GAP is the entry
   point. Left half: red fill anchored to its RIGHT edge, grows out of the gap toward SL,
   width = sl_progress %. Right half: green fill anchored LEFT, grows toward TP, width =
   tp_progress %. Fills are SQUARE at .55 opacity (the 4px track's overflow clipping
   rounds them) — the old dashboard's fill language. Both halves always render. */
.cbar { display: flex; gap: 6px; margin-top: 14px; }
.cbar .half {
  position: relative; flex: 1; height: 18px; border-radius: 4px;
  background: var(--bg); border: 1px solid var(--border2); overflow: hidden;
}
.cbar .fl { position: absolute; top: 0; bottom: 0; opacity: .55; }
.cbar .fl.sl { right: 0; background: var(--red); }
.cbar .fl.tp { left: 0; background: var(--green); }
.cbar .lb { position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font-size: 10.5px; font-weight: 700; }
.cbar .half.hl .lb { color: var(--red); }
.cbar .half.hr .lb { color: var(--green); }

/* THE BOT'S DIARY (right rail): first-person entries with colored timeline dots */
.diary {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 18px 18px 10px; position: sticky; top: 20px; box-shadow: var(--shadow);
}
.diary h2 { margin: 0 0 14px; font-size: 11.5px; letter-spacing: .14em; color: var(--label); }
.entry { border-left: 2px solid var(--border2); padding: 0 0 16px 14px; position: relative; }
.entry::before {
  content: ""; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--dot-off);
}
.entry.good::before { background: var(--green); }
.entry.act::before { background: var(--blue); }
.entry.bad::before { background: var(--red); }
.entry .t { font-size: 11px; color: var(--label); margin-bottom: 3px; }
/* §T8 ④: one ink pair for ALL entry text — bold inherits it, weight carries the
   emphasis (a separate strong color would invert against the near-black/near-white
   pair); timestamps above stay on the label token, untouched */
.entry p { font-size: 12.5px; color: var(--diary-ink); line-height: 1.5; margin: 0; }
.entry .g { color: var(--green); }
.entry .r { color: var(--red); }

/* chart controls (D3.2): timeframe row + EMA toggle */
.chart-controls {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
  gap: 0.4rem; padding: 0.2rem 0.3rem 0.5rem;
}
.tf-btn {
  background: var(--hover); color: var(--label); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.15rem 0.6rem; margin-right: 0.25rem; font-size: 0.8rem;
  cursor: pointer;
}
.tf-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 700; }
.tf-btn.home:not(.active) { border-color: var(--blue); color: var(--blue); }
.ema-label { font-size: 0.85rem; }

/* Trades page (D4): summary row + wide sortable table (scrolls inside its wrap on phones) */
.table-wrap { overflow-x: auto; width: 100%; }
.summary-row { display: flex; flex-wrap: wrap; gap: 1.2rem; width: 100%; margin: 0.5rem 0; }
.summary-row > div { display: flex; flex-direction: column; }
.summary-row .v { font-size: 1.05rem; }
table.trades th a { color: var(--label); }
table.trades th a:hover { color: var(--blue); text-decoration: none; }
table.trades td, table.trades th { white-space: nowrap; }
tr.trow { cursor: pointer; }
tr.trow:hover td { background: var(--hover); }
.pill.blue { color: var(--blue); }
.pill.muted { color: var(--label); }
.pill.red { color: var(--red); background: var(--tint-red); border-color: var(--red); }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 0.8rem; margin: 0.4rem 0; }
.trades-head { display: flex; justify-content: space-between; align-items: center; }
.filter-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; width: 100%;
  margin: 0.5rem 0; font-size: 0.85rem;
}
.filter-row select, .filter-row input[type="date"] {
  background: var(--hover); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.15rem 0.35rem; font-size: 0.85rem;
}
tr.trow-detail td { background: var(--bg); cursor: default; white-space: normal; }
.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 1.4rem; text-align: left;
  font-size: 0.85rem; padding: 0.2rem 0.3rem;
}
.detail-grid > div > div { margin: 0.15rem 0; }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

/* Analytics page (D5): period row, stat grid, the two ~280px chart cards */
.analytics-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  gap: 0.6rem; margin-bottom: 0.6rem;
}
.card.stat { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
/* long values ($ + %) must never spill outside the card — wrap inside it instead */
.card.stat .v { overflow-wrap: anywhere; }
.card.stat .muted { font-size: 0.78rem; }
.card.stat .sub { font-size: 0.72rem; }
.analytics-chart .section-head { padding: 0.15rem 0.3rem 0.35rem; }
#balance-chart, #equity-chart { height: 280px; }
.empty-note { padding: 1.2rem 0; }

/* Analytics Part B: histogram + daily columns, horizontal bars, strategy cards */
.block-card { width: 100%; margin-bottom: 0.6rem; }
.block-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.split { display: flex; gap: 0.6rem; margin-bottom: 0.6rem; }
.split > .card { flex: 1; min-width: 0; margin-bottom: 0; }
@media (max-width: 700px) { .split { flex-direction: column; } }
.hist { display: flex; align-items: flex-end; gap: 2px; margin-top: 0.5rem; }
.hcol { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.15rem; min-width: 0; }
.hcount { font-size: 0.7rem; height: 1em; }
.hbar { width: 100%; height: 120px; display: flex; align-items: flex-end; }
.hfill { width: 100%; display: block; }
.hfill.green { background: var(--green-fill); }
.hfill.red { background: var(--red-fill); }
.hfill.blue { background: var(--blue-fill); }
.hfill.amber { background: var(--amber-fill); }
.hfill.muted { background: var(--hover); }
.hlab { font-size: 0.68rem; }
.hrow { display: flex; align-items: center; gap: 0.5rem; margin: 0.3rem 0; font-size: 0.85rem; }
.hname { min-width: 5.5rem; }
.htrack {
  flex: 1; height: 14px; background: var(--hover); border: 1px solid var(--border);
  border-radius: 4px; overflow: hidden; display: block;
}
.htrack .hfill { height: 100%; }
.hval { white-space: nowrap; }
.divider-head { border-top: 1px solid var(--border); padding-top: 0.7rem; margin: 0.9rem 0 0.5rem; }
.strategy-best { width: 100%; border: 2px solid var(--blue); margin-bottom: 0.6rem; }
.strategy-best .badges { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.4rem 0; }
.best-row { font-size: 0.95rem; }
.krow { display: flex; justify-content: space-between; gap: 1rem; margin: 0.25rem 0; font-size: 0.87rem; }
.note { font-size: 0.78rem; margin-top: 0.4rem; }
.daily { display: flex; align-items: flex-end; gap: 3px; margin-top: 0.5rem; }
.dcol { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; min-width: 40px; }
.dval { font-size: 0.66rem; height: 1em; }
.dbar { width: 100%; height: 90px; display: flex; align-items: flex-end; }
.dbar.empty { border-bottom: 1px solid var(--border); }
.dfill { width: 100%; }
.dfill.green { background: var(--green-fill); }
.dfill.red { background: var(--red-fill); }
.dlab { font-size: 0.64rem; text-align: center; }

/* Bot page (D6): internally-scrolling manual + config grid */
.manual-card { max-height: 60vh; overflow-y: auto; }
.manual { font-size: 0.88rem; line-height: 1.5; }
.manual h1 { font-size: 1.05rem; margin-top: 0.8rem; }
.manual h2 { font-size: 0.95rem; margin-top: 0.8rem; }
.manual h3 { font-size: 0.9rem; margin: 0.6rem 0 0.3rem; }
.manual code { background: var(--hover); border-radius: 4px; padding: 0.05rem 0.3rem; }
.manual pre { background: var(--hover); border-radius: 6px; padding: 0.5rem 0.7rem; overflow-x: auto; }
.manual pre code { background: none; padding: 0; }
.manual blockquote { border-left: 3px solid var(--border); margin: 0.5rem 0; padding: 0.1rem 0.8rem; color: var(--label); }
.manual th, .manual td { text-align: left; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.8rem 1.4rem; }
.cfg-title { margin-bottom: 0.25rem; }

/* Bot page (D6 Part B): the events feed */
.feed-row { display: flex; align-items: baseline; gap: 0.55rem; margin: 0.35rem 0; font-size: 0.88rem; }
.feed-row .dot { flex: none; align-self: center; }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }
.dot.blue { background: var(--blue); }
.dot.muted { background: var(--label); }
.feed-label { min-width: 0; }
.feed-rid { font-size: 0.78rem; }
.feed-time { margin-left: auto; white-space: nowrap; font-size: 0.8rem; }
.feed-older { text-align: right; margin-top: 0.4rem; }

/* chart context menu (D3.3) */
.chart-menu {
  position: fixed; z-index: 1000; min-width: 170px; background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.25rem;
  box-shadow: var(--shadow-pop);
}
.chart-menu-item {
  padding: 0.45rem 0.7rem; border-radius: 6px; font-size: 0.88rem; cursor: pointer;
  user-select: none;
}
.chart-menu-item:hover { background: var(--hover); }

/* Backtest page (BT2): param panel LEFT · result RIGHT (stacks on phones) */
.bt-layout { display: grid; grid-template-columns: 300px 1fr; gap: 0.8rem; align-items: start; }
@media (max-width: 900px) { .bt-layout { grid-template-columns: 1fr; } }
.bt-form-card { position: sticky; top: 0.5rem; max-height: calc(100vh - 1rem); overflow-y: auto; }
.bt-group { margin-bottom: 0.7rem; }
.bt-group-head { text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.06em; margin-bottom: 0.25rem; }
.bt-field { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0.2rem 0; font-size: 0.85rem; }
.bt-field input[type="text"], .bt-field input[type="date"], .bt-field select {
  width: 9.5rem; background: var(--hover); color: inherit; border: 1px solid var(--border);
  border-radius: 6px; padding: 0.25rem 0.45rem; font-size: 0.85rem;
}
/* risk-mode gating: the field the current risk_mode does NOT use is blanked + disabled —
   greyed and non-interactive so it can't be edited or read as meaningful (backtest.js) */
.bt-param:disabled {
  opacity: 0.4; cursor: not-allowed; background: var(--bg); color: var(--label);
}
.bt-field:has(.bt-param:disabled) > .muted { opacity: 0.5; }
.bt-run-btn {
  width: 100%; margin-top: 0.5rem; padding: 0.5rem; border-radius: 8px; border: 1px solid var(--blue);
  background: var(--blue); color: #fff; font-weight: 700; cursor: pointer; font-size: 0.95rem;
}
.bt-run-btn:disabled { opacity: 0.55; cursor: default; }
.bt-msg { margin-top: 0.5rem; font-size: 0.85rem; }
.bt-bar { height: 8px; background: var(--hover); border-radius: 4px; margin-top: 0.3rem; overflow: hidden; }
.bt-bar-fill { height: 100%; width: 0; background: var(--blue); transition: width 0.4s; }
.bt-main { display: flex; flex-direction: column; gap: 0.8rem; min-width: 0; }
.bt-banner .bt-banner-row { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: baseline; margin-top: 0.35rem; font-size: 0.85rem; }
.bt-assumptions { font-size: 0.78rem; }
.bt-trade-row { cursor: pointer; }
.bt-trade-row:hover td, .bt-trade-row.selected td { background: var(--hover); }
.bt-current-run td { background: var(--hover); }
.bt-popover {
  position: absolute; z-index: 900; background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.55rem 0.75rem; font-size: 0.82rem; max-width: 300px;
  box-shadow: var(--shadow-pop);
}
.bt-popover .krow { display: flex; justify-content: space-between; gap: 1rem; }
.chart-card { position: relative; }
.runner-down code { background: var(--hover); padding: 0.1rem 0.4rem; border-radius: 4px; }
.bt-thin-hint { font-size: 0.78rem; margin-left: auto; }
.bt-chart-hint { font-size: 0.78rem; margin: 0.2rem 0 0.4rem; }
.bt-popover .block-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.35rem; }
.bt-pop-close { cursor: pointer; padding: 0 0.3rem; color: var(--label); }
.bt-pop-close:hover { color: var(--red); }
.bt-marker-legend .bt-lg-entry { color: var(--blue); }
.bt-marker-legend .bt-lg-exit { color: var(--label); }

/* Backtest "subs needed" concurrency histogram */
.bt-peak-card .v { font-size: 1.8rem; }
/* peak-exposure rows (2026-08-27): label · value · its own date, stacked and wrap-safe */
.bt-peaks { display: flex; flex-direction: column; gap: 0.5rem; }
.bt-peaks > div { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.bt-peaks b { margin-left: auto; }
.bt-peaks .sub { flex-basis: 100%; text-align: right; font-size: 0.78rem; }
.bt-conc { display: flex; align-items: flex-end; gap: 0.4rem; height: 90px; padding-top: 0.4rem; }
.bt-conc-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; min-width: 0; }
.bt-conc-pct { font-size: 0.68rem; }
.bt-conc-bar { width: 100%; max-width: 34px; height: 60px; display: flex; align-items: flex-end; }
.bt-conc-fill { width: 100%; background: var(--blue); border-radius: 3px 3px 0 0; }
.bt-conc-lab { font-size: 0.72rem; margin-top: 0.2rem; }

/* ===== Backtest page — phone-first responsive (kept side-by-side on desktop) ===== */
/* collapsible form on mobile (toggle hidden on desktop) */
.bt-form-toggle { display: none; }
.bt-form-body { display: block; }
/* trade-list: table on desktop, cards on mobile */
.bt-trades-cards { display: none; }
.bt-trades-tools { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.bt-sort-select { display: none; }
/* chart heights (desktop) — the container drives the canvas; JS reads clientHeight + resizes */
#bt-chart { height: 420px; width: 100%; }
#bt-equity { height: 220px; width: 100%; }
/* mobile card detail collapses; .expanded reveals it */
.bt-tc-detail { display: none; }
.bt-trade-card.expanded .bt-tc-detail { display: grid; }

@media (max-width: 700px) {
  /* FORM: a collapsible section, not a full-height sticky panel */
  .bt-form-card { position: static; max-height: none; overflow: visible; }
  .bt-form-toggle {
    display: flex; width: 100%; justify-content: space-between; align-items: center;
    background: none; border: none; color: inherit; cursor: pointer; min-height: 44px;
    padding: 0.4rem 0.1rem; font: inherit;
  }
  .bt-toggle-caret { transition: transform 0.2s; }
  .bt-form-card.bt-collapsed .bt-form-body { display: none; }
  .bt-form-card.bt-collapsed .bt-toggle-caret { transform: rotate(-90deg); }
  /* touch targets: inputs/selects/buttons ≥44px, full-width fields */
  .bt-field { flex-wrap: wrap; }
  .bt-field input[type="text"], .bt-field input[type="date"], .bt-field select {
    width: 100%; min-height: 44px; font-size: 16px;   /* 16px stops iOS zoom-on-focus */
  }
  .bt-run-btn { min-height: 48px; font-size: 1rem; }
  #bt-reset { min-height: 40px; }

  /* CHART: full width, ~45vh, popover becomes a bottom sheet */
  #bt-chart { height: 45vh; }
  #bt-equity { height: 30vh; }
  .bt-popover {
    position: fixed !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    top: auto !important; max-width: none !important; border-radius: 14px 14px 0 0;
    padding: 0.9rem 1rem 1.2rem; box-shadow: var(--shadow-sheet);
  }

  /* TRADE LIST: hide the wide table, show tap-to-expand cards + a sort dropdown */
  .bt-trades-table { display: none; }
  .bt-trades-cards { display: flex; flex-direction: column; gap: 0.5rem; }
  .bt-sort-select {
    display: inline-block; min-height: 40px; background: var(--hover); color: inherit;
    border: 1px solid var(--border); border-radius: 6px; padding: 0.2rem 0.5rem; font-size: 0.85rem;
  }
  .bt-trade-card {
    border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; cursor: pointer;
  }
  .bt-trade-card.selected { border-color: var(--blue); }
  .bt-tc-head { display: flex; justify-content: space-between; align-items: baseline; }
  .bt-tc-sub { display: flex; gap: 0.55rem; align-items: center; margin-top: 0.3rem; font-size: 0.85rem; }
  .bt-tc-detail {
    grid-template-columns: auto 1fr; gap: 0.2rem 0.9rem; margin-top: 0.5rem;
    padding-top: 0.4rem; border-top: 1px solid var(--border); font-size: 0.82rem;
  }
  .bt-tc-detail span:nth-child(even) { text-align: right; }

  /* stat cards 2-per-row; histogram scrolls within width; banner pills already wrap */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .bt-conc { overflow-x: auto; }
  h1 { font-size: 1.3rem; }
}

/* --- /calc: the risk-first position sizer (2026-07-17) — mobile-first, site theme ---------- */
.calc-card { max-width: 520px; margin: 0 auto; padding: 1.2rem; }
.calc-head { border-bottom: 1px solid var(--border); padding-bottom: 1rem; margin-bottom: 1.4rem; }
.calc-kicker { font-size: 0.7rem; letter-spacing: 3px; color: var(--label); font-family: monospace; }
.calc-title { font-size: 1.7rem; font-weight: 800; margin-top: 0.3rem; }
.calc-sub { font-size: 0.75rem; margin-top: 0.5rem; }
.calc-amber { color: var(--amber); }
.calc-red { color: var(--red); }
.calc-green { color: var(--green); }
.calc-label { display: block; font-size: 0.68rem; letter-spacing: 2px; font-family: monospace;
  margin: 1.1rem 0 0.35rem; }
.calc-hero { width: 100%; background: transparent; border: 0; border-bottom: 2px solid;
  font-size: 2.4rem; font-weight: 700; padding: 0.2rem 0; outline: none; }
.calc-hero-amber { color: var(--amber); border-color: var(--amber); }
.calc-hero-red { color: var(--red); border-color: var(--red); }
.calc-hero-row { display: flex; align-items: baseline; }
.calc-pct { font-size: 1.6rem; font-weight: 700; margin-left: 0.3rem; }
.calc-toggle { display: flex; border: 1px solid var(--border); }
.calc-dir { flex: 1; padding: 0.8rem 0; background: transparent; border: 0; color: var(--label);
  font-size: 0.8rem; font-weight: 700; letter-spacing: 2px; cursor: pointer; }
.calc-dir.active { background: var(--green); color: #fff; }
.calc-dir.active.short { background: var(--red); }
.calc-price-row { display: flex; align-items: baseline; border-bottom: 1px solid var(--calc-rule);
  padding: 0.45rem 0; }
.calc-price-row > span { width: 130px; font-size: 0.68rem; letter-spacing: 1px; flex: none; }
.calc-price { flex: 1; background: transparent; border: 0; outline: none; color: var(--text);
  font-size: 1.1rem; text-align: right; }
.calc-opts { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.9rem;
  font-size: 0.7rem; align-items: center; }
.calc-small { background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 0.3rem 0.5rem; font-size: 0.8rem; width: 90px; }
.calc-error { margin-top: 1rem; padding: 0.8rem; border: 1px solid var(--red); color: var(--red);
  background: var(--red-bg-faint); font-size: 0.78rem; text-align: center; }
.calc-big { border: 1px solid var(--border); background: var(--card); padding: 1rem; margin: 0.4rem 0; }
.calc-size { font-size: 1.9rem; font-weight: 700; }
.calc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem;
  margin: 0.5rem 0; }
.calc-cell { border: 1px solid var(--border); background: var(--card); padding: 0.7rem; }
.calc-cell-label { display: block; font-size: 0.62rem; letter-spacing: 1.5px;
  font-family: monospace; margin-bottom: 0.25rem; }
.calc-liq { margin: 0.5rem 0; }
.calc-liq-head { display: flex; justify-content: space-between; align-items: baseline; }
.calc-liq-danger { border-color: var(--red); background: var(--red-bg-faint); }
.calc-rr { display: flex; justify-content: space-between; margin: 0.5rem 0; }
.calc-footer { margin-top: 1.1rem; padding: 0.8rem; border: 1px solid var(--warn-border);
  background: var(--amber-bg-faint); font-size: 0.78rem; line-height: 1.5; }
.calc-fineprint { margin-top: 1.2rem; font-size: 0.65rem; letter-spacing: 1px;
  text-align: center; }

/* ===== F4 · Money story (an_11 mock, frozen 2026-08-09): cards note + chart tile ===== */
.money-note { font-size: 12px; color: var(--dim); }
.mhead { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.mhead .leg { margin-left: auto; display: flex; gap: 14px; font-size: 11px;
  color: var(--muted); align-items: center; }
.leg i { display: inline-block; vertical-align: -1px; margin-right: 5px; }
.leg .lw { width: 18px; height: 0; border-top: 2.5px solid var(--blue); border-radius: 2px; }
.leg .lu { width: 18px; height: 0; border-top: 2.5px dashed var(--dim); }
.leg .sg { width: 11px; height: 11px; border-radius: 2.5px; background: rgba(55, 195, 132, .28); }
.leg .sr { width: 11px; height: 11px; border-radius: 2.5px; background: rgba(224, 76, 76, .24); }
.mwrap { position: relative; }
.mwrap svg { display: block; width: 100%; height: 300px; }
.mtip { position: absolute; pointer-events: none; background: var(--sidebar);
  color: rgba(255, 255, 255, .85);
  border-radius: 6px; padding: 7px 10px; font-size: 11.5px; line-height: 1.55; display: none;
  white-space: nowrap; box-shadow: var(--shadow); transform: translate(-50%, 0); z-index: 2; }
.mtip b { color: #fff; font-variant-numeric: tabular-nums; }
.mnote { font-size: 11px; color: var(--dim); margin-top: 8px; }

/* ===== kitenatura tracker additions (2026-09-09) — the console's own three needs.
   Everything else on every page is the design system above, unchanged. ===== */
/* the daily Telegram text, shown as it is sent */
.report-text {
  margin: 0.4rem 0 0; padding: 0.6rem 0.8rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  line-height: 1.55; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere;
}
/* the catalogue's view switcher holds eight entries — it must wrap, and scroll on a phone */
.an-head .pills { flex-wrap: wrap; max-width: 100%; }
/* the filter row's text input, matching the selects and date fields above it */
.filter-row input[type="search"], .filter-row input[type="text"] {
  background: var(--hover); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.15rem 0.35rem; font-size: 0.85rem; min-width: 12rem;
}
#sales-chart { height: 280px; }
/* the reference right-aligns every column but the first, because there every column is a number.
   Here a view can be all text, so text columns are marked .txt (left, proportional) and long free
   text .wrap, while numbers keep the reference's right-aligned tabular treatment. */
table.trades th.txt, table.trades td.txt { text-align: left; font-family: inherit; }
table.trades td.wrap, table.trades th.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 15rem; }
@media (max-width: 700px) {
  /* gotcha #1: anything under 16px makes iOS Safari zoom on focus */
  .filter-row input, .filter-row select { font-size: 16px; }
  .an-head .pills { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .an-head .pills::-webkit-scrollbar { display: none; }
}

/* --- phase 1b changes (9.9.2026): sparklines, ECharts mounts, tag rows, the rule builder --- */
.card.stat { position: relative; }
.sparkwrap { display: block; margin-top: 6px; color: var(--blue); line-height: 0; }
.spark { width: 100%; height: 30px; display: block; }
.chart-l { height: 360px; width: 100%; }        /* Today, Product */
.chart-m { height: 280px; width: 100%; }        /* Margin, Search */
.tagrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; margin: 0.35rem 0; }
.taglabel { min-width: 9rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .06em; }
.rulerow { gap: 0.5rem; margin: 0.3rem 0; }
.rulerow select, .rulerow input { background: var(--hover); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.2rem 0.4rem; font-size: 0.85rem; }
.rulerow select { min-width: 11rem; }
.rulerow input { min-width: 14rem; }
@media (max-width: 700px) {
  .chart-l { height: 300px; } .chart-m { height: 240px; }
  .taglabel { min-width: 100%; }
  .rulerow select, .rulerow input { font-size: 16px; flex: 1 1 100%; min-width: 0; }
}

/* --- phase 1c (9.9.2026): the editable sheet grid --- */
table.sheetgrid td, table.sheetgrid th { vertical-align: middle; }
/* one line per row, like the Excel house style: a long path is clipped with an ellipsis, the whole value
   is in the cell's tooltip and in the input as soon as you click it */
table.sheetgrid td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 22rem; }
table.sheetgrid td.cell { cursor: text; min-width: 5rem; }
table.sheetgrid td.cell input { max-width: none; }
table.sheetgrid td.cell:hover { background: var(--row-hover); box-shadow: inset 0 0 0 1px var(--tint-blue-border); }
table.sheetgrid td.cell input { width: 100%; box-sizing: border-box; font: inherit; font-size: 0.85rem;
  color: var(--text); background: var(--bg); border: 1px solid var(--blue); border-radius: 4px;
  padding: 0.1rem 0.25rem; outline: none; }
table.sheetgrid td.cell.bad { background: var(--tint-red); box-shadow: inset 0 0 0 1px var(--red); }
table.sheetgrid .decisioncol { background: var(--tint-amber); }
table.sheetgrid td.computedcol, table.sheetgrid th.computedcol { background: var(--today, #EEF1F5);
  color: var(--muted); font-style: italic; }
:root { --today: #eef1f5; }
:root[data-theme=dark] { --today: #232f44; }
table.sheetgrid td.rowhead, table.sheetgrid th.rowhead { color: var(--dim); font-size: 0.75rem; width: 3rem; }
table.sheetgrid .keycol { position: sticky; left: 0; z-index: 1; background: var(--card); font-weight: 600; }
table.sheetgrid tr:hover .keycol { background: var(--hover); }
table.sheetgrid tr.blockgap td { height: 8px; padding: 0; border-left: 0; border-right: 0;
  background: var(--bg); }
table.sheetgrid .delrow { padding: 0 .45rem; line-height: 1.2; }
#importdiff { max-height: 22rem; overflow: auto; }
@media (max-width: 700px) {
  table.sheetgrid td.cell input { font-size: 16px; }   /* gotcha #1: under 16px iOS zooms on focus */
  table.sheetgrid td.cell { min-width: 8rem; }
}
