/* ---------- Tokens ---------- */
:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --ink-primary: #0b0b0b;
    --ink-secondary: #52514e;
    --ink-muted: #6f6e69;
    --hairline: rgba(11, 11, 11, 0.10);
    --gridline: #e1e0d9;
    --accent: #2a78d6;
    --accent-ink: #1c5cab;
    --map-empty: #e1e0d9;
    --map-border: #fcfcfb;
    --map-sea: #eef3f8;
    --font: system-ui, -apple-system, "Segoe UI", sans-serif;
    --radius: 12px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --ink-primary: #ffffff;
        --ink-secondary: #c3c2b7;
        --ink-muted: #a3a29b;
        --hairline: rgba(255, 255, 255, 0.10);
        --gridline: #2c2c2a;
        --accent: #3987e5;
        --accent-ink: #86b6ef;
        --map-empty: #383835;
        --map-border: #1a1a19;
        --map-sea: #141a21;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink-primary: #ffffff;
    --ink-secondary: #c3c2b7;
    --ink-muted: #a3a29b;
    --hairline: rgba(255, 255, 255, 0.10);
    --gridline: #2c2c2a;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --map-empty: #383835;
    --map-border: #1a1a19;
    --map-sea: #141a21;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--page);
    color: var(--ink-primary);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent-ink); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; font-weight: 650; }
h2 { font-size: 1.25rem; font-weight: 650; margin-bottom: .25rem; }
h3 { font-size: 1rem; font-weight: 600; }
h1:focus { outline: none; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 1000;
    display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--hairline);
}

.brand {
    display: flex; align-items: center; gap: 8px;
    font-weight: 700; font-size: 1.05rem; color: var(--ink-primary); text-decoration: none;
}
.brand-tld { color: var(--ink-muted); font-weight: 500; }
.brand-mark {
    width: 18px; height: 18px; border-radius: 5px;
    background: conic-gradient(#2a78d6 0 25%, #1baf7a 0 45%, #eda100 0 60%, #e87ba4 0 70%, #eb6834 0 100%);
}

.topnav { display: flex; gap: 4px; flex-wrap: wrap; }
.topnav a {
    padding: 6px 12px; border-radius: 8px;
    color: var(--ink-secondary); text-decoration: none; font-weight: 500;
}
.topnav a:hover { background: var(--hairline); color: var(--ink-primary); }
.topnav a.active { background: var(--hairline); color: var(--ink-primary); }

.content { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 24px; }

.footer {
    padding: 16px 24px; color: var(--ink-muted); font-size: .8rem;
    border-top: 1px solid var(--hairline); text-align: center;
}

/* ---------- Page header & filters ---------- */
.page-head {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.lede { color: var(--ink-secondary); margin: 6px 0 0; max-width: 70ch; }
.crumbs { margin: 0 0 4px; font-size: .85rem; color: var(--ink-muted); }
.crumbs a { color: var(--ink-muted); }

.filters { display: flex; gap: 12px; flex-wrap: wrap; }
.filters label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: .8rem; color: var(--ink-secondary); font-weight: 500;
}
.filters select {
    min-width: 220px; max-width: 100%;
    padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--hairline); background: var(--surface); color: var(--ink-primary);
    font: inherit; font-size: .9rem;
}

/* ---------- Cards & grids ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius);
    padding: 16px 16px 12px;
    margin-bottom: 16px;
    min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.card-sub { margin: 2px 0 0; color: var(--ink-muted); font-size: .82rem; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.section { margin-top: 32px; }
.subhead { margin: 8px 0 12px; font-size: 1.05rem; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
    display: flex; flex-direction: column; gap: 2px;
    background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius);
    padding: 14px 16px;
}
.stat-label { font-size: .8rem; color: var(--ink-secondary); }
.stat-value { font-size: 1.6rem; font-weight: 650; }
.stat-note { font-size: .75rem; color: var(--ink-muted); }

/* ---------- Segmented control ---------- */
.segmented { display: inline-flex; border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.segmented button {
    border: 0; background: transparent; color: var(--ink-secondary);
    padding: 4px 10px; font: inherit; font-size: .8rem; cursor: pointer;
}
.segmented button.active { background: var(--hairline); color: var(--ink-primary); font-weight: 600; }

/* ---------- Map ---------- */
.world-map { width: 100%; border-radius: 8px; background: var(--map-sea); }
.world-map.leaflet-container { background: var(--map-sea); font-family: var(--font); }
.world-map path.leaflet-interactive { cursor: pointer; }
.map-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 10px; font-size: .78rem; color: var(--ink-secondary); }
.legend-title { font-weight: 600; }
.legend-step { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.swatch-empty { background: var(--map-empty); }
.leaflet-tooltip.map-tooltip {
    background: var(--surface); color: var(--ink-primary);
    border: 1px solid var(--hairline); border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .15); font-family: var(--font);
}
.leaflet-tooltip.map-tooltip::before { display: none; }
.leaflet-container .leaflet-bar a,
.leaflet-container .leaflet-bar a:hover { background-color: var(--surface); color: var(--ink-primary); border-color: var(--hairline); }
.leaflet-container .leaflet-bar a.leaflet-disabled { background-color: var(--surface); color: var(--ink-muted); }

/* ---------- Charts ---------- */
.apexcharts-tooltip { font-family: var(--font) !important; }
.apexcharts-legend-text { color: var(--ink-secondary) !important; }

.table-view { margin-top: 4px; font-size: .82rem; }
.table-view summary { cursor: pointer; color: var(--ink-muted); padding: 4px 0; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .82rem; }
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--gridline); }
thead th { color: var(--ink-secondary); font-weight: 600; }
tbody th { font-weight: 500; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Misc ---------- */
.loading, .empty { color: var(--ink-muted); padding: 24px 0; }
.hint { margin: 0; font-size: .78rem; color: var(--ink-muted); }
.note { color: var(--ink-secondary); font-size: .85rem; max-width: 90ch; }
.callout {
    padding: 14px 16px; border-radius: var(--radius);
    background: var(--surface); border: 1px dashed var(--hairline); color: var(--ink-secondary);
}

.sector-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 12px; }
.sector-group { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 14px 16px; }
.sector-group ul { list-style: none; padding: 0; margin: 8px 0 0; columns: 2; column-gap: 16px; }
.sector-group li { padding: 3px 0; break-inside: avoid; }
.sector-group a { text-decoration: none; }
.sector-group a:hover { text-decoration: underline; }

table.sources th[scope="row"] { min-width: 200px; }
table.sources tr.used th[scope="row"] { font-weight: 600; }
.badge {
    display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
    font-size: .7rem; font-weight: 600; background: var(--hairline); color: var(--ink-primary);
}

@media (max-width: 640px) {
    .content { padding: 16px; }
    .topbar { padding: 10px 16px; gap: 8px; }
    .filters select { min-width: 0; width: 100%; }
    .filters, .filters label { width: 100%; }
    .sector-group ul { columns: 1; }
}

/* ---------- Blazor defaults ---------- */
.blazor-error-boundary {
    background: #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}
.blazor-error-boundary::after { content: "An error has occurred."; }
