:root {
  color-scheme: light;
  --surface-0: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --seq-450: #2a78d6;
  --status-good: #0ca30c;
  --status-good-bg: #e3f5e3;
  --status-warning: #fab219;
  --status-warning-bg: #fff4e0;
  --status-serious: #ec835a;
  --status-serious-bg: #fde7dd;
  --status-critical: #d03b3b;
  --status-critical-bg: #fbe4e4;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --seq-450: #3987e5;
    --status-good-bg: rgba(12, 163, 12, 0.16);
    --status-warning-bg: rgba(250, 178, 25, 0.16);
    --status-serious-bg: rgba(236, 131, 90, 0.16);
    --status-critical: #e66767;
    --status-critical-bg: rgba(230, 103, 103, 0.16);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 60px; }

.topnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.topnav .brand { font-weight: 650; font-size: 15px; }
.topnav .nav-links { display: flex; gap: 10px; flex-wrap: wrap; }
.topnav a {
  display: inline-flex; align-items: center; text-decoration: none; font-size: 13.5px; font-weight: 650;
  padding: 9px 18px; border-radius: 9px; border: 1px solid var(--border);
  color: var(--text-secondary); background: var(--surface-1);
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}
.topnav a:hover { color: var(--text-primary); border-color: var(--baseline); }
.topnav a.active {
  background: var(--seq-450); color: #fff; border-color: var(--seq-450);
  box-shadow: 0 2px 8px rgba(42, 120, 214, 0.35);
}
.topnav a.active:hover { color: #fff; }

.banner {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 24px;
}
.banner strong { color: var(--text-primary); }

h1 { font-size: 24px; font-weight: 650; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 640; margin: 0 0 4px; }
p.sub { color: var(--text-secondary); font-size: 14px; max-width: 640px; line-height: 1.5; margin: 0 0 20px; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
section { margin-bottom: 30px; }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 700px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.stat-tile .label { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-tile .value { font-size: 24px; font-weight: 650; }
.stat-tile .sub { font-size: 11.5px; color: var(--text-muted); margin-top: 6px; }

table.seg-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.seg-table th, table.seg-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); }
table.seg-table th { color: var(--text-secondary); font-weight: 600; font-size: 11.5px; }
table.seg-table td.num, table.seg-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.tier-pill { display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 650; border-radius: 6px; padding: 2px 7px; white-space: nowrap; }
.pill-good { color: var(--status-good); background: var(--status-good-bg); }
.pill-warning { color: var(--status-warning); background: var(--status-warning-bg); }
.pill-serious { color: var(--status-serious); background: var(--status-serious-bg); }
.pill-critical { color: var(--status-critical); background: var(--status-critical-bg); }

.explorer-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.explorer-controls input, .explorer-controls select {
  font: inherit; font-size: 12.5px; padding: 7px 10px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface-0); color: var(--text-primary);
}
.btn {
  font: inherit; font-size: 13px; font-weight: 600; padding: 8px 16px; border-radius: 8px; border: none;
  background: var(--seq-450); color: #fff; cursor: pointer;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.secondary { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }

.footer-note { font-size: 11.5px; color: var(--text-muted); margin-top: 40px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; flex-wrap: wrap; }
.toggle-btn {
  font-size: 12px; font-weight: 550; color: var(--text-secondary); background: transparent;
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 10px; cursor: pointer;
}
.toggle-btn:hover { color: var(--text-primary); border-color: var(--baseline); }
table.data-table { display: none; width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 14px; }
table.data-table.shown { display: table; }
table.data-table th, table.data-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); }
table.data-table th { color: var(--text-secondary); font-weight: 550; font-size: 12px; }
table.data-table td.num, table.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Risk tier stacked bar */
.tier-bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--surface-1); position: relative; }
.tier-seg { height: 100%; cursor: pointer; transition: filter .1s; }
.tier-seg:hover { filter: brightness(1.08); }
.tier-legend { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 14px; }
.tier-chip { display: flex; align-items: center; gap: 7px; font-size: 12.5px; }
.tier-chip .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.tier-chip .name { font-weight: 600; }
.tier-chip .stat { color: var(--text-secondary); }
.tier-callout {
  margin-top: 14px; padding: 10px 14px; border-radius: 8px; background: var(--status-good-bg);
  font-size: 13px; color: var(--text-primary); border: 1px solid var(--border);
}
.tier-callout b { color: var(--status-good); }

