/* =========================================================================
   Design tokens (from the dataviz reference palette)
   ========================================================================= */
:root {
  color-scheme: light;

  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f2f1ed;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --baseline:        #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --border-strong:   rgba(11, 11, 11, 0.16);

  --series-1: #2a78d6; /* blue    */
  --series-2: #eb6834; /* orange  */
  --series-3: #1baf7a; /* aqua    */
  --series-4: #eda100; /* yellow  */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green   */
  --series-7: #4a3aa7; /* violet  */
  --series-8: #e34948; /* red     */

  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-400: #3987e5;
  --seq-450: #2a78d6;
  --seq-500: #256abf;
  --seq-600: #184f95;
  --seq-700: #0d366b;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;
  --success-text:    #006300;

  --shadow-sm: 0 1px 2px rgba(11,11,11,0.06);
  --shadow-md: 0 4px 16px rgba(11,11,11,0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --sidebar-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface-1:       #1a1a19;
    --surface-2:       #232322;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --grid:            #2c2c2a;
    --baseline:        #383835;
    --border:          rgba(255,255,255,0.10);
    --border-strong:   rgba(255,255,255,0.18);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --status-good:     #0ca30c;
    --status-warning:  #fab219;
    --status-serious:  #ec835a;
    --status-critical: #e66767;
    --success-text:    #0ca30c;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface-1:       #1a1a19;
  --surface-2:       #232322;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --grid:            #2c2c2a;
  --baseline:        #383835;
  --border:          rgba(255,255,255,0.10);
  --border-strong:   rgba(255,255,255,0.18);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #e66767;
  --success-text:    #0ca30c;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.5);
}

/* =========================================================================
   Reset & base
   ========================================================================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.45;
}
a { color: inherit; }
button { font-family: inherit; }
svg text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }

.tabular { font-variant-numeric: tabular-nums; }

/* =========================================================================
   App shell
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 20px;
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--series-1);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  flex: none;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 14px 10px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-link:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-link.active { background: var(--surface-2); color: var(--text-primary); }
.nav-link.active .nav-icon { color: var(--series-1); }
.nav-icon { width: 17px; height: 17px; flex: none; color: var(--text-muted); }
.nav-link.active .nav-icon { color: var(--series-1); }

.sidebar-footer {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---- Main column ---- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.project-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-1);
}
.project-avatar {
  width: 26px; height: 26px; border-radius: 999px;
  background: var(--series-3); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.project-picker-text { display: flex; flex-direction: column; line-height: 1.2; }
.project-picker-domain { font-weight: 600; font-size: 13px; }
.project-picker-meta { font-size: 11px; color: var(--text-muted); }

.topbar-spacer { flex: 1; }

.select-control {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.select-control select {
  border: none; background: none; font: inherit; color: var(--text-primary);
  cursor: pointer;
}
.select-control select:focus { outline: none; }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  border-radius: var(--radius-sm);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 17px; height: 17px; }

.page {
  padding: 24px 28px 60px;
  display: none;
  flex-direction: column;
  gap: 20px;
}
.page.active { display: flex; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* =========================================================================
   Cards, grids
   ========================================================================= */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title { font-size: 14px; font-weight: 600; }
.card-caption { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.card-title-group { display: flex; flex-direction: column; gap: 2px; }

.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 10px; font-weight: 700;
  cursor: help;
  flex: none;
}

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-split { grid-template-columns: 2fr 1fr; }
@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-split { grid-template-columns: 1fr; }
}

/* =========================================================================
   Stat tiles
   ========================================================================= */
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-value-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.stat-delta {
  font-size: 12.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
}
.stat-delta.up { color: var(--success-text); background: color-mix(in srgb, var(--status-good) 14%, transparent); }
.stat-delta.down { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 14%, transparent); }
.stat-delta.flat { color: var(--text-muted); background: var(--surface-2); }
.stat-foot { font-size: 11.5px; color: var(--text-muted); }
.stat-spark { margin-top: 2px; }

