:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #ebeae6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6; /* strategy */
  --series-2: #eb6834; /* buy & hold */
  --good: #0ca30c;
  --good-ink: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  --good-wash: #e7f5e7;
  --critical-wash: #fbeaea;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #33332f;
    --grid: #2a2a27;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --good-ink: #5fd35f;
    --good-wash: #16291a;
    --critical-wash: #2e1818;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #33332f;
  --grid: #2a2a27;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --good-ink: #5fd35f;
  --good-wash: #16291a;
  --critical-wash: #2e1818;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* class display rules must never un-hide an element */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.num, .tile-value, .data td.num { font-variant-numeric: tabular-nums; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.brand svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 2; }
.tabs { display: flex; gap: 2px; }
.tabs button {
  border: 0; background: none; color: var(--text-secondary); font: inherit; padding: 6px 12px;
  border-radius: 6px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.badge {
  margin-left: auto; font-size: 12px; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px;
}
.icon-btn { border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary); border-radius: 6px; width: 30px; height: 30px; cursor: pointer; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 40px; }
footer { max-width: 1200px; margin: 0 auto; padding: 0 24px 32px; color: var(--text-muted); font-size: 12px; }

/* Filter row */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.filters input, .filters select {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; min-width: 110px;
}
#f-days { width: 90px; min-width: 0; }
.actions { display: flex; gap: 8px; }
.btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.small { padding: 3px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: progress; }
.hint { color: var(--text-secondary); margin: 8px 0 16px; font-size: 13px; }

.error { background: var(--critical-wash); border: 1px solid var(--critical); color: var(--text-primary); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

/* Cards */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card > .muted.small { margin: 4px 0 10px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.grid-2 .card { margin-bottom: 0; min-width: 0; }
#report.loading, #matrix.loading { opacity: .5; transition: opacity .15s; }

/* Verdict */
.verdict { border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface-1); }
.verdict.good { background: var(--good-wash); border-color: var(--good); }
.verdict.bad { background: var(--critical-wash); border-color: var(--critical); }
.verdict-head { display: flex; gap: 12px; align-items: center; }
.verdict-title { font-size: 17px; font-weight: 700; }
.status-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; }
.good .status-icon { background: var(--good); }
.bad .status-icon { background: var(--critical); }
.checks { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 8px 20px; }
.checks li { display: flex; align-items: center; gap: 6px; }
.checks .mark { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; font-weight: 700; }
.checks .yes .mark { background: var(--good); }
.checks .no .mark { background: var(--critical); }
.note { margin: 10px 0 0; color: var(--text-secondary); }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 900px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 480px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile-label { font-size: 12px; color: var(--text-secondary); }
.tile-value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.tile-sub { font-size: 12px; color: var(--text-muted); }

