:root {
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  --series-1: #2a78d6; /* blue    - Outreach */
  --series-2: #1baf7a; /* aqua    - Engagement */
  --series-3: #eda100; /* yellow  - Vetting */
  --series-4: #008300; /* green   - Samples */
  --series-5: #4a3aa7; /* violet  - Follow-ups */
  --series-6: #e34948; /* red     - reserved */
  --series-7: #e87ba4; /* magenta - Discovery */
  --series-8: #eb6834; /* orange  - reserved */

  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-450: #2a78d6; --seq-600: #184f95;

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

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);

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

    --seq-100: #184f95; --seq-250: #184f95; --seq-450: #3987e5; --seq-600: #86b6ef;

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

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar .brand .sub {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar nav a {
  display: block;
  padding: 9px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.sidebar nav a:hover {
  background: var(--page-plane);
  text-decoration: none;
  color: var(--text-primary);
}

.sidebar nav a.active {
  border-left-color: var(--series-1);
  color: var(--text-primary);
  background: var(--page-plane);
}

.sidebar .meta {
  padding: 16px 20px 0;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 28px 36px 60px;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}

.page-header h1 {
  font-size: 22px;
  margin: 0;
}

.page-header .crumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ---------- Range toggle ---------- */
.range-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.range-toggle button {
  appearance: none;
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  cursor: pointer;
  font-family: inherit;
}

.range-toggle button + button { border-left: 1px solid var(--border); }
.range-toggle button:hover { background: var(--page-plane); }
.range-toggle button.active {
  background: var(--series-1);
  color: #fff;
}

/* ---------- Group section ---------- */
.kpi-group {
  margin-bottom: 30px;
}

.kpi-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-left: 10px;
  border-left: 4px solid var(--group-accent, var(--series-1));
}

.kpi-group-header h2 {
  font-size: 15px;
  margin: 0;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

/* ---------- Stat tile ---------- */
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat-tile .label {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.stat-tile .value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.stat-tile .value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-tile .delta {
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-tile .delta.up { color: var(--status-good-text); }
.stat-tile .delta.down { color: var(--status-critical); }
.stat-tile .delta.flat { color: var(--text-muted); }

.stat-tile .sparkline { margin-top: 8px; display: block; }
.stat-tile .sparkline path.line { fill: none; stroke: var(--seq-450); stroke-width: 2; }
.stat-tile .sparkline circle.point { fill: var(--seq-450); }

/* ---------- Outcome cards ---------- */
.outcome-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.outcome-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.outcome-card .value {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--status-good-text);
}

.outcome-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ---------- Funnel chart ---------- */
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.chart-card .chart-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.funnel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.funnel-row .stage-label {
  width: 130px;
  flex: 0 0 130px;
  font-size: 12.5px;
  color: var(--text-secondary);
  text-align: right;
}

.funnel-row .bar-track {
  flex: 1;
  background: var(--page-plane);
  border-radius: 4px;
  height: 20px;
  position: relative;
}

.funnel-row .bar-fill {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  border-radius: 4px;
  background: var(--seq-450);
}

.funnel-row .bar-value {
  width: 44px;
  flex: 0 0 44px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  font-weight: 600;
}

.table-view-toggle {
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 8px;
  display: inline-block;
}

.table-view {
  display: none;
  margin-top: 10px;
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}

.table-view.visible { display: table; }
.table-view th, .table-view td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
.table-view th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; }

/* ---------- Entity listing tables ---------- */
.entity-table-wrap { overflow-x: auto; }

.entity-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.entity-table th, .entity-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--gridline);
  font-size: 13.5px;
}

.entity-table th {
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  background: var(--page-plane);
}

.entity-table tr:last-child td { border-bottom: none; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--page-plane);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.pill.status-active, .pill.status-passed { color: var(--status-good-text); border-color: var(--status-good); }
.pill.status-inactive, .pill.status-failed, .pill.status-expired { color: var(--status-critical); border-color: var(--status-critical); }
.pill.status-new, .pill.status-pending, .pill.status-incomplete { color: var(--status-warning); border-color: var(--status-warning); }

/* ---------- Entity link + hover preview ---------- */
.entity-link {
  font-weight: 600;
  border-bottom: 1px dashed var(--series-1);
  cursor: pointer;
  position: relative;
}

.hover-preview {
  position: fixed;
  z-index: 100;
  max-width: 280px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 12px 14px;
  font-size: 13px;
  display: none;
  pointer-events: none;
}

