/* ===== Design Tokens ===== */
:root {
    --bg: #080b14;
    --surface-0: #0d1120;
    --surface-1: #131829;
    --surface-2: #1a2036;
    --surface-3: #1f2640;
    --glass: rgba(13, 17, 32, 0.78);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.20);
    --text-primary: #eef0f7;
    --text-secondary: #c8ccdc;
    --text-muted: #6b7191;
    --text-faint: #3d4260;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --red: #f43f5e;
    --red-glow: rgba(244, 63, 94, 0.25);
    --red-surface: rgba(244, 63, 94, 0.12);
    --orange: #fb923c;
    --green: #10b981;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 0 1px var(--border-subtle);
    --shadow-hover: 0 12px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--border-medium);
    --font: 'Rubik', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--surface-0);
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

/* ===== Body ===== */
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.55;
    word-break: keep-all;
    hyphens: none;
    background-image:
        radial-gradient(ellipse 100% 60% at 50% -20%, rgba(99, 102, 241, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse 70% 50% at 80% 5%, rgba(244, 63, 94, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse 50% 80% at 20% 80%, rgba(99, 102, 241, 0.04) 0%, transparent 50%);
    background-attachment: fixed;
}

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

/* ===== Header ===== */
header {
    background: var(--glass);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-bottom: 1px solid var(--border-subtle);
    padding: 14px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

h1 {
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.01em;
}

.controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.range-selector {
    display: flex;
    gap: 3px;
    background: var(--surface-0);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.range-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 0.84rem;
    font-family: var(--font);
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 36px;
    white-space: nowrap;
}

.range-btn:hover {
    color: var(--text-secondary);
    background: var(--surface-2);
}

.range-btn.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.35);
}

/* ===== City Selector ===== */
.city-selector {
    position: relative;
    display: flex;
    align-items: center;
}

