:root {
    --bg-color: #f8fafc;
    --sidebar-bg: rgba(255, 255, 255, 0.95);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #2563eb;
    --border-color: #e2e8f0;
    --hover-bg: #f1f5f9;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.app-container {
    display: flex;
    height: 100%;
    width: 100%;
    position: relative;
}

/* Common Panel Styles */
.glass-panel {
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    padding: 20px;
}

/* Mobile Search Panel - Default Hidden on Desktop */
.mobile-search-panel {
    display: none;
}

/* Sidebar (Controls) - PC Defaults */
.sidebar {
    width: 340px;
    height: 95%; /* Restore full height */
    position: absolute;
    top: 2.5%;
    left: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: transform 0.3s ease, height 0.3s ease;
}

/* Mobile Toggle - Default Hidden on Desktop */
.mobile-toggle {
    display: none;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

/* Helper classes for responsive visibility */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: flex !important;
}

/* Mobile Styles */
@media (max-width: 768px) {
    /* Show mobile search panel */
    .mobile-search-panel {
        display: flex;
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        width: auto;
        padding: 12px;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.98);
        z-index: 1001;
        flex-direction: column;
        gap: 8px;
    }

    /* Hide desktop-specific search in sidebar */
    .desktop-search-group {
        display: none;
    }

    .mobile-only {
        display: flex !important;
    }
    
    .desktop-only {
        display: none !important;
    }

    /* Sidebar becomes bottom drawer */
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 60vh;
        left: 0;
        bottom: 0;
        top: auto;
        border-radius: 20px 20px 0 0;
        transform: translateY(0);
        padding-top: 10px;
        background: rgba(255, 255, 255, 0.98);
    }

    .sidebar.collapsed {
        transform: translateY(calc(100% - 40px));
    }

    /* Handle for dragging/toggling */
    .mobile-toggle {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 8px 0;
        cursor: pointer;
        width: 100%;
        gap: 4px;
    }

    .toggle-handle {
        width: 36px;
        height: 4px;
        background-color: #cbd5e1;
        border-radius: 2px;
    }

    .toggle-icon {
        font-size: 20px;
        color: #64748b;
        transition: transform 0.3s ease;
    }

    /* Rotate icon when collapsed (to point UP) */
    .sidebar.collapsed .toggle-icon {
        transform: rotate(180deg);
    }

    /* Map Controls adjustment */
    .leaflet-control-container .leaflet-top {
        top: 100px; /* Push map controls below search panel */
    }

    .leaflet-control-container .leaflet-bottom {
        bottom: 50px; /* Push attribution above collapsed sidebar */
    }
    
    /* Ensure legend is visible in mobile scroll */
    .controls {
        padding-bottom: 20px;
    }
}

.logo i {
    font-size: 22px;
    color: var(--accent-color);
}

.logo h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto; 
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 600;
}

.select-wrapper {
    position: relative;
}

select {
    width: 100%;
    appearance: none;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Search Box */
.search-wrapper {
    display: flex;
    gap: 8px;
}

input[type="text"] {
    flex: 1;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    font-family: var(--font-family);
    font-size: 13px;
    color: var(--text-primary);
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.search-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.search-btn:hover {
    background: #1d4ed8;
}

select:hover {
    border-color: var(--text-secondary);
}

select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.select-wrapper i {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-secondary);
}

.divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Radio Group */
.radio-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.radio-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    font-size: 13px;
}

.radio-card:hover {
    background: var(--hover-bg);
}

.radio-card.active {
    background: rgba(37, 99, 235, 0.1);
    border-color: var(--accent-color);
}

.radio-card:not(.active) {
    background: #ffffff;
    border: 1px solid var(--border-color);
}

.color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.radio-card span:last-child {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Status & Legend */
.status-bar {
    margin-top: auto;
    font-size: 11px;
    color: var(--text-secondary);
    padding-top: 4px;
}

.legend-container {
    margin-top: 6px;
}

.legend-container h3 {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.gradient-bar {
    height: 6px;
    width: 100%;
    border-radius: 3px;
    background: linear-gradient(to right, #f7fbff, #08306b);
    margin-bottom: 4px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-secondary);
}

/* Map area */
#map {
    flex: 1;
    height: 100%;
    width: 100%;
    z-index: 1;
}

/* Leaflet Customization */
.leaflet-container {
    background-color: #0f172a;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 20px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    font-size: 16px;
    font-weight: 500;
    color: white;
    margin: 0;
}

/* Mobile Toggle */
.mobile-toggle {
    display: none;
}

.mobile-only {
    display: none;
}

/* Mobile Adaptation */
@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    /* Top Search Bar */
    .search-panel {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        width: auto; /* Full width minus margins */
        height: auto;
        padding: 12px;
        border-radius: 12px;
        gap: 0; /* Tighten up */
        background: rgba(255, 255, 255, 0.98); /* Less transparent for readability */
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    
    .search-panel .logo {
        margin-bottom: 8px;
        justify-content: center;
    }
    
    .search-panel .logo h1 {
        font-size: 16px;
    }

    /* Bottom Drawer */
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 50vh; /* Max height when expanded */
        bottom: 0;
        top: auto;
        left: 0;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 12px 20px 20px 20px;
        transform: translateY(0); /* Expanded state */
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
        z-index: 1002; /* Above map controls */
    }

    /* Collapsed state: hide most content, show handle */
    .sidebar.collapsed {
        transform: translateY(calc(100% - 30px)); /* Only show handle area */
    }
    
    /* When collapsed, let map controls be clickable */
    .sidebar.collapsed {
        pointer-events: all; /* Handle is clickable */
    }

    .mobile-toggle {
        display: flex;
        justify-content: center;
        padding-bottom: 12px;
        cursor: pointer;
        width: 100%;
        margin-top: -5px; /* Pull up slightly */
    }

    .toggle-handle {
        width: 40px;
        height: 5px;
        background-color: #cbd5e1;
        border-radius: 3px;
    }
    
    /* Make controls scrollable on mobile */
    .controls {
        overflow-y: auto;
        padding-bottom: 10px;
        scrollbar-width: none;
    }
    
    .controls::-webkit-scrollbar {
        display: none;
    }
    
    /* Adjust map controls position */
    .leaflet-control-container .leaflet-top {
        top: 100px; /* Push down below search bar */
    }
    
    .leaflet-control-container .leaflet-bottom {
        bottom: 40px; /* Push up above collapsed drawer handle */
    }
}
