/* Layout Core */
body, html {
    margin: 0;
    padding: 0;
    height: 100vh; /* Changed from 100% to 100vh for strictness */
    width: 100vw;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #0f1418;
    overflow: hidden; 
    font-size: 100%; 
}

body {
    display: flex;
    flex-direction: column;
}

/* --- HEADER SECTION --- */
.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1a1a1a;
    color: white;
    padding: 0 1.5%; /* Fixed padding */
    border-bottom: 0.2vh solid #34495e;
    z-index: 2000;
    flex-shrink: 0;
    height: 8vh; 
    box-sizing: border-box;
}

.header-titles h1 { 
    margin: 0; 
    font-size: 1.3rem; 
    color: #3498db; 
}

#dynamic-subtitle { 
    margin: 0.2vh 0 0 0; 
    color: #bdc3c7; 
    font-size: 0.85rem; 
}

/* --- FILTER GROUP --- */
.filter-group {
    display: flex;
    align-items: center;
    gap: 0.8vw;
}

.filter-group select {
    background: #2c3e50;
    color: white;
    border: 0.1vh solid #34495e;
    padding: 0.5vh 0.6vw;
    border-radius: 0.4vh;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
}

#reset-filters {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 0.5vh 0.8vw;
    border-radius: 0.4vh;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: bold;
}

/* --- MAIN CONTENT LAYOUT --- */
.content-body {
    display: flex;
    flex: 1; /* Automatically takes remaining 88vh */
    overflow: hidden;
    width: 100%;
}

.sidebar-common {
    flex: 0 0 25%; 
    background: #1e272e;
    color: #ffffff;
    padding: 1.5%;
    display: flex;
    flex-direction: column;
    gap: 2vh;
    overflow-y: auto;
    z-index: 1500;
    box-sizing: border-box;
}

.sidebar-common::-webkit-scrollbar { width: 0.4vw; }
.sidebar-common::-webkit-scrollbar-track { background: #1a1a1a; }
.sidebar-common::-webkit-scrollbar-thumb { background: #485460; border-radius: 0.2vw; }

#map {
    flex: 1; /* Occupies the rest of the space */
    height: 100%;
    z-index: 1;
    background: #0f1418;
    position: relative;
}

/* --- CARDS & UI COMPONENTS --- */
.card {
    background: rgba(47, 54, 64, 0.8);
    padding: 1.2rem;
    border-radius: 0.8vh;
    border: 0.1vh solid rgba(255, 255, 255, 0.1);
    margin-bottom: 1vh;
}

#legend-card {
    transition: opacity 0.3s ease;
}

h4 { 
    margin: 0 0 1vh 0; 
    color: #f5f6fa; 
    font-size: 0.9rem; 
    border-bottom: 0.1vh solid #485460; 
    padding-bottom: 0.5vh;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
}

.vote-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    padding: 0.4vh 0;
    border-bottom: 0.1vh solid rgba(255,255,255,0.05);
}

/* Timeline Grid */
.timeline-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5vw;
    margin-top: 1.5vh;
}

.timeline-box {
    text-align: center;
    padding: 0.6vh 0.2vw;
    background: rgba(0,0,0,0.3);
    border-radius: 0.4vh;
    border-bottom: 0.3vh solid transparent;
}

.timeline-year { font-size: 0.6rem; color: #95a5a6; display: block; }
.timeline-party { font-size: 0.65rem; font-weight: bold; display: block; margin-top: 0.2vh; }

/* Legend */
#legend-content {
    display: flex;
    flex-direction: column;
    gap: 0.5vh;
}

.legend-item { 
    display: flex; 
    align-items: center; 
    font-size: 0.8rem; 
}
.legend-item i { 
    width: 0.8rem; 
    height: 0.8rem; 
    margin-right: 0.6vw; 
    border-radius: 0.2vh; 
    flex-shrink: 0; 
}

/* --- FOOTER SECTION --- */
.footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1a1a1a;
    color: #bdc3c7;
    padding: 0 1.5%;
    border-top: 0.1vh solid #34495e;
    font-size: 0.75rem;
    z-index: 2000;
    flex-shrink: 0;
    height: 4vh; 
    box-sizing: border-box;
}

.footer-left {
    font-style: italic;
    color: #e67e22;
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 1vw;
}

