:root {
  --bg: #05080f;
  --bg2: #0a101b;
  --panel: #0d1524;
  --line: #1a2740;
  --text: #edf3ff;
  --muted: #8b9bb8;
  --green: #2dff9a;
  --red: #ff4d6d;
  --blue: #4d8dff;
  --gold: #ffc857;
  --purple: #a78bfa;
  --font: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 500px at 0% 0%, #12243f 0%, transparent 55%),
    radial-gradient(700px 400px at 100% 0%, #0f2a22 0%, transparent 50%),
    var(--bg);
}

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail {
  border-right: 1px solid var(--line);
  background: rgba(8, 12, 20, 0.92);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.logo { display: flex; gap: 10px; align-items: center; }
.logo .mark {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, #1a3d32, #1a2f55);
  color: var(--green); border: 1px solid #2a4d40;
}
.logo strong { display: block; letter-spacing: 0.12em; font-size: 0.95rem; }
.logo span { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.14em; }
nav { display: flex; flex-direction: column; gap: 6px; }
.nav {
  text-align: left; background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 10px 12px; border-radius: 10px; cursor: pointer; font-weight: 600;
}
.nav:hover { color: var(--text); border-color: var(--line); }
.nav.active { color: var(--green); background: #0f1c18; border-color: #1f3d32; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.legal-links { display: flex; flex-wrap: wrap; gap: 6px 10px; padding-top: 6px; }
.legal-links a { color: var(--muted); font-size: 0.68rem; text-decoration: none; }
.legal-links a:hover { color: var(--blue); }
.legal-micro { margin: 0; font-size: 0.62rem; color: var(--muted); line-height: 1.35; opacity: 0.85; }
.setup-banner {
  border: 1px solid var(--line);
  background: linear-gradient(90deg, #0f1a14, #101a2b);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}
.setup-banner.ok { border-color: #245c45; color: #c8f5df; }
.setup-banner b { color: var(--text); }
.setup-banner .banner-legal { display: block; margin-top: 6px; font-size: 0.78rem; opacity: 0.9; }
.setup-banner .banner-legal a { color: var(--blue); text-decoration: none; }
.setup-banner .banner-legal a:hover { text-decoration: underline; }
.version-pill {
  font-size: 0.65rem; color: var(--muted); letter-spacing: 0.04em;
  border: 1px dashed var(--line); border-radius: 999px; padding: 4px 8px; text-align: center;
}
.access-pass-box {
  border: 1px solid #3a4a20;
  background: linear-gradient(180deg, #1a2210, #12180c);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0 12px;
}
.access-pass-box .subh { margin-top: 0; color: var(--gold); }
.access-banner {
  border: 1px solid #5c4a18;
  background: #1a1608;
  color: #f0e6c8;
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 12px;
  font-size: 0.9rem;
}
.access-banner button { margin-top: 8px; }
.pill {
  font-size: 0.7rem; letter-spacing: 0.04em; text-transform: uppercase;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; color: var(--muted);
}
.pill.live { color: var(--green); border-color: #245c45; background: #0c1a14; }
.pill.ok { color: var(--blue); border-color: #27406a; }
.pill.bad { color: var(--red); border-color: #5c2434; }

main { padding: 22px 24px 40px; }
.top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
h1 { margin: 0; font-size: 1.45rem; }
.muted { color: var(--muted); margin: 4px 0 0; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button, .chip-btn {
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 9px 12px; font-weight: 650; cursor: pointer;
}
button:hover, .chip-btn:hover { border-color: var(--blue); }
button.primary {
  background: linear-gradient(135deg, #163528, #152a48);
  border-color: #2d6b52; color: var(--green);
}
button.ghost { background: transparent; }
button.wide { width: 100%; margin-top: 6px; }
.bullets { color: var(--muted); line-height: 1.55; padding-left: 1.15rem; margin: 0; }
.bullets b { color: var(--text); }
.form .quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
code { font-family: var(--mono); font-size: 0.85em; color: var(--gold); }
.auto { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 0.9rem; }

.stats {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px;
}
.stat {
  background: linear-gradient(180deg, #101a2b, #0c1320);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
}
.stat label { display: block; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat b { display: block; margin-top: 6px; font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.panel { display: none; }
.panel.active { display: block; }
.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card {
  background: rgba(13, 21, 36, 0.92);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.25);
}
.card.glow { border-color: #2a5c48; box-shadow: 0 0 0 1px rgba(45,255,154,0.08), 0 16px 40px rgba(0,0,0,0.3); }
.card h2 { margin: 0 0 12px; font-size: 0.95rem; color: var(--muted); font-weight: 700; letter-spacing: 0.03em; }
.subh { margin: 16px 0 8px; font-size: 0.85rem; color: var(--muted); }
.warn { color: var(--gold); font-size: 0.85rem; margin: 0 0 12px; }

.table-wrap { overflow: auto; max-height: 420px; }
.table-wrap.short { max-height: 240px; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); position: sticky; top: 0; background: #0d1524; }
.buy { color: var(--green); font-weight: 700; }
.sell { color: var(--red); font-weight: 700; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px;
  background: #0a1220; font-size: 0.8rem;
}
.chip b { color: var(--blue); margin-right: 6px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }
.chip-btn { font-size: 0.8rem; padding: 6px 10px; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; color: var(--muted); }
.form input, .form select {
  background: #080e18; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 0.95rem;
}
.code {
  background: #070c14; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; overflow: auto; max-height: 320px; font-family: var(--mono);
  font-size: 0.75rem; color: #b7c7e0; white-space: pre-wrap;
}
.risk-grid, .edge-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px;
}
.risk-item, .edge-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #0a1220;
}
.risk-item span, .edge-item span { display: block; color: var(--muted); font-size: 0.72rem; text-transform: uppercase; }
.risk-item b, .edge-item b { display: block; margin-top: 4px; }
.edge-item.yes b { color: var(--green); }
.edge-item.no b { color: var(--red); }
.edge-list { color: var(--muted); line-height: 1.55; }
.edge-list b { color: var(--text); }

footer { margin-top: 18px; color: var(--muted); font-size: 0.78rem; }

/* Liquidity Map layout */
.bm-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px; margin: 10px 0;
}
.bm-stats .pill-stat {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #0c1320;
}
.bm-stats .pill-stat span { display: block; font-size: 0.68rem; color: var(--muted); text-transform: uppercase; }
.bm-stats .pill-stat b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.bm-layout {
  display: grid; grid-template-columns: 1.55fr 0.85fr; gap: 12px;
}
.bm-heat-wrap {
  position: relative; border: 1px solid var(--line); border-radius: 12px;
  background: #03060c; overflow: hidden; min-height: 540px;
}
#bmHeat { width: 100%; height: 540px; display: block; }
.bm-side { display: flex; flex-direction: column; gap: 10px; min-height: 540px; }
.bm-book, .bm-tape {
  border: 1px solid var(--line); border-radius: 12px; background: #0a1220;
  padding: 10px; flex: 1; overflow: hidden;
}
.bm-levels { font-family: var(--mono); font-size: 0.72rem; max-height: 140px; overflow: auto; }
.bm-lvl { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; padding: 2px 0; }
.bm-lvl.bid { color: #69f0ae; }
.bm-lvl.ask { color: #ff8a9a; }
.bm-spread {
  text-align: center; padding: 6px; color: var(--gold); font-weight: 700; font-size: 0.8rem;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin: 6px 0;
}
.bm-trades { font-family: var(--mono); font-size: 0.72rem; max-height: 160px; overflow: auto; }
.bm-tr { display: flex; justify-content: space-between; padding: 2px 0; }
.bm-tr.buy { color: #69f0ae; }
.bm-tr.sell { color: #ff8a9a; }
@media (max-width: 1100px) {
  .bm-layout { grid-template-columns: 1fr; }
}

/* Definitive signal board */
.sig-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px; margin-bottom: 12px;
}
.sig-summary .pill-stat {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #0c1320;
}
.sig-summary .pill-stat span { display: block; font-size: 0.68rem; color: var(--muted); text-transform: uppercase; }
.sig-summary .pill-stat b { font-size: 1.2rem; }
.sig-summary .pill-stat.buy b { color: var(--green); }
.sig-summary .pill-stat.sell b { color: var(--red); }
.sig-summary .pill-stat.def b { color: var(--gold); }
.sig-actions-bar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.sig-col-buy h2.buy { color: var(--green); }
.sig-col-sell h2.sell { color: var(--red); }
.sig-cards { display: flex; flex-direction: column; gap: 10px; max-height: 520px; overflow: auto; }
.sig-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #0a1220;
}
.sig-card.buy { border-color: #1f5c40; box-shadow: inset 3px 0 0 var(--green); }
.sig-card.sell { border-color: #5c2434; box-shadow: inset 3px 0 0 var(--red); }
.sig-card.strong { outline: 1px solid rgba(255, 200, 87, 0.45); }
.sig-card .action {
  font-weight: 800; letter-spacing: 0.06em; font-size: 0.85rem; margin-bottom: 4px;
}
.sig-card.buy .action { color: var(--green); }
.sig-card.sell .action { color: var(--red); }
.sig-card .sym { font-size: 1.15rem; font-weight: 800; }
.sig-card .levels {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  margin-top: 8px; font-size: 0.78rem; color: var(--muted);
}
.sig-card .levels b { display: block; color: var(--text); font-variant-numeric: tabular-nums; }
.sig-card .headline { margin-top: 8px; font-size: 0.78rem; color: var(--muted); line-height: 1.35; }
.sig-card .badge {
  display: inline-block; font-size: 0.65rem; font-weight: 800; letter-spacing: 0.08em;
  padding: 2px 6px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}
.sig-card .badge.def { background: #3d3210; color: var(--gold); border: 1px solid #6b5a1a; }
.action-cell { font-weight: 800; letter-spacing: 0.04em; }
.action-cell.STRONG_BUY, .action-cell.BUY { color: var(--green); }
.action-cell.STRONG_SELL, .action-cell.SELL { color: var(--red); }
.action-cell.HOLD { color: var(--muted); }

/* Live action banner under chart */
.chart-signal-banner {
  margin: 8px 0 10px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #0c1320;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  font-size: 0.9rem;
}
.chart-signal-banner .act {
  font-weight: 900; letter-spacing: 0.08em; padding: 4px 10px; border-radius: 8px;
}
.chart-signal-banner.buy { border-color: #1f5c40; }
.chart-signal-banner.buy .act { background: #0f2a1c; color: var(--green); }
.chart-signal-banner.sell { border-color: #5c2434; }
.chart-signal-banner.sell .act { background: #2a1018; color: var(--red); }
.chart-signal-banner.hold .act { background: #1a2030; color: var(--muted); }

/* ── Live charts (KCEX / Cipher) ───────────────────────── */
.chart-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 12px;
}
.tape-card { max-height: calc(100vh - 180px); overflow: hidden; display: flex; flex-direction: column; }
.tape-search {
  width: 100%; margin: 0 0 8px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: #080e18; color: var(--text); font-size: 0.82rem;
}
.tape-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tape-tab {
  flex: 1; padding: 6px 4px; font-size: 0.72rem; border-radius: 8px;
  border: 1px solid var(--line); background: #0a1220; color: var(--muted); cursor: pointer;
}
.tape-tab.active { color: var(--green); border-color: #2d6b52; background: #0f1c18; }
.tape { overflow: auto; display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 280px; }
.tape-section {
  font-size: 0.65rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); padding: 8px 4px 4px; position: sticky; top: 0; background: #0d1524; z-index: 1;
}
.tape-item {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 8px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0a1220;
  color: var(--text);
  cursor: pointer;
  font-size: 0.78rem;
}
.tape-item b { grid-column: 1; color: var(--blue); }
.tape-item span:nth-child(2) { grid-column: 2; font-variant-numeric: tabular-nums; }
.tape-item span:nth-child(3) { grid-column: 1 / -1; font-size: 0.72rem; }
.tape-item:hover { border-color: var(--green); }
.tape-item.active { border-color: var(--green); background: #0f1c18; }

.chart-toolbar {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px;
  align-items: center; margin-bottom: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.chart-toolbar .left { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.chart-toolbar select {
  background: #080e18; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px;
}
.chart-toolbar .px { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.intervals { display: flex; flex-wrap: wrap; gap: 4px; }
.intervals button {
  padding: 6px 10px; font-size: 0.78rem; border-radius: 8px;
}
.intervals button.active {
  color: var(--green); border-color: #2d6b52; background: #0f1c18;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 0 rgba(45,255,154,0.6); display: inline-block;
}
.live-dot.pulse { animation: pulse 1.2s ease-out; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(45,255,154,0.6); }
  100% { box-shadow: 0 0 0 12px rgba(45,255,154,0); }
}
.chart-meta {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  color: var(--muted); font-size: 0.78rem; margin-bottom: 8px;
}
.chart-meta label.leg {
  display: inline-flex; gap: 6px; align-items: center; cursor: pointer;
  font-weight: 650; letter-spacing: 0.01em;
}
.chart-meta b { color: var(--text); }
.meta-hl { color: var(--muted); }
.meta-hl b { font-variant-numeric: tabular-nums; }
.meta-hl:first-of-type b { color: #2dff9a; }  /* High */
.meta-hl:nth-of-type(2) b { color: #ff4d6d; } /* Low */

/* Legend colors match Lightweight Charts series in charts.js */
.leg-sma { color: #22d3ee; }          /* SMA20 cyan · SMA50 purple · EMA gold in chart */
.leg-sma:hover { color: #7eefff; }
.leg-ribbon { color: #2dff9a; }       /* EMA ribbon greens */
.leg-ribbon:hover { color: #7bffc4; }
.leg-bb { color: #8b9bb4; }           /* Bollinger bands */
.leg-bb:hover { color: #b6c3d8; }
.leg-vwap { color: #4d8dff; }         /* VWAP blue */
.leg-vwap:hover { color: #8bb4ff; }
.leg-st { color: #ff6bcb; }           /* SuperTrend pink */
.leg-st:hover { color: #ff9fde; }
.leg-cipher { color: #69f0ae; }       /* Cipher buy dots green (sell is red on chart) */
.leg-cipher:hover { color: #a7ffd4; }

.swatch {
  width: 12px; height: 3px; border-radius: 2px; display: inline-block;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}
.sw-sma {
  background: linear-gradient(90deg, #22d3ee 0 33%, #a78bfa 33% 66%, #ffc857 66% 100%);
  height: 4px;
}
.sw-ribbon { background: linear-gradient(90deg, #1a9f66, #2dff9a, #7bffc4); height: 4px; }
.sw-bb { background: #8b9bb4; border: 1px dashed #c5d0e0; height: 0; border-top-width: 2px; box-shadow: none; }
.sw-vwap { background: #4d8dff; }
.sw-st { background: #ff6bcb; }
.sw-cipher {
  width: 8px; height: 8px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #69f0ae, #00e676 55%, #ff5252 56%);
}

/* Dim legend when toggle unchecked */
.leg:has(input:not(:checked)) {
  opacity: 0.4;
  filter: grayscale(0.35);
}
.chart-stack {
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: #070c14;
}
.chart-pane { border-bottom: 1px solid var(--line); position: relative; }
.chart-pane:last-child { border-bottom: none; }
.chart-pane.short .chart-host { height: 120px; }
.chart-host { width: 100%; height: 420px; }
.pane-label {
  position: absolute; z-index: 2; top: 6px; left: 10px;
  font-size: 0.65rem; letter-spacing: 0.08em; color: var(--muted);
  pointer-events: none; text-transform: uppercase;
}
.cipher-hud-card { margin-top: 12px; }
.cipher-hud {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px;
}
.c-item {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #0a1220;
}
.c-item span { display: block; color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }
.c-item b { display: block; margin-top: 4px; font-size: 0.95rem; }
.chart-error {
  background: rgba(255, 77, 109, 0.12);
  border: 1px solid #5c2434;
  color: #ff8fa3;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.setup-banner {
  border: 1px solid #3d4a20;
  background: linear-gradient(90deg, #1a220f, #0d1524);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  color: #d7e0c8;
  font-size: 0.88rem;
  line-height: 1.45;
}
.setup-banner code {
  background: #121a0c;
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--gold);
}
.setup-banner.ok { border-color: #245c45; background: #0c1a14; color: var(--muted); }

@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: relative; height: auto; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
  .chart-layout { grid-template-columns: 1fr; }
  .chart-host { height: 320px; }
}
