/* ============================================
   NYS Food Access & Literacy Visualization
   Premium Editorial Design System
   ============================================ */

/* Font imports */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Source+Sans+3:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    /* ─────────────────────────────────────────
       Rich, Earthy Color Palette
       Inspired by vintage cartography & nature
       ───────────────────────────────────────── */
    
    /* Deep foundations */
    --bg-deep: #0d1117;
    --bg-canvas: #141a22;
    --bg-elevated: #1b232d;
    --bg-surface: #232d3a;
    --bg-surface-hover: #2a3545;
    
    /* Warm accent palette - terracotta & sage */
    --accent-primary: #c9a66b;
    --accent-primary-muted: rgba(201, 166, 107, 0.15);
    --accent-secondary: #7d9c76;
    --accent-tertiary: #d4856a;
    --accent-cool: #6b9ac4;
    
    /* Text hierarchy */
    --text-display: #f5f0e8;
    --text-primary: #e8e4dc;
    --text-secondary: #a8a099;
    --text-muted: #6d6860;
    --text-inverse: #141a22;
    
    /* Borders & lines */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.16);
    --border-accent: rgba(201, 166, 107, 0.4);
    
    /* ELA Proficiency - refined organic scale */
    --ela-excellent: #2d6a4f;
    --ela-good: #52796f;
    --ela-average: #84a98c;
    --ela-below: #dda15e;
    --ela-poor: #bc6c25;
    --ela-critical: #9b2226;
    --ela-none: #4a4a4a;
    
    /* Typography */
    --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
    --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    
    /* Spacing system */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    
    /* Layout */
    --sidebar-width: 380px;
    --panel-width: 360px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    /* Shadows */
    --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.25);
    --shadow-medium: 0 8px 40px rgba(0, 0, 0, 0.35);
    --shadow-strong: 0 16px 64px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(201, 166, 107, 0.15);
    
    /* Transitions */
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
    --duration-fast: 120ms;
    --duration-normal: 200ms;
    --duration-slow: 400ms;
}

/* ============================================
   Base Reset & Foundations
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 400;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-deep);
    display: flex;
}

/* Selection styling */
::selection {
    background: var(--accent-primary);
    color: var(--text-inverse);
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-canvas);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10;
    
    /* Subtle texture overlay */
    background-image: 
        linear-gradient(180deg, 
            rgba(201, 166, 107, 0.03) 0%, 
            transparent 40%,
            transparent 100%
        ),
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-blend-mode: normal, overlay;
}

/* Elegant left accent line */
.sidebar::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(
        180deg,
        var(--accent-primary) 0%,
        var(--accent-secondary) 50%,
        var(--accent-tertiary) 100%
    );
}

/* Custom scrollbar */
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 4px;
    border: 2px solid var(--bg-canvas);
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

.sidebar {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

/* ============================================
   Sidebar Header
   ============================================ */

.sidebar-header {
    padding: var(--space-8) var(--space-6);
    background: linear-gradient(
        165deg,
        rgba(201, 166, 107, 0.08) 0%,
        transparent 50%
    );
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: var(--space-6);
    right: var(--space-6);
    height: 1px;
    background: linear-gradient(
        90deg,
        var(--accent-primary) 0%,
        transparent 100%
    );
    opacity: 0.4;
}

.sidebar-header h1 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text-display);
}

.sidebar-header .amp {
    font-style: italic;
    color: var(--accent-primary);
    font-weight: 400;
}

.sidebar-header .subtitle {
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: var(--space-2);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ============================================
   Stats Bar
   ============================================ */

.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

.stats-bar::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        rgba(201, 166, 107, 0.04) 0%,
        transparent 50%,
        rgba(125, 156, 118, 0.04) 100%
    );
    pointer-events: none;
}

.stat {
    padding: var(--space-5) var(--space-4);
    text-align: center;
    position: relative;
    transition: background var(--duration-fast);
}

.stat:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    bottom: 25%;
    width: 1px;
    background: var(--border-subtle);
}

.stat:hover {
    background: rgba(255, 255, 255, 0.02);
}

