/* Toronto Incident Map — Stylesheet */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-deep:        #0b1521;
    --bg-mid:         #121f30;
    --bg-card:        #192840;
    --accent:         #0ea5e9;
    --accent-glow:    rgba(14,165,233,0.22);
    --accent-hover:   #38bdf8;
    --red:            #ef4444;
    --red-glow:       rgba(239,68,68,0.25);
    --text-1:         #e2eaf4;
    --text-2:         #94abbe;
    --text-3:         #5a7a96;
    --border:         rgba(14,165,233,0.12);
    --border-hover:   rgba(14,165,233,0.42);
    --shadow-sm:      0 2px 8px rgba(0,0,0,0.25);
    --shadow-md:      0 4px 20px rgba(0,0,0,0.35);
    --shadow-lg:      0 8px 40px rgba(0,0,0,0.45);
    --radius:         10px;
    --transition:     all 0.22s cubic-bezier(0.4,0,0.2,1);
    --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --navbar-h:       56px;
}

html { font-size: 15px; }
body { font-family: var(--font-sans); background: var(--bg-deep); color: var(--text-1); overflow-x: hidden; }

/* ── Nav ──────────────────────────────────────────────────────────────── */
.navbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 2000;
    height: var(--navbar-h);
    display: flex; align-items: center;
    background: rgba(11,21,33,0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 0 1.25rem;
    gap: 1rem;
}

.nav-brand {
    display: flex; align-items: center; gap: 0.55rem;
    text-decoration: none; font-weight: 700; font-size: 1.05rem; color: var(--text-1);
    flex-shrink: 0;
}
.brand-icon {
    width: 32px; height: 32px; background: var(--accent); color: var(--bg-deep);
    border-radius: 7px; display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: 800;
}

.nav-tabs {
    display: flex; gap: 0.25rem; list-style: none;
    overflow-x: auto; scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs li a {
    display: flex; align-items: center; gap: 0.35rem;
    padding: 0.4rem 0.85rem; border-radius: 6px;
    text-decoration: none; font-size: 0.84rem; font-weight: 500; color: var(--text-2);
    transition: var(--transition);
}
.nav-tabs li a:hover,
.nav-tabs li a.active { background: var(--accent-glow); color: var(--accent); }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }

.status-dot {
    display: flex; align-items: center; gap: 0.35rem;
    font-size: 0.78rem; color: var(--text-3);
}
.status-dot .dot {
    width: 8px; height: 8px; border-radius: 50%; background: #6b7280;
}
.status-dot.ok .dot { background: #22c55e; animation: pulse-dot 2s infinite; }
.status-dot.error .dot { background: var(--red); }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; } 50% { opacity: 0.4; }
}

/* ── Layout ───────────────────────────────────────────────────────────── */
.app-body { padding-top: var(--navbar-h); height: 100vh; display: flex; flex-direction: column; }

.section { display: none; }
.section.active { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ── Map Section ──────────────────────────────────────────────────────── */
#section-map { flex-direction: row; }

#map {
    flex: 1; height: 100%;
    z-index: 1;
}

/* ── Filters sidebar ─────────────────────────────────────────────────── */
.filter-panel {
    width: 270px; flex-shrink: 0;
    background: var(--bg-mid);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow-y: auto; overflow-x: hidden;
    z-index: 10;
}

