/* ═══════════════════════════════════════════════════════════════════════════
   PUHUB — Baltic Overlay Design System
   Smoked-glass technique: near-transparent panel + heavy backdrop blur/darken
   + text halos + high-contrast typography.
   Old variable names are aliased so JS-generated SVGs keep working.
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
    /* Smoked-glass palette — solid panels, map visible at edges */
    --panel-bg:        rgba(10, 18, 30, 0.23);
    --panel-border:    rgba(255, 255, 255, 0.14);
    --text-primary:    #FFFFFF;
    --text-secondary:  #BDD4EC;
    --accent-blue:     #3B82F6;
    --accent-cyan:     #22D3EE;
    --accent-warning:  #FBBF24;

    /* Legacy aliases — JS-generated SVG uses var(--accent), var(--text-muted) etc. */
    --bg:           #080F1A;
    --panel:        var(--panel-bg);
    --panel-alt:    rgba(8, 15, 26, 0.30);
    --border:       var(--panel-border);
    --border-mid:   rgba(255, 255, 255, 0.20);
    --accent:       var(--accent-blue);
    --accent-dim:   rgba(59, 130, 246, 0.16);
    --accent-glow:  rgba(59, 130, 246, 0.50);
    --text:         var(--text-primary);
    --text-muted:   var(--text-secondary);
    --text-dim:     #6A8BA8;
    --success:      #34D399;
    --warning:      var(--accent-warning);
    --danger:       #F87171;

    /* Text halos — tight black shadows that shield letters from bright backgrounds */
    --halo:    0 0 6px rgba(0,0,0,1), 0 1px 3px rgba(0,0,0,0.95);
    --halo-lg: 0 0 10px rgba(0,0,0,1), 0 0 4px rgba(0,0,0,1), 0 1px 6px rgba(0,0,0,1);

    /* Layout */
    --timeline-h:   60px;
    --sidebar-w:    320px;
    --margin:       16px;

    /* Radius */
    --r-sm:  6px;
    --r:     10px;
    --r-lg:  16px;

    /* Glass shadow */
    --shadow-sm:  0 2px 8px rgba(0,0,0,0.40), 0 1px 3px rgba(0,0,0,0.30);
    --shadow-md:  0 8px 32px rgba(0,0,0,0.55), 0 2px 8px rgba(0,0,0,0.35),
                  inset 0 1px 0 rgba(255,255,255,0.08);
    --shadow-lg:  0 16px 48px rgba(0,0,0,0.65), 0 4px 16px rgba(0,0,0,0.40),
                  inset 0 1px 0 rgba(255,255,255,0.10);
}

/* ── Light mode ─────────────────────────────────────────────────────────── */
html.light {
    --panel-bg:       rgba(220, 234, 250, 0.92);
    --panel-border:   rgba(0, 0, 0, 0.12);
    --text-primary:   #07111F;
    --text-secondary: #1B3050;
    --accent-blue:    #1D4ED8;
    --accent-cyan:    #0369A1;

    /* Light mode: dark text on light panel — no halos needed */
    --halo:    none;
    --halo-lg: none;

    --bg:          #C8DCF0;
    --panel:       var(--panel-bg);
    --panel-alt:   rgba(215, 230, 248, 0.95);
    --border:      var(--panel-border);
    --border-mid:  rgba(0, 0, 0, 0.18);
    --accent:      var(--accent-blue);
    --accent-dim:  rgba(29, 78, 216, 0.13);
    --accent-glow: rgba(29, 78, 216, 0.35);
    --text:        var(--text-primary);
    --text-muted:  var(--text-secondary);
    --text-dim:    #243F60;
    --success:     #047857;
    --warning:     #B45309;
    --danger:      #B91C1C;

    --shadow-sm:  0 2px 8px rgba(0,0,0,0.14), 0 1px 3px rgba(0,0,0,0.10);
    --shadow-md:  0 8px 32px rgba(0,0,0,0.20), 0 2px 8px rgba(0,0,0,0.12),
                  inset 0 1px 0 rgba(255,255,255,0.60);
    --shadow-lg:  0 16px 48px rgba(0,0,0,0.24), 0 4px 16px rgba(0,0,0,0.14),
                  inset 0 1px 0 rgba(255,255,255,0.70);
}

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

