/* =========================================
   1. Variables & Reset
   ========================================= */
:root {
    /* Colors - Slate & Blue Theme */
    --bg-main: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.95);
    --bg-card: rgba(15, 23, 42, 0.85);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-accent: #60a5fa;

    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;

    --border-color: rgba(148, 163, 184, 0.2);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    /* Z-Index */
    --z-map: 1;
    --z-controls: 1000;
    --z-overlay: 1100;
    --z-modal: 2000;
    --z-toast: 3000;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    width: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    /* Prevent scroll on body */
}

/* =========================================
   2. Layout & Common
   ========================================= */
.layout {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.map-wrapper {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
}

#map {
    width: 100%;
    height: 100%;
    z-index: var(--z-map);
}

/* Utilities */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

/* =========================================
   3. Components
   ========================================= */
/* =========================================
   3. Components
   ========================================= */
/* Buttons - Modernized */
.btn,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 9999px;
    /* Pill shape */
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
    border: 1px solid transparent;
    gap: 0.5rem;
    outline: none;
    box-shadow: var(--shadow-sm);
    background-color: var(--bg-card);
    /* Default background */
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn:hover,
.button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: var(--text-secondary);
}

.btn:active,
.button:active {
    transform: translateY(0);
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    border-color: transparent;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: transparent;
}

/* Reset View Button - Ghost/Outline Style */
#resetView {
    width: 100%;
    margin-top: 16px;
    padding: 12px;
    background-color: transparent;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    box-shadow: none;
    font-weight: normal;
}

#resetView:hover {
    background-color: rgba(148, 163, 184, 0.1);
    color: var(--text-primary);
    border-color: var(--text-secondary);
    transform: none;
}

/* Map Type Buttons */
#switchToGoogle,
#switchToGsiTile,
#gsiTileStd,
#gsiTilePale,
#gsiTileBlank,
#gsiTilePhoto {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    margin-bottom: 4px;
}

.button.active,
.btn.active {
    background-color: rgba(59, 130, 246, 0.2);
    color: var(--text-accent);
    border-color: var(--primary);
}


/* Segmented Control / Radio Group */
.radio-group {
    display: inline-flex;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid var(--border-color);
    gap: 2px;
}

.radio-group label {
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-width: 60px;
}

.radio-group label:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.radio-group label:has(input:checked) {
    background: var(--primary);
    color: white;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.radio-group input {
    display: none;
}

/* Select */
.select-modern,
select {
    appearance: none;
    background-color: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 32px 8px 12px;
    border-radius: 12px;
    font-size: 0.9rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.25em 1.25em;
    transition: border-color 0.2s;
}

.select-modern:focus,
select:focus {
    border-color: var(--primary);
    outline: none;
}


/* ... (Existing styles) ... */

.metric {
    background: rgba(30, 41, 59, 0.6);
    /* Slightly more transparent */
    border-radius: 20px;
    /* Rounder */
    padding: 24px;
    display: grid;
    gap: 20px;
    margin-bottom: 20px;
    /* Space between metrics */
    border: 1px solid transparent;
    /* Prepare for border */
}

/* PC: Floating Panel */
#map-panel {
    position: absolute;
    top: 24px;
    left: 24px;
    width: 360px;
    max-height: calc(100vh - 48px);
    background: var(--bg-panel);
    border-radius: 24px;
    /* Very round panel */
    box-shadow: var(--shadow-xl);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: var(--z-controls);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* PC Minimize State */
@media (min-width: 769px) {
    #map-panel:not(.open) .panel-content {
        display: none !important;
    }

    #map-panel:not(.open) {
        width: auto;
        min-width: 200px;
    }

    #map-panel:not(.open) .arrow {
        transform: rotate(-90deg);
    }
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px;
    cursor: pointer;
    background: var(--bg-panel);
    /* Ensure header has background */
    border-radius: 24px 24px 0 0;
    /* Rounded top */
    flex-shrink: 0;
}

/* When minimized, restore full rounded corners */
#map-panel:not(.open) .panel-header {
    border-radius: 24px;
}

