/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #f3f4f6; /* Soft neutral grey */
    --card-bg: rgba(255, 255, 255, 0.7); /* Translucent white */
    --card-border: rgba(15, 23, 42, 0.08); /* Subtle slate border */
    --card-shadow: rgba(15, 23, 42, 0.06); /* Soft shadow */
    
    --text-primary: #0f172a; /* Slate 900 */
    --text-secondary: #475569; /* Slate 600 */
    --text-muted: #94a3b8; /* Slate 400 */
    
    --accent: #2563eb; /* Royal Blue */
    --accent-glow: rgba(37, 99, 235, 0.15);
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    
    --font-family: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    background-color: var(--bg-color);
    background-image: radial-gradient(at 0% 0%, rgba(96, 165, 250, 0.15) 0, transparent 50%),
                      radial-gradient(at 50% 0%, rgba(139, 92, 246, 0.1) 0, transparent 50%),
                      radial-gradient(at 100% 0%, rgba(244, 63, 94, 0.08) 0, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-family);
    min-height: 100vh;
    overflow-x: clip;
    position: relative;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.1);
    border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(15, 23, 42, 0.25);
}

/* Layout Containers */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 2rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(16px);
    border-radius: 16px;
    box-shadow: 0 10px 30px var(--card-shadow), inset 1px 1px 0px rgba(255, 255, 255, 0.6);
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-icon {
    font-size: 2.2rem;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.badge {
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.2);
    color: var(--accent);
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Mobile controls toggle button (hidden on desktop) */
.mobile-controls-toggle {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    white-space: nowrap;
}
.mobile-controls-toggle:hover {
    background: #1d4ed8;
}
.mobile-controls-toggle:active {
    transform: scale(0.96);
}
.mobile-controls-toggle i {
    font-size: 0.85rem;
}

/* Main Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 350px 16px 1fr;
    gap: 0;
    align-items: start;
}

/* Panel Resizer Style */
.resizer {
    grid-column: 2;
    width: 16px;
    height: 100%;
    cursor: col-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    user-select: none;
    z-index: 10;
    transition: background var(--transition-fast);
}

.resizer:hover {
    background: rgba(15, 23, 42, 0.02);
}

.resizer-handle {
    width: 2px;
    height: 40px;
    background: var(--card-border);
    border-radius: 2px;
    transition: background var(--transition-fast);
}

.resizer:hover .resizer-handle {
    background: var(--accent);
}

/* Scroll Container for Charts */
.charts-scroll-container {
    grid-column: 3;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
}

/* Desktop-only Independent Sticky Scrolling */
@media (min-width: 1025px) {
    body {
        min-height: 100vh;
        overflow-y: auto;
    }
    .app-container {
        min-height: 100vh;
        height: auto;
    }
    .dashboard-grid {
        height: auto;
        overflow: visible;
        align-items: start;
    }
    .controls-panel-wrapper {
        position: sticky;
        top: 1.5rem;
        align-self: start;
        max-height: calc(100vh - 3rem);
        overflow-y: auto;
    }
    .controls-card {
        height: auto;
    }
    .charts-scroll-container {
        height: auto;
        overflow: visible;
        padding-right: 0.5rem;
    }
}

/* Draggable Horizontal Panel Resizer */
.h-resizer {
    width: 100%;
    height: 16px;
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    user-select: none;
    z-index: 10;
    transition: background var(--transition-fast);
}

.h-resizer:hover {
    background: rgba(15, 23, 42, 0.02);
}

.h-resizer-handle {
    width: 40px;
    height: 2px;
    background: var(--card-border);
    border-radius: 2px;
    transition: background var(--transition-fast);
}

.h-resizer:hover .h-resizer-handle {
    background: var(--accent);
}

/* Cards styling */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 10px 30px var(--card-shadow), inset 1px 1px 0px rgba(255, 255, 255, 0.6);
    transition: transform var(--transition-normal), border-color var(--transition-fast);
}