html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: var(--bg);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Map — absolute full-screen base ────────────────────────────────────── */
#map {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: #080F1A; /* always dark — matches satellite tile edges in both themes */
}
#map canvas { image-rendering: auto; }

.nasa-night-layer canvas {
    filter: blur(2px) brightness(1.15);
    image-rendering: smooth;
}

/* ═══════════════════════════════════════════════════════════════════════════
   GLASS PANEL — "Smoked Glass" technique
   The panel background is nearly transparent so the map bleeds through.
   backdrop-filter does three things simultaneously:
     blur(24px)        — dissolves wind particles and tree detail into mist
     brightness(0.50)  — darkens the map behind the panel by ~50 %
     saturate(1.6)     — keeps map colours vivid so geography stays legible
   The result: you can still read coastlines and terrain, but noise is gone.
   ═══════════════════════════════════════════════════════════════════════════ */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-md);
    border-radius: var(--r-lg);
}
html.light .glass-panel {
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.2);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.2);
}

/* ── Text halos — Secret #2 ──────────────────────────────────────────────
   A tight black shadow behind every letter creates an invisible shield.
   Even a bright wind particle directly under white text stays readable.
   ─────────────────────────────────────────────────────────────────────── */

/* Standard halo: labels, names, controls */
.control-label,
#layer-controls label, #overlay-controls label,
#theme-toggle, #lang-toggle,
#panel-brand, #last-updated,
.sp-country-title, .sp-station-name, .sp-station-src,
.sp-loading, .sp-empty,
.sm-title, .sm-dim, .sm-name,
.sr-l, .sr-v,
.tl-rank, .tl-name,
.stats-back-btn,
.tl-tick, #timeline-live,
.tooltip-name, .tooltip-table td,
.widget-name, .widget-wind,
.warn-item strong, .warn-item span, .warn-item small,
.no-warn, .warn-err {
    text-shadow: var(--halo);
}

/* Strong halo: the most important data values */
.sm-val, .sm-avg,
.tl-val,
.widget-data,
.sp-count {
    text-shadow: var(--halo-lg);
}

/* Light mode uses bright halos instead of dark ones (dark text on light bg) */
html.light .control-label,
html.light #layer-controls label, html.light #overlay-controls label,
html.light #theme-toggle, html.light #lang-toggle,
html.light #panel-brand, html.light #last-updated,
html.light .sp-country-title, html.light .sp-station-name,
html.light .sm-title, html.light .sm-val, html.light .sm-avg,
html.light .tl-val, html.light .tl-name, html.light .sr-l, html.light .sr-v,
html.light .widget-name, html.light .widget-data,
html.light #timeline-live {
    text-shadow: var(--halo);
}

/* ── High-contrast typography — Secret #3 ────────────────────────────────
   Data values use stark white / bright cyan, slightly heavier weight.
   ─────────────────────────────────────────────────────────────────────── */

/* ═══════════════════════════════════════════════════════════════════════════
   MAP CONTROLS — top-left vertical stack (zoom + locate)
   OL default controls are overridden; Locate is a custom button.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Hide OL default zoom background */
.ol-zoom {
    top: var(--margin);
    left: var(--margin);
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    padding: 0;
}

.ol-zoom .ol-zoom-in,
.ol-zoom .ol-zoom-out {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    margin: 0;
    background: var(--panel-bg);
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-sm);
    border-radius: var(--r);
    color: #FFFFFF;
    font-size: 20px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    text-decoration: none;
    text-shadow: var(--halo);
}

.ol-zoom .ol-zoom-in:hover,
.ol-zoom .ol-zoom-out:hover {
    background: rgba(34, 211, 238, 0.12);
    border-color: rgba(34, 211, 238, 0.35);
    color: var(--accent-cyan);
}
html.light .ol-zoom .ol-zoom-in,
html.light .ol-zoom .ol-zoom-out {
    color: var(--text-secondary);
}

/* Locate button — injected just after the OL zoom block */
#map-controls-extra {
    position: absolute;
    top: calc(var(--margin) + 40px + 40px + 12px);  /* below both zoom buttons + gaps */
    left: var(--margin);
    z-index: 101;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#btn-locate {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    background: var(--panel-bg);
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-sm);
    border-radius: var(--r);
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#btn-locate:hover {
    background: rgba(34, 211, 238, 0.12);
    border-color: rgba(34, 211, 238, 0.35);
    color: var(--accent-cyan);
}