.city-selector input {
    background: var(--surface-0);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.84rem;
    padding: 8px 36px 8px 14px;
    min-height: 36px;
    width: 200px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.city-selector input::placeholder {
    color: var(--text-faint);
}

.city-selector input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.city-clear-btn {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 1.1rem;
    cursor: pointer;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s, color 0.15s, opacity 0.2s;
    opacity: 0;
    pointer-events: none;
}

.city-clear-btn.visible {
    opacity: 1;
    pointer-events: auto;
}

.city-clear-btn:hover {
    background: var(--surface-3);
    color: var(--text-secondary);
}

.last-update {
    font-size: 0.78rem;
    color: var(--text-faint);
    white-space: nowrap;
}

/* ===== Main ===== */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* ===== Live Panel ===== */
.live-panel {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 20px 24px;
    transition: all 0.4s ease;
    box-shadow: var(--shadow-card);
}

.live-panel.active {
    border-color: var(--red);
    background:
        linear-gradient(135deg, rgba(244, 63, 94, 0.08) 0%, var(--surface-1) 50%, rgba(244, 63, 94, 0.04) 100%);
    box-shadow:
        0 0 40px var(--red-glow),
        0 0 80px rgba(244, 63, 94, 0.1),
        0 0 0 1px var(--red),
        inset 0 1px 0 rgba(244, 63, 94, 0.15);
}

.live-header {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.live-panel.has-alerts .live-header {
    margin-bottom: 0;
}

.live-panel.has-alerts .live-locations:not(.collapsed)~.live-header,
.live-panel .live-locations:not(.collapsed) {
    margin-top: 0;
}

.live-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.live-preview .loc-tag {
    background: var(--red-surface);
    color: var(--red);
    padding: 4px 10px;
    border-radius: var(--radius-xs);
    font-size: 0.78rem;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid rgba(244, 63, 94, 0.18);
}

.live-preview .loc-more {
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.live-expand-icon {
    font-size: 0.65rem;
    color: var(--text-faint);
    transition: transform 0.3s ease;
    margin-inline-start: auto;
    flex-shrink: 0;
}

.live-locations:not(.collapsed)~.live-header .live-expand-icon,
.live-panel.expanded .live-expand-icon {
    transform: rotate(180deg);
}

.live-panel.expanded .live-preview {
    display: none;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--surface-3);
    color: var(--text-muted);
    padding: 5px 14px;
    border-radius: var(--radius-xs);
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.live-panel.active .live-badge {
    background: var(--red);
    color: #fff;
    box-shadow: 0 2px 12px rgba(244, 63, 94, 0.4);
}

.pulse-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.live-panel.active .pulse-dot {
    animation: pulse-dot 1.4s ease-in-out infinite;
    box-shadow: 0 0 6px currentColor;
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.3;
        transform: scale(0.6);
    }
}

.live-count {
    font-size: 0.88rem;
    color: var(--text-muted);
    font-weight: 500;
}

.live-locations {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease, margin-top 0.35s ease;
    max-height: 500px;
    opacity: 1;
    margin-top: 14px;
}

.live-locations.collapsed {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}

.live-locations .loc-tag {
    background: var(--red-surface);
    color: var(--red);
    padding: 6px 14px;
    border-radius: var(--radius-xs);
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid rgba(244, 63, 94, 0.18);
    transition: background 0.2s;
}

.live-locations .loc-tag:hover {
    background: rgba(244, 63, 94, 0.18);
}

.no-alerts {
    color: var(--text-faint);
    font-size: 0.85rem;
    font-style: italic;
}

/* ===== Stats Bar ===== */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.stat-card {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 22px 20px;
    text-align: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: var(--border-medium);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-value {
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 700;
    color: var(--accent-light);
    text-shadow: 0 0 30px rgba(99, 102, 241, 0.25);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-weight: 500;
}

.stat-sub {
    font-size: 0.72rem;
    color: var(--text-faint);
    margin-top: 4px;
}

.timing-bar {
    grid-template-columns: repeat(2, 1fr);
}

.timing-card .stat-value {
    color: var(--orange);
    text-shadow: 0 0 30px rgba(251, 146, 60, 0.25);
}

.timing-card::before {
    background: linear-gradient(90deg, transparent, var(--orange), transparent);
}

/* ===== Charts ===== */
.charts-row {
    display: grid;
    gap: 16px;
}

.charts-row.two-col {
    grid-template-columns: 1fr 1fr;
}

.chart-card {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 22px 24px;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    box-shadow: var(--shadow-card);
    min-width: 0;
    overflow: hidden;
}

.chart-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
    border-color: var(--border-medium);
}

.chart-card.wide {
    grid-column: 1 / -1;
}

.chart-card h3 {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-bottom: 18px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 280px;
}

.chart-container-sq {
    height: 300px;
}

.chart-container-tall {
    height: 360px;
}

.chart-card canvas {
    width: 100% !important;
    max-width: 100%;
}

/* ===== Table ===== */
.table-section {
    background: var(--surface-1);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 22px 24px;
    box-shadow: var(--shadow-card);
}

.table-section h3 {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-bottom: 18px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 16px;
    text-align: start;
    font-size: 0.84rem;
}

th {
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-medium);
    font-weight: 600;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

td {
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
    transition: background 0.15s;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--surface-2);
}

/* ===== Responsive: Tablets (768px) ===== */
@media (max-width: 768px) {
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .charts-row.two-col {
        grid-template-columns: 1fr;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        transition: gap 0.3s ease;
    }

    .controls {
        width: 100%;
        overflow: hidden;
        max-height: 400px;
        opacity: 1;
        transition: max-height 0.35s ease, opacity 0.25s ease;
    }

    header.collapsed .header-content {
        gap: 0;
    }

    header.collapsed .controls {
        max-height: 0;
        opacity: 0;
        pointer-events: none;
    }

    main {
        padding: 16px;
        gap: 16px;
    }

    .chart-card,
    .table-section,
    .live-panel {
        padding: 16px 18px;
    }

    .stat-card {
        padding: 18px 16px;
    }
}

/* ===== Responsive: Small Phones (480px) ===== */
@media (max-width: 480px) {
    header {
        padding: 12px 14px;
    }

    main {
        padding: 12px 10px;
        gap: 12px;
    }

    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .stat-value {
        font-size: clamp(1.2rem, 6vw, 1.5rem);
    }

    .stat-label {
        font-size: 0.72rem;
    }

    .chart-card,
    .table-section,
    .live-panel {
        padding: 12px;
        border-radius: var(--radius-sm);
    }

    .range-btn {
        padding: 10px 12px;
        font-size: 0.78rem;
        min-height: 44px;
    }

    .city-selector {
        width: 100%;
    }

    .city-selector input {
        width: 100%;
        min-height: 44px;
    }

    .range-selector {
        flex-wrap: wrap;
        width: 100%;
    }

    .controls {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    th,
    td {
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    h1 {
        font-size: 1.1rem;
    }

    .chart-card h3,
    .table-section h3 {
        font-size: 0.7rem;
        margin-bottom: 12px;
    }

    .chart-container {
        height: 220px;
    }

    .chart-container-sq {
        height: 260px;
    }

    .chart-container-tall {
        height: 300px;
    }
}

/* ===== Responsive: Large Desktop (1280px+) ===== */
@media (min-width: 1280px) {
    main {
        padding: 32px 40px;
        gap: 24px;
    }

    .stat-card {
        padding: 26px 24px;
    }

    .chart-card {
        padding: 26px 28px;
    }
}