*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ============================================================
   UNITED NATIONS - GLOBAL HEALTH EXPENDITURE EXPLORER
   Design system v3 - refined, minimal, institutional
   ============================================================ */

:root {
    /* United Nations brand colours (Pantone 2925) */
    --un-blue: #009EDB;
    --un-blue-dark: #0083B8;
    --un-blue-deep: #006A96;
    --un-white: #FFFFFF;

    --positive: #2E7D4F;
    --negative: #C0392B;

    --radius-lg: 4px;
    --radius: 3px;
    --radius-sm: 2px;
    --radius-xs: 2px;
    --font: 'Roboto', Helvetica, Arial, sans-serif;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    /* HUD block system */
    --hud-m: 14px;        /* margin from viewport edges */
    --hud-gap: 8px;       /* gap between sibling blocks */
    --hud-h: 44px;        /* standard block height */
    --radius-hud: 10px;
}

/* ---------- LIGHT THEME (default) - UN web standard ---------- */
[data-theme="light"] {
    --bg: #F2F2F2;
    --bg-deep: #FFFFFF;
    --surface: #FFFFFF;
    --surface-solid: #FFFFFF;
    --surface-hover: #F5F5F5;
    --surface-inset: #F7F7F7;
    --border: #DDDDDD;
    --border-bright: #BBBBBB;
    --text: #333333;
    --text-muted: #666666;
    --text-dim: #999999;
    --accent: var(--un-blue);
    --accent-strong: var(--un-blue-deep);
    --accent-soft: rgba(0, 158, 219, 0.08);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.14);
    --surface-hud: rgba(255, 255, 255, 0.86);
    --shadow-hud: 0 2px 10px rgba(15, 40, 60, 0.10), 0 0.5px 1.5px rgba(15, 40, 60, 0.08);
}

/* ---------- DARK THEME ---------- */
[data-theme="dark"] {
    --bg: #1A1A1A;
    --bg-deep: #111111;
    --surface: #232323;
    --surface-solid: #232323;
    --surface-hover: #2D2D2D;
    --surface-inset: rgba(255, 255, 255, 0.04);
    --border: rgba(255, 255, 255, 0.12);
    --border-bright: rgba(255, 255, 255, 0.22);
    --text: #F2F2F2;
    --text-muted: #A6A6A6;
    --text-dim: #757575;
    --accent: var(--un-blue);
    --accent-strong: #33B5E5;
    --accent-soft: rgba(0, 158, 219, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);
    --surface-hud: rgba(30, 30, 30, 0.82);
    --shadow-hud: 0 2px 12px rgba(0, 0, 0, 0.45), 0 0.5px 1.5px rgba(0, 0, 0, 0.4);
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-weight: 400;
    font-size: 14px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
}

#app { height: 100vh; width: 100vw; overflow: hidden; }
.hidden { display: none !important; }
button { font-family: var(--font); }

:focus-visible { outline: 2px solid var(--un-blue); outline-offset: 2px; }

/* ---------- Icon system ---------- */
.ic {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
    display: block;
}

/* ---------- Micro-label (shared) ---------- */
.kpi-label, .year-label, .stat-label, .metric-label, .comp-label,
.chip-label, .about-item-label, .legend-title,
.panel-overline, .insights-overline {
    font-size: 0.615rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-dim);
}

/* ---------- UN emblem ---------- */
.un-logo-img { display: block; object-fit: contain; }
.splash-logo { width: 76px; height: 76px; margin: 0 auto 26px; }
.about-logo { width: 48px; height: 48px; flex-shrink: 0; }

/* ---------- Country flags ---------- */
.country-flag {
    display: block;
    object-fit: cover;
    border-radius: var(--radius-xs);
    border: 1px solid var(--border);
    background: var(--surface-inset);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.panel-flag { width: 52px; height: 36px; }
.result-flag { width: 22px; height: 15px; }
.result-left { display: flex; align-items: center; gap: 9px; min-width: 0; }

/* ============================================================
   SPLASH
   ============================================================ */
#splash {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-deep);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.8s ease;
    overflow: hidden;
}
#splash.fade-out { opacity: 0; pointer-events: none; }

.splash-content {
    position: relative;
    text-align: center;
    max-width: 540px;
    padding: 0 24px;
    animation: splashIn 0.7s var(--ease-out) both;
}

.splash-overline {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    color: var(--un-blue);
    margin-bottom: 14px;
}

.splash-title {
    font-size: 2rem;
    font-weight: 400;
    color: var(--text);
    line-height: 1.25;
}

.splash-divider { width: 44px; height: 2px; background: var(--un-blue); margin: 22px auto; }

.splash-desc { font-size: 0.9375rem; color: var(--text-muted); line-height: 1.6; }
.splash-meta { font-size: 0.78rem; color: var(--text-dim); margin-top: 12px; }

@keyframes splashIn {
    0% { opacity: 0; transform: translateY(14px); }
    100% { opacity: 1; transform: translateY(0); }
}