/* OL scale line */
.ol-scale-line {
    background: rgba(17, 29, 43, 0.70);
    backdrop-filter: blur(6px);
    border: 1px solid var(--panel-border);
    border-radius: var(--r-sm);
    bottom: calc(var(--timeline-h) + var(--margin) + 10px);
    left: var(--margin);
}
.ol-scale-line-inner {
    border: 1px solid rgba(226, 232, 240, 0.35);
    border-top: none;
    color: var(--text-secondary);
    font-size: 11px;
    font-family: 'Inter', system-ui, sans-serif;
}
html.light .ol-scale-line {
    background: var(--panel-bg);
}
html.light .ol-scale-line-inner {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

/* ── Brand badge — below locate button ──────────────────────────────────── */
#brand {
    position: absolute;
    top: calc(var(--margin) + 40px + 40px + 48px);
    left: var(--margin);
    z-index: 100;
    background: var(--panel-bg);
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    border: 1px solid var(--panel-border);
    border-radius: var(--r-sm);
    box-shadow: var(--shadow-sm);
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--accent-cyan);
    text-transform: uppercase;
    pointer-events: none;
    text-shadow: var(--halo);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR — floating glass panel, right side
   ═══════════════════════════════════════════════════════════════════════════ */

#sidebar {
    position: absolute;
    top: var(--margin);
    right: var(--margin);
    bottom: calc(var(--timeline-h) + var(--margin) * 2);
    z-index: 100;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    pointer-events: none;
}
#sidebar > * { pointer-events: auto; }

/* Collapse tab — left ear of the panel */
#sidebar-toggle {
    width: 28px;
    height: 44px;
    margin-top: 14px;
    margin-right: -1px;
    flex-shrink: 0;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-right: none;
    border-radius: var(--r-sm) 0 0 var(--r-sm);
    box-shadow: -4px 0 12px rgba(0,0,0,0.20);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
    z-index: 1;
}
#sidebar-toggle:hover {
    color: var(--accent-cyan);
    background: rgba(34, 211, 238, 0.08);
}

/* Inner panel — glass surface */
#sidebar-inner {
    width: var(--sidebar-w);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* glass-panel class applied in HTML */
}
#sidebar.collapsed #sidebar-inner { display: none; }

/* Panel header bar */
#panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--panel-border);
    flex-shrink: 0;
}
#panel-brand {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent-cyan);
}
#panel-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════════════════════════
   CONTROLS — map/layer toggles inside the sidebar
   ═══════════════════════════════════════════════════════════════════════════ */

#controls {
    flex-shrink: 0;
    padding: 12px 14px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--text-dim);
    margin-bottom: 2px;
}

#layer-controls,
#overlay-controls {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

#layer-controls label,
#overlay-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 5px 6px;
    border-radius: var(--r-sm);
    font-size: 13px;
    color: var(--text-secondary);
    transition: background 0.12s, color 0.12s;
}
#layer-controls label:hover,
#overlay-controls label:hover {
    background: rgba(59, 130, 246, 0.10);
    color: var(--text-primary);
}
input[type="radio"],
input[type="checkbox"] {
    accent-color: var(--accent-blue);
    cursor: pointer;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Theme toggle — map control stack (matches zoom/locate style) */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    background: var(--panel-bg);
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    border: 1px solid var(--panel-border);
    box-shadow: var(--shadow-sm);
    border-radius: var(--r);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
    padding: 0;
}
#theme-toggle:hover {
    background: rgba(34, 211, 238, 0.12);
    border-color: rgba(34, 211, 238, 0.35);
}

/* Sun/moon SVG icons inside theme-toggle */
#theme-toggle svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Dark mode: show sun (click → go light), hide moon */
#theme-toggle #icon-sun  { display: block;  color: #FBBF24; }
#theme-toggle #icon-moon { display: none; }

/* Light mode: show moon (click → go dark), hide sun */
html.light #theme-toggle #icon-sun  { display: none; }
html.light #theme-toggle #icon-moon { display: block; color: var(--accent-blue); }

/* Language toggle — in panel header, right side */
#lang-toggle {
    padding: 3px 7px;
    border-radius: var(--r-sm);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: rgba(59, 130, 246, 0.10);
    border: 1px solid rgba(59, 130, 246, 0.22);
    color: var(--accent-blue);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    font-family: inherit;
    flex-shrink: 0;
}
#lang-toggle:hover {
    background: rgba(59, 130, 246, 0.22);
    color: var(--text-primary);
}
html.light #lang-toggle {
    border-color: rgba(37, 99, 235, 0.25);
}

