/* ============================================================================
   Border Visualization - Main Stylesheet
   Matching VoteValue color scheme
   ============================================================================ */

/* CSS Variables - Matching main VVI page */
:root {
    /* Primary Colors - Patriotic Theme */
    --color-primary: #c1121f;
    --color-primary-dark: #780000;
    --color-primary-light: #669bbc;
    --color-secondary: #003049;
    --color-accent: #f59e0b;
    --color-warning: #d97706;
    --color-success: #059669;
    
    /* Neutrals */
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #003049 0%, #669bbc 50%, #c1121f 100%);
    --gradient-hero: linear-gradient(135deg, #003049 0%, #669bbc 30%, #c1121f 60%, #f59e0b 100%);
    --gradient-accent: linear-gradient(135deg, #669bbc 0%, #c1121f 50%, #f59e0b 100%);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
    
    /* Typography */
    --font-sans: 'Poppins', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ============================================================================
   Landing Page
   ============================================================================ */

.landing-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.landing-header {
    background: var(--gradient-hero);
    background-size: 200% 200%;
    animation: gradientShift 15s ease infinite;
    color: white;
    padding: 4rem 2rem;
    text-align: center;
}

.landing-header h1 {
    margin: 0 0 0.5rem;
    font-size: 2.5rem;
    font-weight: 700;
}

.landing-header .subtitle {
    margin: 0;
    font-size: 1.125rem;
    opacity: 0.9;
}

/* Map Selector */
.map-selector {
    padding: 3rem 2rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.map-selector h2 {
    text-align: center;
    margin: 0 0 2rem;
    font-size: 1.5rem;
    color: var(--color-text);
}

.map-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.map-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    border: 2px solid transparent;
}

.map-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.leaflet-card:hover {
    border-color: var(--color-secondary);
}

.mapbox-card:hover {
    border-color: var(--color-primary);
}

.map-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 1rem;
}

.leaflet-card .map-icon {
    color: var(--color-secondary);
}

.mapbox-card .map-icon {
    color: var(--color-primary);
}

.map-card h3 {
    margin: 0 0 0.5rem;
    font-size: 1.25rem;
}

.map-card p {
    margin: 0 0 1rem;
    color: var(--color-text-muted);
    font-size: 0.9375rem;
}

.map-card .features {
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.map-card .features li {
    background: var(--color-bg);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.map-card .cta {
    margin-top: auto;
    font-weight: 600;
    font-size: 0.9375rem;
}

.leaflet-card .cta {
    color: var(--color-secondary);
}

.mapbox-card .cta {
    color: var(--color-primary);
}

/* Info Section */
.info-section {
    background: var(--color-surface);
    padding: 3rem 2rem;
    border-top: 1px solid var(--color-border);
}

.info-section h2 {
    text-align: center;
    margin: 0 0 2rem;
    font-size: 1.5rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
}

.info-card {
    padding: 1.5rem;
    background: var(--color-bg);
    border-radius: var(--radius-md);
}

.info-card h4 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    color: var(--color-text);
}

.info-card p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* Footer */
.landing-footer {
    margin-top: auto;
    padding: 2rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--color-border);
}

.landing-footer p {
    margin: 0.25rem 0;
}

/* ============================================================================
   Map Pages
   ============================================================================ */

.map-page {
    display: flex;
    height: calc(100vh - 42px);
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 420px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    flex-shrink: 0;
    transition: margin-left 0.3s ease;
}

/* Desktop: collapsed sidebar slides off-screen */
.sidebar.desktop-collapsed {
    margin-left: -420px;
}

/* Desktop sidebar toggle tab */
.desktop-sidebar-toggle {
    display: flex;
    position: absolute;
    top: 50%;
    left: 420px;
    transform: translateY(-50%);
    z-index: 1001;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: none;
    border-radius: 0 8px 8px 0;
    padding: 0.75rem 0.35rem;
    cursor: pointer;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
    font-size: 0.9rem;
    color: var(--color-text-muted);
    align-items: center;
    transition: left 0.3s ease;
    writing-mode: vertical-rl;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    gap: 0.35rem;
}

.desktop-sidebar-toggle:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

.sidebar.desktop-collapsed + .desktop-sidebar-toggle,
.sidebar.desktop-collapsed ~ .desktop-sidebar-toggle {
    left: 0;
}

.sidebar-header {
    background: var(--gradient-hero);
    background-size: 200% 200%;
    animation: gradientShift 15s ease infinite;
    color: white;
    padding: 1.25rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.sidebar-header .header-nav {
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
}

.sidebar-header .header-nav .nav-link {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    transition: background 0.2s, color 0.2s;
}

.sidebar-header .header-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.sidebar-header h1 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

/* Import VVR Section */
.import-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.import-vvr-btn {
    width: 100%;
    padding: 0.625rem 1rem;
    background: var(--gradient-accent);
    background-size: 200% 200%;
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(193, 18, 31, 0.2);
}

.import-vvr-btn:hover {
    background-position: 100% 50%;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(193, 18, 31, 0.35);
}

.vvr-project-info {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: linear-gradient(135deg, #fef3c7 0%, #fff7ed 100%);
    border: 1px solid var(--color-accent);
    border-radius: var(--radius-sm);
}

.vvr-project-info .project-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.vvr-project-info .project-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-secondary);
}

.vvr-project-info .close-vvr-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    line-height: 1;
    border-radius: 4px;
}

.vvr-project-info .close-vvr-btn:hover {
    background: #fee2e2;
    color: #dc2626;
}

.vvr-project-info .project-stats {
    font-size: 0.75rem;
    color: #374151;
    line-height: 1.5;
}

.vvr-project-info .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.125rem 0;
}

