:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface-1: #fcfcfb; --surface-2: #f0efec; --line: #e2e1dc; --line-strong: #cfcec8;
  --text-primary: #0b0b0b; --text-secondary: #52514e; --text-muted: #85847e;
  --accent: #0b0b0b; --good: #0f7b3f; --warn: #a86400; --bad: #c42b2b;
  --grid: #ebeae6;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0f0f0e; --surface-1: #1a1a19; --surface-2: #232321; --line: #2e2e2b; --line-strong: #3d3d39;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #8d8c85;
    --accent: #ffffff; --good: #3fb56f; --warn: #e0a133; --bad: #ef6b6b; --grid: #2a2a27;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e; --surface-1: #1a1a19; --surface-2: #232321; --line: #2e2e2b; --line-strong: #3d3d39;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #8d8c85;
  --accent: #ffffff; --good: #3fb56f; --warn: #e0a133; --bad: #ef6b6b; --grid: #2a2a27;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text-primary); font: 14px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--accent); color: var(--surface-1); border-radius: 8px; padding: 7px 14px; }
button.ghost { background: transparent; color: var(--text-primary); }
button.icon { padding: 7px 11px; }
button:disabled { opacity: .45; cursor: default; }
input, select { background: var(--surface-1); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
a { color: inherit; }
.muted { color: var(--text-muted); } .small { font-size: 12px; } .err { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.top { position: sticky; top: 0; z-index: 6; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 10px 24px; background: var(--surface-1); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs button { background: transparent; color: var(--text-secondary); border-color: transparent; }
.tabs button.on { background: var(--surface-2); color: var(--text-primary); border-color: var(--line); }
.controls { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.providers { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-1); color: var(--text-secondary); white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.pill.warn .dot { background: var(--warn); } .pill.bad .dot { background: var(--bad); } .pill.bad { color: var(--bad); border-color: var(--bad); }

.filters { position: sticky; top: 55px; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 10px 24px; background: var(--bg); border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--text-secondary); padding: 6px 11px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--text-primary); color: var(--surface-1); }
.dates { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.dates input { padding: 5px 8px; font-size: 13px; }
.active-filters { position: sticky; top: 108px; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 24px; background: #fff4d6; border-bottom: 1px solid #f0d68a; color: #5c4400; font-size: 13px; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .active-filters { background: #3a2f10; border-color: #5c4a1a; color: #f3d98f; } }
.active-filters .reset { margin-left: 4px; background: #5c4400; color: #fff4d6; border: 0; padding: 5px 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; color: var(--text-primary); align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface-1); color: var(--text-primary); border-radius: 999px; padding: 4px 6px 4px 11px; font-size: 13px; }
.chip b { font-weight: 600; } .chip button { border: 0; background: var(--surface-2); color: var(--text-secondary); border-radius: 50%; width: 20px; height: 20px; padding: 0; line-height: 20px; }

main { max-width: 1480px; margin: 0 auto; padding: 20px 24px 60px; }
.login { max-width: 420px; margin: 30vh auto 0; display: flex; gap: 8px; } .login input { flex: 1; }
.login.bad input { border-color: var(--bad); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); font-weight: 650; margin: 26px 0 10px; }
h2:first-child { margin-top: 4px; }
.note { color: var(--text-muted); font-size: 12.5px; margin: -4px 0 12px; max-width: 900px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }
.kpi { background: var(--surface-1); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 8px; min-width: 0; }
.kpi .k { color: var(--text-secondary); font-size: 12.5px; display: flex; justify-content: space-between; gap: 8px; }
.kpi .v { font-size: 28px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .d { font-size: 12.5px; margin-top: 1px; font-variant-numeric: tabular-nums; }
.kpi .d.up { color: var(--good); } .kpi .d.down { color: var(--bad); } .kpi .d.flat { color: var(--text-muted); }
.kpi .spark { height: 38px; margin-top: 4px; }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 10px; min-width: 0; }
.card-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.chart { width: 100%; height: 360px; }
.chart.tall { height: 420px; } .chart.short { height: 300px; }
.full { margin-bottom: 12px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input[type=search] { flex: 1; min-width: 240px; }
.toolbar .spacer { flex: 1; }
.table-wrap { overflow: auto; background: var(--surface-1); border: 1px solid var(--line); border-radius: 12px; max-height: 70vh; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; font-weight: 650; color: var(--text-secondary); background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; user-select: none; }
th.sort { cursor: pointer; } th.sort:hover { color: var(--text-primary); }
th .arrow { font-size: 10px; margin-left: 4px; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
td.barcell { width: 140px; min-width: 110px; }
.minibar { height: 8px; border-radius: 0 4px 4px 0; background: #2a78d6; opacity: .85; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; }
.badge.bad { color: var(--bad); } .badge.warn { color: var(--warn); } .badge.good { color: var(--good); }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .25); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface-1); border-left: 1px solid var(--line); z-index: 10; overflow-y: auto; padding: 20px 24px 40px; }
.drawer .close { float: right; }
.drawer h1 { font-size: 19px; margin: 0 0 2px; word-break: break-all; }
.drawer .kpis { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.drawer .kpi .v { font-size: 22px; }
.actions { display: grid; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 12px; }
.actions .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
pre.json { background: var(--surface-2); border-radius: 10px; padding: 12px; overflow: auto; max-height: 360px; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.funnel-table td:first-child { font-weight: 600; }
@media (max-width: 700px) { main { padding: 14px 14px 40px; } .top, .filters { padding: 10px 14px; } .filters { top: 0; position: static; } .controls { margin-left: 0; } }

.preview { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.preview video, .preview img { width: 100%; border-radius: 10px; background: #000; max-height: 420px; object-fit: contain; }
.preview figure { margin: 0; } .preview figcaption { font-size: 12px; color: var(--text-muted); margin-top: 4px; word-break: break-all; }
.money { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.runway.bad { color: var(--bad); font-weight: 650; } .runway.warn { color: var(--warn); font-weight: 650; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--line); }
