/* Blue Marlin ATX — financial overview
   Palette validated with the dataviz palette validator:
   light 4 slots  → all checks pass (contrast WARN on aqua/yellow → every chart
                    ships a legend + table view, satisfying the relief rule)
   dark  4 slots  → all checks pass                                            */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --raise: 0 1px 2px rgba(11, 11, 11, 0.05), 0 1px 1px rgba(11, 11, 11, 0.04);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;

  /* Tenure is an ordered category, so it gets a single-hue ordinal ramp rather
     than four unrelated hues. Validated with --ordinal in both modes. */
  --tenure-1: #86b6ef;
  --tenure-2: #5598e7;
  --tenure-3: #2a78d6;
  --tenure-4: #184f95;

  /* Service tiers: a 5-step ordinal ramp, also validated, plus a neutral for
     the long tail so the stack always reads to 100%. */
  --tier-1: #86b6ef;
  --tier-2: #5598e7;
  --tier-3: #2a78d6;
  --tier-4: #1c5cab;
  --tier-5: #104281;
  --tier-other: #b9b8b0;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --delta-up: #006300;

  --wash: rgba(42, 120, 214, 0.1);
  --ghost: rgba(11, 11, 11, 0.04);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --raise: none;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --tenure-1: #cde2fb;
    --tenure-2: #9ec5f4;
    --tenure-3: #5598e7;
    --tenure-4: #184f95;
    --tier-1: #cde2fb;
    --tier-2: #9ec5f4;
    --tier-3: #6da7ec;
    --tier-4: #3987e5;
    --tier-5: #184f95;
    --tier-other: #6b6a65;
    --delta-up: #0ca30c;
    --wash: rgba(57, 135, 229, 0.14);
    --ghost: rgba(255, 255, 255, 0.05);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --raise: none;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --tenure-1: #cde2fb;
  --tenure-2: #9ec5f4;
  --tenure-3: #5598e7;
  --tenure-4: #184f95;
  --tier-1: #cde2fb;
  --tier-2: #9ec5f4;
  --tier-3: #6da7ec;
  --tier-4: #3987e5;
  --tier-5: #184f95;
  --tier-other: #6b6a65;
  --delta-up: #0ca30c;
  --wash: rgba(57, 135, 229, 0.14);
  --ghost: rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.95rem; }

p { margin: 0 0 0.75rem; }
p:last-child { margin-bottom: 0; }

.hidden { display: none !important; }

/* ---------------------------------------------------------------- sign-in */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--raise);
  padding: 32px;
}

.gate-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.gate-mark svg { display: block; }

.gate-mark span {
  font-weight: 650;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.gate-card h1 { font-size: 1.2rem; margin-bottom: 6px; }

.gate-sub {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 22px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.field input:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
  border-color: transparent;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 5px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
}

.btn-primary {
  width: 100%;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  background: var(--series-1);
}

.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:disabled { opacity: 0.55; cursor: default; filter: none; }

.btn-ghost {
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 550;
  color: var(--text-secondary);
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover { background: var(--ghost); color: var(--text-primary); }
.btn-ghost[aria-pressed='true'] { background: var(--ghost); color: var(--text-primary); }

.alert {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 0.84rem;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.alert-icon { flex: none; margin-top: 1px; }
.alert-error { background: rgba(208, 59, 59, 0.09); border-color: rgba(208, 59, 59, 0.32); }
.alert-good { background: rgba(12, 163, 12, 0.09); border-color: rgba(12, 163, 12, 0.3); }
.alert-warn { background: rgba(250, 178, 25, 0.11); border-color: rgba(250, 178, 25, 0.36); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ------------------------------------------------------------------ shell */

.shell { display: none; min-height: 100vh; flex-direction: column; }
.shell.on { display: flex; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: 4px; }
.brand-text { line-height: 1.15; }
.brand-text strong { display: block; font-size: 0.9rem; font-weight: 650; letter-spacing: -0.01em; }
.brand-text span { font-size: 0.72rem; color: var(--text-muted); }

.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }

.nav button {
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
}

.nav button:hover { background: var(--ghost); color: var(--text-primary); }
.nav button[aria-current='page'] { background: var(--series-1); color: #fff; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.who { text-align: right; line-height: 1.2; }
.who strong { display: block; font-size: 0.8rem; font-weight: 600; }
.who span { font-size: 0.72rem; color: var(--text-muted); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--text-secondary);
  background: transparent;
  border-color: var(--border);
}

.icon-btn:hover { background: var(--ghost); color: var(--text-primary); }

main { flex: 1; padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }

.page-head { margin-bottom: 20px; }
.page-head p { color: var(--text-secondary); font-size: 0.9rem; max-width: 78ch; }

.view { display: none; }
.view.on { display: block; }

/* ------------------------------------------------------------------ cards */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--raise);
  padding: 18px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}

.card-head h2, .card-head h3 { letter-spacing: -0.01em; }

.card-sub {
  color: var(--text-secondary);
  font-size: 0.82rem;
  margin-bottom: 14px;
  max-width: 80ch;
}

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1000px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  main { padding: 16px; }
  .topbar { padding: 10px 14px; }
}