.splash-progress {
    width: 200px;
    height: 2px;
    margin: 30px auto 0;
    background: var(--border);
    border-radius: 1px;
    overflow: hidden;
}
.splash-progress-bar {
    width: 0%;
    height: 100%;
    background: var(--un-blue);
    border-radius: 1px;
    transition: width 0.4s ease;
}
.splash-status { font-size: 0.72rem; color: var(--text-dim); margin-top: 12px; min-height: 1.2em; letter-spacing: 0.04em; }

/* ============================================================
   HUD - floating block system
   Blocks live in anchored zones; every block shares the same
   surface, radius, shadow and a common 44px control height.
   ============================================================ */
.hud-zone {
    position: absolute;
    z-index: 9;
    display: flex;
    flex-direction: column;
    gap: var(--hud-gap);
    pointer-events: none;
}
.hud-zone > * { pointer-events: auto; }

.hud-top-left {
    top: var(--hud-m);
    left: var(--hud-m);
    width: 280px;
    align-items: stretch;
}

.hud-top-right {
    top: var(--hud-m);
    right: var(--hud-m);
    flex-direction: row;
    align-items: stretch;
}

.hud-bottom-left { bottom: var(--hud-m); left: var(--hud-m); align-items: flex-start; }

.hud-bottom-center {
    bottom: var(--hud-m);
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
    z-index: 10;
}

/* Desktop: when the country panel is open, slide the top-right stats
   and tools clear of it instead of letting the panel cover them. */
@media (min-width: 769px) {
    .hud-top-right { transition: right 0.45s var(--ease-out); }
    #globe-container:has(#detail-panel.visible) .hud-top-right {
        right: calc(var(--hud-m) + 384px + 10px);
    }
}

.float-block {
    background: var(--surface-hud);
    border: 1px solid var(--border);
    border-radius: var(--radius-hud);
    box-shadow: var(--shadow-hud);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
}

@keyframes hudPop {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: none; }
}

/* ---------- Brand block ---------- */
.brand-org {
    font-size: 0.56rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.13em;
    color: var(--un-blue);
    line-height: 1;
}

#brand-float {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--hud-h);
    padding: 0 14px 0 11px;
}

.brand-float-logo { width: 27px; height: 27px; flex-shrink: 0; }

.brand-float-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.brand-short {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.1;
}

/* ---------- Stats block ---------- */
#stats-float {
    display: flex;
    align-items: center;
    gap: 13px;
    height: var(--hud-h);
    padding: 0 16px;
}

.hud-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    min-width: 0;
}

.hud-stat-label {
    font-size: 0.55rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    line-height: 1;
    max-width: 118px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hud-divider { width: 1px; align-self: stretch; margin: 9px 0; background: var(--border); flex-shrink: 0; }

#stats-float .year-value,
#stats-float .kpi-value {
    font-size: 1.02rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
#stats-float .year-value { color: var(--text); }
#stats-float .kpi-value { color: var(--accent-strong); }

/* ---------- Tools block ---------- */
#tools-float {
    display: flex;
    align-items: center;
    gap: 2px;
    height: var(--hud-h);
    padding: 0 5px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: calc(var(--radius-hud) - 4px);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.18s, background 0.18s;
}
.icon-btn:hover { color: var(--accent-strong); background: var(--surface-hover); }

.icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: block; }

.lang-btn {
    width: auto;
    min-width: 34px;
    padding: 0 9px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

/* ============================================================
   GLOBE
   ============================================================ */
#globe-container { width: 100%; height: 100%; position: relative; overflow: hidden; }
#globe-map { width: 100%; height: 100%; }
.mapboxgl-ctrl-logo, .mapboxgl-ctrl-attrib { display: none !important; }

/* ============================================================
   SEARCH & FILTERS
   ============================================================ */
#search-panel {
    display: flex;
    flex-direction: column;
    gap: var(--hud-gap);
    width: 100%;
}

.search-row {
    display: flex;
    align-items: center;
    height: var(--hud-h);
    padding: 0;
    overflow: hidden;
    transition: border-color 0.2s;
}
.search-row:focus-within { border-color: var(--un-blue); }

.search-input-wrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 0 0 13px;
    height: 100%;
}

/* "Filters" segment at the right end of the search bar */
.filters-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    align-self: stretch;
    flex-shrink: 0;
    padding: 0 11px 0 12px;
    background: transparent;
    border: none;
    border-left: 1px solid var(--border);
    border-radius: 0 calc(var(--radius-hud) - 1px) calc(var(--radius-hud) - 1px) 0;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.64rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.filters-toggle-btn:hover { color: var(--un-blue); background: var(--surface-hover); }
.filters-toggle-btn[aria-expanded="true"] { color: var(--un-blue); background: var(--accent-soft); }

.filters-toggle-btn .toggle-chevron {
    color: var(--text-dim);
    transition: transform 0.25s var(--ease-out);
}
.filters-toggle-btn[aria-expanded="true"] .toggle-chevron { transform: rotate(180deg); }