.card:hover {
    border-color: rgba(37, 99, 235, 0.15);
}

.card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.card h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.title-icon {
    color: var(--accent);
}

/* Search Box & Dropdown */
.search-box-container {
    position: relative;
    margin-bottom: 1.5rem;
}

.input-wrapper {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.95rem;
}

#county-search {
    width: 100%;
    padding: 0.8rem 1rem 0.8rem 2.8rem;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

#county-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    width: 100%;
    max-height: 250px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    z-index: 100;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.1);
}

.dropdown-menu.hidden {
    display: none;
}

.dropdown-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid rgba(15, 23, 42, 0.03);
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: rgba(37, 99, 235, 0.08);
    color: var(--accent);
}

/* Selected Counties Tags */
.selected-counties-container {
    margin-bottom: 1.5rem;
}

.selected-counties-container h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 0.75rem;
}

.tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 40px;
    align-content: flex-start;
}

.no-selection-msg {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    align-self: center;
}

.county-tag {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.25);
    color: var(--accent);
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    animation: tagFadeIn 0.2s ease-out;
}

.county-tag button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    font-size: 0.85rem;
    transition: color var(--transition-fast);
}

.county-tag button:hover {
    color: var(--accent-danger);
}

@keyframes tagFadeIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* Settings block */
.global-settings h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 0.75rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.custom-select {
    padding: 0.6rem 1rem;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-primary);
    outline: none;
    font-family: var(--font-family);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.custom-select:focus {
    border-color: var(--accent);
}

/* Welcome Card */
.welcome-card {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 6rem 2rem;
    background: radial-gradient(circle at top right, rgba(37, 99, 235, 0.05), transparent 60%), var(--card-bg);
}

.welcome-content h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    justify-content: center;
}

.welcome-content p {
    color: var(--text-secondary);
    font-size: 1.05rem;
    max-width: 500px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Chart Grid (replaces welcome card when active) */
.dashboard-grid.has-selection .welcome-card {
    display: none;
}

.chart-card {
    display: none;
    flex-direction: column;
    gap: 1.25rem;
}

.dashboard-grid.has-selection .chart-card {
    display: flex;
}

/* =============================================
   RESPONSIVE: TABLET (768px – 1024px)
   ============================================= */
@media (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
        height: auto !important;
        overflow: visible;
    }
    .resizer {
        display: none !important;
    }
    .controls-card {
        height: auto;
        overflow: visible;
    }
    .charts-scroll-container {
        grid-column: 1;
        height: auto;
        overflow: visible;
    }
    .app-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 1rem 1.25rem;
    }
    .h-resizer {
        display: none;
    }
}

/* =============================================
   RESPONSIVE: MOBILE (≤ 768px)
   ============================================= */
@media (max-width: 768px) {
    /* Show filter toggle button */
    .mobile-controls-toggle {
        display: flex;
    }
    .header-meta {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        flex-wrap: nowrap;
    }

    /* Header stays horizontal, compact */
    .app-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0.85rem 1rem;
        border-radius: 14px;
        gap: 0.5rem;
    }
    .app-header h1 {
        font-size: 1.15rem;
    }
    .subtitle {
        display: none; /* hide subtitle on mobile to save space */
    }
    .logo {
        gap: 0.65rem;
    }
    .header-icon {
        font-size: 1.7rem;
    }
    .badge {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }
    .badge i {
        display: none; /* icon only for badge, keep text */
    }

    /* Controls panel: collapsible on mobile */
    .controls-panel-wrapper {
        overflow: hidden;
        max-height: 0;
        opacity: 0;
        transition: max-height 0.38s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.28s ease;
        pointer-events: none;
    }
    .controls-panel-wrapper.is-open {
        max-height: 2000px;
        opacity: 1;
        pointer-events: auto;
    }

    /* Bigger touch targets for selects and inputs */
    .custom-select {
        padding: 0.75rem 1rem;
        font-size: 1rem;
        border-radius: 10px;
        min-height: 44px;
    }
    #county-search {
        padding: 0.9rem 1rem 0.9rem 2.8rem;
        font-size: 1rem;
        min-height: 44px;
    }
    .dropdown-item {
        padding: 0.9rem 1rem;
        font-size: 0.9rem;
    }
    .setting-group label {
        font-size: 0.85rem;
    }
}

