/* Component layer for the trade console. Everything is built on tokens.css. */

/* The `hidden` attribute must beat every layout rule below. A class selector
   (.drawer, .popover, .tabbar) outranks the UA's `[hidden] { display: none }`,
   so without this an element with hidden=true still renders. */
[hidden] { display: none !important; }

body { margin: 0; font: var(--t-body); background: var(--bg-0); color: var(--fg-0); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

/* ---------- header ---------- */
.appbar {
  position: sticky; top: 0; z-index: 40; height: var(--header-h);
  display: flex; align-items: center; gap: var(--s-5);
  padding: 0 var(--s-5); background: var(--bg-1); border-bottom: 1px solid var(--line);
}
.brand { text-decoration: none; }
.brand .mark { font: 700 13px var(--font-num); color: var(--gold); letter-spacing: .5px; }
.nav { display: flex; gap: var(--s-4); }
.nav a {
  font: 500 12px var(--font-ui); color: var(--fg-1); text-decoration: none;
  padding: 4px 0; border-bottom: 2px solid transparent; white-space: nowrap;
}
.nav a:hover { color: var(--fg-0); text-decoration: none; }
.nav a.active { color: var(--fg-0); font-weight: 600; border-bottom-color: var(--gold); }
.nav .n { color: var(--fg-2); font-size: 11px; margin-left: 2px; }
.statusbar { margin-left: auto; display: flex; align-items: center; gap: var(--s-4); font-size: 11px; color: var(--fg-1); }
.statusbar .live { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-2); flex: none; }
.dot.live { background: var(--up); box-shadow: 0 0 6px var(--up); animation: live-pulse var(--dur-live) infinite; }
.dot.stale { background: var(--gold); }
.dot.down { background: var(--down); }
.appbar-actions { display: flex; align-items: center; gap: var(--s-2); }
.pause-pill {
  font: 500 10px var(--font-num); color: var(--gold); border: 1px solid var(--gold-line);
  border-radius: var(--r-pill); padding: 3px 9px; white-space: nowrap;
}
.icon-btn {
  position: relative; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-2); border: 1px solid transparent; border-radius: var(--r-ctrl);
  color: var(--fg-1); font-size: 13px; text-decoration: none;
}
.icon-btn:hover { color: var(--fg-0); border-color: var(--line-strong); text-decoration: none; }
.icon-btn .badge {
  position: absolute; top: -4px; right: -4px; min-width: 15px; height: 15px; padding: 0 3px;
  background: var(--down); color: #fff; border-radius: var(--r-pill);
  font: 600 9px/15px var(--font-num); text-align: center;
}

/* ---------- layout ---------- */
main { padding: var(--s-4) var(--s-5) 64px; }
@media (min-width: 901px) { main { padding-bottom: var(--s-5); } }
.cols { display: grid; gap: var(--s-4); align-items: start; }
.cols-now { grid-template-columns: 1fr 1fr 420px; }
.cols-split { grid-template-columns: 640px 1fr; }
.cols-analyze { grid-template-columns: 1fr 760px; }
@media (max-width: 1500px) { .cols-now { grid-template-columns: 1fr 1fr; } .cols-now > :last-child { grid-column: 1 / -1; } }
@media (max-width: 1300px) { .cols-analyze { grid-template-columns: 1fr 520px; } .cols-split { grid-template-columns: 480px 1fr; } }
@media (max-width: 1000px) { .cols-now, .cols-split, .cols-analyze { grid-template-columns: 1fr; } .cols-now > :last-child { grid-column: auto; } }
.stack { display: flex; flex-direction: column; gap: var(--s-4); }

