/* Tokens. Series colors are the validated reference categorical slots 1-4, fixed per platform. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --band: rgba(11, 11, 11, 0.08);
  --up: #006300;
  --down: #d03b3b;
  --good: #0ca30c;
  --critical: #d03b3b;
  --demo-bg: #fff4d6;
  --demo-ink: #7a5200;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --spotify: #2a78d6;
  --tiktok: #eb6834;
  --youtube: #1baf7a;
  --shazam: #eda100;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --band: rgba(255, 255, 255, 0.13);
    --up: #0ca30c;
    --down: #e66767;
    --demo-bg: #3a2e10;
    --demo-ink: #f5c86b;
    --shadow: none;
    --spotify: #3987e5;
    --tiktok: #d95926;
    --youtube: #199e70;
    --shazam: #c98500;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --band: rgba(255, 255, 255, 0.13);
  --up: #0ca30c;
  --down: #e66767;
  --demo-bg: #3a2e10;
  --demo-ink: #f5c86b;
  --shadow: none;
  --spotify: #3987e5;
  --tiktok: #d95926;
  --youtube: #199e70;
  --shazam: #c98500;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.container { max-width: 1200px; margin: 0 auto; padding: 24px 24px 64px; }
@media (max-width: 640px) { .container { padding: 16px 16px 48px; } }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--page) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
@media (max-width: 640px) { .topbar-inner { padding: 10px 16px; } }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand img { border-radius: 8px; }
:root[data-theme="dark"] .brand img { outline: 1px solid var(--border); }
.freshness { color: var(--muted); font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.pill-demo { background: var(--demo-bg); color: var(--demo-ink); }
.icon-btn, .ghost-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 10px;
  height: 34px; min-width: 34px; padding: 0 10px; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover, .ghost-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Filter row */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 4px 0 20px; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; cursor: pointer;
  color: var(--ink-2); font-weight: 500;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.search {
  height: 34px; min-width: 220px; flex: 0 1 280px; padding: 0 12px 0 34px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface) no-repeat 11px 50%/14px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23898781' stroke-width='1.6'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5' stroke-linecap='round'/%3E%3C/svg%3E");
  color: var(--ink); font: inherit;
}
.search:focus, .segmented button:focus-visible, .icon-btn:focus-visible, .ghost-btn:focus-visible { outline: 2px solid var(--spotify); outline-offset: 2px; }

/* Headings */
.page-head { margin: 8px 0 16px; }
.page-head h1 { font-size: 28px; line-height: 1.15; letter-spacing: -0.02em; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.back { display: inline-flex; gap: 6px; color: var(--ink-2); text-decoration: none; font-size: 13px; margin-bottom: 8px; }
.back:hover { color: var(--ink); }
.section-head { display: flex; align-items: baseline; gap: 10px; margin: 32px 0 12px; }
.section-head h2 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.section-head .count { color: var(--muted); font-size: 13px; }
.section-head .right { margin-left: auto; }

/* Loading keeps the frame: previous render stays, dimmed */
#app.is-loading > * { opacity: 0.55; transition: opacity 0.15s; pointer-events: none; }

/* Cards & tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.tile { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile-label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.tile-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.tile-value small { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.tile-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; background: var(--c); flex: none; }

.delta { font-weight: 600; font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat, .delta.new { color: var(--muted); }

/* Alerts */
.alerts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.alert {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; text-decoration: none;
  border-left: 3px solid var(--k); transition: transform 0.12s, box-shadow 0.12s;
}
.alert:hover, .alert:focus-visible { transform: translateY(-1px); box-shadow: 0 0 0 1px var(--border), 0 6px 24px rgba(0,0,0,0.08); outline: none; }
.alert.spike { --k: var(--good); }
.alert.drop { --k: var(--critical); }
.alert-top { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.status { font-weight: 700; font-size: 12px; display: inline-flex; gap: 4px; align-items: center; }
.alert.spike .status { color: var(--up); }
.alert.drop .status { color: var(--down); }
.alert-title { font-weight: 650; font-size: 15px; }
.alert-title span { color: var(--muted); font-weight: 500; }
.alert-detail { color: var(--ink-2); font-size: 13px; }
.alert-top .date { margin-left: auto; }
.empty { padding: 28px; text-align: center; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.empty code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: 12px; }

/* Charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.charts.stacked { grid-template-columns: 1fr; }
.chart-card { padding: 16px 16px 10px; min-width: 0; }
.chart-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.chart-head h3 { margin: 0; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.chart-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.chart-head .ghost-btn { margin-left: auto; height: 28px; font-size: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); margin: 4px 0 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch-band { width: 14px; height: 10px; background: var(--band); border-radius: 3px; }
.legend .swatch-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 2px var(--surface); }
.chart { position: relative; width: 100%; overflow: hidden; }
.chart svg { display: block; overflow: visible; }
.chart svg:focus-visible { outline: 2px solid var(--spotify); outline-offset: 2px; border-radius: 6px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .endlabel { fill: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--band); }
.chart .line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--c); opacity: 0.08; }
.chart .marker { stroke: var(--surface); stroke-width: 2; }
.chart .marker.spike { fill: var(--good); }
.chart .marker.drop { fill: var(--critical); }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .focus { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute; top: 8px; pointer-events: none; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.14); padding: 8px 10px; font-size: 12px; opacity: 0; transition: opacity 0.08s;
}
.tip.on { opacity: 1; }
.tip .t-date { color: var(--muted); margin-bottom: 4px; }
.tip .t-row { display: flex; align-items: center; gap: 8px; }
.tip .t-val { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.tip .t-sub { color: var(--ink-2); margin-top: 2px; }
.tip .t-alert { margin-top: 4px; font-weight: 600; }
.tip .t-alert.spike { color: var(--up); }
.tip .t-alert.drop { color: var(--down); }
.no-data { height: 160px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 14px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; min-width: 180px; }
thead th { font-size: 12px; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--grid); position: sticky; top: 0; background: var(--surface); }
thead th button { border: 0; background: none; cursor: pointer; font-weight: 600; color: inherit; padding: 0; display: inline-flex; align-items: center; gap: 6px; }
thead th button:hover { color: var(--ink); }
thead th[aria-sort] button { color: var(--ink); }
tbody td { border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--surface-2); }
.song-cell a { text-decoration: none; font-weight: 600; }
.song-cell a:hover { text-decoration: underline; }
.song-cell .artist { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.num { font-weight: 600; }
.num + .delta { margin-left: 6px; }
.spark { display: block; margin-left: auto; }
.spark path { fill: none; stroke: var(--c); stroke-width: 1.5; stroke-linejoin: round; }
.chart-table { max-height: 260px; overflow: auto; }

.table-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.note { margin-top: 32px; font-size: 12px; color: var(--muted); max-width: 720px; }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.login-card img { border-radius: 10px; }
.login-card h1 { margin: 8px 0 0; font-size: 22px; letter-spacing: -0.02em; }
.login-card p { margin: 0 0 12px; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.login-card input {
  height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--page); color: var(--ink);
  padding: 0 12px; font: inherit;
}
.login-card input:focus { outline: 2px solid var(--spotify); outline-offset: 1px; }
.login-error { color: var(--down); font-size: 13px; }
.primary-btn {
  margin-top: 8px; height: 40px; border: 0; border-radius: 10px; background: var(--ink); color: var(--page);
  font-weight: 600; cursor: pointer;
}
.primary-btn:hover { opacity: 0.9; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
