:root {
    --bg: #f4f7f9;
    --card: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --text-faded: #95a5a6;
    --rain: #2980b9;
    --shadow-soft: rgba(0,0,0,0.08);
    --shadow-medium: rgba(0,0,0,0.15);
    --border-faint: #f0f0f0;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--text);
}

body {
    display: flex;
    flex-direction: column;
}

.kaart-header {
    flex-shrink: 0;
    background: var(--card);
    box-shadow: 0 2px 10px var(--shadow-soft);
    z-index: 1000;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 10px 16px;
    gap: 12px;
}

.logo-link {
    color: var(--rain);
    font-weight: 800;
    font-size: 1.1em;
    text-decoration: none;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}
.logo-link .logo-dot { color: var(--text-faded); }

.kaart-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.kaart-datatype {
    display: flex;
    gap: 2px;
    background: #f4f7f9;
    padding: 3px;
    border-radius: 10px;
}

.kaart-datatype-btn {
    background: transparent;
    border: none;
    padding: 7px 14px;
    font-size: 0.85em;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 7px;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}
.kaart-datatype-btn:hover { color: var(--text); }
.kaart-datatype-btn.active {
    background: var(--text);
    color: white;
    box-shadow: 0 1px 3px var(--shadow-medium);
}

.kaart-tabs {
    display: flex;
    gap: 4px;
    background: #f4f7f9;
    padding: 3px;
    border-radius: 10px;
}

.kaart-tabs.hidden {
    display: none;
}

.kaart-tab {
    background: transparent;
    border: none;
    padding: 7px 14px;
    font-size: 0.85em;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 7px;
    font-family: inherit;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}
.kaart-tab:hover { color: var(--text); }
.kaart-tab.active {
    background: var(--rain);
    color: white;
    box-shadow: 0 1px 3px var(--shadow-medium);
}

#map {
    flex: 1;
    width: 100%;
    background: var(--bg);
    z-index: 1;
    position: relative;
}

.legend {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: var(--card);
    border-radius: 10px;
    box-shadow: 0 4px 14px var(--shadow-medium);
    z-index: 500;
    font-size: 0.82em;
    max-width: 240px;
    overflow: hidden;
}

.legend-title {
    font-weight: 800;
    color: var(--text);
    padding: 10px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    user-select: none;
    gap: 8px;
}
.legend-title::-webkit-details-marker { display: none; }
.legend-title::after {
    content: '';
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-top: -3px;
}
.legend[open] .legend-title::after { transform: rotate(-135deg); margin-top: 2px; }
.legend:not([open]) .legend-title { padding: 8px 14px; }

.legend-body {
    padding: 4px 14px 12px 14px;
}

.legend-scale {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 8px;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text-muted);
}

.legend-swatch {
    width: 18px;
    height: 14px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.06);
}

.legend-disclaimer {
    font-size: 0.85em;
    color: var(--text-faded);
    line-height: 1.4;
    font-weight: 600;
    border-top: 1px solid var(--border-faint);
    padding-top: 6px;
    margin-top: 4px;
}

.station-marker {
    background: var(--card);
    border: 2px solid var(--rain);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72em;
    font-weight: 800;
    color: var(--rain);
    box-shadow: 0 2px 6px var(--shadow-soft);
    text-align: center;
    line-height: 1;
    padding: 0 2px;
    box-sizing: border-box;
}
.station-marker.dry { color: var(--text-faded); border-color: var(--text-faded); }
.station-marker.wet-low    { color: #fff; background: #74b9e8; border-color: #74b9e8; }
.station-marker.wet-mid    { color: #fff; background: #2980b9; border-color: #2980b9; }
.station-marker.wet-high   { color: #fff; background: #1f5e8e; border-color: #1f5e8e; }
.station-marker.wet-extr   { color: #fff; background: #6c3e9e; border-color: #6c3e9e; }

.station-marker.temp-cold-extr { color: #fff; background: #2c5282; border-color: #2c5282; }
.station-marker.temp-cold      { color: #fff; background: #4299e1; border-color: #4299e1; }
.station-marker.temp-cool      { color: #fff; background: #63b3ed; border-color: #63b3ed; }
.station-marker.temp-mild      { color: #fff; background: #48bb78; border-color: #48bb78; }
.station-marker.temp-warm      { color: #fff; background: #ed8936; border-color: #ed8936; }
.station-marker.temp-hot       { color: #fff; background: #e53e3e; border-color: #e53e3e; }
.station-marker.temp-extr      { color: #fff; background: #9b2c2c; border-color: #9b2c2c; }

.station-popup {
    font-family: inherit;
    min-width: 180px;
}
.station-popup-name {
    font-weight: 800;
    font-size: 1.1em;
    color: var(--text);
    margin-bottom: 6px;
}
.station-popup-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 0.9em;
}
.station-popup-row span:first-child {
    color: var(--text-muted);
    font-weight: 600;
}
.station-popup-row span:last-child {
    color: var(--rain);
    font-weight: 800;
}
.station-popup-link {
    display: block;
    margin-top: 8px;
    text-align: center;
    color: var(--rain);
    text-decoration: none;
    font-weight: 700;
    padding: 6px;
    border-radius: 6px;
    background: #f4f7f9;
    font-size: 0.85em;
}
.station-popup-link:hover { background: #e8edf2; }

.status-toast {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(44, 62, 80, 0.95);
    color: white;
    padding: 10px 18px;
    border-radius: 24px;
    font-size: 0.85em;
    font-weight: 600;
    z-index: 600;
    box-shadow: 0 4px 14px var(--shadow-medium);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.status-toast.visible {
    opacity: 1;
}

.updated-pill {
    position: fixed;
    bottom: 16px;
    left: 16px;
    background: var(--card);
    color: var(--text-muted);
    padding: 7px 12px;
    border-radius: 20px;
    font-size: 0.78em;
    font-weight: 700;
    z-index: 500;
    box-shadow: 0 2px 8px var(--shadow-soft);
    display: flex;
    align-items: center;
    gap: 7px;
    user-select: none;
}
.updated-pill-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #48bb78;
    flex-shrink: 0;
    animation: pill-pulse 2s ease-in-out infinite;
}
.updated-pill.stale .updated-pill-dot {
    background: #ed8936;
    animation: none;
}
.updated-pill.error .updated-pill-dot {
    background: #e53e3e;
    animation: none;
}
@keyframes pill-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

@media (max-width: 600px) {
    .header-inner {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 12px;
    }
    .logo-link {
        font-size: 0.95em;
        text-align: center;
    }
    .kaart-controls {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    .kaart-datatype {
        width: 100%;
    }
    .kaart-datatype-btn {
        flex: 1;
        padding: 8px 10px;
        font-size: 0.85em;
    }
    .kaart-tabs {
        width: 100%;
    }
    .kaart-tab {
        flex: 1;
        padding: 7px 6px;
        font-size: 0.78em;
    }
    .legend {
        bottom: 10px;
        right: 10px;
        font-size: 0.78em;
        max-width: 180px;
    }
    .legend-disclaimer { font-size: 0.85em; }
    .updated-pill {
        bottom: 10px;
        left: 10px;
        font-size: 0.72em;
        padding: 6px 10px;
    }
}

.leaflet-container { font-family: inherit; background: var(--bg); }
.leaflet-popup-content-wrapper { border-radius: 10px; }
.leaflet-popup-content { margin: 12px 16px; }