/* ---------- panels ---------- */
.panel { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.panel-h {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-3); min-height: 34px;
  padding: var(--s-3) var(--panel-pad); border-bottom: 1px solid var(--line);
  font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2);
}
.panel-h .spacer { margin-left: auto; }
.panel-h .sub { font: 400 11px var(--font-num); text-transform: none; letter-spacing: 0; color: var(--fg-2); }
.panel-h .count { font: 600 11px var(--font-num); color: var(--fg-1); }
.panel-f {
  padding: var(--s-3) var(--panel-pad); border-top: 1px solid var(--line);
  font: 400 11px var(--font-ui); color: var(--fg-2); display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap;
}
.panel-body { padding: var(--panel-pad); }
.scroll-y { overflow-y: auto; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 12px var(--font-ui); padding: 6px 12px; min-height: 28px;
  border-radius: var(--r-ctrl); border: 1px solid transparent; background: var(--bg-2); color: var(--fg-0);
  white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ai { background: var(--info); color: var(--on-info); border-color: var(--info); }
.btn-ai:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--fg-0); font-weight: 500; }
.btn-ghost:hover { border-color: var(--fg-2); }
.btn-danger { background: transparent; border-color: var(--down-line); color: var(--down); font-weight: 500; }
.btn-sm { min-height: 22px; padding: 2px 8px; font-size: 11px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-link { background: none; border: none; color: var(--info); padding: 0; font-weight: 500; min-height: 0; }
.btn-link:hover { text-decoration: underline; }
@media (max-width: 900px) { .btn { min-height: 44px; padding: 10px 16px; } .btn-sm { min-height: 32px; } }

/* ---------- form controls ---------- */
.input, .select, .textarea {
  background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-ctrl);
  padding: 6px 10px; color: var(--fg-0); width: 100%; min-height: 28px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--info); box-shadow: 0 0 0 2px rgba(74,140,255,.35);
}
.input.num, .input[type="number"] { font-family: var(--font-num); }
.input.invalid { border-color: var(--down); }
.textarea { resize: vertical; min-height: 52px; font: var(--t-body); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label, .flabel { font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2); }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-ctrl); padding: 2px; gap: 2px; }
.seg button {
  background: none; border: none; border-radius: 4px; padding: 4px 10px; min-height: 22px;
  font: 500 11px var(--font-ui); color: var(--fg-1);
}
.seg button:hover { color: var(--fg-0); }
.seg button.on { background: var(--bg-3); color: var(--fg-0); font-weight: 600; }
.seg button.on[data-v="long"] { background: var(--up-soft); color: var(--up); }
.seg button.on[data-v="short"] { background: var(--down-soft); color: var(--down); }
.seg .c { color: var(--fg-2); font: 400 10px var(--font-num); margin-left: 4px; }
.switch { position: relative; width: 30px; height: 16px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; background: var(--bg-3); border: 1px solid var(--line-strong); border-radius: var(--r-pill); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--fg-1); transition: transform .15s, background .15s; }
.switch input:checked + i { background: var(--up-soft); border-color: var(--up-line); }
.switch input:checked + i::after { transform: translateX(14px); background: var(--up); }
.toolbar {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-3) var(--panel-pad); border-bottom: 1px solid var(--line); background: var(--bg-1);
}
.toolbar .spacer { margin-left: auto; }

/* ---------- badges & chips ---------- */
.badge-v {
  display: inline-block; font: 600 10px var(--font-num); letter-spacing: .5px;
  padding: 3px 7px; border-radius: var(--r-chip); border: 1px solid transparent; white-space: nowrap;
}
.badge-v .s { opacity: .7; }
.v-STRONG_BUY { background: var(--up-soft); border-color: var(--up-line); color: var(--up); }
.v-BUY { color: var(--up); border-color: var(--up-line); }
.v-NEUTRAL { color: var(--fg-1); border-color: var(--line-strong); }
.v-SELL { color: var(--down); border-color: var(--down-line); }
.v-STRONG_SELL { background: var(--down-soft); border-color: var(--down-line); color: var(--down); }
.chip {
  display: inline-block; font: 500 10px var(--font-num); padding: 2px 6px;
  border-radius: var(--r-chip); border: 1px solid var(--line-strong); color: var(--fg-1); white-space: nowrap;
}
.chip-up { color: var(--up); border-color: var(--up-line); }
.chip-gold { color: var(--gold); border-color: var(--gold-line); }
.chip-info { color: var(--info); border-color: var(--info-line); }
.chip-down { color: var(--down); border-color: var(--down-line); }
.chip-tag { font: 400 11px var(--font-ui); background: var(--bg-2); border-color: var(--line); color: var(--fg-1); }
.chip-tag.gold { color: var(--gold); border-color: var(--gold-line); background: var(--gold-soft); }
.chip-tag.on { background: var(--info-soft); border-color: var(--info); color: var(--info); }
.chip-conf { font: 500 10px var(--font-num); border-radius: 10px; padding: 2px 7px; border: none; background: var(--bg-3); color: var(--fg-1); }
.chip-conf.fib { background: var(--gold-soft); color: var(--gold); }
.chip-conf.info { background: var(--info-soft); color: var(--info); }
.chip-conf.up { background: var(--up-soft); color: var(--up); }
.chip-conf.down { background: var(--down-soft); color: var(--down); }
.chip-conf.none { background: none; border: 1px dashed var(--line-strong); color: var(--fg-2); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }

/* ---------- symbol ---------- */
.sym { font: 600 13px var(--font-num); color: var(--fg-0); white-space: nowrap; }
.sym .q { font-size: 9px; color: var(--fg-2); margin-left: 1px; }
.sym-btn { background: none; border: none; padding: 0; text-align: left; }
.sym-btn:hover .b { text-decoration: underline; }
.star { background: none; border: none; color: var(--fg-2); font-size: 13px; padding: 0; line-height: 1; }
.star.on, .star:hover { color: var(--gold); }

