/* High Jump Analytics dashboard chrome.
   Tokens follow the validated reference dataviz palette (light + dark selected
   independently); charts are drawn against the role names, never raw hex. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;  /* blue */
  --series-2: #eb6834;  /* orange */
  --series-3: #1baf7a;  /* aqua */
  --series-4: #eda100;  /* yellow */
  --series-5: #e87ba4;  /* magenta */
  --delta-good: #006300;
  --delta-bad: #d03b3b;
  --seq-100: #cde2fb; --seq-200: #9ec5f4; --seq-300: #6da7ec;
  --seq-400: #3987e5; --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --delta-good: #0ca30c;
    --delta-bad: #e66767;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand svg { border-radius: 5px; }
.auth-area { display: flex; align-items: center; gap: 10px; color: var(--text-secondary); font-size: 13px; }
.auth-area .dev-badge {
  background: color-mix(in srgb, var(--series-4) 18%, var(--surface-1));
  border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px;
  color: var(--text-secondary); font-size: 12px;
}
.auth-area button { font: inherit; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 20px 60px; }

/* one filter row above everything it scopes */
.filters {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: end;
  margin: 6px 0 18px;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.filters select {
  font: inherit; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; min-width: 140px;
}

/* KPI row of stat tiles */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px 12px;
}
.tile .label { font-size: 12px; color: var(--text-secondary); }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px 16px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.card-note { margin: 0 0 10px; font-size: 12px; color: var(--text-muted); }
.card-body { position: relative; }
.card-body.loading { opacity: 0.45; transition: opacity 0.15s; }
.view-toggle {
  font: inherit; font-size: 12px; color: var(--text-secondary);
  background: none; border: 1px solid var(--border); border-radius: 7px;
  padding: 3px 10px; cursor: pointer;
}
.view-toggle:hover { background: color-mix(in srgb, var(--text-primary) 5%, transparent); }
.empty { color: var(--text-muted); padding: 24px 0; text-align: center; }

/* legend: swatch mirrors the mark (rect for bars/areas, line for lines) */
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 2px 0 8px; font-size: 12px; color: var(--text-secondary); }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch-rect { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .swatch-line { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

svg.chart { display: block; width: 100%; height: auto; }
svg.chart text { font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--text-muted); }
svg.chart .tick-label { font-variant-numeric: tabular-nums; }
svg.chart .end-label { fill: var(--text-secondary); font-weight: 600; }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
svg.chart .crosshair { stroke: var(--baseline); stroke-width: 1; }
svg.chart .hit { fill: transparent; }
svg.chart .cell-label { font-variant-numeric: tabular-nums; }

/* tooltip: values lead, labels follow; line keys not boxes */
.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
  max-width: 260px;
}
.tooltip .tt-title { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .tt-name { color: var(--text-secondary); }

/* tables (also the accessibility view of every chart) */
table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
  font-variant-numeric: tabular-nums;
}
table.data th {
  text-align: right; font-weight: 600; color: var(--text-secondary);
  border-bottom: 1px solid var(--baseline); padding: 5px 8px; white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: color-mix(in srgb, var(--text-primary) 4%, transparent); }
table.data tr.selected td { background: color-mix(in srgb, var(--series-1) 12%, transparent); }
.table-scroll { max-height: 420px; overflow: auto; }

/* retention heatmap */
.heatmap { border-collapse: separate; border-spacing: 2px; font-size: 12px; font-variant-numeric: tabular-nums; }
.heatmap th { font-weight: 600; color: var(--text-secondary); padding: 2px 6px; text-align: center; }
.heatmap th.rowh { text-align: left; white-space: nowrap; font-weight: 400; color: var(--text-secondary); }
.heatmap td {
  min-width: 44px; height: 26px; text-align: center; border-radius: 4px;
  color: var(--text-secondary);
}
.heatmap td.reach0 { color: var(--text-muted); }

.gate { max-width: 420px; margin: 12vh auto; text-align: center; color: var(--text-secondary); }
.error-bar {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: var(--surface-1); border: 1px solid var(--delta-bad);
  color: var(--text-primary); border-radius: 8px; padding: 8px 14px; font-size: 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