.filters-count {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--un-blue);
    border-radius: 999px;
    color: var(--un-white);
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1;
}

.search-icon { color: var(--text-dim); }
.search-brand-logo { display: none; flex-shrink: 0; }

#search-input {
    background: none; border: none; outline: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.83rem;
    width: 100%;
}
#search-input::placeholder { color: var(--text-dim); }

.search-filters {
    display: flex;
    flex-direction: column;
    background: var(--surface-hud);
    border: 1px solid var(--border);
    border-radius: var(--radius-hud);
    box-shadow: var(--shadow-hud);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    overflow: hidden;
}

.filters-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 13px 13px;
    overflow: hidden;
    max-height: 520px;
    opacity: 1;
    transition: max-height 0.35s var(--ease-out), opacity 0.25s ease, padding 0.35s var(--ease-out);
}

.search-filters.collapsed .filters-body {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    pointer-events: none;
}

.search-filters.collapsed {
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    margin-top: calc(var(--hud-gap) * -1);
}

.filter-row { display: flex; align-items: center; gap: 9px; }
.filter-icon { color: var(--text-dim); }

.search-filters select {
    width: 100%;
    padding: 7px 26px 7px 10px;
    background-color: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.75rem;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.15s;
}
.search-filters select:hover { border-color: var(--border-bright); }
.search-filters select:focus { border-color: var(--un-blue); }
.search-filters select option { background: var(--surface-solid); color: var(--text); }

.range-filter { padding-top: 1px; }

/* Expenditure bracket filter */
.expenditure-filter { padding-top: 1px; }

.expenditure-label {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 8px;
    font-size: 0.615rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
}

.expenditure-brackets {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.bracket-btn {
    padding: 6px 4px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.66rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    text-align: center;
    line-height: 1.2;
}

.bracket-btn:hover { color: var(--text); border-color: var(--border-bright); }

.bracket-btn.active {
    background: var(--un-blue);
    border-color: var(--un-blue);
    color: var(--un-white);
}

.expenditure-brackets .bracket-btn:nth-child(4),
.expenditure-brackets .bracket-btn:nth-child(5) {
    grid-column: span 1;
}

@media (min-width: 260px) {
    .expenditure-brackets {
        grid-template-columns: repeat(5, 1fr);
    }
    .expenditure-brackets .bracket-btn:nth-child(4),
    .expenditure-brackets .bracket-btn:nth-child(5) {
        grid-column: auto;
    }
}

.filters-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 7px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.filters-reset:hover { color: var(--accent-strong); border-color: var(--un-blue); }

/* Search results */
#search-results {
    list-style: none;
    background: var(--surface-hud);
    border: 1px solid var(--border);
    border-radius: var(--radius-hud);
    box-shadow: var(--shadow-hud);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    overflow: hidden;
    max-height: 246px;
    overflow-y: auto;
    display: none;
}
#search-results.open { display: block; }

#search-results li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 9px 13px;
    font-size: 0.8rem;
    color: var(--text);
    cursor: pointer;
    transition: background 0.12s;
}
#search-results li + li { border-top: 1px solid var(--border); }
#search-results li:hover { background: var(--surface-hover); }

#search-results li .result-value {
    font-size: 0.73rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--accent-strong);
}

#search-results li .result-value.no-value {
    color: var(--text-dim);
    font-weight: 500;
}

/* ============================================================
   LEGEND - toggle pill, panel opens upward
   ============================================================ */
#legend {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--hud-gap);
}

.legend-toggle {
    order: 2;
    display: flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    padding: 0 12px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.64rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    cursor: pointer;
    transition: color 0.15s;
}

.legend-toggle:hover { color: var(--un-blue); }
.legend-toggle .toggle-chevron { transition: transform 0.25s var(--ease-out); }
#legend.collapsed .legend-toggle .toggle-chevron { transform: rotate(180deg); }

.legend-body {
    order: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    width: 208px;
    animation: hudPop 0.25s var(--ease-out) both;
}

#legend.collapsed .legend-body { display: none; }

