/* ================= Design tokens ================= */
:root {
  --bg: #0a0d13;
  --bg-elev: #10141d;
  --surface: #141924;
  --surface-2: #1a2030;
  --border: #242b3d;
  --border-soft: #1c2231;
  --text: #e8ebf2;
  --text-dim: #9aa3b8;
  --text-faint: #616b82;
  --up: #26c281;
  --up-bg: rgba(38, 194, 129, 0.12);
  --down: #f2495c;
  --down-bg: rgba(242, 73, 92, 0.12);
  --amber: #f0a83c;
  --amber-bg: rgba(240, 168, 60, 0.12);
  --blue: #5b8def;
  --blue-bg: rgba(91, 141, 239, 0.12);
  --purple: #a685e2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, "Menlo", monospace;
  --header-h: 56px;
  --nav-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.amber { color: var(--amber); }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }

/* ================= Header ================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: rgba(10, 13, 19, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.topbar .brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--up); box-shadow: 0 0 8px var(--up); }
.topbar .brand-sub { color: var(--text-faint); font-weight: 500; font-size: 11px; }
.topbar .back { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; color: var(--text-dim); }
.topbar .user-chip {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 20px; padding: 5px 10px 5px 6px;
}
.user-chip .avatar {
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; color: #fff;
}

/* ================= Layout ================= */
.page { max-width: 720px; margin: 0 auto; padding: 12px 14px 28px; }
.section { margin-bottom: 20px; }
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-faint); font-weight: 700; margin: 0 0 8px 2px;
  display: flex; align-items: center; justify-content: space-between;
}
.section-title a.see-all { text-transform: none; letter-spacing: 0; color: var(--blue); font-weight: 600; font-size: 12.5px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
}
.card + .card { margin-top: 10px; }

/* ================= Mock-data banner ================= */
.mock-banner {
  background: var(--amber-bg);
  border: 1px solid rgba(240, 168, 60, 0.35);
  color: var(--amber);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  text-align: center;
}

/* ================= Regime banner ================= */
.regime-banner {
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.regime-banner.trend { background: linear-gradient(135deg, var(--up-bg), transparent); border-color: rgba(38,194,129,0.3); }
.regime-banner.range { background: linear-gradient(135deg, var(--blue-bg), transparent); border-color: rgba(91,141,239,0.3); }
.regime-banner.high_risk { background: linear-gradient(135deg, var(--down-bg), transparent); border-color: rgba(242,73,92,0.35); }
.regime-banner .label { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.regime-banner .reasons { font-size: 12.5px; color: var(--text-dim); }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 3px 8px; border-radius: 20px;
}
.badge.trend { background: var(--up-bg); color: var(--up); }
.badge.range { background: var(--blue-bg); color: var(--blue); }
.badge.high_risk { background: var(--down-bg); color: var(--down); }

/* ================= Cues strip ================= */
.cues-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.cues-strip::-webkit-scrollbar { display: none; }
.cue-chip {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  min-width: 84px;
}
.cue-chip .cue-label { font-size: 10.5px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.cue-chip .cue-val { font-size: 15px; font-weight: 700; margin-top: 2px; }
.cue-chip .cue-note { font-size: 10px; color: var(--text-faint); margin-top: 1px; }

/* ================= Flags row ================= */
.flags-row { display: flex; gap: 8px; flex-wrap: wrap; }
.flag-pill {
  font-size: 11.5px; font-weight: 600; padding: 6px 10px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  display: flex; align-items: center; gap: 5px;
}
.flag-pill.hot { background: var(--amber-bg); color: var(--amber); border-color: rgba(240,168,60,0.3); }

/* ================= Sector card ================= */
.sector-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-soft);
}
.sector-card + .sector-card { margin-top: 8px; }
.sector-rank {
  width: 26px; height: 26px; border-radius: 7px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: var(--text-dim); flex: 0 0 auto;
}
.sector-rank.top1 { background: var(--up-bg); color: var(--up); }
.sector-rank.short { background: var(--down-bg); color: var(--down); }
.sector-main { flex: 1; min-width: 0; }
.sector-name-row { display: flex; align-items: center; gap: 6px; }
.sector-name { font-weight: 700; font-size: 14.5px; }
.sector-driver { font-size: 12px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sector-score { text-align: right; flex: 0 0 auto; }
.sector-score .val { font-size: 16px; font-weight: 800; }
.sector-score .bar { width: 54px; height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.sector-score .bar > span { display: block; height: 100%; border-radius: 2px; }
.chev { color: var(--text-faint); font-size: 18px; margin-left: 2px; }

/* Component attribution bars (sector detail) */
.attr-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border-soft); }
.attr-row:last-child { border-bottom: none; }
.attr-label { flex: 0 0 132px; font-size: 12.5px; color: var(--text-dim); }
.attr-track { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); position: relative; overflow: hidden; }
.attr-track .zero { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--border); }
.attr-track .fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.attr-val { flex: 0 0 44px; text-align: right; font-size: 12.5px; font-weight: 700; }