.footer-separator { color: #485460; font-weight: bold; }
.footer-right a { color: #3498db; text-decoration: none; }
.footer-right a:hover { text-decoration: underline; }

/* --- GLASSMORPHISM LEAFLET OVERRIDES --- */
.leaflet-control-layers {
    background: rgba(30, 39, 46, 0.7) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 0.1vh solid rgba(255, 255, 255, 0.2) !important;
    color: #fff !important;
    border-radius: 0.8vh !important;
    padding: 0.5vh 0.5vw !important;
}

.leaflet-control-layers-expanded {
    padding: 1vh 1vw !important;
    background: rgba(30, 39, 46, 0.85) !important;
}

.layer-group-header {
    background: #3498db;
    color: white;
    padding: 0.5vh 0.6vw;
    margin-top: 0.8vh;
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: bold;
    border-radius: 0.3vh;
}

.map-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: rgba(255, 255, 255, 0.9) !important;
    font-weight: 600;
    font-size: 0.7rem;
    text-shadow: 0 0 0.3vh #000, 0 0 0.5vh #000;
    pointer-events: none;
}

/* Transform the icon into a small blue button with text */
.leaflet-control-layers-toggle {
    background-color: #3498db !important;
    background-image: none !important;
    width: auto !important;
    height: 32px !important;
    padding: 0 12px !important;
    border-radius: 4px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
}

.leaflet-control-layers-toggle::after {
    content: 'Select Data';
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    white-space: nowrap;
}

.leaflet-control-layers-toggle:hover {
    background-color: #2980b9 !important;
}

/* Style the expanded menu card */
.leaflet-control-layers-expanded {
    background: #1a1a1a !important; 
    color: #fff !important;
    border: 1px solid #444 !important;
    border-radius: 8px !important;
    padding: 12px !important;
    margin-top: 5px !important;
    min-width: 200px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5) !important;
}

/* Style the text inside the expanded menu */
.leaflet-control-layers-list label {
    margin-bottom: 5px;
    cursor: pointer;
    font-size: 0.85rem;
}

/* --- GLASSMORPHIC LEAFLET POPUP FIXES --- */

.leaflet-popup {
    margin-bottom: 10px;
    z-index: 1000 !important; /* Stays below Header (2000) */
}

.leaflet-popup-content-wrapper {
    background: rgba(26, 26, 26, 0.8) !important; /* Slight opacity increase for legibility */
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px !important;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.8);
    padding: 0 !important;
    max-height: 70vh !important; /* CRITICAL: Caps popup height relative to map */
    overflow: hidden !important;
}

.leaflet-popup-tip {
    background: rgba(26, 26, 26, 0.8) !important;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.leaflet-popup-content {
    margin: 0 !important; /* Padding is handled by .glass-popup-content */
    font-family: 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    width: 320px !important;
}

.leaflet-container a.leaflet-popup-close-button {
    color: rgba(255, 255, 255, 0.5) !important;
    top: 10px !important;
    right: 10px !important;
    font-size: 16px !important;
    z-index: 2001;
}

.leaflet-container a.leaflet-popup-close-button:hover {
    color: #e74c3c !important;
}

.glass-popup-content {
    padding: 15px;
    color: #fff;
    display: flex;
    flex-direction: column;
}

.glass-popup-content h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 8px 0;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: #3498db;
}

.popup-subtitle {
    color: #95a5a6;
    font-size: 0.75rem;
    margin: 0 0 10px 0;
}

/* --- Internal Scrollbar --- */
.scroll-area {
    max-height: 320px; /* Reduced to ensure visibility */
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px;
}

.scroll-area::-webkit-scrollbar { width: 4px; }
.scroll-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.chart-box {
    height: 140px; /* Standardized height to prevent expansion */
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 8px;
}

.chart-box label {
    font-size: 0.7rem;
    color: #aaa;
    display: block;
    margin-bottom: 5px;
}

.popup-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.census-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 0.75rem;
}

.popup-help-text {
    font-size: 0.65rem; 
    color: #888; 
    font-style: italic; 
    text-align: center; 
    margin-top: 10px; 
    padding: 8px 0; 
    border-top: 1px dashed #444;
}

#map-info-dock {
    position: absolute;
    z-index: 1001; /* Ensure it stays above map controls */
    display: none; /* JS will change to 'flex' */
    flex-direction: column;
    width: 350px;
    max-height: 85vh; /* Prevents dock from being taller than the screen */
    background: rgba(15, 33, 44, 0.877);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    overflow: hidden; /* Keeps children inside rounded corners */
}

#dock-header {
    flex-shrink: 0; /* Prevents header from squishing */
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: move;
}

#dock-content {
    flex-grow: 1; /* Takes up remaining space */
    overflow-y: auto !important; /* Forces scrollbar for long data */
    padding: 15px;
    pointer-events: auto !important; /* Vital for chart interaction */
}

/* Custom Scrollbar */
#dock-content::-webkit-scrollbar { width: 6px; }
#dock-content::-webkit-scrollbar-thumb { 
    background: #333e57d5; 
    border-radius: 10px; 
}