:root {
    /* Color System */
    --bg-dark: #0b0f17;
    --bg-card: #131a26;
    --bg-elevated: #1a2332;
    --border-color: #243044;
    --border-subtle: #1e293b;
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --primary: #2563eb;
    --primary-hover: #3b82f6;
    --primary-glow: rgba(37, 99, 235, 0.25);

    --danger: #ef4444;
    --danger-subtle: rgba(239, 68, 68, 0.12);
    --warning: #f59e0b;
    --warning-subtle: rgba(245, 158, 11, 0.12);
    --success: #10b981;
    --success-subtle: rgba(16, 185, 129, 0.12);
    --info: #06b6d4;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-main: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
    --font-sans: 'Fira Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Fira Code', monospace;
}

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

html {
    overflow-x: hidden;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    min-height: 100vh;
    padding: 20px;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.skip-link {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1000;
    transform: translateY(-150%);
    background: var(--primary-hover);
    color: #fff;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-weight: 700;
}

.skip-link:focus {
    transform: translateY(0);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-container {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

body.data-loading .app-container {
    visibility: hidden;
    pointer-events: none;
}

.data-loading-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40vh;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
}

body:not(.data-loading) .data-loading-screen {
    display: none;
}

.data-loading-text {
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
}

/* Header & Status */
.app-header {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-main);
}

.header-main {
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.header-main h1 {
    font-size: 1.65rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

/* Buttons & Controls */
.btn {
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:disabled {
    cursor: wait;
    opacity: 0.65;
}

.btn:focus-visible,
.preset-btn:focus-visible,
.zoom-btn:focus-visible,
.legend-item:focus-visible,
details summary:focus-visible {
    outline: 2px solid var(--primary-hover);
    outline-offset: 3px;
}

.btn-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--bg-elevated);
    border-color: var(--primary);
}

.btn-sm {
    font-size: 0.72rem;
    padding: 4px 8px;
}

/* Risk Summary */
.risk-summary {
    padding: 22px 24px;
    background:
        radial-gradient(circle at 12% 20%, rgba(239, 68, 68, 0.16), transparent 26%),
        linear-gradient(135deg, rgba(19, 26, 38, 0.98), rgba(11, 15, 23, 0.92));
}

.header-risk {
    margin-top: 20px;
    padding: 20px 0 0;
    border-top: 1px solid var(--border-color);
    background: none;
}

.section-eyebrow {
    color: var(--warning);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.risk-meter-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.risk-meter-top span:first-child {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-weight: 800;
}

.reserve-track {
    position: relative;
    height: 18px;
    margin: 12px 0 0;
    overflow: hidden;
    border-radius: 999px;
    background: #090d14;
    border: 1px solid var(--border-subtle);
}

.reserve-band,
.reserve-fill,
.reserve-marker {
    position: absolute;
    top: 0;
    bottom: 0;
}

.collapse-band { left: 0; width: 21%; background: rgba(127, 29, 29, 0.48); }
.floor-band { left: 21%; width: 13%; background: rgba(239, 68, 68, 0.28); }
.risk-band { left: 34%; width: 8%; background: rgba(245, 158, 11, 0.25); }

.reserve-fill {
    left: 0;
    z-index: 1;
    background: linear-gradient(90deg, var(--danger), var(--warning) 68%, var(--primary-hover));
    box-shadow: 0 0 24px rgba(59, 130, 246, 0.25);
}

.reserve-marker {
    z-index: 2;
    width: 2px;
    background: rgba(255, 255, 255, 0.86);
}

.risk-marker { left: 42%; }
.floor-marker { left: 34%; }

.week-progress {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.week-progress-labels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.week-progress-copy {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 2px;
}

.week-progress-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.week-bar {
    display: flex;
    width: 100%;
    gap: 3px;
    list-style: none;
}

.week-bar li {
    flex: 1 1 0;
    min-width: 0;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    background: #090d14;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 700;
}

.week-bar.closest li.filled {
    background: var(--danger);
    border-color: rgba(239, 68, 68, 0.7);
    color: #fff;
}

.week-bar.furthest li.filled {
    background: var(--warning);
    border-color: rgba(245, 158, 11, 0.7);
    color: #111827;
}

.methodology-drawer {
    border-color: rgba(59, 130, 246, 0.32);
}

.methodology-drawer summary {
    cursor: pointer;
    color: var(--text-primary);
    font-weight: 800;
    list-style-position: inside;
}

.methodology-copy p {
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.45;
}

/* Main Layout Grid */
.main-grid {
    display: grid;
    grid-template-columns: 1fr;
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-main);
    overflow: hidden;
}

.panel-header {
    padding: 20px 20px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.panel-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* SVG Chart */
.chart-panel {
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.chart-panel-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
}

.chart-header-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.chart-header-tools {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.chart-zoom {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.zoom-btn {
    background: rgba(26, 35, 50, 0.8);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 800;
    padding: 6px 10px;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.zoom-btn:hover,
.zoom-btn.active {
    background: var(--bg-elevated);
    border-color: var(--primary-hover);
    color: var(--text-primary);
}

.chart-viewport {
    width: 100%;
    position: relative;
    margin-top: 12px;
}

.chart-viewport svg {
    width: 100%;
    height: auto;
    display: block;
    min-height: 380px;
}

.chart-tooltip {
    position: absolute;
    z-index: 10;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: rgba(19, 26, 38, 0.96);
    color: var(--text-primary);
    font-size: 0.78rem;
    font-family: var(--font-mono);
    line-height: 1.4;
    white-space: pre-line;
    pointer-events: none;
    box-shadow: var(--shadow-main);
}


/* Side Panel / Model Selector */
.side-panel {
    display: none;
}

.model-controls {
    padding: 10px 20px;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.preset-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px 20px 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.preset-btn {
    background: rgba(26, 35, 50, 0.8);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.76rem;
    font-weight: 800;
    padding: 8px 10px;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.preset-btn:hover,
.preset-btn.active {
    background: var(--bg-elevated);
    border-color: var(--primary-hover);
    color: var(--text-primary);
}

.legend-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    max-height: 520px;
}

.legend-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.legend-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.legend-group-title {
    color: var(--text-secondary);
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.legend-item {
    display: flex;
    width: 100%;
    align-items: flex-start;
    text-align: left;
    gap: 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s;
}

.legend-item:hover {
    border-color: var(--primary);
}

.legend-item.disabled {
    opacity: 0.4;
}

.legend-item[aria-pressed="true"] {
    border-color: rgba(59, 130, 246, 0.65);
}

.legend-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 4px;
    flex-shrink: 0;
}

.legend-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.78rem;
}

.legend-name {
    font-weight: 700;
    color: var(--text-primary);
}

.legend-meta {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.methodology-drawer {
    margin: 0 12px 12px;
    padding: 10px 12px;
    background: rgba(26, 35, 50, 0.58);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.model-drawer {
    display: none;
}

.methodology-copy {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 10px;
}

/* SVG Line Styles */
.grid-line { stroke: var(--border-subtle); stroke-width: 1; }
.grid-line.vertical { opacity: 0.5; }
.axis-line { stroke: var(--border-color); stroke-width: 1.5; }
.axis-text { font-size: 10px; fill: var(--text-secondary); font-family: var(--font-mono); }
.direct-label { font-size: 10px; fill: var(--text-primary); font-family: var(--font-mono); font-weight: 700; paint-order: stroke; stroke: var(--bg-card); stroke-width: 3px; }
.threshold-label { fill: var(--warning); }
.floor-label { fill: var(--danger); }
.historical-path { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linecap: round; }
.forecast-range { fill: rgba(16, 185, 129, 0.28); stroke: none; }
.forecast-upper-path { fill: none; stroke: var(--primary); stroke-width: 2.2; stroke-dasharray: 7 5; stroke-linecap: round; }
.forecast-lower-path { fill: none; stroke: var(--warning); stroke-width: 2.2; stroke-dasharray: 7 5; stroke-linecap: round; }
.forecast-label { fill: var(--success); }
.forecast-hinge { fill: var(--primary); stroke: var(--bg-card); stroke-width: 2; }
.forecast-hit { stroke: var(--bg-card); stroke-width: 2; }
.floor-line { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 4 4; }
.degradation-line { stroke: var(--warning); stroke-width: 1.5; stroke-dasharray: 6 4; }
.midterm-election-line { stroke: var(--primary-hover); stroke-width: 1.5; stroke-dasharray: 2 5; opacity: 0.85; }
.midterm-election-label { fill: var(--primary-hover); font-size: 10px; font-family: var(--font-mono); font-weight: 700; }
.chart-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }

/* Mobile Responsiveness */
@media (max-width: 850px) {
    body {
        padding: 6px;
    }
    .app-container {
        gap: 10px;
    }
    .chart-header-main {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }
    .chart-header-tools {
        align-items: flex-start;
    }
    .chart-zoom {
        flex-wrap: wrap;
        justify-content: flex-start;
    }
    .chart-panel {
        padding: 6px;
    }
    .chart-panel-header {
        padding: 8px 6px 6px;
        gap: 8px;
    }
    .chart-viewport {
        margin-top: 2px;
    }
    .chart-viewport svg {
        min-height: 0;
    }
}

@media (max-width: 520px) {
    body {
        padding: 4px;
    }
    .app-header,
    .risk-summary {
        padding: 12px;
    }
    .header-main h1 {
        font-size: 1.35rem;
    }
    .chart-panel {
        padding: 4px;
    }
    .chart-panel-header {
        padding: 6px 4px 4px;
    }
    .zoom-btn {
        padding: 5px 8px;
    }
    .week-progress-labels {
        grid-template-columns: 1fr;
    }
}

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