/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fafafa;
    min-height: 100vh;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1.25rem;
    color: #666;
}

/* Search section */
.search-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

@media (min-width: 600px) {
    .search-section {
        flex-direction: row;
        align-items: flex-end;
    }
}

.input-group {
    flex: 1;
    position: relative;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #555;
    margin-bottom: 0.25rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background-color: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: #0d9488;
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

.search-button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background-color: #0d9488;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.search-button:hover {
    background-color: #0f766e;
}

/* Autocomplete */
.autocomplete-items {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background-color: white;
    border: 2px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.autocomplete-items.active {
    display: block;
}

.autocomplete-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background-color: #ccfbf1;
}

.autocomplete-item .county-name {
    font-weight: 500;
}

/* Examples */
.examples {
    text-align: center;
    margin-bottom: 2rem;
    color: #666;
    font-size: 0.9rem;
}

.example-btn {
    background: none;
    border: none;
    color: #0f766e;
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.9rem;
    padding: 0.25rem;
    margin: 0 0.25rem;
}

.example-btn:hover {
    color: #115e59;
}

/* Loading spinner */
.loading-spinner {
    text-align: center;
    padding: 3rem 1rem;
    color: #666;
}

.loading-spinner.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #e5e7eb;
    border-top-color: #0d9488;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

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

/* Map section */
.map-section {
    margin-bottom: 2rem;
}

.map-section.hidden {
    display: none;
}

.map-container {
    width: 100%;
    height: 300px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    background-color: #f0f0f0;
}

@media (min-width: 768px) {
    .map-container {
        height: 450px;
    }
}

/* Leaflet info box override */
.info-box {
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    font-size: 0.85rem;
    line-height: 1.4;
    min-width: 160px;
}

.info-box h4 {
    margin: 0 0 4px 0;
    font-size: 0.9rem;
    color: #1a1a1a;
}

.info-box .info-value {
    font-weight: 700;
    color: #0d9488;
}

.info-box .info-class {
    color: #666;
    font-size: 0.8rem;
}

/* Year slider */
.slider-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 0.5rem;
    max-width: 600px;
    margin: 0 auto;
}

.play-button {
    width: 36px;
    height: 36px;
    border: 2px solid #0d9488;
    border-radius: 50%;
    background: white;
    color: #0d9488;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    flex-shrink: 0;
}

.play-button:hover {
    background-color: #0d9488;
    color: white;
}

.play-button.playing {
    background-color: #0d9488;
    color: white;
}

#year-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    outline: none;
}

#year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #0d9488;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

#year-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #0d9488;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.year-display {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1a1a1a;
    min-width: 3.5rem;
    text-align: center;
}

/* Map legend */
.map-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    font-size: 0.8rem;
    color: #666;
}

.legend-scale {
    display: flex;
    gap: 2px;
}

.legend-scale span {
    width: 28px;
    height: 14px;
    border-radius: 2px;
}

.legend-label {
    font-weight: 500;
}

/* Results / Detail panel */
.results {
    margin-top: 2rem;
}

.results.hidden {
    display: none;
}

/* Back button */
.back-button {
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    color: #666;
    cursor: pointer;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s, color 0.2s;
}

.back-button:hover {
    border-color: #0d9488;
    color: #0d9488;
}

/* Hero section */
.hero-section {
    text-align: center;
    background-color: white;
    border-radius: 12px;
    padding: 2rem 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.county-title {
    font-size: 1.1rem;
    color: #666;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.hero-stat {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.hero-value {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    color: #0d9488;
}

.hero-unit {
    font-size: 1rem;
    color: #888;
}

.hero-badge-row {
    margin-bottom: 1.25rem;
}

/* Classification badge */
.classification-badge {
    display: inline-block;
    padding: 0.375rem 1rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-surge {
    background-color: #ccfbf1;
    color: #115e59;
    border: 2px solid #0d9488;
}

.badge-boom {
    background-color: #ccfbf1;
    color: #115e59;
    border: 2px solid #5eead4;
}

.badge-pace {
    background-color: #f3f4f6;
    color: #374151;
    border: 2px solid #9ca3af;
}

.badge-below {
    background-color: #fee2e2;
    color: #991b1b;
    border: 2px solid #fca5a5;
}

.badge-under {
    background-color: #fee2e2;
    color: #991b1b;
    border: 2px solid #ef4444;
}

/* Percentile bar */
.percentile-display {
    max-width: 400px;
    margin: 0 auto;
}

.percentile-bar {
    display: block;
    height: 8px;
    background-color: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.percentile-fill {
    display: block;
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease-out;
    background: linear-gradient(90deg, #ef4444, #9ca3af 50%, #0d9488);
}

.percentile-text {
    display: block;
    font-size: 0.85rem;
    color: #666;
    text-align: center;
}

/* Stats row */
.stats-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

@media (min-width: 600px) {
    .stats-row {
        grid-template-columns: repeat(3, 1fr);
    }
}

.stat-card {
    background-color: white;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: #1a1a1a;
}

.stat-sublabel {
    display: block;
    font-size: 0.75rem;
    color: #999;
    margin-top: 0.25rem;
}

/* Chart panel */
.chart-panel {
    background-color: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.chart-panel h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #666;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chart-container {
    position: relative;
    margin-bottom: 0.75rem;
}

.ts-chart {
    height: 250px;
}

.breakdown-chart {
    height: 220px;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: #666;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-dot.sf-dot {
    background-color: #5eead4;
}

.legend-dot.mf-dot {
    background-color: #0d9488;
}

/* Insight callout */
.insight-callout {
    background-color: white;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-left: 4px solid #0d9488;
    margin-bottom: 1rem;
}

.insight-callout.insight-surge,
.insight-callout.insight-boom {
    border-left-color: #0d9488;
}

.insight-callout.insight-pace {
    border-left-color: #9ca3af;
}

.insight-callout.insight-below {
    border-left-color: #fca5a5;
}

.insight-callout.insight-under {
    border-left-color: #ef4444;
}

.insight-callout .insight-text {
    font-size: 1rem;
    color: #333;
    line-height: 1.5;
}

/* Small county notice */
.small-county-notice {
    background-color: #fffbeb;
    color: #92400e;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

.small-county-notice.hidden {
    display: none;
}

/* Error */
.error {
    background-color: #fef2f2;
    color: #dc2626;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
    text-align: center;
}

.error.hidden {
    display: none;
}

/* Footer */
footer {
    margin-top: 4rem;
    text-align: center;
    color: #888;
    font-size: 0.875rem;
}

footer a {
    color: #0f766e;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

footer p {
    margin-bottom: 0.5rem;
}

/* Highlighted county on map */
.county-highlighted {
    stroke: #1a1a1a !important;
    stroke-width: 3 !important;
}