.vvr-project-info .stat-label {
    color: #6b7280;
}

.vvr-project-info .stat-value {
    font-weight: 500;
}

.vvr-project-info .partisan-shift {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed #bbf7d0;
}

.vvr-project-info .shift-positive {
    color: #2563eb;
}

.vvr-project-info .shift-negative {
    color: #dc2626;
}

.vvr-project-info .toggle-original-btn {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.5rem;
    background: var(--color-secondary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.vvr-project-info .toggle-original-btn:hover {
    background: #004466;
    transform: translateY(-1px);
}

.vvr-project-info .toggle-original-btn.showing-original {
    background: var(--color-primary);
    color: white;
}

/* --- VVR Section Titles --- */
.vvr-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #92400e;
    margin: 0.75rem 0 0.4rem;
    padding-top: 0.5rem;
    border-top: 1px solid #fbbf24;
}

.vvr-description {
    font-size: 0.7rem;
    color: #6b7280;
    font-style: italic;
    margin-top: 0.25rem;
    line-height: 1.4;
}

/* --- VVR Minimap --- */
.vvr-mini-diagram {
    margin-top: 0.25rem;
}

.vvr-mini-diagram svg {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
}

/* --- VVR Toggle Section --- */
.vvr-toggle-section {
    margin-top: 0.25rem;
}

/* --- VVR Overall Results --- */
.vvr-results-grid {
    font-size: 0.75rem;
}

.vvr-results-header {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.75rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0.2rem;
}

.vvr-result-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.75rem;
    padding: 0.15rem 0;
    align-items: center;
}

.vvr-result-label {
    color: #374151;
    font-weight: 500;
}

.vvr-result-val {
    font-weight: 700;
    text-align: center;
    min-width: 2rem;
}