.legend-title {
    font-size: 0.62rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.legend-bar {
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, #8E1B10 0%, #C43D2B 35%, #E6DFCE 50%, #2F8F52 65%, #0A5C33 100%);
}

[data-theme="dark"] .legend-bar {
    background: linear-gradient(to right, #9A2015 0%, #CC4936 35%, #CFC7B4 50%, #37995A 65%, #0E6B3C 100%);
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 0.62rem;
    font-variant-numeric: tabular-nums;
    color: var(--text-dim);
    font-weight: 500;
}

/* ============================================================
   MAP TOOLTIP
   ============================================================ */
#tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    padding: 9px 13px;
    box-shadow: var(--shadow);
    z-index: 20;
    transition: opacity 0.15s ease;
    max-width: 240px;
}

.tooltip-name { font-size: 0.8rem; font-weight: 500; color: var(--text); margin-bottom: 2px; }
.tooltip-value { font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ============================================================
   DETAIL PANEL - country analysis
   ============================================================ */
#detail-panel {
    position: absolute;
    top: 0; right: 0;
    width: 384px;
    height: 100%;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 15;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.45s var(--ease-out);
}
#detail-panel.visible { transform: translateX(0); display: block !important; }

#panel-close { position: absolute; top: 14px; right: 14px; z-index: 2; }

#panel-content { padding: 24px 22px 26px; }

.panel-header { margin-bottom: 18px; }
.panel-overline { display: block; color: var(--un-blue); margin-bottom: 10px; }

.panel-title-row { display: flex; align-items: center; gap: 13px; padding-right: 34px; }
.panel-title-text { min-width: 0; flex: 1; }
.panel-title-text h2 { font-size: 1.3rem; font-weight: 500; line-height: 1.25; margin-bottom: 7px; }

.panel-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
    padding: 2px 9px;
    font-size: 0.61rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    border-radius: var(--radius-xs);
    background: var(--surface-inset);
    color: var(--text-muted);
    border: 1px solid var(--border);
    white-space: nowrap;
}

/* --- Hero metric --- */
.stat-hero {
    padding: 14px 16px 13px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-left: 3px solid var(--un-blue);
    border-radius: var(--radius);
    margin-bottom: 10px;
}

.stat-hero .stat-label { display: block; margin-bottom: 6px; }

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

.stat-hero-value {
    font-size: 2rem;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    color: var(--un-blue-deep);
    line-height: 1.05;
}
[data-theme="dark"] .stat-hero-value { color: var(--accent-strong); }

.stat-trend { font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-trend.up { color: var(--positive); }
.stat-trend.down { color: var(--negative); }

.stat-hero-note { display: block; font-size: 0.66rem; color: var(--text-dim); margin-top: 7px; }

/* --- Metric grid --- */
.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 22px;
}

.metric {
    padding: 10px 12px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-label { display: flex; align-items: center; gap: 6px; }
.metric-label .ic { color: var(--un-blue); }
.metric-label em { font-style: normal; opacity: 0.65; letter-spacing: 0.04em; }

.metric-value {
    font-size: 0.92rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Section titles --- */
.panel-chart-section h3,
.panel-section-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.66rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    margin-bottom: 11px;
}
.panel-chart-section h3 .ic,
.panel-section-title .ic { color: var(--un-blue); }

.panel-chart-section { margin-bottom: 22px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* --- Compare control --- */
.compare-control { position: relative; margin: 2px 0 10px; }

.compare-search { position: relative; display: flex; align-items: center; }
.compare-icon { position: absolute; left: 10px; color: var(--text-dim); pointer-events: none; }

#compare-input {
    width: 100%;
    padding: 7px 10px 7px 30px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.75rem;
    outline: none;
    transition: border-color 0.15s;
}
#compare-input:focus { border-color: var(--un-blue); }
#compare-input::placeholder { color: var(--text-dim); }

#compare-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 5;
    list-style: none;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-height: 170px;
    overflow-y: auto;
    overflow-x: hidden;
    display: none;
}
#compare-results.open { display: block; }

#compare-results li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    font-size: 0.75rem;
    color: var(--text);
    cursor: pointer;
}
#compare-results li + li { border-top: 1px solid var(--border); }
#compare-results li:hover { background: var(--surface-hover); }

.compare-active {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text);
}
.compare-swatch { width: 14px; height: 0; border-top: 2px dashed var(--text-muted); flex-shrink: 0; }
.compare-flag { width: 20px; height: 14px; }

#compare-remove {
    margin-left: auto;
    width: 20px; height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: color 0.15s;
}
#compare-remove:hover { color: var(--negative); }

/* --- Chart --- */
.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 150px;
    border-radius: var(--radius);
    background: var(--surface-inset);
    border: 1px solid var(--border);
    overflow: hidden;
}
#panel-chart { display: block; width: 100%; height: 100%; }

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 3;
    background: var(--surface-solid);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-xs);
    padding: 5px 9px;
    font-size: 0.675rem;
    line-height: 1.5;
    color: var(--text);
    white-space: nowrap;
    box-shadow: var(--shadow);
}
.chart-tooltip strong { font-variant-numeric: tabular-nums; }

.chart-legend { display: flex; gap: 14px; margin-top: 9px; flex-wrap: wrap; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.7rem; color: var(--text-muted); }
.chart-legend-item strong { color: var(--text); font-variant-numeric: tabular-nums; }
.legend-swatch { width: 16px; height: 0; flex-shrink: 0; }
.legend-swatch.primary { border-top: 2px solid var(--un-blue); }
.legend-swatch.secondary { border-top: 2px dashed var(--text-muted); }

/* --- Benchmarks --- */
.panel-comparisons { display: flex; flex-direction: column; gap: 8px; }

.comparison-card {
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 11px 13px;
}

