:root {
  --bg: #0e1013;
  --panel: #15181d;
  --panel-2: #1b1f25;
  --line: #262b33;
  --line-2: #323844;
  --text: #e7e9ec;
  --muted: #8a919c;
  --accent: #e9a23b;
  --accent-ink: #1a1306;
  --up: #34c17b;
  --down: #ef5a5a;
  --sma50: #5aa9ff;
  --sma200: #c78bff;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, Segoe UI, sans-serif;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h2 {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 10px;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; z-index: 5; min-height: 57px;
}
.brand { font-weight: 600; font-size: 15px; white-space: nowrap; }
.ts-tabs { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.ts-tabs::-webkit-scrollbar { display: none; }
.ts-tabs a { padding: 5px 12px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 13px; white-space: nowrap; }
.ts-tabs a:hover { color: var(--text); }
.ts-tabs a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.mark { color: var(--accent); }
.status { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px;
}
.chip.ok { color: var(--text); }
.sync { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.progress { width: 260px; }
.progress-text {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px;
}
.progress-bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.progress.indeterminate #progress-fill { width: 30%; animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line-2); background: var(--panel-2);
  padding: 7px 14px; border-radius: var(--radius); cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.icon-btn {
  background: none; border: 1px solid var(--line); border-radius: var(--radius);
  width: 32px; height: 32px; cursor: pointer; color: var(--muted);
}

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 340px 1fr; gap: 16px;
  padding: 16px 20px; height: calc(100vh - 57px);
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-height: 0;
}

/* ---------- filters ---------- */
.filters { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.preset {
  font-size: 12px; padding: 5px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-2); background: transparent;
}
.preset:hover { border-color: var(--accent); color: var(--accent); }
.preset.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.filter-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.filter {
  display: grid; grid-template-columns: 1fr 64px 28px; gap: 6px;
  padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
.filter .value-row { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; }
.filter select, .filter input, .field input {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; min-width: 0;
}
.filter input { font-family: var(--mono); }
.filter select:focus, .filter input:focus, .field input:focus { outline: none; border-color: var(--accent); }
.filter .remove {
  background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px;
}
.filter .remove:hover { color: var(--down); }
.vs-toggle {
  flex: none; font-size: 11px; padding: 5px 7px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--muted);
}
.vs-toggle.on { color: var(--accent); border-color: var(--accent); }
.mult { width: 64px !important; flex: none; }
.times { color: var(--muted); font-size: 12px; }

.options { display: flex; flex-direction: column; gap: 10px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); }

.saved-list { display: flex; flex-direction: column; gap: 4px; }
.saved {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.saved:hover { background: var(--panel-2); }
.saved button { background: none; border: 0; color: var(--muted); cursor: pointer; }
.run {
  margin-top: auto; padding: 10px; position: sticky; bottom: 0;
  box-shadow: 0 -12px 16px var(--panel);
}

/* ---------- results ---------- */
.results { display: flex; flex-direction: column; overflow: hidden; }
.results-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.count { font-weight: 600; font-size: 15px; margin-right: 8px; }
.results-actions { display: flex; gap: 8px; }
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 8px; width: 240px; max-height: 420px; overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.dropdown-menu .group { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 8px 4px 4px; }
.dropdown-menu label { display: flex; gap: 8px; padding: 4px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.dropdown-menu label:hover { background: var(--panel); }
.dropdown-menu input { accent-color: var(--accent); }
.dropdown-menu label.locked { opacity: .5; cursor: not-allowed; }

.table-wrap { flex: 1; overflow: auto; position: relative; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; background: var(--panel); z-index: 1;
  text-align: right; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
  cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted { color: var(--accent); }
thead th.sorted::after { content: " ↓"; }
thead th.sorted.asc::after { content: " ↑"; }
th.left, td.left { text-align: left; }
tbody td {
  padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: right;
  white-space: nowrap; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums;
}
tbody td.left { font-family: var(--sans); }
tbody td.name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
tbody td.sym { font-weight: 600; font-family: var(--mono); }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--panel-2); }
tbody tr.selected td { background: rgba(233,162,59,.08); }
.rsi-hi { color: var(--down); }
.rsi-lo { color: var(--up); }
.flag-on { color: var(--accent); font-weight: 600; }

.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 40px;
}
.empty p { max-width: 440px; margin: 4px 0; }
.empty-title { font-weight: 600; font-size: 16px; }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(760px, 100vw);
  background: var(--panel); border-left: 1px solid var(--line-2); z-index: 20;
  transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 15; display: none; }