.vvr-result-val.dem { color: #2563eb; }
.vvr-result-val.rep { color: #dc2626; }
.vvr-result-val.comp { color: #7c3aed; }

/* --- VVR District Cards --- */
.vvr-district-cards {
    margin-top: 0.25rem;
}

.vvr-card {
    background: white;
    border-radius: 6px;
    border-left: 4px solid #64748b;
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.4rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    font-size: 0.75rem;
}

.vvr-card-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
}

.vvr-card-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.vvr-card-name {
    font-weight: 600;
    color: #1f2937;
    flex: 1;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vvr-card-lean {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    flex-shrink: 0;
}

.vvr-card-lean.dem { background: #dbeafe; color: #1d4ed8; }
.vvr-card-lean.rep { background: #fee2e2; color: #b91c1c; }
.vvr-card-lean.even { background: #ede9fe; color: #6d28d9; }

/* Before/after comparison layout */
.vvr-card-comparison {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.3rem;
    align-items: center;
    margin-bottom: 0.3rem;
}

.vvr-card-col {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.vvr-card-col-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #9ca3af;
    font-weight: 600;
}

.vvr-card-margin {
    font-weight: 700;
    font-size: 0.75rem;
    color: #1f2937;
}

.vvr-card-pct {
    font-size: 0.65rem;
    display: flex;
    gap: 0.4rem;
}

.vvr-card-pct .dem { color: #2563eb; }
.vvr-card-pct .rep { color: #dc2626; }

.vvr-card-arrow {
    color: #9ca3af;
    font-size: 1rem;
    font-weight: 300;
}

.vvr-card-shift-row {
    font-size: 0.65rem;
    color: #6b7280;
    text-align: right;
}

.vvr-card-shift {
    font-weight: 700;
}

.vvr-card-shift.shift-positive { color: #2563eb; }
.vvr-card-shift.shift-negative { color: #dc2626; }

.vvr-card-stats {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.vvr-card-stats .dem { color: #2563eb; }
.vvr-card-stats .rep { color: #dc2626; }

.vvr-card-total {
    font-size: 0.65rem;
    color: #6b7280;
    margin-top: 0.2rem;
}

/* Google Places Autocomplete Dropdown */
.pac-container {
    z-index: 10000 !important;
    font-family: var(--font-family, system-ui, -apple-system, sans-serif);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
    margin-top: 4px;
}

.pac-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.875rem;
    border-top: 1px solid #f3f4f6;
}

.pac-item:first-child {
    border-top: none;
}

.pac-item:hover {
    background-color: #f0f9ff;
}

.pac-item-selected {
    background-color: #e0f2fe;
}

.pac-icon {
    margin-right: 8px;
}

.pac-item-query {
    font-weight: 500;
    color: #1f2937;
}

.pac-matched {
    font-weight: 600;
    color: #2563eb;
}

/* Search Box */
.search-box {
    margin-bottom: 1.5rem;
}

.search-box label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--color-text-muted);
}

.search-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.search-input-wrapper input {
    flex: 1;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-wrapper input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-input-wrapper button {
    padding: 0.625rem 1rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(193, 18, 31, 0.25);
}

.search-input-wrapper button:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(193, 18, 31, 0.35);
}

.search-input-wrapper button:disabled {
    background: var(--color-text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* State Selector */
.state-selector {
    margin-bottom: 1.5rem;
}

.state-selector label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--color-text-muted);
}

.state-select-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.state-selector select {
    flex: 1;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: white;
    cursor: pointer;
    outline: none;
}

.state-selector select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#reset-view-btn {
    padding: 0.5rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

#reset-view-btn:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

#reset-view-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#reset-view-btn:disabled:hover {
    background: var(--color-bg);
    color: inherit;
    border-color: var(--color-border);
}

/* Layer Controls */
.layer-controls h3 {
    font-size: 0.8125rem;
    font-weight: 500;
    margin: 0 0 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.layer-toggle {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.layer-toggle:hover {
    background: var(--color-border);
}

.layer-toggle input {
    margin: 0;
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.layer-toggle .color-indicator {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    margin-left: 0.75rem;
}

.layer-toggle span:last-child {
    margin-left: 0.75rem;
    font-size: 0.875rem;
}

.layer-group {
    margin-bottom: 0.5rem;
}

.layer-toggle.sub-toggle {
    margin-left: 1.5rem;
    padding: 0.4rem 0.75rem;
    background: transparent;
    font-size: 0.8rem;
    margin-bottom: 0;
}

.layer-toggle.sub-toggle span:last-child {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.layer-toggle.sub-toggle:hover {
    background: var(--color-bg);
}

.layer-toggle.sub-toggle.disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: not-allowed;
}

.layer-toggle.sub-toggle.disabled input {
    cursor: not-allowed;
}

/* District Info Panel */
.district-info {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

.district-info h3 {
    font-size: 0.8125rem;
    font-weight: 500;
    margin: 0 0 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.district-info .placeholder {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.district-card {
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-left: 3px solid var(--color-border);
}

.district-card.congressional {
    border-left-color: var(--color-primary);
}

.district-card.state-senate {
    border-left-color: var(--color-secondary);
}

.district-card.state-house {
    border-left-color: var(--color-accent);
}

.district-card.precinct {
    border-left-color: var(--color-warning);
}

.district-card h4 {
    margin: 0 0 0.25rem;
    font-size: 0.9375rem;
}

.district-card p {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

/* Map Container */
.map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.loading-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Legend */
.map-legend {
    position: absolute;
    bottom: 2rem;
    right: 1rem;
    background: var(--color-surface);
    padding: 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    min-width: 160px;
}

.map-legend h4 {
    margin: 0 0 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.8125rem;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    margin-right: 0.625rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Popup Styling */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-md);
    padding: 0;
}

.leaflet-popup-content {
    margin: 0;
    min-width: 200px;
}

.popup-content {
    padding: 1rem;
}

.popup-content h3 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.popup-content p {
    margin: 0.25rem 0;
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

/* Mobile sidebar toggle button (hidden on desktop) */
.sidebar-toggle-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    border-radius: 4px;
    color: #374151;
    margin-left: 0.5rem;
}
.sidebar-toggle-btn:hover { background: #f3f4f6; }

/* Hidden on desktop */
.map-drawer-toggle { display: none; }
.sidebar-backdrop { display: none; }
.bottom-sheet-handle { display: none; }
.sheet-nav { display: none; }
.bottom-sheet-hint { display: none; }
.mobile-sheet-toggle { display: none; }

@media (max-width: 768px) {
    .landing-header { padding: 2.5rem 1.5rem; }
    .landing-header h1 { font-size: 1.75rem; }
    .map-selector { padding: 2rem 1rem; }

    /* --- Full-screen map + bottom sheet --- */
    .map-page {
        flex-direction: column;
        position: relative;
        height: calc(100vh - 46px);
        height: calc(100dvh - 46px);
    }

    /* Map fills screen below header */
    .map-container {
        position: fixed;
        top: 46px;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 1;
    }

    /* Hide old toggles */
    .map-drawer-toggle { display: none !important; }
    .sidebar-toggle-btn { display: none !important; }
    .desktop-sidebar-toggle { display: none !important; }
    .bottom-sheet-handle { display: none !important; }

    /* Sidebar as bottom drawer */
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 80vh;
        height: 80vh;
        border-right: none;
        border-top: none;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
        z-index: 2000;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        overflow: hidden;
        display: flex;
        flex-direction: column;
        background: rgba(255, 255, 255, 0.97);
        -webkit-backdrop-filter: blur(20px);
        backdrop-filter: blur(20px);
    }

    .sidebar.sheet-open {
        transform: translateY(0);
        overflow-y: auto;
    }

    /* Mobile floating Show/Hide button */
    .mobile-sheet-toggle {
        display: flex !important;
        position: fixed;
        bottom: 1rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 2001;
        background: var(--color-surface);
        border: none;
        border-radius: 999px;
        box-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
        padding: 0.55rem 1.25rem;
        font-size: 0.8rem;
        font-weight: 600;
        font-family: var(--font-sans);
        color: var(--color-secondary);
        cursor: pointer;
        align-items: center;
        gap: 0.4rem;
        transition: box-shadow 0.2s, opacity 0.25s;
    }

    .mobile-sheet-toggle:active {
        box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
    }

    /* Hide button when sheet is open */
    .mobile-sheet-toggle.is-hidden {
        opacity: 0;
        pointer-events: none;
    }

    /* Hide gradient header on mobile */
    .sidebar-header {
        display: none;
    }

    /* Scrollable content */
    .sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding: 0 1rem 1.5rem;
        -webkit-overflow-scrolling: touch;
    }

    /* Move search box up as the peek-visible element */
    .search-box {
        padding-top: 0.25rem;
    }

    .search-box label {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--color-text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

    /* Compact controls */
    .layer-controls {
        flex-direction: column;
        gap: 0.25rem;
    }

    .layer-controls h3 {
        font-size: 0.8rem;
        margin-bottom: 0.25rem;
    }

    .modify-mode-section h3 {
        font-size: 0.8rem;
    }

    .district-info h3 {
        font-size: 0.8rem;
    }

    .import-section {
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
    }

    .import-vvr-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Legend repositioned above the sheet */
    .map-legend {
        bottom: 5.5rem;
        right: 0.5rem;
        padding: 0.5rem 0.65rem;
        font-size: 0.7rem;
        z-index: 1500;
    }

    .map-legend h4 {
        font-size: 0.65rem;
        margin-bottom: 0.2rem;
    }

    /* Back-to-home link inside the sheet */
    .sheet-nav {
        display: flex;
        gap: 0.75rem;
        padding: 0.5rem 0 0.25rem;
        border-bottom: 1px solid var(--color-border);
        margin-bottom: 0.5rem;
        flex-wrap: wrap;
    }

    .sheet-nav a {
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--color-primary);
        text-decoration: none;
    }
}


/* ============================================================================
   Partisan Color Legend
   ============================================================================ */

.partisan-legend {
    position: absolute;
    bottom: 2rem;
    left: 1rem;
    background: var(--color-surface);
    padding: 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    min-width: 200px;
}

.partisan-legend h4 {
    margin: 0 0 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.partisan-gradient {
    display: flex;
    flex-direction: column;
}

.gradient-bar {
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.gradient-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.375rem;
    font-size: 0.6875rem;
    color: var(--color-text-muted);
}

@media (max-width: 768px) {
    .partisan-legend {
        bottom: 1rem;
        left: 0.5rem;
        padding: 0.75rem;
        min-width: 160px;
    }
}

/* Modify Mode Section */
.modify-mode-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modify-mode-section h3 {
    font-size: 0.8125rem;
    font-weight: 500;
    margin: 0 0 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modify-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius-sm);
    transition: background 0.15s ease;
}

.modify-toggle:hover {
    background: var(--color-border);
}

.modify-toggle input {
    cursor: pointer;
}

.modify-toggle span {
    font-size: 0.875rem;
    font-weight: 500;
}

.modify-controls {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #fef3c7;
    border-radius: var(--radius-sm);
    border: 1px solid #fcd34d;
}

.modify-controls.hidden {
    display: none;
}

.selection-info {
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #92400e;
}

.selection-type {
    font-weight: 400;
    font-size: 0.75rem;
    display: block;
    margin-top: 0.25rem;
}

.modify-hint {
    margin: 0 0 0.75rem;
    font-size: 0.75rem;
    color: #a16207;
    line-height: 1.4;
}

.modify-buttons {
    display: flex;
    gap: 0.5rem;
}

.modify-buttons button {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-secondary {
    background: white;
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(193, 18, 31, 0.25);
    transition: all 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(193, 18, 31, 0.35);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Selected district highlight */
.district-selected {
    stroke: #f59e0b !important;
    stroke-width: 4 !important;
    stroke-dasharray: none !important;
}

/* Selection mode cursor */
.selection-mode-active {
    cursor: crosshair !important;
}

/* Layer mode hint for selection mode */
.layer-mode-hint {
    font-size: 0.75rem;
    color: #92400e;
    background: #fef3c7;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    border-left: 3px solid #f59e0b;
}

.layer-mode-hint.hidden {
    display: none;
}

/* Disabled layer group in selection mode */
.layer-group.disabled-in-selection {
    opacity: 0.4;
    pointer-events: none;
}

.layer-group.disabled-in-selection .layer-toggle {
    cursor: not-allowed;
}

/* Radio-style appearance for district layers in selection mode */
.layer-group.radio-mode .layer-toggle input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--color-border);
    border-radius: 50%;
    background: white;
    cursor: pointer;
    position: relative;
}

.layer-group.radio-mode .layer-toggle input[type="checkbox"]:checked {
    border-color: var(--color-primary);
    background: var(--color-primary);
}

.layer-group.radio-mode .layer-toggle input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: white;
}

/* Active/selected district type indicator */
.layer-group.active-selection-type {
    background: #fef3c7;
    border-radius: var(--radius-sm);
    margin: -0.25rem;
    padding: 0.25rem;
}

/* =============================================
   District Coloring — inline sidebar legend
   ============================================= */
.district-color-legend {
    margin: 0.5rem 0 0;
    padding: 0.625rem 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
}

.legend-title {
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    color: var(--color-text);
    font-size: 0.8rem;
}

.legend-row:last-child {
    margin-bottom: 0;
}

.legend-swatch {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,0.1);
}