.panel-content {
    padding: 0 24px 24px;
    /* Move scroll to content area */
    overflow-y: auto;
    /* Subtract header height approx 80px + padding */
    max-height: calc(100vh - 140px);
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.panel-content::-webkit-scrollbar {
    width: 6px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.status {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.metric-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.8;
}

/* Legend Overlay */
/* Legend Overlay */
.overlay-card {
    position: absolute;
    top: 24px;
    /* Move to Top Right to avoid Google Logo/Terms overlap */
    right: 24px;
    bottom: auto;
    background: var(--bg-card);
    border-radius: 20px;
    padding: 12px 24px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    z-index: var(--z-controls);
    backdrop-filter: blur(4px);
}

.legend {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.legend-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.legend-bar {
    width: 120px;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(90deg,
            rgb(79, 70, 229),
            rgb(59, 130, 246),
            rgb(34, 197, 94),
            rgb(234, 179, 8),
            rgb(249, 115, 22),
            rgb(239, 68, 68),
            rgb(185, 28, 28),
            rgb(157, 23, 77),
            rgb(219, 39, 119),
            rgb(236, 72, 153));
}

.legend-labels {
    display: none;
    /* Deprecated/Unused */
}

/* =========================================
   5. Mobile Styles
   ========================================= */
/* Mobile FAB */
.mobile-fab {
    display: none;
    /* Hidden on Desktop */
    position: absolute;
    bottom: 30px;
    left: 24px;
    /* Move to Bottom Left on Mobile to avoid Google Shortcuts (Bottom Right) */
    right: auto;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: var(--shadow-xl);
    color: white;
    z-index: var(--z-controls);
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    border: none;
    transition: transform 0.2s;
}

.mobile-fab:active {
    transform: scale(0.95);
}

/* Mobile Specific Overrides */
@media (max-width: 768px) {

    /* Hide default panel on mobile */
    #map-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 80vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        /* Hidden by default */
        z-index: var(--z-modal);
        border: none;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    }

    #map-panel.open {
        transform: translateY(0);
    }

    .panel-header {
        position: sticky;
        top: 0;
        background: var(--bg-panel);
        z-index: 10;
        padding: 20px;
    }

    /* Legend stays top-right on mobile */
    .overlay-card {
        top: 24px;
        right: 12px;
        left: auto;
        bottom: auto;
        padding: 6px 12px;
        transform: scale(0.9);
        transform-origin: right top;
    }

    /* Mobile: Zoom display styles (inside header) */
    .zoom-display {
        /* Reset any specific mobile positioning if needed, 
           but since it's now in flow, default styles apply */
        background: rgba(255, 255, 255, 0.1);
        padding: 4px 8px;
        font-size: 0.75rem;
    }

    /* Show FAB */
    .mobile-fab {
        display: flex;
        /* Position: defined in base class as bottom left */
        bottom: 40px;
        /* Slight adjustment */
        left: 20px;
    }

    /* Toast position */
    .status-toast {
        bottom: 120px;
        width: 90%;
        font-size: 0.85rem;
    }

    /* Backdrop for mobile modal */
    #mobile-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: var(--z-overlay);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    #mobile-backdrop.open {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Leaflet control tweaks */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.leaflet-control-zoom a {
    background: rgba(15, 23, 42, 0.9) !important;
    color: #e2e8f0 !important;
    border: 1px solid rgba(148, 163, 184, 0.2) !important;
}

.leaflet-control-zoom a:hover {
    background: rgba(30, 41, 59, 0.9) !important;
}

.leaflet-control-attribution {
    background: rgba(15, 23, 42, 0.85) !important;
    color: #94a3b8 !important;
    font-size: 0.75rem !important;
}

.leaflet-control-attribution a {
    color: #60a5fa !important;
}

/* ===== Check Map Specific Styles ===== */
.check-results {
    margin-top: 12px;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    padding-top: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 4px;
    color: #e2e8f0;
}

.stat-row strong {
    color: #93c5fd;
}

.scrollable-list {
    max-height: 150px;
    overflow-y: auto;
    margin-top: 8px;
    padding-right: 4px;
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 4px;
    padding: 4px;
    background: rgba(15, 23, 42, 0.3);
}

.scrollable-list::-webkit-scrollbar {
    width: 4px;
}

.scrollable-list::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 2px;
}

/* ===== Zoom Display ===== */
.zoom-display {
    /* Flow in header */
    background: rgba(30, 41, 59, 0.5);
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border: 1px solid rgba(148, 163, 184, 0.2);
    /* No absolute positioning */
    z-index: 1001;
    pointer-events: none;
    transition: all 0.3s ease;
}