/* Status bar */
#status-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--text-secondary);
    border-top: 1px solid var(--panel-border);
    padding-top: 8px;
}

.dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-dim);
}
.dot.fresh { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.stale { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.dot.error { background: var(--danger);  box-shadow: 0 0 6px var(--danger); }

/* ═══════════════════════════════════════════════════════════════════════════
   STATS PANEL — scrollable data section
   ═══════════════════════════════════════════════════════════════════════════ */

#stats-panel {
    flex: 1;
    overflow-y: auto;
    padding: 10px 14px 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.25) transparent;
}
#stats-panel::-webkit-scrollbar { width: 3px; }
#stats-panel::-webkit-scrollbar-track { background: transparent; }
#stats-panel::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.30);
    border-radius: 2px;
}
#stats-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.55);
}

.stats-back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    text-align: left;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.18);
    border-radius: var(--r-sm);
    color: var(--accent-blue);
    font-size: 12px;
    font-weight: 500;
    padding: 7px 10px;
    cursor: pointer;
    margin-bottom: 10px;
    transition: background 0.12s, color 0.12s;
    font-family: inherit;
}
.stats-back-btn:hover {
    background: rgba(59, 130, 246, 0.15);
    color: var(--text-primary);
}

#stats-bottom {
    border-top: 1px solid var(--panel-border);
    padding-top: 10px;
    margin-top: 6px;
}

/* Country header */
.sp-country-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: baseline;
    gap: 0;
}
.sp-count {
    font-weight: 400;
    color: var(--text-dim);
    font-size: 12px;
    margin-left: 7px;
}
.sp-divider { border-top: 1px solid var(--panel-border); margin: 10px 0; }

/* Station header */
.sp-station-name {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.sp-station-src {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.sp-loading,
.sp-empty {
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
    padding: 8px 0;
}

/* Metric block — min / avg / max */
.sm { margin-bottom: 14px; }

.sm-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--text-dim);
    margin-bottom: 7px;
}

.sm-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; }
.sm-cell { display: flex; flex-direction: column; }
.sm-center { align-items: center; }
.sm-right  { align-items: flex-end; }