.filter-header {
    padding: 0.9rem 1rem 0.6rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.filter-header h3 { font-size: 0.88rem; font-weight: 700; color: var(--text-1); }
.filter-reset {
    font-size: 0.75rem; color: var(--accent); cursor: pointer; background: none; border: none;
    font-family: var(--font-sans); padding: 0; transition: color 0.2s;
}
.filter-reset:hover { color: var(--accent-hover); }

.filter-section { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.filter-section label,
.filter-section .filter-label { display: block; font-size: 0.75rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 0.5rem; }

.filter-section select,
.filter-section input[type="text"] {
    width: 100%; padding: 0.45rem 0.7rem;
    background: var(--bg-card); border: 1px solid rgba(14,165,233,0.2);
    border-radius: 6px; color: var(--text-1); font-family: var(--font-sans); font-size: 0.85rem;
    transition: border-color 0.2s;
}
.filter-section select:focus,
.filter-section input:focus { outline: none; border-color: var(--accent); }

.checkbox-group { display: flex; flex-direction: column; gap: 0.35rem; }
.checkbox-item { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox-item input[type="checkbox"] { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }
.checkbox-item span { font-size: 0.84rem; color: var(--text-2); }
.type-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.filter-row { display: flex; gap: 0.4rem; margin-top: 0.4rem; }
.btn-xs {
    flex: 1; padding: 0.3rem 0.5rem; font-size: 0.75rem; cursor: pointer;
    background: rgba(14,165,233,0.08); color: var(--accent);
    border: 1px solid rgba(14,165,233,0.25); border-radius: 5px;
    font-family: var(--font-sans); transition: var(--transition);
}
.btn-xs:hover { background: rgba(14,165,233,0.18); }

.quick-dates { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.4rem; }
.btn-quick {
    padding: 0.28rem 0.65rem; font-size: 0.75rem; cursor: pointer;
    background: var(--bg-card); color: var(--text-2);
    border: 1px solid var(--border); border-radius: 5px;
    font-family: var(--font-sans); transition: var(--transition);
}
.btn-quick:hover,
.btn-quick.active { background: var(--accent-glow); color: var(--accent); border-color: rgba(14,165,233,0.4); }

/* Time slider */
.time-slider-wrap { display: flex; flex-direction: column; gap: 0.4rem; }
.time-slider-labels { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--text-3); }
input[type="range"] {
    width: 100%; accent-color: var(--accent);
    -webkit-appearance: none; appearance: none;
    height: 4px; background: var(--bg-card); border-radius: 2px; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
}
.time-play-row { display: flex; align-items: center; gap: 0.5rem; }
.btn-play {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--accent-glow); border: 1px solid rgba(14,165,233,0.35);
    color: var(--accent); cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; flex-shrink: 0; transition: var(--transition);
}
.btn-play:hover { background: var(--accent); color: var(--bg-deep); }
#sliderDateLabel { font-size: 0.78rem; color: var(--text-2); }

/* View toggle */
.view-toggle { display: flex; gap: 0.4rem; }
.btn-view {
    flex: 1; padding: 0.35rem 0.5rem; font-size: 0.78rem; cursor: pointer;
    background: var(--bg-card); color: var(--text-2);
    border: 1px solid var(--border); border-radius: 6px;
    font-family: var(--font-sans); transition: var(--transition);
}
.btn-view.active { background: var(--accent); color: var(--bg-deep); border-color: var(--accent); font-weight: 700; }

/* Stats bar (below map) */
.stats-bar {
    flex-shrink: 0;
    display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
}
.stat-item { display: flex; align-items: center; gap: 0.4rem; color: var(--text-2); }
.stat-item strong { color: var(--text-1); font-weight: 700; }
.stat-item .accent { color: var(--accent); font-weight: 700; }

/* Load history btn */
#loadHistoryBtn {
    display: none; margin-left: auto; padding: 0.3rem 0.85rem;
    background: var(--accent-glow); color: var(--accent);
    border: 1px solid rgba(14,165,233,0.35); border-radius: 6px;
    font-size: 0.78rem; cursor: pointer; font-family: var(--font-sans); transition: var(--transition);
}
#loadHistoryBtn:hover { background: var(--accent); color: var(--bg-deep); }

/* ── Dashboard / Stats Section ────────────────────────────────────────── */
.stats-page { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; }
.stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }

.stat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.1rem 1.25rem;
    display: flex; flex-direction: column; gap: 0.35rem;
    transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-hover); }
.stat-card .sc-label { font-size: 0.75rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.8px; }
.stat-card .sc-value { font-size: 2rem; font-weight: 800; color: var(--accent); line-height: 1; }
.stat-card .sc-sub { font-size: 0.8rem; color: var(--text-2); }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.25rem; }
.chart-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.25rem;
}
.chart-card h4 { font-size: 0.85rem; font-weight: 700; color: var(--text-2); margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.6px; }

