/* ==========================================
   VARIABLES & RESET
   ========================================== */
:root {
    --primary-red: #c41e3a;
    --primary-black: #1a1a1a;
    --soft-green: #2d5016;
    --soft-white: #f8f9fa;
    --text-dark: #2d2d2d;
    --text-light: #666666;
    --bg-light: #ffffff;
    --border-color: #e0e0e0;
    --navbar-height: 60px;
}

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

body {
    font-family: Arial, sans-serif;
    color: var(--text-dark);
    line-height: 1.6;
}

/* ==========================================
   NAVBAR
   ========================================== */
.navbar {
    background: var(--primary-black);
    color: white;
    padding: 0.8rem 0;
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand h1 { font-size: 1.3rem; margin-bottom: 0.25rem; }
.tagline { font-size: 0.85rem; color: var(--primary-red); font-weight: bold; }

.nav-links { display: flex; list-style: none; gap: 2rem; }
.nav-links a { color: white; text-decoration: none; font-weight: 500; transition: color 0.3s; }
.nav-links a:hover, .nav-links a.active { color: var(--primary-red); }

.mobile-menu-toggle {
    display: none; flex-direction: column; background: none; border: none; cursor: pointer; padding: 0.5rem;
}
.mobile-menu-toggle span { width: 25px; height: 3px; background: white; margin: 3px 0; transition: 0.3s; }

/* ==========================================
   MAP PAGE SPECIFIC LAYOUT
   ========================================== */
body.map-page {
    overflow: hidden; /* Prevents whole page scroll, lets map handle it */
    height: 100vh;
}

#map { 
    position: absolute; 
    top: var(--navbar-height);
    bottom: 0; 
    left: 0;
    right: 400px;
    width: 100%; 
    z-index: 1;
}

/* ==========================================
   FILTER CONTROLS (Top Left)
   ========================================== */
.controls {
    position: absolute;
    top: calc(var(--navbar-height) + 25px);
    left: 44px;
    background: var(--bg-light);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    max-width: 300px;
    max-height: calc(100vh - var(--navbar-height) - 20px);
    overflow-y: auto;
}