.scrim.open { display: block; }
.drawer-head { display: flex; align-items: center; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.drawer-head > div:first-child { flex: 1; min-width: 0; }
.d-symbol { font-family: var(--mono); font-weight: 600; font-size: 20px; }
.d-price { text-align: right; }
.d-close { font-family: var(--mono); font-size: 20px; }
.d-change { font-family: var(--mono); font-size: 13px; }
.ranges { display: flex; gap: 4px; padding: 12px 20px 0; align-items: center; }
.ranges button {
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 4px 10px; cursor: pointer; color: var(--muted); font-family: var(--mono); font-size: 12px;
}
.ranges button.active { border-color: var(--line-2); color: var(--text); background: var(--panel-2); }
.legend { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 2px; margin-left: 8px; }
.l50 { background: var(--sma50); } .l200 { background: var(--sma200); }
.chart-box { position: relative; height: 380px; margin: 8px 12px 0; }
#chart { width: 100%; height: 100%; display: block; }
.readout {
  position: absolute; top: 6px; left: 10px; font-family: var(--mono); font-size: 11px;
  color: var(--muted); pointer-events: none;
}
.readout b { color: var(--text); font-weight: 500; }
.d-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin: 16px 20px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.stat { background: var(--panel); padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 14px; margin-top: 2px; }
.drawer-body { flex: 1; min-height: 0; overflow-y: auto; }

/* ---------- technical analysis ---------- */
.ta { margin: 4px 20px 24px; }
.ta-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 22px 0 8px; }
.ta-head h2 { margin: 0; }
.ta-table {
  border: 1px solid var(--line); border-radius: var(--radius); border-collapse: separate;
  border-spacing: 0; overflow: hidden;
}
.ta-table thead th {
  position: static; cursor: default; background: var(--panel-2); padding: 8px 12px; font-size: 11px;
}
.ta-table thead th:hover { color: var(--muted); }
.ta-table tbody tr { cursor: default; }
.ta-table tbody tr:hover td { background: transparent; }
.ta-table tbody tr:last-child td { border-bottom: 0; }
.ta-table tbody td { padding: 7px 12px; font-size: 13px; }
.ta-table td.ta-k { font-family: var(--sans); color: var(--muted); width: 34%; }
.ta-table td.ta-sig { font-family: var(--sans); font-size: 12px; color: var(--muted); width: 40%; }
.ta-table td.ta-sig.up { color: var(--up); }
.ta-table td.ta-sig.down { color: var(--down); }
.ta-table tr.ta-group td {
  background: var(--panel-2) !important; font-family: var(--sans); font-size: 10px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted); text-align: left; padding: 6px 12px;
}
.ta-bands, .ta-test { margin-top: 10px; }
.ta-bands td.ta-k, .ta-test td.ta-k { width: auto; }
.ta-pill {
  display: inline-block; font-family: var(--sans); font-size: 11px; font-weight: 600;
  padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor;
}
.ta-pill.up { color: var(--up); }
.ta-pill.accent { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.ta-pill.off { color: var(--muted); border-color: var(--line-2); font-weight: 500; }
.ta-formula { text-transform: none; letter-spacing: 0; font-family: var(--mono); font-weight: 500; }
.ta-table tr.ta-close td { background: rgba(233,162,59,.08) !important; color: var(--accent); }
.ta-table tr.ta-close td.ta-k { color: var(--accent); font-weight: 600; }
.ta-sr td.ta-k { width: auto; }
.ta-dots { color: var(--accent); letter-spacing: 1px; font-size: 10px; }
.spark { width: 120px; height: 26px; display: block; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ta-pivots {
  display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-family: var(--mono); font-size: 12px; color: var(--muted);
}
.ta-pivots span:first-child { font-family: var(--sans); margin-right: auto; }
.ta-pivots b { color: var(--text); font-weight: 500; }
.ta-note { margin: 0 0 10px; }

/* daily TA history */
.tah-wrap {
  max-height: 420px; overflow: auto; border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 8px;
}
.tah { width: max-content; min-width: 100%; }
.tah thead th { cursor: default; padding: 8px 10px; background: var(--panel-2); z-index: 2; }
.tah thead th:hover { color: var(--muted); }
.tah tbody tr { cursor: default; }
.tah tbody td { padding: 6px 10px; font-size: 12px; }
.tah tbody tr:hover td { background: var(--panel-2); }
.tah .tah-date { position: sticky; left: 0; background: var(--panel); z-index: 1; font-family: var(--mono); }
.tah thead .tah-date { background: var(--panel-2); z-index: 3; }
.tah tr.tah-latest td { background: rgba(233,162,59,.08); }
.tah tr.tah-latest td.tah-date { color: var(--accent); background: #2a2419; }
.ta-head .link { margin-left: 8px; }
.h-open {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px;
  padding: 10px 14px; border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--panel-2); color: var(--text); text-decoration: none;
}
.h-open:hover { border-color: var(--accent); }
.h-open > span:last-child { color: var(--accent); font-size: 16px; }
.pod-key { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; }
.pod-key i { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); display: inline-block; }
.pod-size { display: flex; gap: 4px; }
.pod-size button {
  background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 8px; cursor: pointer;
  color: var(--muted); font-family: var(--mono); font-size: 12px;
}
.pod-size button.active { border-color: var(--line-2); color: var(--text); background: var(--panel-2); }
.pods { display: flex; flex-direction: column; gap: 3px; }
.pod {
  display: grid; grid-template-columns: 130px 1fr 92px; align-items: center; gap: 10px;
  font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; padding: 1px 0;
}
.pod-range { color: var(--muted); text-align: right; white-space: nowrap; }
.pod-track { height: 14px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.pod-bar { display: block; height: 100%; background: var(--sma50); opacity: .55; border-radius: 3px; min-width: 1px; }
.pod.top .pod-bar { opacity: .9; }
.pod.current .pod-bar { background: var(--accent); opacity: 1; }
.pod.current .pod-range { color: var(--accent); }
.pod-val { white-space: nowrap; }

.drawer-foot {
  margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 20px; border-top: 1px solid var(--line);
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px;
  border-radius: var(--radius); z-index: 30; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: 90vw;
}
.toast.error { border-color: var(--down); }

@media (max-width: 960px) {
  .topbar { flex-wrap: wrap; }
  .sync { width: 100%; margin: 0; }
  .progress { flex: 1; }
  .layout { grid-template-columns: 1fr; height: auto; padding: 12px 16px; }
  .results { min-height: 70vh; }
  .d-stats { grid-template-columns: repeat(2, 1fr); }
  .ta { margin: 4px 12px 20px; }
  .pod { grid-template-columns: 96px 1fr 76px; gap: 6px; font-size: 11px; }
  .ta-table td.ta-k { width: auto; }
  .spark { width: 72px; }
}

/* ---------- Edge score card (drawer) ---------- */
.edge-top { display: flex; gap: 16px; align-items: center; margin: 4px 0 12px; }
.edge-score { flex: none; display: flex; align-items: baseline; gap: 2px; font-family: var(--mono); padding: 8px 14px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel-2); }
.edge-score b { font-size: 30px; font-weight: 500; }
.edge-score span { color: var(--muted); font-size: 12px; }
.edge-score.up b { color: var(--up); } .edge-score.down b { color: var(--down); }
.edge-zone { font-weight: 600; font-size: 14px; }
.edge-zone.up { color: var(--up); } .edge-zone.down { color: var(--down); }
.edge-bars { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; height: 70px; align-items: end; margin: 6px 0 4px; }
.edge-bar { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 3px; }
.edge-bar i { display: block; background: var(--line-2); border-radius: 2px 2px 0 0; }
.edge-bar span { font-family: var(--mono); font-size: 10px; color: var(--muted); text-align: center; }
.edge-bar.cur i { background: var(--accent); }
.edge-bar.cur span { color: var(--accent); }
.edge-parts { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 6px; }
.edge-part { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 70px; gap: 10px; align-items: center; font-size: 12.5px; }
.edge-part .num { font-family: var(--mono); text-align: right; font-size: 12px; }
.q-ebar { position: relative; height: 10px; background: var(--panel-2); border-radius: 2px; }
.q-ebar::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line-2); }
.q-ebar i { position: absolute; top: 0; bottom: 0; border-radius: 2px; }