/* =============================================
   RESPONSIVE: SMALL MOBILE (≤ 480px)
   ============================================= */
@media (max-width: 480px) {
    .app-container {
        padding: 0.65rem;
        gap: 0.85rem;
    }
    .card {
        padding: 1rem;
        border-radius: 12px;
    }
    .app-header {
        padding: 0.75rem 0.9rem;
        border-radius: 12px;
    }
    .app-header h1 {
        font-size: 1rem;
    }
    .header-icon {
        font-size: 1.5rem;
    }
    .mobile-controls-toggle span {
        display: none; /* icon-only on very small screens */
    }
    .mobile-controls-toggle {
        padding: 0.4rem 0.65rem;
        border-radius: 50%;
    }
    .badge {
        display: none; /* hide badge entirely on very small screens */
    }
    .chart-wrapper {
        height: 240px;
        min-height: 220px;
    }
    .welcome-card {
        padding: 3rem 1.25rem;
    }
    .welcome-content h2 {
        font-size: 1.4rem;
    }
    .welcome-content p {
        font-size: 0.95rem;
    }
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-icon {
    color: var(--accent);
}

.tooltip-icon {
    color: var(--text-muted);
    cursor: help;
    font-size: 0.95rem;
    transition: color var(--transition-fast);
}

.tooltip-icon:hover {
    color: var(--text-secondary);
}

.chart-wrapper {
    position: relative;
    width: 100%;
    min-height: 250px;
    height: 350px;
    resize: vertical;
    overflow: hidden;
    padding-bottom: 8px;
}

/* Hidden elements helper */
.hidden {
    display: none !important;
}

/* Footer styling */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--card-border);
    margin-top: 2rem;
}

/* Nav buttons hover */
.nav-btn:not(.active):hover {
    background: rgba(15, 23, 42, 0.05);
    color: var(--accent) !important;
}

/* =============================================
   LOADING OVERLAY & ADAPTIVE ETA STYLING
   ============================================= */
.charts-scroll-container {
    position: relative;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 400px;
    background: rgba(243, 244, 246, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    animation: fadeInOverlay 0.25s ease-out;
}

@keyframes fadeInOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

.loading-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--card-border);
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.8) inset;
    border-radius: 16px;
    padding: 2.25rem 2.5rem;
    max-width: 440px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1.25rem;
    animation: scaleUpCard 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes scaleUpCard {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.spinner-container {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    width: 52px;
    height: 52px;
    border: 3.5px solid rgba(37, 99, 235, 0.15);
    border-top: 3.5px solid var(--accent);
    border-right: 3.5px solid #7c3aed;
    border-radius: 50%;
    animation: spinSpinner 0.85s linear infinite;
    z-index: 2;
}

.pulse-ring {
    position: absolute;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    animation: pulseRing 1.5s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
    z-index: 1;
}

@keyframes spinSpinner {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulseRing {
    0% { transform: scale(0.85); opacity: 0.8; }
    50% { transform: scale(1.3); opacity: 0.3; }
    100% { transform: scale(0.85); opacity: 0.8; }
}

.loading-text-container {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.loading-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.loading-subtitle {
    font-size: 0.88rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.eta-progress-bar-bg {
    width: 100%;
    height: 8px;
    background: rgba(15, 23, 42, 0.08);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.eta-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #7c3aed);
    border-radius: 999px;
    transition: width 0.15s ease-out;
}

.eta-badge-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.eta-badge {
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.2);
    color: var(--accent);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.eta-history-badge {
    background: rgba(124, 58, 237, 0.08);
    border: 1px solid rgba(124, 58, 237, 0.2);
    color: #7c3aed;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
}