/* ---------- tables ---------- */
.tbl { width: 100%; }
/* Keep wide tables inside their panels, with every column reachable. */
.table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.table-scroll:focus-visible { outline: 2px solid var(--info); outline-offset: -2px; }
.table-content { min-width: var(--table-min-width, 640px); }
.table-hint { font-size: 11px; }
.tbl-h, .tbl-r { display: grid; gap: var(--s-3); align-items: center; padding: 0 var(--panel-pad); }
.tbl-h {
  min-height: 28px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  font: var(--t-label); letter-spacing: .6px; text-transform: uppercase; color: var(--fg-2); position: sticky; top: 0; z-index: 2;
}
.tbl-h .num, .tbl-r .num { font-family: var(--font-num); }
.tbl-h span.r, .tbl-r .r { text-align: right; }
.tbl-r {
  min-height: var(--row-h); border-bottom: 1px solid var(--line); font-size: var(--cell-font); cursor: pointer;
}
.tbl-r:last-child { border-bottom: none; }
.tbl-r:hover { background: var(--bg-3); }
.tbl-r.flash { animation: row-flash var(--dur-flash) ease-out; }
.tbl-r.sel { background: var(--bg-3); box-shadow: inset 2px 0 0 var(--gold); }
.tbl-r .cell-tick-up { animation: tick-up var(--dur-tick) ease-out; }
.tbl-r .cell-tick-down { animation: tick-down var(--dur-tick) ease-out; }
.up { color: var(--up); } .down { color: var(--down); } .gold { color: var(--gold); } .info { color: var(--info); }
.muted { color: var(--fg-1); } .dim { color: var(--fg-2); }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expander { background: none; border: none; color: var(--fg-2); padding: 0 2px; font-size: 10px; }
.row-x { padding: var(--s-4) var(--panel-pad); background: var(--bg-2); border-bottom: 1px solid var(--line); }
.row-x-grid { display: grid; grid-template-columns: 260px 1fr 200px; gap: var(--s-5); align-items: start; }
@media (max-width: 900px) { .row-x-grid { grid-template-columns: 1fr; } }

/* ---------- states ---------- */
.empty {
  margin: var(--s-4); padding: var(--s-6) var(--s-5); text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--r-ctrl); color: var(--fg-1); font-size: 12px;
}
.empty .btn { margin-top: var(--s-4); }
.err-box { margin: var(--s-4); padding: var(--s-4); background: var(--down-soft); border: 1px solid var(--down-line); border-radius: var(--r-ctrl); color: var(--fg-0); font-size: 12px; }
.stale-box { margin: var(--s-4); padding: var(--s-3) var(--s-4); background: var(--gold-soft); border: 1px solid var(--gold-line); border-radius: var(--r-ctrl); font-size: 11px; color: var(--fg-0); }
.degraded { padding: var(--s-3) var(--s-4); background: var(--bg-2); border-radius: var(--r-ctrl); font-size: 11px; color: var(--fg-1); }
.skel { padding: 0 var(--panel-pad); }
.skel i {
  display: block; height: 9px; margin: 11px 0; border-radius: 3px;
  background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 40%, var(--bg-2) 80%);
  background-size: 800px 100%; animation: shimmer 1.4s infinite linear;
}

/* ---------- fib ladder ---------- */
.rungs { display: flex; flex-direction: column; gap: 3px; }
.rung { display: grid; grid-template-columns: 40px 1fr 74px 52px; gap: var(--s-3); align-items: center; font: 400 11px var(--font-num); color: var(--fg-1); }
.rung .lv { color: var(--fg-2); }
.rung.l618 .lv { color: var(--gold); font-weight: 600; }
.rung .bar { position: relative; height: 5px; background: var(--bg-2); border-radius: 3px; overflow: hidden; }
.rung .bar > i { display: block; height: 100%; background: var(--line-strong); border-radius: 3px; }
.rung .bar > u { position: absolute; top: -2px; width: 2px; height: 9px; background: var(--info); }
.rung .r { text-align: right; }
.rung.hit { color: var(--up); }
.rung.hit .bar > i { background: var(--up); }
.rung.near { color: var(--gold); }
.rung.near .bar > i { background: var(--gold); }
.fibstrip { display: flex; gap: 3px; align-items: center; }
.fibstrip i { flex: 1; height: 7px; border-radius: 2px; background: var(--bg-3); position: relative; }
.fibstrip i.hit { background: var(--up); }
.fibstrip i.gold { background: var(--gold); box-shadow: 0 0 5px var(--gold); }
.fibstrip i.below { background: var(--down); }
.fibstrip i.at::after { content: ""; position: absolute; top: -2px; left: 50%; width: 2px; height: 11px; background: var(--info); }