.comparison-rank {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.comparison-rank .comp-label { margin: 0; }

.comp-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 8px;
}
.comp-label { display: block; }
.comp-value { font-size: 0.9rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

.comp-bar-wrapper {
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    position: relative;
    overflow: visible;
}
.comp-bar { height: 100%; border-radius: 3px; transition: width 0.5s ease; min-width: 2px; }
.comp-bar-marker {
    position: absolute;
    top: -3px;
    width: 2px; height: 11px;
    background: var(--text-muted);
    border-radius: 1px;
    transition: left 0.5s ease;
}

/* ============================================================
   INSIGHTS DRAWER
   ============================================================ */
#insights-panel {
    position: absolute;
    top: var(--hud-m);
    left: var(--hud-m);
    bottom: var(--hud-m);
    z-index: 14;
    width: 368px;
    max-width: calc(100% - var(--hud-m) * 2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--un-blue);
    border-radius: var(--radius-hud);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    transform: translateX(calc(-100% - 48px));
    transition: transform 0.45s var(--ease-out);
}
#insights-panel.visible { transform: translateX(0); display: block !important; }

.insights-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px;
}

.insights-overline { display: block; color: var(--un-blue); margin-bottom: 4px; }

.insights-header h2 {
    font-size: 1.15rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 9px;
}

.insights-year {
    font-size: 0.72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--un-white);
    background: var(--un-blue);
    padding: 2px 8px;
    border-radius: var(--radius-xs);
}

.insights-chips {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 22px;
}

