:root {
  --bg: #0d0d0d;
  --bg2: #111111;
  --bg3: #1a1a1a;
  --bg4: #222222;
  --border: #2a2a2a;
  --accent: #00d4aa;
  --accent2: #00a88a;
  --red: #ff4455;
  --green: #00cc66;
  --yellow: #ffc107;
  --blue: #4d9fff;
  --text: #e0e0e0;
  --text2: #aaaaaa;
  --muted: #555555;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }

nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 20px;
  height: 48px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-logo {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  letter-spacing: 2px;
  margin-right: 24px;
  font-weight: 700;
}

.nav-tab {
  padding: 6px 16px;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text2);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.nav-tab:hover { color: var(--text); border-color: var(--border); }
.nav-tab.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(0,212,170,0.06);
}

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--muted); }
.exchange-badge {
  font-family: var(--font-mono);
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
  color: var(--text2);
}

.page { flex: 1; overflow-y: auto; padding: 20px; display: none; }
.page.active { display: block; }

/* ── Banner ── */
.banner {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 13px;
}
.banner.demo { background: rgba(255,193,7,0.08); border: 1px solid rgba(255,193,7,0.3); color: var(--yellow); }
.banner.no-edge { background: rgba(255,68,85,0.08); border: 1px solid rgba(255,68,85,0.3); color: var(--red); }
.banner.info { background: rgba(0,212,170,0.06); border: 1px solid rgba(0,212,170,0.2); color: var(--accent); }
.banner.visible { display: flex; }

/* ── Cards grid ── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.card-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.card-value { font-family: var(--font-mono); font-size: 22px; font-weight: 700; color: var(--text); }
.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }
.card-sub { font-size: 11px; color: var(--text2); margin-top: 4px; }

/* ── Section ── */
.section { margin-bottom: 28px; }
.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text2);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ── Chart containers ── */
.chart-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text2);
}

/* ── Tables ── */
.table-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}
th {
  background: var(--bg3);
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(42,42,42,0.5);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }
.hit { color: var(--green); }
.miss { color: var(--red); }
.pending { color: var(--yellow); }
.wait { color: var(--muted); }