.stat-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 1.375rem;
    font-weight: 500;
    color: var(--accent-primary);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.stat-label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-top: var(--space-1);
}

/* ============================================
   Filter Sections
   ============================================ */

.filter-section {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

.filter-section h2 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-display);
    margin-bottom: var(--space-1);
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-section h2::before {
    content: '';
    width: 4px;
    height: 4px;
    background: var(--accent-primary);
    border-radius: 50%;
}

.filter-desc {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: var(--space-4);
    line-height: 1.5;
    padding-left: calc(4px + var(--space-2));
}

/* ============================================
   Radio Buttons (Demographic Selection)
   ============================================ */

.radio-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.radio-option {
    display: flex;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--duration-normal) var(--ease-out-quart);
    position: relative;
    overflow: hidden;
}

.radio-option::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: linear-gradient(
        90deg,
        var(--accent-primary) 0%,
        transparent 100%
    );
    opacity: 0;
    transition: all var(--duration-normal) var(--ease-out-quart);
}

.radio-option:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-default);
    transform: translateX(2px);
}

.radio-option:hover::before {
    width: 3px;
    opacity: 0.5;
}

.radio-option input {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    margin-right: var(--space-3);
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--duration-fast);
}

.radio-option input::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform var(--duration-normal) var(--ease-out-expo);
}

.radio-option input:checked {
    border-color: var(--accent-primary);
}

.radio-option input:checked::after {
    transform: translate(-50%, -50%) scale(1);
}

.radio-option:has(input:checked) {
    background: var(--accent-primary-muted);
    border-color: var(--border-accent);
}

.radio-option:has(input:checked)::before {
    width: 3px;
    opacity: 1;
}

.radio-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: color var(--duration-fast);
    font-weight: 400;
}

.radio-option:has(input:checked) .radio-label {
    color: var(--text-display);
    font-weight: 500;
}

/* ============================================
   Checkboxes (Income & Food Filters)
   ============================================ */

.checkbox-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
}

.checkbox-option {
    display: flex;
    align-items: center;
    padding: var(--space-3);
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--duration-normal) var(--ease-out-quart);
}

.checkbox-option:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-default);
}

.checkbox-option input {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    margin-right: var(--space-2);
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--duration-fast);
}

.checkbox-option input::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23141a22' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
    background-size: contain;
    transition: transform var(--duration-normal) var(--ease-out-expo);
}

.checkbox-option input:checked {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
}

.checkbox-option input:checked::after {
    transform: translate(-50%, -50%) scale(1);
}

.checkbox-option:has(input:checked) {
    border-color: rgba(125, 156, 118, 0.3);
}

.checkbox-label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    transition: color var(--duration-fast);
    white-space: nowrap;
    font-weight: 400;
}

.checkbox-option:has(input:checked) .checkbox-label {
    color: var(--text-primary);
}

/* ============================================
   Legend Section
   ============================================ */

.legend-section {
    padding: var(--space-6);
    border-bottom: 1px solid var(--border-subtle);
}

.legend-section h2 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-display);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.legend-section h2::before {
    content: '';
    width: 4px;
    height: 4px;
    background: var(--accent-primary);
    border-radius: 50%;
}

.legend {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 32px;
    height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* ELA color overrides */
.legend-item:nth-child(1) .legend-color { background: var(--ela-excellent); }
.legend-item:nth-child(2) .legend-color { background: var(--ela-good); }
.legend-item:nth-child(3) .legend-color { background: var(--ela-average); }
.legend-item:nth-child(4) .legend-color { background: var(--ela-below); }
.legend-item:nth-child(5) .legend-color { background: var(--ela-poor); }
.legend-item:nth-child(6) .legend-color { background: var(--ela-critical); }
.legend-item:nth-child(7) .legend-color { background: var(--ela-none); }

/* ============================================
   Sidebar Footer
   ============================================ */

.sidebar-footer {
    margin-top: auto;
    padding: var(--space-6);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border-subtle);
    position: relative;
}

.sidebar-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: var(--space-6);
    right: var(--space-6);
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--accent-primary) 50%,
        transparent 100%
    );
    opacity: 0.3;
}