.insight-chip {
    padding: 9px 11px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.chip-label { display: block; margin-bottom: 3px; }
.chip-value { font-size: 1.02rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

.insights-section { margin-bottom: 24px; }
.insights-section:last-child { margin-bottom: 4px; }

.insights-section h3 {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.66rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.insights-section h3 .ic { color: var(--un-blue); }

.insights-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 8px;
}
.insights-section-head h3 { margin-bottom: 0; }

.insights-trend-wrapper {
    position: relative;
    height: 130px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
}
#insights-trend { display: block; width: 100%; height: 100%; }

.insights-hint { font-size: 0.65rem; color: var(--text-dim); margin-top: 7px; }

/* Tabs */
.insights-tabs {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    overflow: hidden;
}

.insights-tab {
    padding: 4px 11px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.67rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.insights-tab.active { background: var(--un-blue); color: var(--un-white); }
.insights-tab:not(.active):hover { color: var(--text); }

/* Ranking */
.insights-ranking {
    list-style: none;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.insights-ranking li {
    display: grid;
    grid-template-columns: 26px 24px 1fr auto;
    align-items: center;
    gap: 9px;
    padding: 7px 11px;
    cursor: pointer;
    transition: background 0.12s;
}
.insights-ranking li + li { border-top: 1px solid var(--border); }
.insights-ranking li:hover { background: var(--surface-hover); }

.rank-num { font-size: 0.68rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.rank-flag { width: 24px; height: 16px; object-fit: cover; border-radius: 2px; border: 1px solid var(--border); }
.rank-name-cell { min-width: 0; }

.rank-name {
    display: block;
    font-size: 0.775rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.rank-bar-track { height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.rank-bar { height: 100%; background: var(--un-blue); border-radius: 2px; transition: width 0.4s ease; }

.rank-value { font-size: 0.75rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

/* Regions */
.insights-regions { display: flex; flex-direction: column; gap: 7px; }

.region-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 5px 10px;
    padding: 8px 11px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
.region-row:hover { border-color: var(--un-blue); }
.region-row.active { border-color: var(--un-blue); background: var(--accent-soft); }

.region-name { font-size: 0.725rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.region-value { font-size: 0.725rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }

.region-bar-track { grid-column: 1 / -1; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; }
.region-bar { height: 100%; background: var(--un-blue); border-radius: 2px; transition: width 0.4s ease; }

/* ============================================================
   TIMELINE - pill that expands horizontally
   ============================================================ */
#timeline { max-width: calc(100vw - var(--hud-m) * 2); }

.timeline-body {
    display: flex;
    align-items: center;
    min-height: var(--hud-h);
    padding: 0 5px;
}

#timeline:not(.collapsed) .timeline-body { padding: 7px 10px 8px; }

.timeline-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    height: 34px;
    padding: 0 11px;
    background: transparent;
    border: none;
    border-radius: calc(var(--radius-hud) - 4px);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.64rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.timeline-toggle:hover { color: var(--text); background: var(--surface-hover); }

.timeline-toggle-year {
    font-size: 0.86rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
    text-transform: none;
    color: var(--un-blue-deep);
}
[data-theme="dark"] .timeline-toggle-year { color: var(--accent-strong); }

.timeline-toggle .toggle-chevron {
    color: var(--text-dim);
    transition: transform 0.25s var(--ease-out);
}

#timeline.collapsed .timeline-toggle .toggle-chevron { transform: rotate(180deg); }

.timeline-controls {
    display: flex;
    align-items: center;
    gap: 13px;
    margin-left: 13px;
    width: min(460px, calc(100vw - var(--hud-m) * 2 - 170px));
    min-width: 0;
    overflow: hidden;
    opacity: 1;
    transition: width 0.35s var(--ease-out), opacity 0.2s ease, margin-left 0.35s var(--ease-out);
}

#timeline.collapsed .timeline-controls {
    width: 0;
    margin-left: 0;
    opacity: 0;
    pointer-events: none;
}

#timeline:not(.collapsed) .timeline-toggle-label,
#timeline:not(.collapsed) .timeline-toggle-year { display: none; }

.timeline-year-badge {
    flex-shrink: 0;
    font-size: 0.92rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--un-blue-deep);
    min-width: 40px;
    text-align: center;
}
[data-theme="dark"] .timeline-year-badge { color: var(--accent-strong); }

.timeline-btn {
    width: 34px; height: 34px;
    border: none;
    border-radius: calc(var(--radius-hud) - 4px);
    background: var(--un-blue);
    color: var(--un-white);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s ease;
    flex-shrink: 0;
}
.timeline-btn:hover { background: var(--un-blue-dark); }
.timeline-btn .play-icon { fill: currentColor; stroke: none; }
.timeline-btn .pause-icon { fill: none; stroke: currentColor; stroke-width: 2; }
.timeline-btn .play-icon { margin-left: 2px; }
.timeline-btn .pause-icon { display: none; }
.timeline-btn.playing .play-icon { display: none; }
.timeline-btn.playing .pause-icon { display: block; }

.timeline-track { flex: 1; min-width: 120px; }

#timeline-spark {
    display: block;
    width: calc(100% - 18px);
    height: 16px;
    margin: 0 9px 3px;
    pointer-events: none;
    opacity: 0.85;
}

#year-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--border-bright);
    outline: none;
    cursor: pointer;
}
#year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 17px; height: 17px;
    border-radius: 50%;
    background: var(--un-blue);
    border: 3px solid var(--surface-solid);
    box-shadow: 0 0 0 1px var(--border-bright);
    cursor: pointer;
}
#year-slider::-moz-range-thumb {
    width: 17px; height: 17px;
    border-radius: 50%;
    background: var(--un-blue);
    border: 3px solid var(--surface-solid);
    cursor: pointer;
}

.timeline-ticks { display: flex; justify-content: space-between; padding: 0 9px; margin-top: 5px; }
.timeline-ticks span { font-size: 0.56rem; line-height: 1; font-variant-numeric: tabular-nums; color: var(--text-dim); }

.speed-btn {
    flex-shrink: 0;
    height: 34px;
    padding: 0 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius-hud) - 4px);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.speed-btn:hover { border-color: var(--un-blue); color: var(--accent-strong); }

/* ============================================================
   SHARED CLOSE BUTTON
   ============================================================ */
.panel-close-btn {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.panel-close-btn:hover { color: var(--text); border-color: var(--border-bright); background: var(--surface-hover); }

/* ============================================================
   ABOUT MODAL
   ============================================================ */
#about-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.25s ease both;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

#about-modal {
    position: relative;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 32px;
    animation: modalIn 0.4s var(--ease-out) both;
}

@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }

#about-close { position: absolute; top: 16px; right: 16px; }

.about-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.about-brand h2 { font-size: 1.125rem; font-weight: 500; }
.about-brand .brand-org { margin-bottom: 4px; }

.about-lead { font-size: 0.9rem; line-height: 1.6; color: var(--text-muted); margin-bottom: 22px; }
.about-lead strong { color: var(--text); font-weight: 500; }

.about-grid { display: flex; flex-direction: column; gap: 10px; }

.about-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 15px;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.about-item-label { color: var(--un-blue); }
.about-item-value { font-size: 0.86rem; color: var(--text); line-height: 1.5; }

.about-note { margin-top: 20px; font-size: 0.73rem; color: var(--text-dim); line-height: 1.55; }

.about-disclaimer {
    margin-top: 12px;
    font-size: 0.73rem;
    color: var(--text-dim);
    line-height: 1.55;
}

.about-credit {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: right;
}


/* ============================================================
   RESPONSIVE (desktop)
   ============================================================ */

/* ============================================================
   MOBILE (<= 768px)
   ============================================================ */
@media (max-width: 768px) {
    :root { --hud-m: 8px; --hud-gap: 6px; --hud-h: 40px; }

    #app { height: 100vh; height: 100dvh; }

    #brand-float { padding: 0 10px 0 8px; gap: 7px; }
    .brand-float-logo { width: 22px; height: 22px; }
    .brand-short { font-size: 0.68rem; }
    .brand-org { font-size: 0.48rem; }

    #stats-float { gap: 10px; padding: 0 12px; }
    .hud-divider { margin: 8px 0; }
    #stats-float .year-value,
    #stats-float .kpi-value { font-size: 0.88rem; }
    .hud-stat-label { font-size: 0.5rem; max-width: 84px; }
    .hud-stat { gap: 2px; }

    #tools-float { padding: 0 4px; }
    .icon-btn { width: 30px; height: 30px; }
    .lang-btn { min-width: 30px; padding: 0 7px; font-size: 0.62rem; }

    .panel-flag { width: 44px; height: 30px; }
    .panel-title-row { padding-right: 28px; gap: 10px; }
    .panel-title-text h2 { font-size: 1.05rem; margin-bottom: 5px; }

    #globe-container { height: 100%; min-height: 0; }

    .hud-top-left { width: min(260px, calc(100vw - 158px)); }
    .search-input-wrapper { padding-left: 10px; gap: 7px; }
    .filters-toggle-btn { padding: 0 9px 0 10px; font-size: 0.6rem; }
    .search-icon { width: 12px; height: 12px; }
    #search-input { font-size: 13px; }
    .filters-body { padding: 9px 10px 10px; gap: 7px; }
    .search-filters select { padding: 5px 22px 5px 7px; font-size: 11px; min-height: 30px; }
    .filter-icon { width: 12px; height: 12px; }
    .range-filter label { margin-bottom: 5px; }
    .expenditure-brackets { grid-template-columns: repeat(3, 1fr); gap: 3px; }
    .bracket-btn { font-size: 0.58rem; padding: 5px 2px; }
    #search-results { max-height: 180px; }
    #search-results li { padding: 8px 10px; font-size: 12px; min-height: 34px; }
    #search-results li .result-value { font-size: 0.65rem; }

    .legend-toggle { height: 32px; padding: 0 10px; }
    .legend-toggle-label { display: none; }
    .legend-body { width: 168px; padding: 9px 11px; }
    .legend-title { font-size: 0.5rem; }
    .legend-bar { height: 5px; }
    .legend-labels { font-size: 0.5rem; margin-top: 3px; }

    #detail-panel {
        width: 100%;
        height: 42vh; height: 42dvh; max-height: 46dvh;
        top: auto; bottom: 0; right: 0; left: 0;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
        transform: translateY(100%);
    }
    #detail-panel.visible { transform: translateY(0); }
    #detail-panel::before {
        content: '';
        position: absolute;
        top: 8px; left: 50%;
        transform: translateX(-50%);
        width: 34px; height: 4px;
        background: var(--border-bright);
        border-radius: 2px;
        z-index: 1;
    }
    #panel-close { top: 10px; right: 10px; width: 28px; height: 28px; font-size: 1rem; }
    #panel-content { padding: 24px 14px 16px; }
    .panel-header { margin-bottom: 12px; }
    .panel-overline { margin-bottom: 6px; }
    .tag { padding: 1px 7px; font-size: 0.53rem; }

    .stat-hero { padding: 12px 13px 11px; margin-bottom: 8px; }
    .stat-hero-value { font-size: 1.7rem; }
    .stat-trend { font-size: 0.68rem; }
    .stat-hero-note { font-size: 0.58rem; margin-top: 4px; }

    .metric-grid { gap: 6px; margin-bottom: 14px; }
    .metric { padding: 8px 9px; gap: 2px; }
    .metric-value { font-size: 0.8rem; }

    .panel-chart-section { margin-bottom: 14px; }
    .canvas-wrapper { height: 110px; }

    .panel-comparisons { gap: 5px; }
    .comparison-card { padding: 8px 10px; }
    .comp-row { margin-bottom: 5px; }
    .comp-value { font-size: 0.8rem; }

    .timeline-controls { gap: 8px; margin-left: 8px; width: min(400px, calc(100vw - 130px)); }
    #timeline.collapsed .timeline-controls { margin-left: 0; width: 0; }
    .timeline-btn { width: 34px; height: 34px; }
    .timeline-btn svg { width: 14px; height: 14px; }
    .timeline-year-badge { font-size: 0.82rem; min-width: 34px; }
    .timeline-track { min-width: 80px; }
    #timeline-spark { display: none; }
    #year-slider { height: 4px; }
    #year-slider::-webkit-slider-thumb { width: 18px; height: 18px; border-width: 2px; }
    #year-slider::-moz-range-thumb { width: 18px; height: 18px; border-width: 2px; }
    .timeline-ticks { display: none; }
    .speed-btn { height: 34px; padding: 0 10px; font-size: 0.6rem; }

    #tooltip { max-width: 170px; padding: 7px 11px; }
    .tooltip-name { font-size: 0.72rem; }
    .tooltip-value { font-size: 0.8rem; }

    #insights-panel {
        top: 8px; left: 8px; right: 8px; bottom: 8px;
        width: auto;
        max-width: none;
        padding: 14px;
        border-radius: var(--radius-hud);
    }
    .insights-chips { gap: 6px; margin-bottom: 16px; }
    .chip-value { font-size: 0.875rem; }
    .insights-trend-wrapper { height: 110px; }

    .splash-logo { width: 60px; height: 60px; margin-bottom: 20px; }
    .splash-title { font-size: 1.6rem; }
    .splash-desc { font-size: 0.82rem; }
    .splash-overline { font-size: 0.6rem; }
    .splash-divider { margin: 16px auto; }
    .splash-progress { width: 170px; margin-top: 22px; }

    #about-modal { padding: 24px 20px; }
}