/* ------------------------------------------------------- hero & stat tiles */

.hero { padding: 22px 20px; }
.hero-label { font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 2px; }

.hero-value {
  font-size: 3rem;
  font-weight: 640;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.hero-note { font-size: 0.82rem; color: var(--text-muted); margin-top: 6px; }

.tile { padding: 15px 16px; }
.tile-label { font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 3px; }
.tile-value { font-size: 1.5rem; font-weight: 620; letter-spacing: -0.02em; line-height: 1.15; }
.tile-note { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }
.tile-spark { margin-top: 8px; }

/* ----------------------------------------------------------------- charts */

.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: none;
}

.legend-line { width: 14px; height: 3px; border-radius: 2px; flex: none; }

.tooltip {
  position: absolute;
  z-index: 40;
  min-width: 150px;
  padding: 9px 11px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: 0 4px 14px rgba(11, 11, 11, 0.16);
  font-size: 0.8rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.08s;
}

.tooltip.on { opacity: 1; }
.tooltip-title { font-weight: 620; margin-bottom: 5px; }

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  color: var(--text-secondary);
}

.tooltip-row + .tooltip-row { margin-top: 3px; }
.tooltip-key { display: inline-flex; align-items: center; gap: 6px; }
.tooltip-val { font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 550; }

.tooltip-rule {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.axis-text { font-size: 11px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.axis-text-cat { font-size: 11.5px; fill: var(--text-secondary); }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: var(--axis); stroke-width: 1; }
.mark-label { font-size: 11px; font-weight: 600; fill: var(--text-primary); }
.hit { fill: transparent; cursor: default; }

/* ----------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--ghost); }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 620; border-top: 2px solid var(--axis); border-bottom: none; }
td.wrap { white-space: normal; min-width: 220px; }

.scroll-y { max-height: 460px; overflow-y: auto; }

.swatch-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: baseline;
}

/* ------------------------------------------------------------------ misc */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.pill-good { color: var(--delta-up); border-color: rgba(12, 163, 12, 0.4); background: rgba(12, 163, 12, 0.08); }
.pill-warn { color: var(--text-primary); border-color: rgba(250, 178, 25, 0.5); background: rgba(250, 178, 25, 0.14); }
.pill-bad { color: var(--critical); border-color: rgba(208, 59, 59, 0.4); background: rgba(208, 59, 59, 0.08); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.controls-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 2px;
}

select, .controls input[type='search'] {
  font: inherit;
  font-size: 0.84rem;
  padding: 6px 10px;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 11px 13px;
  border-left: 3px solid var(--axis);
  background: var(--ghost);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin-bottom: 14px;
}

.note strong { color: var(--text-primary); }
.note-warn { border-left-color: var(--warning); }
.note-critical { border-left-color: var(--critical); }

.def { margin-bottom: 13px; }
.def dt { font-weight: 620; font-size: 0.86rem; margin-bottom: 2px; }
.def dd { margin: 0; font-size: 0.84rem; color: var(--text-secondary); max-width: 86ch; }

.footer {
  padding: 18px 24px 28px;
  font-size: 0.76rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

.footer strong { color: var(--text-secondary); }

.check-ok { color: var(--delta-up); font-weight: 600; }
.check-bad { color: var(--critical); font-weight: 600; }

.toggle-row { display: flex; gap: 6px; align-items: center; flex: none; }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--border);
  border-top-color: var(--series-1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: -2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media print {
  .topbar, .controls, .toggle-row { display: none !important; }
  .view { display: block !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