.controls h2 { margin: 0 0 15px 0; font-size: 18px; color: #2E75B6; }
.controls input[type="text"], .controls select {
    width: 100%; padding: 8px; margin-bottom: 10px; border: 1px solid var(--border-color);
    border-radius: 4px; background: var(--bg-light); color: var(--text-dark);
}
.controls button {
    width: 100%; padding: 10px; background: #2E75B6; color: white; border: none;
    border-radius: 4px; cursor: pointer; font-size: 14px; margin-top: 5px;
}
.controls button:hover { background: #1f5a8a; }
.export-buttons { display: flex; gap: 5px; margin-top: 10px; }
.export-btn { width: 100%; padding: 8px; background: #28a745; font-size: 12px; }
.export-btn:hover { background: #218838; }

/* ==========================================
   SIDE PANEL (Right)
   ========================================== */
.side-panel {
    position: absolute;
    top: var(--navbar-height);
    right: 0px; /* Hidden by default */
    width: 400px;
    bottom: 0;
    background: var(--bg-light);
    box-shadow: -2px 0 10px rgba(0,0,0,0.2);
    z-index: 1000;
    transition: right 0.3s ease;
    display: flex;
    height: 75vh !important;
    flex-direction: column;
}

.side-panel.open { right: 0; }

.panel-header {
    padding: 20px; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.panel-header h3 { margin: 0; color: #2E75B6; }
.close-panel { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-dark); }

.panel-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.station-list { flex: 1; padding: 10px; }
.station-item {
    padding: 15px; border-bottom: 1px solid var(--border-color); cursor: pointer; transition: background 0.2s;
}
.station-item:hover { background: var(--soft-white); }
.station-item h4 { margin: 0 0 5px 0; color: #2E75B6; font-size: 1rem; }
.station-item p { margin: 3px 0; font-size: 14px; color: var(--text-light); }

/* ==========================================
   BOTTOM INFO BAR (Foolproof Toggle)
   ========================================== */
.map-info-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-light);
    border-top: 2px solid var(--border-color);
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
}

/* When collapsed, push up so ONLY the 40px toggle button is visible */
.map-info-bar.collapsed {
    transform: translateY(calc(100% - 40px));
}

.info-bar-toggle {
    width: 100%;
    height: 40px;
    background: var(--bg-light);
    border: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
}

.info-bar-toggle:hover { background: var(--soft-white); }

.info-bar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    gap: 20px;
}

.stats { flex: 1; }
.stats p { margin: 3px 10px 3px 0; font-size: 13px; color: var(--text-dark); display: inline-block; }

.legend { display: flex; align-items: center; gap: 5px; }
.legend h3 { margin: 0 0 10px 0; font-size: 14px; font-weight: bold; color: var(--text-dark); }
.legend-item { display: inline-flex; align-items: center; margin: 3px 10px 3px 0; font-size: 12px; color: var(--text-dark); }
.legend-color { width: 15px; height: 15px; border-radius: 50%; margin-right: 8px; border: 1px solid #fff; }

/* ==========================================
   LOADING SPINNER & HELP BUTTON
   ========================================== */
.loading {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.9); z-index: 9999;
    display: none; flex-direction: column; align-items: center; justify-content: center;
}
.loading.active { display: flex; }
.spinner {
    border: 3px solid #f3f3f3; border-top: 3px solid #2E75B6; border-radius: 50%;
    width: 30px; height: 30px; animation: spin 1s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.help-btn {
    position: absolute; top: calc(var(--navbar-height) + 10px); right: 10px; width: 40px; height: 40px;
    border-radius: 50%; background: #2E75B6; color: white; border: none; font-size: 20px; font-weight: bold;
    cursor: pointer; z-index: 1000; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

/* ==========================================
   MOBILE RESPONSIVENESS
   ========================================== */
@media (max-width: 768px) {
    .mobile-menu-toggle { display: flex !important; }
    .nav-links {
        position: absolute; top: 100%; left: 0; right: 0; background: var(--primary-black);
        flex-direction: column; gap: 0; padding: 0; max-height: 0; overflow: hidden; transition: max-height 0.3s;
    }
    .nav-links.active { max-height: 300px; }
    .nav-links li { border-bottom: 1px solid rgba(255,255,255,0.1); }
    .nav-links a { display: block; padding: 1rem 2rem; }

    /* Controls become a bottom sheet on mobile */
    .controls {
        top: auto; bottom: 0; left: 0; right: 0; max-width: 100%;
        border-radius: 12px 12px 0 0; transform: translateY(0);
        bottom: 60px;
        
        z-index: 1000;
        transition: transform 0.3s ease;
    }
    .controls.mobile-open { transform: translateY(0);
     }

    /* Side panel takes full width */
    .side-panel { width: 100%; right: -100%; }
    .side-panel.open { right: 0; }

    /* Info bar adjustments */
    .map-info-bar.collapsed { transform: translateY(calc(100% - 45px)); }
    .info-bar-content { flex-direction: column; padding: 10px 15px; gap: 10px; text-align: center; }
    .stats p { display: block; margin: 4px 0; font-size: 12px; }
    .legend h3 { font-size: 12px; margin-bottom: 5px; }
    .legend-item { font-size: 11px; margin: 2px 5px; }
}

/* ==========================================
   FIX 1: CONTROLS (Always visible, higher z-index)
   ========================================== */
.controls {
    position: absolute;
    top: calc(var(--navbar-height) + 10px);
    left: 10px;
    background: var(--bg-light);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1002; /* 👈 HIGHER than side panel and info bar */
    max-width: 300px;
    max-height: calc(100vh - var(--navbar-height) - 20px);
    overflow-y: auto;
}

/* ==========================================
   FIX 2: SIDE PANEL (Proper closing, won't cover controls)
   ========================================== */
.side-panel {
    position: absolute;
    top: var(--navbar-height);
    right: -400px; /* Hidden by default */
    width: 400px;
    bottom: 0;
    background: var(--bg-light);
    box-shadow: -2px 0 10px rgba(0,0,0,0.2);
    z-index: 1001; /* 👈 LOWER than controls */
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.side-panel.open { 
    right: 0; /* Slides in */
}

/* ==========================================
   FIX 3: BOTTOM INFO BAR (Toggle button stays visible)
   ========================================== */
.map-info-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-light);
    border-top: 2px solid var(--border-color);
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
}

/* 👈 CRITICAL FIX: Only hide the content, keep the 45px button visible */
.map-info-bar.collapsed {
    transform: translateY(calc(100% - 45px)); 
}

.info-bar-toggle {
    width: 100%;
    height: 45px; /* 👈 EXPLICIT HEIGHT MATCHES THE CALC ABOVE */
    background: var(--bg-light);
    border: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
}

/* ==========================================
   FIX 4: MOBILE RESPONSIVENESS (Prevent controls from hiding)
   ========================================== */
@media (max-width: 768px) {
    .controls {
        top: auto; 
        bottom: 60px; /* 👈 Sit ABOVE the info bar, not off-screen */
        left: 10px; 
        right: 10px; 
        max-width: none;
        border-radius: 8px; 
        transform: translateY(0); /* 👈 FORCE VISIBLE, NO HIDING */
        max-height: 50vh; /* Don't cover the whole map */
        z-index: 1002;
    }

    .side-panel { 
        width: 100%; 
        right: -100%; 
        z-index: 1001;
    }
    
    .map-info-bar.collapsed { 
        transform: translateY(calc(100% - 45px)); 
    }
}

/* ==========================================
   CUSTOM MAP MARKERS
   ========================================== */
.custom-marker {
    background: transparent !important;
    border: none !important;
    transition: transform 0.2s ease;
}

.custom-marker:hover {
    transform: scale(1.2);
    z-index: 1000 !important;
}

/* Make popups look nicer */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.leaflet-popup-content {
    margin: 12px 16px;
    line-height: 1.5;
}