.sm-dim {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.sm-val {
    font-size: 17px;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
    font-weight: 600;
}
.sm-avg {
    color: var(--accent-cyan);
    font-weight: 700;
}
.sm-name {
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
}

/* Stat rows */
.sr {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
html.light .sr { border-bottom-color: rgba(0, 0, 0, 0.05); }
.sr-l { font-size: 12px; color: var(--text-secondary); }
.sr-v { font-size: 12px; color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }
.sr-sub { font-size: 11px; color: var(--text-dim); margin-left: 3px; }

/* Top-N lists */
.tl-row {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 5px 4px;
    border-radius: var(--r-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
html.light .tl-row { border-bottom-color: rgba(0, 0, 0, 0.04); }

.tl-row[data-name] { cursor: pointer; transition: background 0.12s; }
.tl-row[data-name]:hover {
    background: rgba(59, 130, 246, 0.10);
}
.tl-row[data-name]:hover .tl-name { color: #93C5FD; }
.tl-row[data-name]:active { background: rgba(59, 130, 246, 0.18); }

.tl-rank {
    font-size: 11px;
    color: var(--text-dim);
    width: 16px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.tl-name {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 8px;
}
.tl-val {
    font-size: 13px;
    color: var(--accent-cyan);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    flex-shrink: 0;
}

/* ── Collapsible top-N list sections (replaces bare .sm wrapper) ─────────── */
details.tl-section {
    margin-bottom: 14px;
}
details.tl-section > summary {
    list-style: none;         /* Firefox */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    cursor: pointer;
    padding: 4px 0 7px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.10em;
    color: var(--text-dim);
    text-shadow: var(--halo);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
/* Remove the default browser disclosure triangle */
details.tl-section > summary::-webkit-details-marker { display: none; }
details.tl-section > summary::marker            { display: none; }
.tl-chevron {
    font-size: 9px;
    flex-shrink: 0;
    opacity: 0.60;
    transition: transform 0.20s ease;
    /* counteract text-shadow halo — chevron doesn't need it */
    text-shadow: none;
}
details.tl-section[open] > summary .tl-chevron {
    transform: rotate(180deg);
}

/* Charts */
.chart-wrap { display: block; padding: 2px 0 4px; }
.chart-svg  { display: block; width: 100%; overflow: visible; }

/* Sparkline compat */
.sparkline-wrap   { display: flex; flex-direction: column; gap: 5px; padding: 2px 0; }
.sparkline-svg    { display: block; overflow: visible; }
.sparkline-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); }
.sp-range         { color: var(--accent-cyan); }

/* ═══════════════════════════════════════════════════════════════════════════
   TIMELINE — floating glass bar at the bottom
   ═══════════════════════════════════════════════════════════════════════════ */

#timeline-panel {
    position: absolute;
    bottom: var(--margin);
    left: var(--margin);
    right: var(--margin);
    z-index: 100;
    height: var(--timeline-h);
    /* glass-panel class applied in HTML */
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 18px;
}
#timeline-panel.hidden { display: none; }

/* Live button */
#timeline-live {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: var(--r-sm);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: var(--accent-blue);
    cursor: pointer;
    white-space: nowrap;
    min-height: 34px;
    transition: background 0.15s, box-shadow 0.15s, color 0.15s;
    font-family: inherit;
}
#timeline-live:disabled { opacity: 0.35; cursor: default; }
#timeline-live:not(:disabled):hover {
    background: rgba(59, 130, 246, 0.22);
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.40);
    color: var(--text-primary);
}

/* Track wrapper */
#timeline-track-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Slider */
#timeline-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(
        to right,
        var(--accent-blue)        0%,
        var(--accent-blue)        var(--fill-pct, 100%),
        rgba(255,255,255,0.12)    var(--fill-pct, 100%)
    );
    border-radius: 2px;
    cursor: pointer;
    outline: none;
    padding: 8px 0;
    box-sizing: content-box;
    margin: 0;
}
#timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--accent-blue);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.60), 0 2px 6px rgba(0,0,0,0.30);
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s;
}
#timeline-slider:hover::-webkit-slider-thumb,
#timeline-slider:focus::-webkit-slider-thumb {
    transform: scale(1.25);
    box-shadow: 0 0 18px rgba(59, 130, 246, 0.70), 0 2px 8px rgba(0,0,0,0.35);
}
#timeline-slider::-moz-range-thumb {
    width: 18px; height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2.5px solid var(--accent-blue);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.55);
    cursor: pointer;
}
#timeline-slider::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.12);
}
#timeline-slider::-moz-range-progress {
    height: 4px;
    border-radius: 2px 0 0 2px;
    background: var(--accent-blue);
}

/* Tick labels */
#timeline-ticks {
    display: flex;
    justify-content: space-between;
    padding: 0 9px;
    pointer-events: none;
}
.tl-tick {
    font-size: 11px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    line-height: 1;
    text-align: center;
    font-family: inherit;
}
.tl-tick-now {
    color: var(--accent-blue);
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════════════
   STATION TOOLTIP — glass floating card
   ═══════════════════════════════════════════════════════════════════════════ */

#station-tooltip {
    position: absolute;
    z-index: 200;
    pointer-events: none;
    background: var(--panel-bg);
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    border: 1px solid var(--panel-border);
    border-radius: var(--r-lg);
    padding: 12px 15px;
    max-width: 250px;
    box-shadow: var(--shadow-lg);
}
#station-tooltip.hidden { display: none; }

.tooltip-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 8px;
    color: var(--text-primary);
    letter-spacing: 0.01em;
}
.tooltip-table {
    width: 100%;
    border-collapse: collapse;
}
.tooltip-table td { padding: 2px 4px; font-size: 12px; }
.tooltip-table td:first-child {
    color: var(--text-secondary);
    width: 80px;
}
.tooltip-table td:last-child {
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.tooltip-table tr.sep td {
    padding-top: 8px;
    color: var(--accent-cyan);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}
.tooltip-note {
    margin-top: 7px;
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
}
.tooltip-src {
    margin-top: 4px;
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CITY WIDGETS — OL overlay labels for major stations
   ═══════════════════════════════════════════════════════════════════════════ */

.city-widget {
    position: relative;
    background: var(--panel-bg);
    backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) brightness(0.65) saturate(1.4);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--r);
    padding: 6px 11px;
    color: var(--text-primary);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    overflow: hidden;
    transform: translate(-50%, -120%);
    pointer-events: none;
    box-shadow: 0 4px 20px rgba(0,0,0,0.50), inset 0 1px 0 rgba(255,255,255,0.08);
    white-space: nowrap;
}
html.light .city-widget {
    background: rgba(226, 238, 250, 0.82);
    border-color: rgba(0, 0, 0, 0.12);
}