.data-sources {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: var(--space-3);
}

.data-sources strong {
    color: var(--text-secondary);
    font-weight: 600;
}

.attribution {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.8;
}

/* ============================================
   Map Container
   ============================================ */

.map-container {
    flex: 1;
    position: relative;
    background: var(--bg-deep);
}

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

/* Map vignette overlay */
.map-container::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background: radial-gradient(
        ellipse 80% 60% at 50% 50%,
        transparent 0%,
        transparent 60%,
        rgba(13, 17, 23, 0.4) 100%
    );
}

/* ============================================
   MapLibre Overrides
   ============================================ */

.maplibregl-ctrl-attrib {
    background: rgba(13, 17, 23, 0.85) !important;
    backdrop-filter: blur(8px);
    color: var(--text-muted) !important;
    font-size: 0.625rem !important;
    font-family: var(--font-body) !important;
    padding: 4px 8px !important;
    border-radius: var(--radius-sm) !important;
}

.maplibregl-ctrl-attrib a {
    color: var(--text-secondary) !important;
}

.maplibregl-ctrl-group {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-default) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-soft) !important;
    overflow: hidden;
}

.maplibregl-ctrl-group button {
    width: 36px !important;
    height: 36px !important;
    background-color: var(--bg-surface) !important;
    border: none !important;
    transition: background-color var(--duration-fast) !important;
}

.maplibregl-ctrl-group button:hover {
    background-color: var(--bg-surface-hover) !important;
}

.maplibregl-ctrl-group button + button {
    border-top: 1px solid var(--border-subtle) !important;
}

.maplibregl-ctrl-icon {
    filter: invert(0.85) sepia(0.1) saturate(0.5);
}

.maplibregl-ctrl-group button:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--accent-primary);
}

/* ============================================
   Tooltip
   ============================================ */

.tooltip {
    position: absolute;
    z-index: 100;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: 
        opacity var(--duration-fast),
        transform var(--duration-fast) var(--ease-out-quart);
    max-width: 300px;
    box-shadow: var(--shadow-medium);
    backdrop-filter: blur(12px);
}

.tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.tooltip::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(
        90deg,
        var(--accent-primary) 0%,
        var(--accent-secondary) 100%
    );
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.tooltip-name {
    font-family: var(--font-display);
    font-size: 1.0625rem;
    font-weight: 500;
    color: var(--text-display);
    margin-bottom: var(--space-2);
    line-height: 1.3;
    padding-top: var(--space-1);
}

.tooltip-demographic {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-primary);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
}

.tooltip-row:not(:last-child) {
    border-bottom: 1px dashed var(--border-subtle);
}

.tooltip-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.tooltip-value {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.tooltip-value.highlight {
    color: var(--accent-primary);
}

.tooltip-value.no-data {
    color: var(--text-muted);
    font-style: italic;
    font-family: var(--font-body);
    font-weight: 400;
}

/* ============================================
   Info Panel (Click Detail)
   ============================================ */

.info-panel {
    position: absolute;
    top: var(--space-6);
    right: var(--space-6);
    width: var(--panel-width);
    max-height: calc(100vh - var(--space-12));
    background: var(--bg-canvas);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-strong), var(--shadow-glow);
    overflow: hidden;
    transform: translateX(calc(100% + 48px));
    opacity: 0;
    transition: 
        transform var(--duration-slow) var(--ease-out-expo),
        opacity var(--duration-normal);
    z-index: 200;
}

.info-panel.visible {
    transform: translateX(0);
    opacity: 1;
}

/* Panel accent border */
.info-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(
        90deg,
        var(--accent-primary) 0%,
        var(--accent-secondary) 50%,
        var(--accent-tertiary) 100%
    );
}

.close-btn {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    width: 32px;
    height: 32px;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
    z-index: 10;
}

.close-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.close-btn:active {
    transform: scale(0.95);
}

.panel-content {
    padding: var(--space-6);
    padding-top: var(--space-8);
    overflow-y: auto;
    max-height: calc(100vh - 100px);
}