/* ================= Signal card ================= */
.signal-card {
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border-soft);
  padding: 14px; display: block;
}
.signal-card + .signal-card { margin-top: 10px; }
.signal-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.signal-symbol { font-size: 17px; font-weight: 800; }
.signal-sector { font-size: 11.5px; color: var(--text-faint); margin-top: 1px; }
.signal-side {
  font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 6px; text-transform: uppercase;
}
.signal-side.long { background: var(--up-bg); color: var(--up); }
.signal-side.short { background: var(--down-bg); color: var(--down); }
.signal-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { font-size: 10.5px; font-weight: 700; padding: 3px 7px; border-radius: 5px; background: var(--surface-2); color: var(--text-dim); }
.tag.results { background: var(--purple); color: #1a1030; }
.tag.expiry { background: var(--amber); color: #1a1030; }
.tag.news { background: var(--blue); color: #0a1530; }
.levels-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.level-box { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 6px; text-align: center; }
.level-box .k { font-size: 9.5px; text-transform: uppercase; color: var(--text-faint); font-weight: 700; letter-spacing: 0.02em; }
.level-box .v { font-size: 13.5px; font-weight: 800; margin-top: 3px; }
.signal-meta-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 12px; color: var(--text-dim); }
.state-pill { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 20px; display: inline-flex; align-items: center; gap: 5px; }
.state-pill.waiting { background: var(--surface-2); color: var(--text-dim); }
.state-pill.triggered { background: var(--blue-bg); color: var(--blue); }
.state-pill.t1_hit { background: var(--up-bg); color: var(--up); }
.state-pill.closed { background: var(--surface-2); color: var(--text-faint); }
.state-pill.stopped { background: var(--down-bg); color: var(--down); }
.state-pill .pulse { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ================= Bottom nav ================= */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(13, 16, 24, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-soft);
  display: flex;
  max-width: 720px;
  margin: 0 auto;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-faint); font-size: 10.5px; font-weight: 600;
}
.bottom-nav a.active { color: var(--blue); }
.bottom-nav svg { width: 21px; height: 21px; }

/* ================= Misc components ================= */
.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 40px 20px; color: var(--text-dim); gap: 8px;
}
.empty-state .big-icon { font-size: 34px; }
.empty-state h3 { margin: 4px 0 0; color: var(--text); font-size: 16px; }
.empty-state p { margin: 0; font-size: 13px; max-width: 280px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat-box { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 12px 14px; }
.stat-box .k { font-size: 11px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.stat-box .v { font-size: 21px; font-weight: 800; margin-top: 4px; }
.stat-box .sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 1.5px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 14px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
  content: ""; position: absolute; left: -20px; top: 3px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface-2); border: 2px solid var(--text-faint);
}
.timeline-item.done::before { border-color: var(--up); background: var(--up); }
.timeline-item.active::before { border-color: var(--blue); background: var(--blue); box-shadow: 0 0 0 4px var(--blue-bg); }
.timeline-item .tt-label { font-size: 13px; font-weight: 700; }
.timeline-item .tt-time { font-size: 11px; color: var(--text-faint); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data-table th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.02em; padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
table.data-table td { padding: 8px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
.table-scroll { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border-soft); }
.table-scroll table.data-table { border: none; border-radius: 0; }
.table-scroll .card { border: none; }

.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border-soft); gap: 12px; }
.settings-row:last-child { border-bottom: none; }
.settings-row .sr-label { font-size: 13.5px; font-weight: 600; }
.settings-row .sr-desc { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
input[type="range"] { -webkit-appearance: none; width: 120px; height: 4px; border-radius: 2px; background: var(--surface-2); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--blue); cursor: pointer; }
.toggle { position: relative; width: 42px; height: 24px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); flex: 0 0 auto; cursor: pointer; }
.toggle.on { background: var(--up); border-color: var(--up); }
.toggle .knob { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left 0.15s ease; }
.toggle.on .knob { left: 20px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 700; font-size: 13px; padding: 9px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.block { width: 100%; }

.source-link { font-size: 10.5px; color: var(--text-faint); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.source-link.stale { color: var(--amber); }

.chart-wrap { width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; }

.pill-tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.pill-tab { flex: 0 0 auto; font-size: 12.5px; font-weight: 600; padding: 7px 13px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border-soft); color: var(--text-dim); }
.pill-tab.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.divider { height: 1px; background: var(--border-soft); margin: 14px 0; }

.footer-note { text-align: center; font-size: 11px; color: var(--text-faint); margin-top: 22px; padding: 0 20px; }

@media (min-width: 481px) {
  .levels-grid { grid-template-columns: repeat(4, 1fr); }
}