.widget-content { position: relative; z-index: 2; text-align: center; }
.widget-name {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}
.widget-data {
    font-size: 17px;
    font-weight: 600;
    margin-top: 1px;
    font-variant-numeric: tabular-nums;
    color: var(--accent-cyan);
}
.widget-wind {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.widget-fx { position: absolute; inset: 0; z-index: 1; border-radius: inherit; overflow: hidden; }

.fx-wind {
    background: repeating-linear-gradient(
        90deg, transparent 0, transparent 14px,
        rgba(34, 211, 238, 0.55) 14px, rgba(34, 211, 238, 0.55) 24px
    );
    background-size: 200% 100%;
    animation: wSlide 0.5s linear infinite;
    opacity: 0.10;
}
.fx-rain {
    background: repeating-linear-gradient(
        180deg, transparent 0, transparent 9px,
        rgba(96, 165, 250, 0.70) 9px, rgba(96, 165, 250, 0.70) 14px
    );
    background-size: 100% 200%;
    animation: rFall 0.35s linear infinite;
    opacity: 0.25;
}
@keyframes wSlide { from { background-position: 0% 0; } to { background-position: 100% 0; } }
@keyframes rFall  { from { background-position: 0 -100%; } to { background-position: 0 0%; } }

/* ═══════════════════════════════════════════════════════════════════════════
   LOCATION PIN — glowing amber dot + glass label
   ═══════════════════════════════════════════════════════════════════════════ */

.location-pin {
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    /* When used as an OL overlay, JS applies transform */
}

.location-pin__label {
    position: relative;
    background: var(--panel-bg);
    backdrop-filter: blur(10px) saturate(1.4);
    -webkit-backdrop-filter: blur(10px) saturate(1.4);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 5px 11px;
    font-size: 12px;
    font-weight: 600;
    font-family: 'Inter', system-ui, sans-serif;
    color: var(--text-primary);
    white-space: nowrap;
    margin-bottom: 7px;
    box-shadow: var(--shadow-md);
}
/* Callout arrow */
.location-pin__label::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0; height: 0;
    border: 6px solid transparent;
    border-top-color: var(--panel-border);
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
}

.location-pin__dot-wrap {
    position: relative;
    width: 16px; height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.location-pin__dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    background: var(--accent-warning);
    box-shadow: 0 0 0 3px rgba(251,191,36,0.25),
                0 0 14px rgba(251,191,36,0.55),
                0 0 28px rgba(251,191,36,0.25);
    position: relative;
    z-index: 2;
}

.location-pin__pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--accent-warning);
    animation: pin-pulse 2.2s ease-out infinite;
    z-index: 1;
}

