/* Analytics tab (analytics.js). Scoped to #analytics-view so the rest of the
   portal is untouched. Light by default; its own dark steps under
   prefers-color-scheme: dark. Chart colors: single-hue blue (sequential). */
#analytics-view {
  --an-surface: #fcfcfb;
  --an-card: #ffffff;
  --an-ink: #14110d;
  --an-ink-soft: #52514e;
  --an-border: #e7e1d7;
  --an-grid: #ebe8e2;
  --an-bar: #2a78d6;
  --an-bar-hover: #1c5cab;
  --an-heat-0: #f4f2ee;
  --an-heat-1: #cde2fb;
  --an-heat-2: #9ec5f4;
  --an-heat-3: #5598e7;
  --an-heat-4: #256abf;
  --an-heat-5: #184f95;
  /* Ink per heat step, chosen for >= 4.5:1 on that step. */
  --an-heat-ink-1: #0b0b0b;
  --an-heat-ink-2: #0b0b0b;
  --an-heat-ink-3: #0b0b0b;
  --an-heat-ink-4: #ffffff;
  --an-heat-ink-5: #ffffff;
  --an-tag-bg: #fde9d8;
  --an-tag-ink: #7a4a14;
  color-scheme: light;
  background: var(--an-surface);
  color: var(--an-ink);
  padding: 4px 0 24px;
}
@media (prefers-color-scheme: dark) {
  #analytics-view {
    --an-surface: #1a1a19;
    --an-card: #232321;
    --an-ink: #f4f3ef;
    --an-ink-soft: #c3c2b7;
    --an-border: #3a3a37;
    --an-grid: #33332f;
    --an-bar: #3987e5;
    --an-bar-hover: #6da7ec;
    --an-heat-0: #2a2a27;
    --an-heat-1: #104281;
    --an-heat-2: #1c5cab;
    --an-heat-3: #2a78d6;
    --an-heat-4: #5598e7;
    --an-heat-5: #9ec5f4;
    --an-heat-ink-1: #ffffff;
    --an-heat-ink-2: #ffffff;
    --an-heat-ink-3: #0b0b0b;
    --an-heat-ink-4: #0b0b0b;
    --an-heat-ink-5: #0b0b0b;
    --an-tag-bg: #4a3216;
    --an-tag-ink: #fde9d8;
    color-scheme: dark;
    border-radius: 12px;
    padding: 16px;
  }
}

#analytics-view .content-panel { background: var(--an-card); border-color: var(--an-border); color: var(--an-ink); }
#analytics-view .muted, #analytics-view .an-note, #analytics-view .status { color: var(--an-ink-soft); }
#analytics-view h2, #analytics-view h3, #analytics-view h4 { color: var(--an-ink); }
#analytics-view h3 { margin: 0 0 8px; font-size: 16px; }
#analytics-view h4 { margin: 16px 0 6px; font-size: 14px; }
#analytics-view select, #analytics-view button { font: inherit; }
#analytics-view label { color: var(--an-ink-soft); }

.an-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 12px 0 20px;
}
.an-kpi {
  background: var(--an-card);
  border: 1px solid var(--an-border);
  border-radius: 12px;
  padding: 14px 16px;
}
.an-kpi-label { font-size: 13px; color: var(--an-ink-soft); }
.an-kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; margin: 2px 0; color: var(--an-ink); font-variant-numeric: tabular-nums; }
.an-kpi-sub { font-size: 12px; color: var(--an-ink-soft); }

.an-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.an-section { margin-top: 16px; }
.an-section svg { width: 100%; height: auto; max-height: 220px; display: block; }
.an-bar { fill: var(--an-bar); }
.an-hit { fill: transparent; }
.an-hit:hover + .an-bar { fill: var(--an-bar-hover); }
.an-grid { stroke: var(--an-grid); stroke-width: 1; }
.an-axis { fill: var(--an-ink-soft); font-size: 11px; font-variant-numeric: tabular-nums; }

.an-table { width: 100%; margin-top: 8px; }
#analytics-view .an-table th, #analytics-view .an-table td { color: var(--an-ink); border-color: var(--an-border); }
#analytics-view .an-table { background: var(--an-card); border-color: var(--an-border); }
#analytics-view .an-table th { background: var(--an-surface); color: var(--an-ink-soft); }
#analytics-view .an-table tbody th { color: var(--an-ink); font-size: 13px; text-transform: none; letter-spacing: 0; }
#analytics-view .an-table tr:hover td:not(.an-cell) { background: var(--an-grid); }
#analytics-view .an-table code { color: var(--an-ink-soft); }
.an-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.an-table .an-group { text-align: center; }
.an-table-toggle { margin-top: 6px; font-size: 13px; color: var(--an-ink-soft); }
.an-scroll { overflow-x: auto; }

.an-heat td.an-cell { min-width: 52px; }
.an-cell-future { background: transparent; }
#analytics-view .an-table td.an-heat-0 { background: var(--an-heat-0); }
#analytics-view .an-table td.an-heat-1 { background: var(--an-heat-1); color: var(--an-heat-ink-1); }
#analytics-view .an-table td.an-heat-2 { background: var(--an-heat-2); color: var(--an-heat-ink-2); }
#analytics-view .an-table td.an-heat-3 { background: var(--an-heat-3); color: var(--an-heat-ink-3); }
#analytics-view .an-table td.an-heat-4 { background: var(--an-heat-4); color: var(--an-heat-ink-4); }
#analytics-view .an-table td.an-heat-5 { background: var(--an-heat-5); color: var(--an-heat-ink-5); }

.an-tag {
  display: inline-block;
  font-size: 11px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--an-tag-bg);
  color: var(--an-tag-ink);
  margin-left: 4px;
}
.an-empty { color: var(--an-ink-soft); font-style: italic; margin: 8px 0; }
.an-two { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.an-defs { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 13px; color: var(--an-ink-soft); }
.an-defs dt { font-weight: 600; color: var(--an-ink); }
.an-defs dd { margin: 0; }