/* ============================================================
   PHONES (<= 640px) - dedicated layout
   Search bar spans the top, stats+tools row under it,
   permanent timeline bar at the bottom.
   ============================================================ */
@media (max-width: 640px) {
    :root { --hud-m: 10px; --hud-gap: 8px; --hud-h: 46px; }

    /* --- Full-width search bar with the UN emblem as brand --- */
    .hud-top-left {
        top: calc(var(--hud-m) + env(safe-area-inset-top, 0px));
        left: var(--hud-m);
        right: var(--hud-m);
        width: auto;
        z-index: 11; /* dropdowns overlay the stats/tools row */
    }
    #brand-float { display: none; }
    .search-brand-logo { display: block; }
    .search-icon { display: none; }
    .search-input-wrapper { padding-left: 11px; gap: 9px; }
    #search-input { font-size: 16px; } /* keeps iOS from zooming on focus */
    .filters-toggle-btn { padding: 0 12px; font-size: 0.66rem; gap: 7px; }
    .filters-body { padding: 12px 12px 13px; gap: 10px; }
    .search-filters select { padding: 8px 26px 8px 10px; font-size: 13px; min-height: 38px; }
    .expenditure-brackets { grid-template-columns: repeat(5, 1fr); gap: 4px; }
    .bracket-btn { font-size: 0.62rem; padding: 8px 2px; }
    #search-results { max-height: 240px; }
    #search-results li { padding: 10px 12px; font-size: 13px; min-height: 40px; }

    /* --- Stats + tools on one row under the search bar --- */
    .hud-top-right {
        top: calc(var(--hud-m) + env(safe-area-inset-top, 0px) + var(--hud-h) + var(--hud-gap));
        left: var(--hud-m);
        right: var(--hud-m);
        flex-direction: row;
        align-items: stretch;
        justify-content: space-between;
    }
    #stats-float { height: 44px; padding: 0 13px; }
    /* the year already lives in the timeline bar */
    #stats-float .hud-stat:first-of-type,
    #stats-float .hud-divider { display: none; }
    #stats-float .kpi-value { font-size: 0.95rem; }
    .hud-stat-label { font-size: 0.52rem; max-width: 130px; }
    #tools-float { height: 44px; padding: 0 4px; gap: 3px; }
    .icon-btn { width: 38px; height: 38px; }
    .lang-btn { min-width: 38px; padding: 0 8px; font-size: 0.66rem; }

    /* --- Permanent timeline bar at the bottom --- */
    .hud-bottom-center {
        left: var(--hud-m);
        right: var(--hud-m);
        bottom: calc(var(--hud-m) + env(safe-area-inset-bottom, 0px));
        transform: none;
    }
    #timeline { width: 100%; max-width: none; }
    #timeline .timeline-body,
    #timeline:not(.collapsed) .timeline-body { padding: 5px 8px; }
    .timeline-toggle { display: none; }
    .timeline-controls,
    #timeline.collapsed .timeline-controls {
        width: 100%;
        margin-left: 0;
        opacity: 1;
        pointer-events: auto;
        gap: 10px;
    }
    .timeline-btn { width: 38px; height: 38px; }
    .timeline-btn svg { width: 15px; height: 15px; }
    .timeline-track { order: 1; min-width: 0; }
    .timeline-year-badge { order: 2; font-size: 0.92rem; min-width: 42px; }
    .speed-btn { order: 3; height: 38px; padding: 0 11px; font-size: 0.66rem; }
    #year-slider::-webkit-slider-thumb { width: 20px; height: 20px; }
    #year-slider::-moz-range-thumb { width: 20px; height: 20px; }

    /* --- Legend floats above the timeline bar --- */
    .hud-bottom-left {
        bottom: calc(var(--hud-m) + env(safe-area-inset-bottom, 0px) + 48px + var(--hud-gap));
    }
    .legend-toggle { height: 38px; padding: 0 12px; }
    .legend-body { width: 190px; padding: 11px 13px; }
}

/* Very small phones */
@media (max-width: 380px) {
    #detail-panel { height: 44dvh; max-height: 48dvh; }
    .splash-title { font-size: 1.4rem; }
    .speed-btn { display: none; }
}

/* ============================================================
   SCROLLBARS
   ============================================================ */
#detail-panel::-webkit-scrollbar,
#insights-panel::-webkit-scrollbar,
#about-modal::-webkit-scrollbar { width: 5px; }
#detail-panel::-webkit-scrollbar-track,
#insights-panel::-webkit-scrollbar-track,
#about-modal::-webkit-scrollbar-track { background: transparent; }
#detail-panel::-webkit-scrollbar-thumb,
#insights-panel::-webkit-scrollbar-thumb,
#about-modal::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 3px; }
#search-results::-webkit-scrollbar,
#compare-results::-webkit-scrollbar { width: 4px; }
#search-results::-webkit-scrollbar-thumb,
#compare-results::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }
