:root {
    --bg-color: #0b1329;
    --text-color: #f8fafc;
    --nav-bg: rgba(11, 19, 41, 0.95);
    --nav-border: rgba(255, 255, 255, 0.1);
    --panel-bg: rgba(15, 23, 42, 0.9);
    --panel-border: rgba(255, 255, 255, 0.1);
    --panel-title: #e2e8f0;
    --panel-text: #cbd5e1;
    --popup-bg: rgba(15, 23, 42, 0.95);
    --popup-text: #f8fafc;
}

[data-theme="light"] {
    --bg-color: #f1f5f9;
    --text-color: #1e293b;
    --nav-bg: rgba(255, 255, 255, 0.95);
    --nav-border: rgba(0, 0, 0, 0.1);
    --panel-bg: rgba(255, 255, 255, 0.95);
    --panel-border: rgba(0, 0, 0, 0.1);
    --panel-title: #0f172a;
    --panel-text: #475569;
    --popup-bg: rgba(255, 255, 255, 0.95);
    --popup-text: #1e293b;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Sarabun', sans-serif;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

.top-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--nav-border);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: #38bdf8;
    white-space: nowrap;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.region-select {
    background: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid var(--nav-border);
    padding: 5px 12px;
    border-radius: 20px;
    font-family: 'Sarabun', sans-serif;
    font-size: 14px;
    outline: none;
    cursor: pointer;
}

.region-select option:disabled {
    color: #64748b;
    background: #1e293b;
}

.theme-switch-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-color);
}

.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 22px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #334155;
    transition: 0.3s;
    border-radius: 22px;
    border: 1px solid var(--nav-border);
}

.slider:before {
    position: absolute;
    content: "🌙";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
}

input:checked + .slider {
    background-color: #38bdf8;
}

input:checked + .slider:before {
    transform: translateX(20px);
    content: "☀️";
}

#map {
    position: absolute;
    top: 60px;
    left: 0;
    width: 100%;
    height: calc(100% - 60px);
    z-index: 1;
}

.leaflet-control-attribution {
    display: none !important;
}

.legend-panel {
    position: absolute;
    bottom: 65px;
    left: 15px;
    width: 240px;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    z-index: 1000;
    padding: 10px 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.legend-toggle-btn {
    display: none;
    background: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid var(--panel-border);
    padding: 6px 12px;
    border-radius: 20px;
    font-family: 'Sarabun', sans-serif;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    align-items: center;
    gap: 6px;
}

.bottom-status-panel {
    position: absolute;
    bottom: 20px;
    left: 15px;
    right: 15px;
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    z-index: 1000;
    padding: 6px 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    font-size: 12px;
    color: var(--panel-text);
    text-align: center;
}

.sidebar-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--panel-title);
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 3px;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 11px;
    margin-bottom: 4px;
    color: var(--panel-text);
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    box-shadow: 0 0 6px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

.leaflet-popup-content-wrapper {
    background: var(--popup-bg);
    color: var(--popup-text);
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

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

.leaflet-popup-content {
    font-family: 'Sarabun', sans-serif;
    font-size: 12px;
    line-height: 1.4;
    margin: 8px 12px;
}

.popup-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.popup-list li {
    margin-bottom: 3px;
    font-weight: normal;
}

.popup-title-bold {
    font-weight: bold;
}

.popup-source {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 5px;
    border-top: 1px solid rgba(128,128,128,0.2);
    padding-top: 3px;
    text-align: right;
}

@media (min-width: 769px) {
    .bottom-status-panel {
        left: auto;
        right: 20px;
        bottom: 25px;
        width: auto;
        text-align: left;
    }
    .legend-panel {
        bottom: 25px;
        left: 20px;
    }
}

@media (max-width: 768px) {
    .top-navbar {
        height: auto;
        padding: 10px 12px;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .nav-brand {
        font-size: 13px;
        justify-content: flex-start;
        white-space: normal;
        line-height: 1.3;
    }
    .nav-controls {
        justify-content: space-between;
        width: 100%;
    }
    .region-select {
        font-size: 12px;
        padding: 4px 10px;
        flex: 1;
    }
    #map {
        top: 95px;
        height: calc(100% - 95px);
    }
    .legend-toggle-btn {
        display: flex;
        position: absolute;
        bottom: 65px;
        left: 15px;
        z-index: 1000;
        font-size: 11px;
    }
    .legend-panel {
        position: absolute;
        bottom: 105px;
        left: 15px;
        transform: translateY(20px);
        opacity: 0;
        pointer-events: none;
    }
    .legend-panel.show {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }
    .bottom-status-panel {
        bottom: 20px;
        left: 15px;
        right: 15px;
        font-size: 11px;
        padding: 5px 10px;
    }
}