/* ── Live page ── */
.live-layout { display: grid; grid-template-columns: 1fr 280px; gap: 16px; height: calc(100vh - 140px); }
.live-main { display: flex; flex-direction: column; gap: 12px; }
.live-sidebar { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

select, input[type="text"], input[type="date"] {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
}
select:focus, input:focus { border-color: var(--accent); }

.btn {
  padding: 7px 16px;
  border-radius: 4px;
  border: 1px solid;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #000; }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text2); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(255,68,85,0.1); }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ── Signal panel ── */
.signal-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.signal-direction {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 900;
  margin-bottom: 8px;
}
.signal-direction.long { color: var(--green); }
.signal-direction.short { color: var(--red); }
.signal-direction.wait { color: var(--muted); }

.signal-conf { font-family: var(--font-mono); font-size: 14px; color: var(--text2); margin-bottom: 12px; }

.signal-prices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.price-item label { font-size: 10px; color: var(--muted); text-transform: uppercase; display: block; margin-bottom: 2px; }
.price-item span { font-family: var(--font-mono); font-size: 13px; }
.price-tp { color: var(--green); }
.price-sl { color: var(--red); }

.reasons-list { list-style: none; }
.reasons-list li {
  font-size: 12px;
  color: var(--text2);
  padding: 4px 0;
  padding-left: 14px;
  position: relative;
}
.reasons-list li::before { content: '→'; position: absolute; left: 0; color: var(--accent); }

.ws-status {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ws-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
}
.ws-dot.connected { background: var(--green); }
.ws-dot.error { background: var(--red); }

/* ── Backtest page ── */
.backtest-form {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.progress-wrap {
  display: none;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
}
.progress-wrap.visible { display: block; }
.progress-bar-bg {
  height: 4px;
  background: var(--bg4);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}
.progress-msg { font-size: 12px; color: var(--text2); }

.leaderboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* Gate badges */
.gate { display: inline-block; font-size: 10px; padding: 2px 6px; border-radius: 3px; margin: 2px; }
.gate.ok { background: rgba(0,204,102,0.15); color: var(--green); border: 1px solid rgba(0,204,102,0.3); }
.gate.fail { background: rgba(255,68,85,0.12); color: var(--red); border: 1px solid rgba(255,68,85,0.3); }

.strategy-row { font-family: var(--font-mono); }
.strategy-name { font-weight: 700; }
.best-badge {
  display: inline-block;
  background: rgba(0,212,170,0.15);
  color: var(--accent);
  border: 1px solid rgba(0,212,170,0.3);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 3px;
  margin-left: 8px;
}
.new-badge {
  display: inline-block;
  background: rgba(77,159,255,0.12);
  color: var(--blue);
  border: 1px solid rgba(77,159,255,0.3);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
}
.legacy-badge {
  display: inline-block;
  background: rgba(255,68,85,0.1);
  color: var(--red);
  border: 1px solid rgba(255,68,85,0.3);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 3px;
}

/* ── Autopsy ── */
.autopsy-card {
  background: var(--bg2);
  border: 1px solid rgba(255,68,85,0.25);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}
.autopsy-header { font-size: 13px; font-weight: 600; color: var(--red); margin-bottom: 8px; }
.autopsy-diagnosis { font-size: 12px; color: var(--text2); font-family: var(--font-mono); }

/* ── Calib chart ── */
.calib-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.calib-canvas { width: 100%; height: 160px; display: block; }

/* ── Misc ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.lookahead-warn {
  font-size: 11px;
  color: var(--yellow);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255,193,7,0.06);
  border: 1px solid rgba(255,193,7,0.2);
  border-radius: 4px;
  margin-top: 8px;
}

/* ── Pagination ── */
.pagination { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text2); }
.pagination button { padding: 4px 10px; }

/* ── Calibration chart (canvas) ── */
.calib-section { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 10px; }
.calib-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; height: 100%; justify-content: flex-end; }
.calib-bar-container { width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; }
.calib-bar-claimed { width: 60%; background: rgba(100,100,100,0.4); border-radius: 2px 2px 0 0; }
.calib-bar-actual { width: 60%; border-radius: 2px 2px 0 0; transition: height 0.4s; }
.calib-label { font-family: var(--font-mono); font-size: 9px; color: var(--muted); white-space: nowrap; transform: rotate(-45deg); margin-top: 4px; }

/* ── Consensus panel ── */
.consensus-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.consensus-side {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 900;
}
.consensus-side.long { color: var(--green); }
.consensus-side.short { color: var(--red); }
.consensus-side.wait { color: var(--muted); }

.consensus-strength {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}
.consensus-strength.strong { background: rgba(0,204,102,0.12); color: var(--green); }
.consensus-strength.moderate { background: rgba(255,193,7,0.12); color: var(--yellow); }
.consensus-strength.weak { background: rgba(255,68,85,0.08); color: var(--red); }
.consensus-strength.none { color: var(--muted); }

.consensus-bar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid rgba(42,42,42,0.5);
  font-size: 12px;
}
.consensus-bar-row:last-child { border-bottom: none; }
.cons-label { color: var(--muted); font-size: 11px; }
.cons-count { font-family: var(--font-mono); color: var(--accent); font-weight: 700; }
.cons-pos { font-family: var(--font-mono); color: var(--text); }

/* ── Per-strategy live rows ── */
.strategy-row-live {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(42,42,42,0.4);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: default;
}
.strategy-row-live:last-child { border-bottom: none; }
.strategy-row-live.has-signal { opacity: 1; }
.strategy-row-live:not(.has-signal) { opacity: 0.45; }
.strat-name { flex: 1; color: var(--text2); }
.strat-side { width: 50px; text-align: center; font-weight: 700; }
.strat-side.long { color: var(--green); }
.strat-side.short { color: var(--red); }
.strat-side.wait { color: var(--muted); }
.strat-conf { width: 50px; text-align: right; color: var(--text2); }