.hover-preview.visible { display: block; }
.hover-preview .hp-title { font-weight: 700; margin-bottom: 6px; font-size: 13.5px; }
.hover-preview .hp-row { display: flex; justify-content: space-between; gap: 12px; color: var(--text-secondary); margin-bottom: 2px; }
.hover-preview .hp-row span:last-child { color: var(--text-primary); font-weight: 600; }
.hover-preview .hp-link { margin-top: 8px; display: block; font-size: 12.5px; font-weight: 600; }

/* ---------- Detail page ---------- */
.detail-shell {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 26px;
  max-width: 760px;
}

.detail-shell dl { display: grid; grid-template-columns: 160px 1fr; row-gap: 8px; column-gap: 12px; margin: 16px 0; }
.detail-shell dt { color: var(--text-muted); font-size: 12.5px; }
.detail-shell dd { margin: 0; font-size: 14px; font-variant-numeric: tabular-nums; }

.linked-section { margin-top: 22px; }
.linked-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin-bottom: 8px; }

/* ---------- Stub / fallback page ---------- */
.stub-notice {
  background: var(--surface-1);
  border: 1px dashed var(--baseline);
  border-radius: 10px;
  padding: 22px 26px;
  max-width: 620px;
  color: var(--text-secondary);
}

.stub-notice .stub-title { font-weight: 700; color: var(--text-primary); margin-bottom: 6px; font-size: 15px; }

/* ---------- Clickable widgets ---------- */
.stat-tile.clickable, .outcome-card.clickable, .chart-card.clickable {
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.stat-tile.clickable:hover, .outcome-card.clickable:hover, .chart-card.clickable:hover {
  border-color: var(--series-1);
}
.stat-tile.clickable:active, .outcome-card.clickable:active, .chart-card.clickable:active {
  transform: scale(0.99);
}
.clickable .expand-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
  visibility: hidden;
}
.clickable:hover .expand-hint, .clickable:focus-visible .expand-hint { visibility: visible; }
.clickable:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* ---------- Detail modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  z-index: 200;
  padding: 40px 20px;
}
.modal-overlay.visible { display: flex; }

.modal-box {
  background: var(--surface-1);
  border-radius: 14px;
  border: 1px solid var(--border);
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: modal-in 0.15s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body { padding: 20px 22px 24px; }

.detail-chart-wrap { position: relative; margin-bottom: 18px; }
.detail-chart-wrap svg { display: block; width: 100%; height: auto; }
.detail-chart-wrap .grid-line { stroke: var(--gridline); stroke-width: 1; }
.detail-chart-wrap .grid-label { fill: var(--text-muted); font-size: 10px; }
.detail-chart-wrap .x-label { fill: var(--text-muted); font-size: 10px; text-anchor: middle; }
.detail-chart-wrap .trend-line { fill: none; stroke: var(--seq-450); stroke-width: 2; }
.detail-chart-wrap .hover-dot { fill: var(--seq-450); opacity: 0; }
.detail-chart-wrap .crosshair { stroke: var(--baseline); stroke-width: 1; opacity: 0; pointer-events: none; }
.detail-chart-wrap .chart-tooltip {
  position: absolute;
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
  transform: translate(-50%, -110%);
}

.period-table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.period-table th, .period-table td {
  text-align: right;
  padding: 6px 10px;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  border-bottom: 1px solid var(--gridline);
}
.period-table th:first-child, .period-table td:first-child { text-align: left; font-variant-numeric: normal; color: var(--text-secondary); }
.period-table th { color: var(--text-muted); font-size: 11px; text-transform: uppercase; font-weight: 600; }

.records-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 10px; }
.records-list { list-style: none; margin: 0; padding: 0; }
.records-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 13px;
}
.records-list li:last-child { border-bottom: none; }
.records-list .rec-label { flex: 1; min-width: 0; }
.records-list .rec-label a { font-weight: 600; }
.records-list .rec-detail { display: block; color: var(--text-muted); font-size: 12px; margin-top: 1px; }
.records-list .rec-date { color: var(--text-muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.records-note { font-size: 12.5px; color: var(--text-muted); font-style: italic; }
.funnel-stage-group { margin-bottom: 16px; }
.funnel-stage-group h4 { font-size: 12.5px; margin: 0 0 6px; color: var(--text-secondary); }

@media (max-width: 720px) {
  .sidebar { display: none; }
  .main { padding: 20px; }
  .funnel-row .stage-label { width: 90px; flex-basis: 90px; }
}