/* ---------- plan levels ---------- */
.lvl-row {
  display: grid; grid-template-columns: 8px 90px 1fr 70px 60px 70px; gap: var(--s-3);
  align-items: center; min-height: 26px; font-size: 12px;
}
.lvl-row .tdot { width: 8px; height: 8px; border-radius: 50%; }
.lvl-row .tname { font: 600 10px var(--font-num); letter-spacing: .4px; }
.lvl-row .px { font-family: var(--font-num); }
.lvl-row .zone { font-size: 10px; color: var(--fg-2); margin-left: 3px; }
.lvl-row .d { text-align: right; font-family: var(--font-num); color: var(--fg-1); font-size: 11px; }
.lvl-row .st { font: 500 10px var(--font-num); text-align: center; border: 1px solid var(--line-strong); border-radius: var(--r-chip); padding: 1px 5px; color: var(--fg-1); }
.lvl-row .mode { font-size: 10px; color: var(--fg-2); text-align: right; }
.lvl-row.s-triggered .st { background: var(--up-soft); border-color: var(--up-line); color: var(--up); }
.lvl-row.s-triggered .tdot { box-shadow: 0 0 6px currentColor; }
.lvl-row.s-stop .st { background: var(--down-soft); border-color: var(--down-line); color: var(--down); }
.lvl-row.s-near .st { border-color: var(--gold-line); color: var(--gold); }
.lvl-row.s-near .d { color: var(--gold); font-weight: 600; }
.lvl-row.s-disabled { opacity: .45; }
.lvl-row.s-disabled .px { text-decoration: line-through; }
.t-entry { color: var(--lvl-entry); } .t-take-profit { color: var(--lvl-tp); }
.t-stop-loss, .t-invalidation, .t-breakdown { color: var(--lvl-sl); }
.t-breakout { color: var(--lvl-breakout); } .t-custom { color: var(--lvl-custom); }
.bg-entry { background: var(--lvl-entry); } .bg-take-profit { background: var(--lvl-tp); }
.bg-stop-loss, .bg-invalidation, .bg-breakdown { background: var(--lvl-sl); }
.bg-breakout { background: var(--lvl-breakout); } .bg-custom { background: var(--lvl-custom); }
.lvl-list { display: flex; flex-direction: column; gap: 2px; }
.price-sep {
  display: grid; grid-template-columns: 8px 90px 1fr auto; gap: var(--s-3); align-items: center;
  font: 500 10px var(--font-num); color: var(--info); margin: 3px 0;
}
.price-sep .line { border-top: 1px dashed var(--info-line); }
.lvl-dots { display: flex; gap: 3px; align-items: center; }
.lvl-dots i { width: 8px; height: 8px; border-radius: 50%; }
.lvl-dots i.hit { box-shadow: 0 0 5px currentColor; }
.lvl-dots i.pend { opacity: .4; }
.lvl-dots i.off { background: none !important; border: 1px solid var(--line-strong); }

/* ---------- editor ---------- */
.ed { display: flex; flex-direction: column; gap: var(--s-4); padding: var(--panel-pad); }
.ed-row { display: flex; gap: var(--s-3); align-items: flex-end; flex-wrap: wrap; }
.ed-grid-h, .ed-grid {
  display: grid; grid-template-columns: 118px 1fr 110px 104px 54px 24px; gap: var(--s-3); align-items: center;
}
.ed-grid-h { font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2); }
.ed-grid { min-height: 34px; }
.ed-grid .zone-in { display: flex; gap: 4px; align-items: center; }
.ed-grid .dpct { font: 400 10px var(--font-num); color: var(--fg-2); white-space: nowrap; }
.ed-grid .dpct.near { color: var(--gold); font-weight: 600; }
.ed-del { background: none; border: none; color: var(--fg-2); font-size: 15px; padding: 0; }
.ed-del:hover { color: var(--down); }
.ed-add {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  border: 1px dashed var(--line-strong); border-radius: var(--r-ctrl); padding: var(--s-3);
}
.rr-strip {
  display: flex; gap: var(--s-5); flex-wrap: wrap; background: var(--bg-2);
  border-radius: var(--r-ctrl); padding: var(--s-3) var(--s-4); font: 400 11px var(--font-num); color: var(--fg-1);
}
.rr-strip b { color: var(--fg-0); font-weight: 600; }
.warn-line { color: var(--gold); font-size: 11px; }
.err-line { color: var(--down); font-size: 11px; }
.ed-foot { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: var(--s-4); }

/* ---------- confidence meter ---------- */
.meter { display: flex; flex-direction: column; gap: var(--s-3); }
.meter-top { display: flex; align-items: baseline; gap: var(--s-3); flex-wrap: wrap; }
.meter-num { font: var(--t-hero); }
.meter-grade { font: 600 18px var(--font-num); border: 1px solid; border-radius: var(--r-ctrl); padding: 1px 8px; }
.g-A, .g-B { color: var(--up); border-color: var(--up-line); }
.g-C { color: var(--gold); border-color: var(--gold-line); }
.g-D, .g-F { color: var(--down); border-color: var(--down-line); }
.meter-rules { margin-left: auto; font: 400 11px var(--font-num); color: var(--fg-2); }
.meter-track {
  position: relative; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, var(--down) 0%, var(--down) 35%, var(--fg-2) 35%, var(--fg-2) 60%, var(--up) 60%, var(--up) 100%);
}
.meter-track .needle { position: absolute; top: -4px; width: 3px; height: 16px; background: #fff; border-radius: 1px; transform: translateX(-1.5px); }
.meter-track .tick { position: absolute; top: -2px; width: 2px; height: 12px; background: var(--fg-2); transform: translateX(-1px); }
.comp-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--line); }
.comp-bar i { display: block; height: 100%; }
.comp-legend { display: flex; gap: var(--s-3); flex-wrap: wrap; font: 400 10px var(--font-num); color: var(--fg-2); }
.comp-legend span::before { content: "■ "; }
.ledger { display: flex; flex-direction: column; gap: 2px; font: 400 11px var(--font-num); }
.ledger div { display: flex; justify-content: space-between; gap: var(--s-3); }

/* ---------- review ---------- */
.rv-grid { display: grid; grid-template-columns: 300px 1fr 1fr; gap: var(--s-4); }
@media (max-width: 1200px) { .rv-grid { grid-template-columns: 1fr; } }
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-ctrl); padding: var(--s-4); }
.card + .card { margin-top: var(--s-3); }
.card-h { font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2); margin-bottom: var(--s-3); }
.card.weak { border-color: var(--down-line); }
.strength { font: 600 10px var(--font-num); letter-spacing: .4px; }
.s-strong { color: var(--up); } .s-good { color: var(--up); opacity: .85; }
.s-fair { color: var(--gold); } .s-weak { color: var(--down); }
.pill-list li { padding: 3px 0 3px 10px; font-size: 12px; line-height: 1.5; }
.pill-list.pos li { border-left: 2px solid var(--up-line); }
.pill-list.neg li { border-left: 2px solid var(--down-line); }
.adj { display: flex; flex-direction: column; gap: var(--s-3); }
.adj-row { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; font-size: 12px; }
.adj-row .why { color: var(--fg-1); flex: 1 1 180px; }
.chart-read { color: var(--fg-1); font-size: 12px; line-height: 1.55; }

/* ---------- feed ---------- */
.feed-list { max-height: 640px; overflow-y: auto; }
.feed-i { display: grid; grid-template-columns: 44px 1fr; gap: var(--s-3); padding: 7px var(--panel-pad); border-bottom: 1px solid var(--line); font-size: 12px; }
.feed-i:last-child { border-bottom: none; }
.feed-i .t { font: 400 10px var(--font-num); color: var(--fg-2); }
.feed-i .l2 { color: var(--fg-2); font-size: 11px; margin-top: 2px; }
.feed-i b { font-family: var(--font-num); }