/* ── Incidents List Section ───────────────────────────────────────────── */
.incidents-page { flex: 1; overflow-y: auto; padding: 1rem 1.5rem; }
.incidents-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.incidents-header h3 { font-size: 1rem; font-weight: 700; color: var(--text-1); }
.incidents-search {
    flex: 1; min-width: 180px; max-width: 340px;
    padding: 0.45rem 0.85rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-1); font-family: var(--font-sans); font-size: 0.85rem;
}
.incidents-search:focus { outline: none; border-color: var(--accent); }
.incident-count { font-size: 0.8rem; color: var(--text-3); }

.incidents-list { display: flex; flex-direction: column; gap: 0.5rem; }
.incident-row {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 8px; padding: 0.75rem 1rem;
    display: flex; align-items: flex-start; gap: 0.75rem;
    transition: var(--transition); cursor: pointer; text-decoration: none;
}
.incident-row:hover { border-color: var(--border-hover); transform: translateX(3px); }
.incident-type-badge {
    flex-shrink: 0; padding: 0.22rem 0.55rem;
    border-radius: 5px; font-size: 0.72rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.5px;
    white-space: nowrap;
}
.incident-row-content { flex: 1; min-width: 0; }
.incident-row-title { font-size: 0.88rem; font-weight: 600; color: var(--text-1); margin-bottom: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.incident-row-meta { font-size: 0.76rem; color: var(--text-3); display: flex; gap: 0.75rem; flex-wrap: wrap; }
.incident-row-meta span { display: flex; align-items: center; gap: 0.25rem; }

/* ── Popup ────────────────────────────────────────────────────────────── */
.popup-card { min-width: 220px; max-width: 280px; font-family: var(--font-sans); }
.popup-type {
    display: inline-block; padding: 0.2rem 0.55rem; border-radius: 5px;
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.5px; margin-bottom: 0.5rem;
}
.popup-title { font-size: 0.88rem; font-weight: 700; color: #1a202c; margin-bottom: 0.4rem; line-height: 1.35; }
.popup-meta { font-size: 0.75rem; color: #4a5568; margin-bottom: 0.5rem; display: flex; flex-direction: column; gap: 0.2rem; }
.popup-summary { font-size: 0.78rem; color: #4a5568; margin-bottom: 0.6rem; line-height: 1.5; max-height: 80px; overflow: hidden; }
.popup-footer { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.popup-link {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.28rem 0.65rem; border-radius: 5px;
    font-size: 0.75rem; font-weight: 600; text-decoration: none;
    background: #e8f4ff; color: #0369a1; border: 1px solid #bfdbfe;
    transition: background 0.2s;
}
.popup-link:hover { background: #bfdbfe; }
.popup-report {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.28rem 0.65rem; border-radius: 5px;
    font-size: 0.75rem; font-weight: 600; text-decoration: none;
    background: #fff3f3; color: #b91c1c; border: 1px solid #fecaca;
}
.popup-report:hover { background: #fecaca; }

/* ── Loading spinner ─────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bg-deep); display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 1rem;
}
.spinner {
    width: 44px; height: 44px; border: 3px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 0.9rem; color: var(--text-2); }

/* ── Legend ──────────────────────────────────────────────────────────── */
.legend {
    background: rgba(11,21,33,0.92); border: 1px solid var(--border);
    border-radius: 8px; padding: 0.65rem 0.85rem;
    font-size: 0.75rem; color: var(--text-2);
}
.legend-title { font-weight: 700; color: var(--text-1); margin-bottom: 0.45rem; font-size: 0.78rem; }
.legend-item { display: flex; align-items: center; gap: 0.45rem; margin-bottom: 0.3rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #section-map { flex-direction: column-reverse; }
    .filter-panel {
        width: 100%; flex-direction: row; flex-wrap: wrap;
        border-left: none; border-top: 1px solid var(--border);
        max-height: 38vh; overflow-y: auto;
    }
    .filter-section { width: 50%; border-right: 1px solid var(--border); }
    .stats-bar { gap: 0.75rem; padding: 0.5rem; font-size: 0.75rem; }
}
@media (max-width: 480px) {
    .filter-section { width: 100%; }
    .charts-grid { grid-template-columns: 1fr; }
}