/* =========================================================================
   Badges / chips
   ========================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-dot { width: 6px; height: 6px; border-radius: 999px; flex: none; }
.badge.critical { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 16%, transparent); }
.badge.critical .badge-dot { background: var(--status-critical); }
.badge.warning { color: color-mix(in srgb, var(--status-warning) 55%, var(--text-primary) 45%); background: color-mix(in srgb, var(--status-warning) 22%, transparent); }
.badge.warning .badge-dot { background: var(--status-warning); }
.badge.notice { color: var(--text-secondary); background: var(--surface-2); }
.badge.notice .badge-dot { background: var(--text-muted); }
.badge.good { color: var(--success-text); background: color-mix(in srgb, var(--status-good) 16%, transparent); }
.badge.good .badge-dot { background: var(--status-good); }

.chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.tag-branded { color: var(--series-1); }
.tag-local { color: var(--series-3); }
.tag-informational { color: var(--text-secondary); }
.tag-transactional { color: var(--series-2); }

/* =========================================================================
   Tables
   ========================================================================= */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.data-table td.wrap { white-space: normal; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-primary { font-weight: 600; color: var(--text-primary); }
.cell-muted { color: var(--text-muted); }
.cell-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

.pos-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.pos-pill.tier-top { color: var(--success-text); background: color-mix(in srgb, var(--status-good) 16%, transparent); }
.pos-pill.tier-warn { color: color-mix(in srgb, var(--status-warning) 55%, var(--text-primary) 45%); background: color-mix(in srgb, var(--status-warning) 22%, transparent); }
.pos-pill.tier-low { color: var(--text-muted); background: var(--surface-2); }
.move { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.move.up { color: var(--success-text); }
.move.down { color: var(--status-critical); }
.move.flat { color: var(--text-muted); }

.serp-icons { display: inline-flex; gap: 4px; }
.serp-icon {
  width: 20px; height: 20px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  border: 1px solid var(--border);
}

/* =========================================================================
   Meters
   ========================================================================= */
.meter-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.meter-fill { height: 100%; border-radius: 999px; }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-row .meter-track { flex: 1; }
.meter-value { font-size: 12.5px; font-weight: 700; min-width: 32px; text-align: right; font-variant-numeric: tabular-nums; }

.gauge-wrap { display: flex; align-items: center; gap: 18px; }
.gauge-score { display: flex; flex-direction: column; }
.gauge-score .big { font-size: 34px; font-weight: 700; letter-spacing: -0.01em; }
.gauge-score .label { font-size: 12px; color: var(--text-muted); }

/* =========================================================================
   Legends / tooltip / charts chrome
   ========================================================================= */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.legend-key { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.legend-key.dot { width: 8px; height: 8px; border-radius: 999px; }
.legend-item.is-off { opacity: 0.35; }

.viz-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  z-index: 40;
  opacity: 0;
  transition: opacity 0.08s ease;
  min-width: 140px;
}
.viz-tooltip.show { opacity: 1; }
.viz-tooltip-title { font-weight: 600; margin-bottom: 5px; color: var(--text-primary); font-size: 11.5px; }
.viz-tooltip-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.viz-tooltip-row + .viz-tooltip-row { margin-top: 3px; }
.viz-tooltip-key { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.viz-tooltip-line { width: 10px; height: 2px; border-radius: 2px; flex: none; }
.viz-tooltip-val { font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }

.table-toggle-btn {
  font-size: 11.5px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}
.table-toggle-btn:hover { color: var(--text-primary); background: var(--surface-2); }

.chart-figure { position: relative; }
.chart-svg-wrap { position: relative; width: 100%; }
.chart-svg-wrap svg { width: 100%; display: block; overflow: visible; }

.hover-line { stroke: var(--baseline); stroke-width: 1; pointer-events: none; }
.mark-hit { fill: transparent; }

/* =========================================================================
   Misc
   ========================================================================= */
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 1180px) { .two-col { grid-template-columns: 1fr; } }

.list-clean { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 40px 20px; color: var(--text-muted); text-align: center;
}

.footnote {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.calc-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--series-1);
  background: color-mix(in srgb, var(--series-1) 14%, transparent);
  padding: 2px 6px;
  border-radius: 4px;
}

::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