/* ---------- candidates & inbox ---------- */
.cand { padding: var(--s-4) var(--panel-pad); border-bottom: 1px solid var(--line); }
.cand:last-child { border-bottom: none; }
.cand-top { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.cand-why { color: var(--fg-1); font: 400 11px var(--font-num); margin: 5px 0; line-height: 1.5; }
.cand-act { display: flex; gap: var(--s-3); }
.popover {
  position: fixed; top: calc(var(--header-h) + 6px); right: var(--s-5); width: 400px; max-height: 70vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-panel); box-shadow: var(--e1); z-index: 60;
}
@media (max-width: 640px) { .popover { left: var(--s-3); right: var(--s-3); width: auto; } }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 45; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(880px, 46vw); z-index: 50;
  background: var(--bg-1); border-left: 1px solid var(--line-strong); box-shadow: var(--e1);
  display: flex; flex-direction: column; animation: drawer-in var(--dur-drawer) var(--ease-drawer);
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: .4 } to { transform: none; opacity: 1 } }
@media (max-width: 1100px) { .drawer { width: 92vw; } }
@media (max-width: 700px) { .drawer { width: 100vw; border-left: none; } }
.drawer[data-mode="pane"] {
  position: static; width: auto; box-shadow: none; border-left: none; border: 1px solid var(--line);
  border-radius: var(--r-panel); animation: none; height: 100%;
}
.dr-h { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; padding: var(--s-3) var(--panel-pad); border-bottom: 1px solid var(--line); }
.dr-h .px { font: 600 14px var(--font-num); }
.dr-h .sym { font-size: 16px; }
.dr-h .spacer { margin-left: auto; }
.dr-tabs { display: flex; gap: var(--s-4); padding: 0 var(--panel-pad); border-bottom: 1px solid var(--line); }
.dr-tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 0;
  font: 500 12px var(--font-ui); color: var(--fg-1);
}
.dr-tabs button.on { color: var(--fg-0); font-weight: 600; border-bottom-color: var(--gold); }
.dr-tabs button .n { font: 400 10px var(--font-num); color: var(--fg-2); margin-left: 4px; }
.dr-body { flex: 1; overflow-y: auto; }
.tf-group { display: inline-flex; gap: 2px; background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-ctrl); padding: 2px; }
.tf-group button { background: none; border: none; border-radius: 4px; padding: 3px 9px; font: 500 11px var(--font-num); color: var(--fg-1); min-height: 20px; }
.tf-group button.on { background: var(--bg-3); color: var(--gold); }
.chart-wrap { position: relative; width: 100%; }
.chart-status { padding: var(--s-3) var(--panel-pad); font: 400 11px var(--font-num); color: var(--fg-2); }
.ta-strip {
  display: flex; gap: var(--s-4); flex-wrap: wrap; align-items: center;
  padding: var(--s-3) var(--panel-pad); border-bottom: 1px solid var(--line); font: 400 11px var(--font-num); color: var(--fg-1);
}
.ta-strip b { color: var(--fg-0); font-weight: 600; }
.layers { display: flex; gap: var(--s-3); flex-wrap: wrap; font-size: 11px; color: var(--fg-1); }
.layers label { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- analyze ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s-3); }
.tile { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-ctrl); padding: 10px 12px; }
.tile.pos { border-color: var(--up-line); } .tile.neg { border-color: var(--down-line); }
.tile .k { font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2); }
.tile .v { font: 600 16px var(--font-num); margin-top: 3px; }
.tile .s { font-size: 11px; color: var(--fg-1); margin-top: 2px; }
.score-meter { position: relative; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--down), var(--down) 22%, var(--fg-2) 40%, var(--fg-2) 60%, var(--up) 78%, var(--up)); }
.score-meter .needle { position: absolute; top: -4px; width: 3px; height: 16px; background: #fff; border-radius: 1px; }
.score-meter .cut { position: absolute; top: -1px; width: 1px; height: 10px; background: var(--bg-0); opacity: .5; }
.reasons li { display: grid; grid-template-columns: 42px 1fr; gap: var(--s-3); padding: 3px 0; font-size: 12px; }
.reasons .w { font: 600 11px var(--font-num); text-align: right; }
.chat { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--panel-pad); }
.msg { max-width: 82%; padding: 8px 11px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--info-soft); border-radius: 8px 8px 2px 8px; }
.msg.ai { align-self: flex-start; background: var(--bg-2); border-radius: 8px 8px 8px 2px; }
.msg .num, .msg code { font-family: var(--font-num); }
.chat-in { display: flex; gap: var(--s-3); padding: var(--s-3) var(--panel-pad); border-top: 1px solid var(--line); }
.quick { display: flex; gap: var(--s-2); flex-wrap: wrap; padding: 0 var(--panel-pad) var(--s-3); }
.quick button { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 4px 10px; font-size: 11px; color: var(--fg-1); min-height: 24px; }
.quick button:hover { color: var(--fg-0); border-color: var(--line-strong); }

