/* Palette roles from the validated reference palette (dataviz skill). */
:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-views: #2a78d6;    /* blue, slot 1 */
  --series-visitors: #1baf7a; /* aqua, slot 2 */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --delta-good: #006300;
  --wash: rgba(42, 120, 214, 0.12); /* bar-list fill wash */
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-views: #3987e5;
    --series-visitors: #199e70;
    --delta-good: #0ca30c;
    --wash: rgba(57, 135, 229, 0.18);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: light dark; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
main { max-width: 1100px; margin: 0 auto; padding: 0 20px 60px; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1100px; margin: 0 auto; padding: 16px 20px;
  flex-wrap: wrap; gap: 10px;
}
.brand { font-size: 18px; font-weight: 700; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
select {
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px;
}
.mini-select { font-size: 12px; padding: 3px 6px; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--ink-2);
}
/* "Other sites got traffic while you were looking elsewhere" — the badges
   inside the <select> are hidden until it is opened, so this carries it. */
.new-pill {
  font: inherit; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--wash); color: var(--ink);
  border: 1px solid var(--series-views);
  border-radius: 999px; padding: 6px 12px;
}
.new-pill::before {
  content: ''; flex: none;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--series-views);
  animation: pulse 2s ease-in-out infinite;
}
.new-pill:hover { filter: brightness(1.05); }
.new-pill.hidden { display: none; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--good);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---- Filter chips ---- */
.filter-bar {
  max-width: 1100px; margin: 0 auto 4px; padding: 0 20px 8px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.filter-label { color: var(--muted); font-size: 13px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
  color: var(--ink); cursor: pointer; font-family: inherit;
}
.chip b { font-weight: 600; }
.chip .x { color: var(--muted); font-weight: 700; }
.chip:hover .x { color: var(--critical); }
.chip-clear { color: var(--ink-2); }
.chip-danger { color: var(--critical); border-color: var(--critical); }
.chip-danger:hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }
.hidden { display: none !important; }

/* ---- Stat tiles ---- */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin: 8px 0 16px;
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.tile .label { font-size: 12.5px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.tile .delta { font-size: 12px; margin-top: 2px; color: var(--muted); }
.tile .delta.up { color: var(--delta-good); }
.tile .delta.down { color: var(--critical); }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px; flex-wrap: wrap;
}
.card h2 { font-size: 14.5px; font-weight: 650; }
.subtle { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
@media (max-width: 760px) { .grid { grid-template-columns: 1fr; } }

/* ---- Chart ---- */
.chart-wrap { position: relative; height: 260px; }
#chart { width: 100%; height: 100%; display: block; overflow: visible; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch-views { background: var(--series-views); }
.swatch-visitors { background: var(--series-visitors); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15); white-space: nowrap;
}
.tooltip .tt-date { color: var(--muted); margin-bottom: 3px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 2px; }
.tab {
  font: inherit; font-size: 12px; color: var(--muted);
  background: none; border: none; border-radius: 6px;
  padding: 4px 8px; cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); background: var(--wash); font-weight: 600; }

/* ---- Bar lists ---- */
.list { display: flex; flex-direction: column; gap: 3px; min-height: 60px; }
.list-head {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.04em; padding: 0 6px 2px;
}
.list-head .cols { display: flex; gap: 0; }
.list-head .cols span { width: 58px; text-align: right; }
.row {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 5px 6px; border-radius: 6px; cursor: pointer;
  border: none; background: none; font: inherit; color: var(--ink);
  text-align: left; width: 100%;
}
.row:hover { outline: 1.5px solid var(--series-views); }
.row .bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--wash); border-radius: 6px; z-index: 0;
}
.row .rlabel {
  position: relative; z-index: 1; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row .rvals { position: relative; z-index: 1; display: flex; }
.row .rvals span {
  width: 58px; text-align: right;
  font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px;
}
.row .rvals span:first-child { color: var(--ink); font-weight: 600; }
.empty { color: var(--muted); font-size: 13px; padding: 14px 6px; }

/* ---- Event property drill-down ---- */
.event-props { margin-top: 12px; border-top: 1px solid var(--grid); padding-top: 10px; }
.event-props h3 { font-size: 13px; margin-bottom: 8px; }
.event-props h4 { font-size: 12px; color: var(--ink-2); margin: 10px 0 4px; }
.props-close { float: right; }

/* ---- Realtime feed ---- */
.feed { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.feed-row {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 6px; border-radius: 6px; font-size: 13px;
  animation: feed-in 0.4s ease;
}
.feed-row:nth-child(odd) { background: color-mix(in srgb, var(--grid) 35%, transparent); }
@keyframes feed-in { from { opacity: 0; transform: translateY(-4px); } }
.feed-time { color: var(--muted); font-size: 11.5px; min-width: 88px; white-space: nowrap; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.feed-kind {
  font-size: 11px; font-weight: 650; border-radius: 5px; padding: 1px 7px; flex-shrink: 0;
}
.feed-kind.pv { color: var(--series-views); background: var(--wash); }
.feed-kind.ev { color: var(--delta-good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.feed-meta { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-empty { color: var(--muted); padding: 12px 6px; font-size: 13px; }

/* ---- Footer ---- */
.foot { color: var(--ink-2); font-size: 13px; }
.foot pre {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; margin: 8px 0; overflow-x: auto;
  font-size: 12.5px;
}
.foot code {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-size: 12.5px;
}
.foot summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

/* ---- Danger zone: pick sites, delete them together ---- */
.reset-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin: 10px 0 6px;
}
.reset-all { display: flex; align-items: center; gap: 7px; cursor: pointer; font-weight: 600; }
.reset-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 2px 14px; max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 12px;
}
.reset-group {
  grid-column: 1 / -1; color: var(--muted); font-size: 11.5px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; margin: 8px 0 2px;
}
.reset-group:first-child { margin-top: 0; }
.reset-site {
  display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reset-site input { flex: none; }
.reset-empty { color: var(--muted); }
#reset-data:disabled { opacity: .45; cursor: default; border-color: var(--border); color: var(--muted); }
#reset-data:disabled:hover { background: transparent; }

/* ---- Report download ---- */
.chip-export { font-weight: 600; }
.chip-export:hover { background: var(--wash); border-color: var(--series-views); }
.chip-primary {
  background: var(--series-views); border-color: var(--series-views);
  color: #fff; font-weight: 600;
}
.chip-primary:hover { filter: brightness(1.08); }

.export-dialog {
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--ink);
  padding: 0; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
}
.export-dialog::backdrop { background: rgba(0, 0, 0, .38); }
.export-form { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.export-form h2 { font-size: 16px; }
.export-form .subtle { color: var(--muted); font-size: 12.5px; }
.export-field {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
}
.export-field select { width: 100%; font-weight: 400; color: var(--ink); }
.export-check {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--ink-2); cursor: pointer;
}
.export-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.export-actions .chip { padding: 7px 16px; font-size: 13px; }
