/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-democrat: #2563eb;
    --color-democrat-light: #dbeafe;
    --color-democrat-transparent: rgba(37, 99, 235, 0.15);
    --color-republican: #dc2626;
    --color-republican-light: #fee2e2;
    --color-republican-transparent: rgba(220, 38, 38, 0.15);
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #f8fafc;
    --color-text-secondary: #94a3b8;
    --color-border: #334155;
    --color-accent: #3b82f6;
    --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-primary);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
    border-bottom: 1px solid var(--color-border);
}

.header h1 {
    font-size: clamp(1.75rem, 4vw, 2.75rem);
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #60a5fa 0%, #a78bfa 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: clamp(1rem, 2vw, 1.25rem);
    color: var(--color-text-secondary);
    margin-bottom: 1.5rem;
}

/* Legend */
.legend {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.color-box {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.color-box.democrat {
    background-color: var(--color-democrat);
}

.color-box.republican {
    background-color: var(--color-republican);
}

/* Date Range Picker */
.date-range-picker {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
    padding: 1.25rem;
    background-color: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
}

.date-inputs {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

.date-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.date-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.date-field input[type="date"] {
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    font-family: var(--font-primary);
    color: var(--color-text);
    background-color: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 150px;
}

.date-field input[type="date"]:hover {
    border-color: var(--color-accent);
}

.date-field input[type="date"]:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Webkit date input styling */
.date-field input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.date-field input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.date-separator {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    padding-bottom: 0.75rem;
    font-weight: 500;
}

.apply-btn {
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
    font-family: var(--font-primary);
    color: white;
    background: linear-gradient(135deg, var(--color-accent) 0%, #2563eb 100%);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.apply-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.apply-btn:active {
    transform: translateY(0);
}

.apply-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

/* Responsive date picker */
@media (max-width: 640px) {
    .date-range-picker {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }

    .date-inputs {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
    }

    .date-separator {
        padding-bottom: 0;
        display: none;
    }

    .date-field input[type="date"] {
        min-width: 200px;
        text-align: center;
    }

    .apply-btn {
        width: 200px;
    }
}

/* Charts Container */
.charts-container {
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

/* Chart Section */
.chart-section {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
}

.chart-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}

.chart-header h2 {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.chart-description {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

/* Chart Wrapper */
.chart-wrapper {
    position: relative;
    width: 100%;
    height: 400px;
}

@media (max-width: 768px) {
    .chart-wrapper {
        height: 300px;
    }
}

/* Canvas */
canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Footer */
.footer {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--color-border);
}

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

.presidential-timeline {
    margin-bottom: 2rem;
}

.presidential-timeline h3 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--color-text);
}

.timeline {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.timeline-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.timeline-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.timeline-item.democrat {
    background-color: var(--color-democrat-transparent);
    border: 1px solid var(--color-democrat);
    color: #60a5fa;
}

.timeline-item.republican {
    background-color: var(--color-republican-transparent);
    border: 1px solid var(--color-republican);
    color: #f87171;
}

.timeline-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.timeline-item.democrat .timeline-dot {
    background-color: var(--color-democrat);
}

.timeline-item.republican .timeline-dot {
    background-color: var(--color-republican);
}

.data-source {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.data-source span {
    font-family: var(--font-mono);
}

/* Loading State */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 300px;
    color: var(--color-text-secondary);
    font-size: 1rem;
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }
    
    .header {
        padding: 1.5rem 0;
        margin-bottom: 2rem;
    }
    
    .chart-section {
        padding: 1rem;
    }
    
    .legend {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .timeline {
        flex-direction: column;
        align-items: center;
    }
}

/* Print Styles */
@media print {
    body {
        background-color: white;
        color: black;
    }
    
    .chart-section {
        break-inside: avoid;
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