/* ---------- Signal Lab track record (screener) ---------- */
.preset .vd { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-left: 6px; vertical-align: middle; background: var(--line-2); }
.preset .vd.v-edge { background: var(--up); }
.preset .vd.v-costs { background: var(--accent); }
.preset .vd.v-ranks { background: var(--sma50); }
.preset .vd.v-negative { background: var(--down); }
.preset.active .vd { box-shadow: 0 0 0 1.5px var(--accent-ink); }
.preset-key { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.preset-key i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.track { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; padding: 9px 16px; border-bottom: 1px solid var(--line); background: var(--panel-2); font-size: 12.5px; color: var(--muted); }
.track b { color: var(--text); font-weight: 500; }
.track .tr-v { font-weight: 600; font-size: 12px; padding: 1px 9px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.track .tr-v.v-edge { color: var(--up); } .track .tr-v.v-costs { color: var(--accent); } .track .tr-v.v-ranks { color: var(--sma50); }
.track .tr-v.v-negative { color: var(--down); } .track .tr-v.v-none, .track .tr-v.v-insufficient, .track .tr-v.v-untestable { color: var(--muted); }
.track .tr-h { display: inline-flex; gap: 2px; margin-left: auto; }
.track .tr-h button { background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 8px; color: var(--muted); cursor: pointer; font-family: var(--mono); font-size: 11.5px; }
.track .tr-h button.on { border-color: var(--line-2); color: var(--text); background: var(--panel); }
.track a { color: var(--accent); text-decoration: none; white-space: nowrap; }
.track a:hover { text-decoration: underline; }
.track .up { color: var(--up); } .track .down { color: var(--down); }

[hidden] { display: none !important; }