/* Chart */
.legend { display: flex; gap: 18px; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.chart { position: relative; height: 320px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--text-muted); font-size: 11px; }
.chart .end-label { fill: var(--text-primary); font-size: 12px; font-weight: 600; }
.chart .end-name { fill: var(--text-secondary); font-size: 11px; }
.chart .baseline { stroke: var(--text-muted); stroke-dasharray: 3 3; stroke-width: 1; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; }
.chart .dot { stroke: var(--surface-1); stroke-width: 2; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 20; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12.5px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12); min-width: 160px;
}
.tooltip .tt-date { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row i { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; }
.tooltip .tt-row span { color: var(--text-secondary); }

/* Tables */
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 380px; overflow-y: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
.data th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface-1); white-space: nowrap; }
.data td { padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.data .num { text-align: right; }
.data tr.best td { background: var(--surface-2); font-weight: 600; }
.data tbody tr.clickable { cursor: pointer; }
.data tbody tr.clickable:hover td { background: var(--surface-2); }
.pos { color: var(--good-ink); }
.neg { color: var(--critical); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.pill.good::before { background: var(--good); }
.pill.bad::before { background: var(--critical); }
.pill.run::before { background: var(--warning); }

.empty { color: var(--text-secondary); max-width: 720px; padding: 24px 0; }
.card.empty { padding: 16px 20px; max-width: none; margin-top: 12px; }
.empty h2 { color: var(--text-primary); font-size: 18px; margin-bottom: 8px; }

/* Bots */
.bot { margin-top: 12px; }
.bot-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.bot-grid div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.bot-grid .k { font-size: 12px; color: var(--text-secondary); }
.bot-grid .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.log { background: var(--surface-2); border-radius: 8px; padding: 10px; font: 12px/1.5 ui-monospace, Consolas, monospace; max-height: 280px; overflow: auto; white-space: pre; }
code { font: 12.5px ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .badge { margin-left: 0; }
  main { padding: 16px; }
  footer { padding: 0 16px 24px; }
  .grid-2 { grid-template-columns: 1fr; }
  .filters label { flex: 1 1 40%; }
  .filters input, .filters select { min-width: 0; width: 100%; }
  #f-days { width: 100%; }
  .actions { flex: 1 1 100%; }
  .actions .btn { flex: 1; }
}

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; }
.login-wrap { width: 100%; max-width: 380px; padding: 24px 16px; }
.login-brand { justify-content: center; font-size: 18px; margin-bottom: 16px; }
.login-card { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.login-card input[type=email], .login-card input[type=password] {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
}
.login-card input:focus-visible, .filters input:focus-visible, .filters select:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.login-card label.check { flex-direction: row; align-items: center; gap: 8px; }
.login-card .error { margin: 0; }
.login-card .btn { padding: 9px 14px; }
.login-card.setup { gap: 6px; }
.login-card.setup p { margin: 0; }
.login-card.setup code { white-space: normal; word-break: break-all; }

/* Signed-in user */
.user { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-secondary); }
.badge + .user { margin-left: 0; }

/* Bot control */
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 10px 0; }
.notice ol { margin: 8px 0; padding-left: 20px; }
.notice li { margin-bottom: 6px; }
code.block { display: block; margin-top: 6px; white-space: normal; word-break: break-all; }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; font-weight: 600; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 7px; }
.filters label.wide select { min-width: 260px; }
#b-size, #b-stop { width: 110px; min-width: 0; }
#b-symbol { width: 120px; min-width: 0; }
#bot-control .filters { margin-top: 8px; }
@media (max-width: 640px) {
  .filters label.wide { flex: 1 1 100%; }
  .filters label.wide select { min-width: 0; }
  #b-size, #b-stop, #b-symbol { width: 100%; }
}
.filters input[type=checkbox] { min-width: 0; width: auto; padding: 0; }

/* Live mode */
.mode { display: flex; gap: 18px; flex-wrap: wrap; margin: 6px 0 4px; }
.mode label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.mode-live { color: var(--critical); font-weight: 700; }
.live-banner { background: var(--critical); color: #fff; font-weight: 700; padding: 8px 12px; border-radius: 8px; margin: 8px 0; letter-spacing: .02em; }
.live-confirm { flex: 1 1 100%; border: 2px solid var(--critical); background: var(--critical-wash); border-radius: 8px; padding: 10px 12px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.live-confirm p { flex: 1 1 100%; margin: 0; color: var(--text-primary); }
.live-confirm input { min-width: 180px; }
#bot-control.is-live { border: 2px solid var(--critical); }
#bot-control.is-live .btn.primary { background: var(--critical); border-color: var(--critical); }
.badge.live { background: var(--critical); color: #fff; border-color: var(--critical); font-weight: 700; }
.pill.live::before { background: var(--critical); }
.net-tag { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; margin-left: 8px; vertical-align: 2px; }
.net-tag.live { background: var(--critical); color: #fff; }
.net-tag.testnet { background: var(--surface-2); color: var(--text-secondary); }
.card.bot.is-live { border: 2px solid var(--critical); }
#b-maxtrades, #b-cooldown { width: 110px; min-width: 0; }
@media (max-width: 640px) { #b-maxtrades, #b-cooldown { width: 100%; } }

/* Performance */
.verdict.neutral { background: var(--surface-1); }
.grid-2-wide { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }
@media (max-width: 900px) { .grid-2-wide { grid-template-columns: 1fr; } }
.grid-2-wide .card h2 { margin-bottom: 8px; }
.tiles.tiles-12 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 900px) { .tiles.tiles-12 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 480px) { .tiles.tiles-12 { grid-template-columns: repeat(2, 1fr); } }
.tiles.tiles-12 .tile-value { font-size: 17px; }

/* Alerts */
details.setup { margin-top: 10px; }
details.setup summary { cursor: pointer; font-weight: 600; color: var(--text-secondary); }
details.setup ol { padding-left: 20px; }
details.setup li { margin-bottom: 8px; }
#al-actions { margin: 8px 0; }
details.setup h3 { font-size: 14px; margin: 16px 0 6px; }
.net-tag.paper { background: var(--series-1); color: #fff; }