.panel-content::-webkit-scrollbar {
    width: 6px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.panel-header {
    margin-bottom: var(--space-6);
    padding-right: var(--space-10);
}

.panel-name {
    font-family: var(--font-display);
    font-size: 1.375rem;
    font-weight: 500;
    color: var(--text-display);
    line-height: 1.25;
    margin-bottom: var(--space-1);
}

.panel-subtitle {
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.panel-subtitle::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--accent-primary);
    border-radius: 50%;
}

.panel-section {
    margin-bottom: var(--space-6);
}

.panel-section-title {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent-primary);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.panel-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(
        90deg,
        var(--border-subtle) 0%,
        transparent 100%
    );
}

.panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.panel-stat {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    border: 1px solid var(--border-subtle);
    transition: border-color var(--duration-fast);
}

.panel-stat:hover {
    border-color: var(--border-default);
}

.panel-stat-value {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-display);
    line-height: 1.2;
}

.panel-stat-value.no-data {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-weight: 400;
}

.panel-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.panel-stat.full-width {
    grid-column: span 2;
}

.panel-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border-subtle);
}

.panel-row:last-child {
    border-bottom: none;
}

.panel-row-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.panel-row-value {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Demographics bar chart */
.demo-bar-container {
    margin-top: var(--space-3);
}

.demo-bar-row {
    margin-bottom: var(--space-3);
}

.demo-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.demo-bar-label span:last-child {
    font-family: var(--font-mono);
    font-weight: 500;
}

.demo-bar-track {
    height: 8px;
    background: var(--bg-deep);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.demo-bar-track::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.03) 50%,
        transparent 100%
    );
}

.demo-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width var(--duration-slow) var(--ease-out-expo);
    position: relative;
}

.demo-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.2) 0%,
        transparent 100%
    );
    border-radius: 4px 4px 0 0;
}

.demo-bar-fill.white { background: linear-gradient(90deg, #8b9dc3, #6b7d9c); }
.demo-bar-fill.black { background: linear-gradient(90deg, #7d9c76, #5d7c56); }
.demo-bar-fill.hispanic { background: linear-gradient(90deg, #d4a373, #b48353); }
.demo-bar-fill.asian { background: linear-gradient(90deg, #9b7e9b, #7b5e7b); }

/* ============================================
   Loading State
   ============================================ */

.loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-deep);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity var(--duration-slow);
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 2px solid var(--border-subtle);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--space-4);
}

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

.loading-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-family: var(--font-display);
    font-style: italic;
}

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

@media (max-width: 1200px) {
    :root {
        --sidebar-width: 340px;
        --panel-width: 320px;
    }
}

@media (max-width: 900px) {
    :root {
        --sidebar-width: 300px;
    }
    
    .checkbox-group {
        grid-template-columns: 1fr;
    }
    
    .info-panel {
        width: calc(100vw - var(--sidebar-width) - var(--space-12));
        max-width: 320px;
    }
    
    .sidebar-header h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 700px) {
    body {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 50vh;
        order: 2;
    }
    
    .sidebar::before {
        display: none;
    }
    
    .sidebar::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3px;
        background: linear-gradient(
            90deg,
            var(--accent-primary) 0%,
            var(--accent-secondary) 50%,
            var(--accent-tertiary) 100%
        );
    }
    
    .map-container {
        height: 50vh;
        order: 1;
    }
    
    .map-container::before {
        display: none;
    }
    
    .info-panel {
        top: auto;
        bottom: var(--space-4);
        left: var(--space-4);
        right: var(--space-4);
        width: auto;
        max-width: none;
        max-height: 45vh;
        transform: translateY(120%);
    }
    
    .info-panel.visible {
        transform: translateY(0);
    }
    
    .stats-bar {
        position: sticky;
        top: 0;
        z-index: 5;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .sidebar {
        width: 100%;
        height: auto;
        overflow: visible;
    }
    
    .map-container {
        display: none;
    }
    
    .info-panel {
        position: static;
        width: 100%;
        max-height: none;
        transform: none;
        opacity: 1;
        box-shadow: none;
    }
}

/* ============================================
   Accessibility
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible styles */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}