/* ---------- settings ---------- */
.set-grid { display: grid; grid-template-columns: 200px 1fr 520px; gap: var(--s-4); align-items: start; }
@media (max-width: 1400px) { .set-grid { grid-template-columns: 180px 1fr; } .set-grid > :last-child { grid-column: 1 / -1; } }
@media (max-width: 800px) { .set-grid { grid-template-columns: 1fr; } }
.set-nav button { display: block; width: 100%; text-align: left; background: none; border: none; padding: 8px 12px; border-radius: var(--r-ctrl); color: var(--fg-1); font-size: 12px; }
.set-nav button.on { background: var(--bg-3); color: var(--fg-0); font-weight: 600; }
.matrix-h, .matrix-r { display: grid; grid-template-columns: 150px repeat(6, 58px) 88px 92px; gap: var(--s-2); align-items: center; padding: 0 var(--panel-pad); }
.matrix-h { min-height: 46px; background: var(--bg-2); border-bottom: 1px solid var(--line); font: var(--t-label); letter-spacing: .4px; text-transform: uppercase; color: var(--fg-2); text-align: center; }
.matrix-h > :first-child { text-align: left; }
.matrix-r { min-height: 46px; border-bottom: 1px solid var(--line); font-size: 12px; text-align: center; }
.matrix-r > :first-child { text-align: left; }
.matrix-r:last-child { border-bottom: none; }
.cellbtn { background: none; border: none; font-size: 14px; color: var(--line-strong); padding: 4px; line-height: 1; }
.cellbtn.on { color: var(--up); }
.cellbtn:disabled { opacity: .3; }
.cellbtn.pending { opacity: .55; }
.cellbtn.pending.on { color: var(--gold); }
.matrix-r .ch-name { font-weight: 600; }
.matrix-r .ch-detail { font-size: 10px; color: var(--fg-2); line-height: 1.4; }
@media (max-width: 1000px) {
  .matrix-h { display: none; }
  .matrix-r { grid-template-columns: 1fr; gap: var(--s-3); padding: var(--s-4) var(--panel-pad); text-align: left; }
  .matrix-r .cells { display: flex; gap: var(--s-4); flex-wrap: wrap; }
}
.log-r { display: grid; grid-template-columns: 46px 74px 1fr 70px; gap: var(--s-3); padding: 6px var(--panel-pad); border-bottom: 1px solid var(--line); font-size: 11px; align-items: baseline; }
.log-r:last-child { border-bottom: none; }
.log-r.failed { background: var(--down-soft); }
.log-r .t { font-family: var(--font-num); color: var(--fg-2); }
.cmd-strip { font: 400 11px var(--font-num); color: var(--gold); line-height: 1.8; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: var(--s-5); bottom: var(--s-5); z-index: 70; display: flex; flex-direction: column; gap: var(--s-3); max-width: 380px; }
@media (max-width: 640px) { .toasts { left: var(--s-3); right: var(--s-3); bottom: 70px; max-width: none; } }
.toast {
  background: var(--bg-3); border: 1px solid var(--line-strong); border-left: 3px solid var(--fg-2);
  border-radius: var(--r-ctrl); box-shadow: var(--e2); padding: 10px 12px; display: flex; gap: var(--s-3); align-items: center; font-size: 12px;
}
.toast.hit { border-left-color: var(--gold); } .toast.up { border-left-color: var(--up); }
.toast.down { border-left-color: var(--down); } .toast.info { border-left-color: var(--info); }
.toast .x { margin-left: auto; background: none; border: none; color: var(--fg-2); }

/* ---------- mobile tab bar ---------- */
.tabbar { display: none; }
@media (max-width: 900px) {
  .appbar .nav { display: none; }
  main { padding: var(--s-3) max(var(--s-3), env(safe-area-inset-right)) calc(76px + env(safe-area-inset-bottom)) max(var(--s-3), env(safe-area-inset-left)); }
  .appbar { gap: var(--s-3); padding-inline: var(--s-3); }
  .appbar-actions { flex-shrink: 0; }
  .statusbar { min-width: 0; }
  .statusbar .live { min-width: 0; }
  #conn-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .toolbar .seg { flex-wrap: wrap; max-width: 100%; }
  .statusbar { font-size: 10px; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(6, 1fr);
    background: var(--bg-1); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 7px;
    font: 500 10px var(--font-ui); color: var(--fg-2); text-decoration: none;
  }
  .tabbar a span { font-size: 15px; }
  .tabbar a.active { color: var(--gold); }
  .sticky-foot {
    position: sticky; bottom: 0; display: flex; gap: var(--s-3); padding: var(--s-3) var(--panel-pad);
    background: var(--bg-1); border-top: 1px solid var(--line);
  }
  .sticky-foot .btn { flex: 1; }
}
.hide-desk { display: none; }
@media (max-width: 900px) { .hide-mob { display: none !important; } .hide-desk { display: revert; } }

/* ---------- overflow containment ----------------------------------------
   Nothing should ever push the page wider than the window.

   The root cause of horizontal overflow in a grid/flex layout is that a `1fr`
   track is really `minmax(auto, 1fr)`, and a flex item defaults to
   `min-width: auto`. Both mean "never shrink below my content's own minimum
   width". One long unbreakable token — a price like 0.0021200, a coin symbol,
   a URL — therefore inflates its column and, with it, the whole page.

   Three layers below, in order of how much they change appearance:
     1. let every grid/flex child shrink,
     2. let long unbroken tokens wrap instead of forcing width,
     3. give the few genuinely wide, fixed-width tables their own scroller
        rather than letting them stretch the page.
------------------------------------------------------------------------- */

/* 1 — Allow shrinking. `min-width: auto` on grid/flex children is the single
   biggest source of overflow; this neutralises it everywhere. Applied to the
   layout containers rather than universally so component-level intent
   (e.g. the notification badge's min-width) is preserved. */
.cols > *,
.stack > *,
.row-x-grid > *,
.rung > *,
.feed-i > *,
.reasons li > *,
.rv-grid > *,
.set-grid > *,
.log-r > * { min-width: 0; }