@keyframes pin-pulse {
    0%   { transform: scale(1);   opacity: 0.55; }
    100% { transform: scale(3.2); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   WARNINGS PANEL — glass card bottom-left
   ═══════════════════════════════════════════════════════════════════════════ */

#warnings-panel {
    position: absolute;
    bottom: calc(var(--timeline-h) + var(--margin) * 2 + 6px);
    left: var(--margin);
    z-index: 100;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(251, 191, 36, 0.22);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
    padding: 12px 15px;
    max-width: 370px;
    max-height: 290px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(251,191,36,0.30) transparent;
}
#warnings-panel.hidden { display: none; }

.warn-item {
    padding: 8px 10px;
    border-radius: var(--r-sm);
    background: rgba(255,255,255,0.03);
    border-left: 3px solid var(--accent-warning);
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.warn-item.level-2 { border-left-color: var(--danger); }
.warn-item.level-3 {
    border-left-color: #DC2626;
    background: rgba(220, 38, 38, 0.10);
}
.warn-item strong {
    font-size: 11px;
    color: #FCD34D;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 700;
}
.warn-item span { font-size: 13px; color: var(--text-primary); }
.warn-item small { font-size: 11px; color: var(--text-secondary); }

.no-warn  { color: var(--success);  font-size: 13px; }
.warn-err { color: var(--danger);   font-size: 13px; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE FAB — hidden on desktop
   ═══════════════════════════════════════════════════════════════════════════ */
#mobile-fab { display: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE  ≤ 640 px
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    :root {
        --timeline-h: 58px;
        --margin: 10px;
    }

    /* Sidebar becomes a full-viewport overlay drawer */
    #sidebar {
        position: fixed;
        inset: 0;
        bottom: 0;
        pointer-events: none;
        z-index: 300;
        display: block;
    }

    /* Backdrop */
    #sidebar::before {
        content: '';
        position: absolute;
        inset: 0;
        background: rgba(0, 8, 18, 0.62);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.28s ease;
    }
    #sidebar:not(.collapsed)::before {
        opacity: 1;
        pointer-events: auto;
    }

    /* Drawer — slides in from right */
    #sidebar-inner {
        position: absolute;
        top: 0; right: 0; bottom: 0;
        width: min(90vw, 330px);
        pointer-events: auto;
        border-radius: var(--r-lg) 0 0 var(--r-lg);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transform: translateX(0);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: transform;
        box-shadow: -6px 0 30px rgba(0,0,0,0.55);
        /* Near-solid bg on mobile: maximise contrast, avoid costly blur */
        background: rgba(7, 17, 30, 0.98);
        backdrop-filter: none;
    }
    #sidebar.collapsed #sidebar-inner {
        display: flex;
        transform: translateX(100%);
    }

    /* Desktop toggle tab: hidden on mobile */
    #sidebar-toggle { display: none; }

    /* FAB */
    #mobile-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: calc(var(--timeline-h) + var(--margin) + 10px);
        right: var(--margin);
        width: 50px; height: 50px;
        border-radius: 50%;
        background: var(--accent-blue);
        color: #fff;
        border: none;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
        z-index: 400;
        box-shadow: 0 4px 16px rgba(59,130,246,0.50);
        -webkit-tap-highlight-color: transparent;
        transition: background 0.15s, transform 0.15s;
        user-select: none;
    }
    #mobile-fab:active {
        transform: scale(0.92);
    }

    /* Brand: below larger zoom buttons */
    #brand { top: calc(var(--margin) + 44px + 44px + 52px); }

    /* OL zoom: larger tap targets */
    .ol-zoom { top: var(--margin); left: var(--margin); }
    .ol-zoom .ol-zoom-in,
    .ol-zoom .ol-zoom-out {
        width: 44px; height: 44px;
        font-size: 24px;
    }

    /* Locate button position update */
    #map-controls-extra {
        top: calc(var(--margin) + 44px + 44px + 12px);
    }
    #btn-locate { width: 44px; height: 44px; font-size: 20px; }

    /* Scale line: above FAB */
    .ol-scale-line {
        bottom: calc(var(--timeline-h) + var(--margin) + 62px);
        left: var(--margin);
    }

    /* Timeline */
    #timeline-panel {
        padding: 0 var(--margin);
        gap: 10px;
    }
    #timeline-live { min-height: 38px; padding: 0 10px; font-size: 11px; }
    #timeline-slider::-webkit-slider-thumb { width: 22px; height: 22px; }
    #timeline-slider::-moz-range-thumb     { width: 22px; height: 22px; }

    /* Tooltip hidden on mobile — info in drawer */
    #station-tooltip { display: none !important; }

    /* Controls: bigger tap targets */
    #controls { padding: 12px 14px; gap: 12px; }
    #layer-controls label,
    #overlay-controls label { min-height: 42px; padding: 9px 6px; font-size: 14px; }
    input[type="radio"],
    input[type="checkbox"] { width: 18px; height: 18px; }
    #lang-toggle { min-height: 28px; font-size: 11px; }
    #theme-toggle { width: 44px; height: 44px; }

    /* Stats panel */
    #stats-panel { padding: 10px 14px 28px; }
    .sm-val { font-size: 16px; }
    .sr-l, .sr-v { font-size: 13px; }
    .tl-row { min-height: 42px; padding: 9px 4px; align-items: center; }
    .tl-name, .tl-val { font-size: 13px; }
    .stats-back-btn { min-height: 42px; font-size: 13px; padding: 10px; }

    /* Warnings panel */
    #warnings-panel { left: var(--margin); right: var(--margin); max-width: none; }
}
