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

:root {
    --bg-dark: #0f172a;
    --bg-glass: rgba(15, 23, 42, 0.85);
    --border-glass: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-risk-high: #ef4444;
    --accent-risk-med: #f59e0b;
    --accent-risk-low: #10b981;
    --primary-action: #38bdf8;

    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-glow: 0 0 15px rgba(56, 189, 248, 0.15);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Map Container */
#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* UI Overlay Container */
.ui-overlay {
    position: relative;
    z-index: 1000;
    pointer-events: none;
    /* Let clicks pass through empty spaces */
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.5rem;
}

/* Common Glassmorphism */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    pointer-events: auto;
    /* Re-enable clicks */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Header */
header.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
}

.app-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
    margin-top: 0.25rem;
    font-weight: 400;
}

/* Sidebar / Controls */
.sidebar {
    width: 320px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.25rem;
}

.panel-section {
    margin-bottom: 1.5rem;
}

.panel-section:last-child {
    margin-bottom: 0;
}

.section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

/* Custom Checkboxes */
.layer-toggle-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.layer-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.layer-checkbox {
    appearance: none;
    width: 1.1em;
    height: 1.1em;
    border: 2px solid var(--text-secondary);
    border-radius: 4px;
    background-color: transparent;
    display: grid;
    place-content: center;
    transition: all 0.2s;
}

.layer-checkbox::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--bg-dark);
    transform-origin: center;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.layer-checkbox:checked {
    border-color: var(--primary-action);
    background-color: var(--primary-action);
}

.layer-checkbox:checked::before {
    transform: scale(1);
    background-color: white;
    /* Important, was using box-shadow trick which fails on solid */
    box-shadow: none;
    background-color: var(--bg-dark);
}

.layer-label {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Insight Card */
.insight-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
}

.insight-metric {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.insight-value {
    font-weight: 600;
    color: var(--primary-action);
}

.insight-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
    font-style: italic;
    border-left: 2px solid var(--primary-action);
    padding-left: 0.75rem;
    margin-top: 0.75rem;
}

/* Popups */
.leaflet-popup-content-wrapper {
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
}

.leaflet-popup-tip {
    background: var(--bg-dark);
}

.popup-header {
    font-weight: 700;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

/* Legend/Disclaimer Bottom Right */
.bottom-panel {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    max-width: 350px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.status-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.status-light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ade80;
    /* Green */
    box-shadow: 0 0 10px #4ade80;
    flex-shrink: 0;
}

.status-light.offline {
    background: #ef4444;
    /* Red */
    box-shadow: 0 0 10px #ef4444;
}

.credits {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 0.5rem;
}

.credits a {
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.credits a:hover {
    color: #fff;
    border-bottom-color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Animations */
@keyframes pulse-risk {
    0% {
        fill-opacity: 0.4;
    }

    50% {
        fill-opacity: 0.7;
    }

    100% {
        fill-opacity: 0.4;
    }
}

.risk-polygon-high {
    animation: pulse-risk 4s infinite;
}