/* Bar charts */
.hbar-row { display: grid; grid-template-columns: 108px 1fr; align-items: center; gap: 10px; margin-bottom: 6px; }
.hbar-row:last-child { margin-bottom: 0; }
.hbar-label { font-size: 12.5px; color: var(--text-secondary); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { position: relative; height: 22px; background: var(--grid); border-radius: 4px; }
.hbar-fill { position: absolute; left: 0; top: 0; height: 100%; background: var(--seq-450); border-radius: 4px 6px 6px 4px; }
.hbar-value { position: absolute; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 600; color: var(--text-primary); white-space: nowrap; }
.chart-card h3 { font-size: 13.5px; font-weight: 620; margin: 0 0 2px; }
.chart-card .chart-note { font-size: 11.5px; color: var(--text-muted); margin-bottom: 12px; }
.seg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .seg-grid { grid-template-columns: 1fr; } }

/* Segment table flag */
tr.flagged td:first-child { border-left: 3px solid var(--status-critical); }
.flag-pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 650; color: var(--status-critical); background: var(--status-critical-bg); border-radius: 6px; padding: 2px 7px; }

/* Line chart */
.line-chart-wrap { position: relative; }
.line-tooltip {
  position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,0.12);
  opacity: 0; transition: opacity .1s; white-space: nowrap; z-index: 5;
}

/* Drivers panel */
.drivers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
@media (max-width: 760px) { .drivers-grid { grid-template-columns: 1fr; } }
.driver-list { list-style: none; margin: 10px 0 0; padding: 0; }
.driver-list li { display: flex; gap: 9px; align-items: flex-start; font-size: 13px; padding: 6px 0; line-height: 1.4; }
.driver-list .arrow { flex: none; width: 18px; height: 18px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; margin-top: 1px; }
.arrow.up { background: var(--status-critical-bg); color: var(--status-critical); }
.arrow.down { background: var(--status-good-bg); color: var(--status-good); }
.governance-note {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 9px; background: var(--status-warning-bg);
  border: 1px solid var(--border); font-size: 12.5px; line-height: 1.5;
}
.governance-note .icon { flex: none; font-weight: 700; color: var(--status-warning); }

/* Explorer table */
table.explorer-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.explorer-table th, table.explorer-table td { text-align: left; padding: 8px 9px; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.explorer-table th { color: var(--text-secondary); font-weight: 600; font-size: 11px; white-space: nowrap; }
table.explorer-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.explorer-table td.reasons { font-size: 11.5px; color: var(--text-secondary); line-height: 1.5; }
.outcome-pill { font-size: 10.5px; padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.outcome-pill.paid { color: var(--status-good); background: var(--status-good-bg); }
.outcome-pill.charged { color: var(--status-critical); background: var(--status-critical-bg); }
.explorer-count { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.explorer-pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 12.5px; }
.filter-hint { font-size: 11.5px; color: var(--text-muted); margin-top: -6px; margin-bottom: 12px; }

/* Both-ends cards */
.ends-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 760px) { .ends-grid { grid-template-columns: 1fr; } }
.ends-col h3 { font-size: 13px; margin: 0 0 10px; display: flex; align-items: center; gap: 7px; }
.loan-example { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.loan-example .row1 { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; margin-bottom: 6px; }
.loan-example .idline { color: var(--text-muted); font-size: 11.5px; }
.loan-example .score { font-weight: 650; }
.loan-example .reasons { font-size: 12px; color: var(--text-secondary); line-height: 1.55; margin-top: 4px; }

/* Analyst panel */
details.analyst { border: 1px solid var(--border); border-radius: 12px; background: var(--surface-1); }
details.analyst summary {
  cursor: pointer; padding: 14px 20px; font-size: 13.5px; font-weight: 620;
  display: flex; align-items: center; justify-content: space-between; list-style: none;
}
details.analyst summary::-webkit-details-marker { display: none; }
details.analyst summary .chev { color: var(--text-muted); font-size: 12px; transition: transform .15s; }
details.analyst[open] summary .chev { transform: rotate(90deg); }
.analyst-body { padding: 0 20px 20px; font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.analyst-metrics { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin: 4px 0 16px; }
@media (max-width: 760px) { .analyst-metrics { grid-template-columns: repeat(2,1fr); } }
.analyst-metric { background: var(--surface-0); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.analyst-metric .n { font-size: 18px; font-weight: 650; color: var(--text-primary); }
.analyst-metric .l { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.calibration-note { background: var(--surface-0); border-left: 3px solid var(--seq-450); border-radius: 0 8px 8px 0; padding: 10px 14px; margin-top: 8px; }