/* 2 — Wrap long unbreakable content. Numeric tokens (0.0021200, ~0.0022070)
   and symbols have no natural break opportunity, so they must be told they
   may break anywhere rather than dictate the column width. */
.cand-why,
.reasons li,
.feed-i,
.log-r,
.panel-f { overflow-wrap: anywhere; }

/* Long single-line values stay on one line but truncate rather than push. */
.sym, .tbl-r .num, .log-r .mono { min-width: 0; }

/* `.ellip` truncates with an ellipsis, which requires `nowrap` — so it must be
   exempt from the wrapping rule above, and its own children must not spill out
   of the box doing the truncating. */
.ellip { min-width: 0; overflow-wrap: normal; }
.ellip > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* 3 — Wide fixed-width tables scroll inside their panel instead of stretching
   the page. `.matrix` needs 678px of fixed columns before gaps and cannot
   shrink; the same applies to the widest `.tbl` variants on narrow screens. */
.panel-scroll-x { overflow-x: auto; overscroll-behavior-x: contain; }
.panel-scroll-x > * { min-width: max-content; }

/* Final backstop: the page itself never scrolls sideways. This is deliberately
   last — it hides nothing that the rules above have not already handled, and
   makes any future regression visibly clip rather than silently shift the
   whole layout. */
html, body { max-width: 100%; overflow-x: hidden; }

/* ---------- direction & leverage ---------- */
.chip .lev { opacity: .75; font-weight: 700; }
.lev-box { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-ctrl); padding: var(--s-3) var(--s-4); display: flex; flex-direction: column; gap: 5px; }
.lev-row { display: grid; grid-template-columns: 84px 1fr; gap: var(--s-3); align-items: center; font-size: 12px; }
.lev-row .k { font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2); }
.lev-note { font-size: 11px; color: var(--fg-1); line-height: 1.5; }

/* ---------- pending review ---------- */
.pend { border-bottom: 1px solid var(--line); padding: var(--s-4) var(--panel-pad); }
.pend:last-child { border-bottom: none; }
.pend-top { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.pend-grid { display: grid; grid-template-columns: 1fr 260px; gap: var(--s-4); margin-top: var(--s-3); align-items: start; }
@media (max-width: 900px) { .pend-grid { grid-template-columns: 1fr; } }
.pend-why { font: 400 11px var(--font-num); color: var(--fg-1); line-height: 1.6; }
.pend-act { display: flex; gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-3); }

/* ---------- market context / calibration ---------- */
.ctx-rows { display: flex; flex-direction: column; gap: 6px; }
.ctx-row { display: grid; grid-template-columns: 96px 1fr; gap: var(--s-3); font-size: 12px; align-items: baseline; }
.ctx-row .k { font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2); }
.calib-line { font-size: 11px; line-height: 1.5; padding-top: 4px; border-top: 1px dashed var(--line); margin-top: 4px; }
#regime-chip .chip { font-size: 10px; }

/* ---------- paper trader ---------- */
.cols-paper { grid-template-columns: minmax(0, 1fr) 340px; }
.pp-trades { grid-column: 1 / -1; }
.pp-table { --table-min-width: 1520px; }
.pp-strategy { grid-template-columns: minmax(0, 1fr) 24px 48px 72px; }
.pp-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: var(--s-4); }
.pp-hero > div { min-width: 0; }
.pp-hero > div:first-child { grid-column: 1 / -1; }
.pp-hero .k { font: var(--t-label); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--fg-2); }
.pp-hero .v { font: 600 22px var(--font-num); margin-top: 3px; }
.pp-hero > div:first-child .v { font-size: 28px; }
.pp-hero .s { font-size: 11px; color: var(--fg-1); margin-top: 2px; }
.pp-margin { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: var(--s-4); margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.pp-margin .k { font: var(--t-label); color: var(--fg-2); text-transform: uppercase; }
.pp-margin .v { font-size: 18px; margin-top: 4px; overflow-wrap: anywhere; }
.pp-margin .s, .pp-margin-note { font-size: 11px; color: var(--fg-1); }
.pp-margin-note { margin-top: var(--s-4); }
.pp-unrecorded { font: 400 11px var(--font-ui); }
@media (max-width: 1000px) {
  .cols-paper { grid-template-columns: minmax(0, 1fr); }
  .pp-sidebar { order: 1; }
}
@media (max-width: 480px) {
  .pp-hero { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pp-table .btn-sm { min-height: 44px; }
  .pp-trades .chip-tag { min-height: 36px; padding-inline: 10px; }
  .pp-strategy { grid-template-columns: minmax(0, 1fr) 20px 44px 66px; gap: 4px; }
}