/* ── Annual sim card ── */
.annual-card {
  background: var(--bg2);
  border: 1px solid rgba(0,212,170,0.2);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 4px;
}
.annual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.annual-item { }
.annual-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 4px; }
.annual-val { font-family: var(--font-mono); font-size: 16px; font-weight: 700; }

/* ── Robustness validation ── */
.banner.no-stable-edge { background: rgba(255,193,7,0.08); border: 1px solid rgba(255,193,7,0.3); color: var(--yellow); display: flex; }
.robustness-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.robust-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.robust-name { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.robust-verdict { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.robust-meta { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 12px; margin-bottom: 4px; }
.robust-avg { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

/* ── Color helpers ── */
.positive { color: var(--green); }
.negative { color: var(--red); }
.long { color: var(--green); }
.short { color: var(--red); }

/* ══════════════════════ ПУЛЬТ ══════════════════════ */

.ctrl-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
  flex-shrink: 0;
}
.ctrl-status-dot.running { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); animation: pulse-dot 1s infinite; }
.ctrl-status-dot.done    { background: var(--green); }
.ctrl-status-dot.error   { background: var(--red); }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:0.4} }

.btn-danger {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: background 0.15s;
}
.btn-danger:hover:not(:disabled) { background: rgba(255,68,85,0.12); }
.btn-danger:disabled { opacity: 0.35; cursor: not-allowed; }

.ctrl-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  flex: 1;
  overflow: hidden;
}

.ctrl-left {
  padding: 16px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.ctrl-right {
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
}

/* Кнопки скриптов */
.ctrl-scripts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.ctrl-script-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
}
.ctrl-script-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg4);
}
.ctrl-script-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ctrl-script-btn .script-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}
.ctrl-script-btn .script-desc {
  font-size: 11px;
  color: var(--muted);
}
.ctrl-script-btn.missing .script-name { color: var(--muted); }
.ctrl-select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 140px;
}
.ctrl-select:focus { outline: none; border-color: var(--accent); }

.ctrl-progress-wrap {
  margin-top: 16px;
}

/* Лог */
.ctrl-log {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  scroll-behavior: smooth;
}

.log-line         { color: var(--text2); }
.log-line.info    { color: var(--text); }
.log-line.success { color: var(--green); }
.log-line.error   { color: var(--red); }
.log-line.warn    { color: var(--yellow); }
.log-line.epoch   { color: var(--accent); }
.log-line.header  { color: var(--accent); font-weight: bold; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

/* Confusion matrix */
.conf-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
}
.conf-table th, .conf-table td {
  text-align: center;
  padding: 6px 8px;
  border: 1px solid var(--border);
}
.conf-table th { background: var(--bg3); color: var(--text2); font-size: 11px; }
.conf-table td:first-child { background: var(--bg3); font-size: 11px; }
.conf-table .cm-hit  { background: rgba(0,204,102,0.15); color: var(--green); font-weight: 700; }
.conf-table .cm-miss { background: rgba(255,68,85,0.10); color: var(--text2); }

/* Грид примеров */
.ctrl-samples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 4px 0 20px;
}

.sample-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.sample-card.correct  { border-color: rgba(0,204,102,0.5); }
.sample-card.wrong    { border-color: rgba(255,68,85,0.4); }
.sample-card img      { width: 100%; display: block; }

.sample-footer {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sample-verdict {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sample-verdict .tick  { color: var(--green); }
.sample-verdict .cross { color: var(--red); }

.sample-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
}
.sample-row span { color: var(--text2); }

.sample-probs {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.prob-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 9px;
  font-family: var(--font-mono);
}
.prob-bar-fill {
  width: 100%;
  border-radius: 2px;
  transition: height 0.3s;
}
