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

:root {
    --bg-primary: rgba(18, 18, 18, 0.8);
    --bg-surface: rgba(30, 30, 30, 0.75);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --success: #10b981;
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --radius: 16px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: #0b0f19;
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

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

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: radial-gradient(circle at 50% 40%, #0f1b2d 0%, #0b0f19 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.4s ease;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-box {
    text-align: center;
}

.loader-spinner {
    width: 54px;
    height: 54px;
    margin: 0 auto 20px;
    border: 4px solid rgba(255, 255, 255, 0.12);
    border-top-color: #0ea5e9;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-title {
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, #2dd4bf, #0ea5e9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.loader-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* UI Overlay Container */
.ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    display: flex;
}

.interactive-panel {
    pointer-events: auto;
}

/* Sidebar Styling */
.sidebar {
    width: 380px;
    height: calc(100% - 40px);
    margin: 20px;
    background: var(--bg-primary);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition);
}

.sidebar.collapsed {
    transform: translateX(-420px);
}

/* Suppress the slide animation when collapsing on first load (mobile) */
.sidebar.no-anim {
    transition: none !important;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h1 {
    font-size: 20px;
    font-weight: 600;
    background: linear-gradient(135deg, #2dd4bf, #0ea5e9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-header p {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.close-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.close-btn:hover {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

/* Sidebar Scrollable Content */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.section-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

/* Map / Area Selector (the 5 maps) */
.map-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.map-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
}

.map-card:hover:not(.active) {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(30, 30, 30, 0.9);
}

.map-card.active {
    border-color: var(--accent);
    background: rgba(14, 165, 233, 0.12);
}

.map-card .map-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--accent);
}

.map-card .map-meta {
    flex: 1;
    min-width: 0;
}

.map-card .map-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-card .map-sub {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Floating Opacity Panel (top-right) */
.opacity-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 11;
    background: var(--bg-primary);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 16px;
    width: 280px;
}

.opacity-panel-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* Opacity Control */
.opacity-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.opacity-btn {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: var(--transition);
}

.opacity-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(14, 165, 233, 0.1);
}

.opacity-value {
    flex-shrink: 0;
    width: 44px;
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}

.opacity-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.12);
    outline: none;
    cursor: pointer;
}

.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.opacity-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.opacity-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

/* Layer Control List */
.layer-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 24px;
}

.layer-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: var(--transition);
}

.layer-item:hover {
    border-color: rgba(14, 165, 233, 0.5);
    background: rgba(30, 30, 30, 0.9);
}

.layer-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.layer-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.layer-name {
    font-size: 14px;
    font-weight: 500;
}

.layer-count {
    font-size: 11px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 8px;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .3s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
}

input:checked + .slider:before {
    transform: translateX(18px);
}

/* Base Map Selector */
.basemap-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.basemap-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.basemap-card.active {
    border-color: var(--accent);
    background: rgba(14, 165, 233, 0.1);
}

.basemap-card:hover:not(.active) {
    border-color: rgba(255, 255, 255, 0.2);
}

.basemap-card span {
    font-size: 13px;
    font-weight: 500;
    display: block;
    margin-top: 4px;
}

.basemap-icon {
    font-size: 20px;
}

/* Search Box */
.search-container {
    margin-bottom: 24px;
    position: relative;
}

.search-input {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
}

/* Floating Sidebar Toggle Button */
.toggle-sidebar-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 11;
    background: var(--bg-primary);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    color: var(--text-primary);
    transition: var(--transition);
    transform: scale(0);
}

.toggle-sidebar-btn.visible {
    transform: scale(1);
}

.toggle-sidebar-btn:hover {
    background: rgba(30, 30, 30, 0.9);
}

/* Legend / Stats Footer */
.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Popups and Tooltips overrides for Leaflet */
.leaflet-popup-content-wrapper {
    background: var(--bg-primary) !important;
    backdrop-filter: blur(12px) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    border-radius: 12px !important;
    box-shadow: var(--shadow) !important;
}

.leaflet-popup-tip {
    background: var(--bg-primary) !important;
    border: 1px solid var(--border-color) !important;
}

.leaflet-popup-content {
    font-family: 'Outfit', sans-serif !important;
    line-height: 1.5;
}

.popup-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 6px;
    color: #38bdf8;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 4px;
}

.popup-detail {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.popup-detail strong {
    color: var(--text-primary);
}

/* Zoom controls styling */
.leaflet-control-zoom {
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius) !important;
    overflow: hidden;
    box-shadow: var(--shadow) !important;
}

.leaflet-control-zoom-in, .leaflet-control-zoom-out {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border-bottom: 1px solid var(--border-color) !important;
    transition: var(--transition);
}

.leaflet-control-zoom-in:hover, .leaflet-control-zoom-out:hover {
    background-color: rgba(30, 30, 30, 0.9) !important;
    color: var(--accent) !important;
}

/* Styled measurement values inside popups */
.popup-measurement {
    font-family: 'JetBrains Mono', monospace;
    color: #fbbf24;
    font-weight: 600;
    font-size: 11.5px;
}

/* ===================== Mobile ===================== */
@media (max-width: 768px) {
    /* Sidebar opens as an overlay ON TOP of the opacity panel */
    .sidebar {
        position: relative;
        z-index: 1200;
        width: calc(100% - 24px);
        max-width: 360px;
        height: calc(100% - 24px);
        margin: 12px;
    }

    .sidebar.collapsed {
        transform: translateX(-115%);
    }

    /* Opacity slider sits BELOW the sidebar */
    .opacity-panel {
        z-index: 11;
        top: 12px;
        right: 12px;
        width: calc(100% - 88px);
        max-width: 280px;
        padding: 10px 12px;
    }

    /* Open button stays tappable */
    .toggle-sidebar-btn {
        z-index: 1201;
        top: 12px;
        left: 12px;
    }

    /* Close button: bigger, highlighted, easy to tap */
    .close-btn {
        width: 46px;
        height: 46px;
        font-size: 28px;
        background: var(--accent);
        color: #fff;
        border-color: var(--accent);
        box-shadow: 0 4px 14px rgba(14, 165, 233, 0.5);
    }
}
