/* Bets panel: dark, mobile first. Tokens follow the dataviz reference palette (dark steps). */
:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --up: #3987e5;
  --down: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --radius: 14px;
  --gap: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary); font: 15px/1.45 var(--font); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 26px; }
h2 { font-size: 15px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.error { color: var(--down); min-height: 1.2em; margin: 0; font-size: 13px; }

.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid var(--surface-3); flex: none; }
.avatar-xl { width: 112px; height: 112px; border-width: 3px; box-shadow: 0 0 0 4px rgba(57, 135, 229, 0.25); }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 22px;
  padding: 28px 22px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.login-card p { margin: 0; }
.field { width: 100%; display: flex; flex-direction: column; gap: 6px; text-align: left; margin-top: 8px; }
.field span { font-size: 12px; color: var(--text-secondary); }
input, select { font: inherit; color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 12px; min-height: 44px; width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn { font: inherit; border: 0; border-radius: 10px; min-height: 44px; padding: 0 16px; cursor: pointer; }
.btn-primary { width: 100%; background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 0 8px; min-height: 36px; font-size: 13px; }

/* ---------------------------------------------------------------- layout */
.app { max-width: 1100px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 12px 0;
  background: linear-gradient(var(--page) 80%, rgba(13, 13, 13, 0)); }
.topbar-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.topbar-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.pill.ok::before { background: var(--good); }
.pill.degraded::before { background: var(--warning); }
.pill.down::before { background: var(--critical); }

.tabs { display: flex; gap: 4px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.tab { flex: 1; font: inherit; font-weight: 600; font-size: 14px; color: var(--text-secondary); background: transparent;
  border: 0; border-radius: 9px; min-height: 40px; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--surface-3); color: var(--text-primary); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; align-items: center; }
.filters select { width: auto; flex: 1 1 160px; min-height: 40px; padding: 8px 10px; }
.segmented { display: flex; gap: 2px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented button { font: inherit; font-size: 13px; color: var(--text-secondary); background: transparent; border: 0;
  border-radius: 7px; padding: 0 10px; min-height: 34px; cursor: pointer; white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text-primary); font-weight: 600; }
.segmented-wide { overflow-x: auto; scrollbar-width: none; margin-bottom: 8px; }
.segmented-wide::-webkit-scrollbar { display: none; }
.segmented-wide button { flex: 1 0 auto; }

.view { display: flex; flex-direction: column; gap: var(--gap); }
.view.loading { opacity: 0.55; transition: opacity 0.2s; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.note { margin: 4px 2px 0; }

/* ---------------------------------------------------------------- run cards */
.cards { display: grid; grid-template-columns: 1fr; gap: 10px; }
.run-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px; cursor: pointer; text-align: left; color: inherit; font: inherit; width: 100%; }
.run-card:hover { border-color: rgba(255, 255, 255, 0.22); }
.run-card .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.run-card .head.sub { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.run-card .label { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.run-card .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-card .tag { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-card .total { font-weight: 700; font-size: 18px; white-space: nowrap; }
.run-card .sect { display: flex; align-items: center; gap: 8px; margin: 8px 0 3px; font-size: 11px; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-muted); }
.run-card .sect::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.run-card .row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px;
  color: var(--text-secondary); padding: 1px 0; }
.run-card .row .v { font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.run-card .row.muted .v { color: var(--text-muted); font-weight: 500; }
.run-card .row .v.strong { font-weight: 700; }
.run-card .row:has(.v.strong) { border-top: 1px dashed var(--border); margin-top: 2px; padding-top: 3px; }
.run-card .eff { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; font-size: 13px; color: var(--text-secondary); }
.run-card .eff b { font-weight: 700; font-variant-numeric: tabular-nums; }
.badge.prod { background: rgba(167, 139, 250, 0.25); color: var(--text-primary); }
.rank { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--surface-3); color: var(--text-secondary); }
.rank.best { background: rgba(57, 135, 229, 0.25); color: var(--text-primary); }
.rank.worst { background: rgba(230, 103, 103, 0.22); color: var(--text-primary); }
.cards-bar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px 12px; margin-top: 4px; }
.cards-bar .card-head { margin-bottom: 0; }
.sort { display: flex; align-items: center; gap: 8px; }
.sort select { width: auto; min-height: 40px; padding: 8px 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------------------------------------------------------------- run detail */
.run-head { display: flex; flex-direction: column; gap: 2px; }
.run-head .big { font-size: 34px; font-weight: 700; line-height: 1.1; }
.run-head .delta { font-size: 15px; font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.kpi .k { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .v { font-size: 18px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 11px; line-height: 1.3; color: var(--text-secondary); overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; height: 220px; touch-action: pan-y; }
.chart-sm { height: 160px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: 0.12; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; }
.chart .endlabel { font-size: 11px; font-weight: 600; fill: var(--text-secondary); }
.chart .bar:hover, .chart .bar.hot { filter: brightness(1.3); }
.chart .empty { fill: var(--text-muted); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); min-width: 140px; max-width: 260px; }
.tooltip .t { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .row b { font-variant-numeric: tabular-nums; }
.tooltip .row span { color: var(--text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.tooltip i { width: 12px; height: 2px; display: inline-block; border-radius: 1px; }

/* ---------------------------------------------------------------- lists */
.list { display: flex; flex-direction: column; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 2px; border-top: 1px solid var(--border); }
.item:first-child { border-top: 0; }
.item .q { font-size: 13px; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item .r { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .d { font-size: 12px; color: var(--text-muted); }
.item .dr { grid-column: 1 / -1; font-size: 13px; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.03em; padding: 1px 6px; border-radius: 5px;
  margin-right: 6px; vertical-align: 1px; background: var(--surface-3); color: var(--text-secondary); }
.badge.buy { background: rgba(57, 135, 229, 0.18); color: #86b6ef; }
.badge.sell { background: rgba(217, 89, 38, 0.2); color: #ec835a; }
.badge.win { background: rgba(12, 163, 12, 0.18); color: #3fcf3f; }
.badge.loss { background: rgba(208, 59, 59, 0.2); color: #f08a8a; }
.empty-list { padding: 18px 4px; color: var(--text-muted); font-size: 13px; text-align: center; }
.more { margin-top: 6px; }

@media (min-width: 640px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .chart { height: 280px; }
  .chart-sm { height: 180px; }
}
@media (min-width: 980px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #view-run { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #view-run[hidden] { display: none !important; }
  #view-run .run-head, #view-run .kpis, #view-run > .card:first-of-type, #view-run > .card:last-of-type { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* realised per-day table (run view) */
.dtable { margin-top: 10px; font-size: 13px; }
.drow { display: grid; grid-template-columns: 1.1fr 1.4fr 1fr 1fr 1fr 1fr; gap: 6px; padding: 6px 2px; border-top: 1px solid var(--border); }
.drow span:not(:first-child) { text-align: right; white-space: nowrap; }
.drow.dhead { border-top: 0; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.drow .strong { font-weight: 700; }
@media (max-width: 560px) {
  .drow { grid-template-columns: 1fr 1fr 1fr; }
  .drow.dhead span:nth-child(4), .drow.dhead span:nth-child(5),
  .drow span:nth-child(4), .drow span:nth-child(5) { display: none; }
  .drow span:nth-child(3) { display: none; }
}
.run-card .row .v.sub { font-weight: 500; }
.run-card .row:has(.v.sub) .k { padding-left: 10px; font-size: 12px; }

/* admin (basic) */
.admin-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.admin-form input:not([type=checkbox]) { flex: 1 1 180px; width: auto; }
.admin-form .btn-primary { width: auto; }
#admin-out { white-space: pre-wrap; word-break: break-all; margin: 8px 0 0; }

/* first-login authenticator modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(4px); }
.modal-card { width: 100%; max-width: 380px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 18px; padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.modal-card p { margin: 0; }
.qr { align-self: center; background: #fff; border-radius: 12px; padding: 8px; line-height: 0; }
.qr svg { width: 200px; height: 200px; }
#mfa-secret { word-break: break-all; font-size: 13px; }
