/* ── V2 Baseline — Google Maps-style traffic view ─────────────────────── */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #111;
    color: #ddd;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Nav ── */
#nav-bar {
    height: 44px;
    min-height: 44px;
    background: rgba(20,20,20,0.97);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 20px;
    z-index: 1000;
    backdrop-filter: blur(8px);
}
.nav-brand { text-decoration: none; color: #fff; font-size: 15px; font-weight: 600; white-space: nowrap; }
.nav-brand span { color: #42a5f5; font-weight: 400; }
.nav-links { display: flex; gap: 4px; }
.nav-links a { color: #aaa; text-decoration: none; padding: 5px 10px; border-radius: 4px; font-size: 13px; }
.nav-links a:hover { color: #fff; background: rgba(255,255,255,0.07); }
.nav-links a.active { color: #fff; background: rgba(66,165,245,0.18); }
.nav-links a.nav-admin { color: #e57373; }
.nav-links a.nav-admin:hover { color: #fff; background: rgba(229,57,53,0.15); }
.nav-spacer { flex: 1; }
.nav-version { font-size: 10px; color: #555; margin-left: 4px; }

/* ── Layout ── */
#main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Map ── */
#map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}
#map { width: 100%; height: 100%; }

/* ── Side Panel ── */
#panel {
    width: 320px;
    min-width: 280px;
    background: rgba(16,16,22,0.96);
    border-right: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    backdrop-filter: blur(8px);
    z-index: 500;
    transition: width 0.2s;
}
#panel.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
}

.panel-section {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.section-label {
    display: block;
    font-size: 9px;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

/* ── AM/PM Toggle ── */
.period-toggle {
    display: flex;
    gap: 2px;
    background: rgba(255,255,255,0.04);
    border-radius: 6px;
    padding: 2px;
}
.period-btn {
    flex: 1;
    padding: 7px 0;
    background: none;
    border: 1px solid transparent;
    color: #888;
    font-size: 12px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}
.period-btn:hover { color: #bbb; background: rgba(255,255,255,0.06); }
.period-btn.active {
    background: rgba(66,165,245,0.15);
    border-color: rgba(66,165,245,0.4);
    color: #90caf9;
}

/* ── Colour mode buttons ── */
.colour-mode-group {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
}
.colour-mode-btn {
    padding: 5px 8px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    color: #888;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.colour-mode-btn:hover { background: rgba(255,255,255,0.08); color: #bbb; }
.colour-mode-btn.active {
    background: rgba(66,165,245,0.12);
    border-color: rgba(66,165,245,0.35);
    color: #90caf9;
}

/* ── Layer toggles ── */
.layer-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 12px;
    color: #aaa;
    cursor: pointer;
}
.layer-toggle input { accent-color: #42a5f5; cursor: pointer; }
.layer-count {
    margin-left: auto;
    font-size: 10px;
    color: #555;
    font-variant-numeric: tabular-nums;
}

/* ── Summary chips ── */
.summary-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.summary-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 6px;
    min-width: 55px;
    flex: 1;
}
.chip-val {
    font-size: 16px;
    font-weight: 700;
    color: #e0e0e0;
    line-height: 1.2;
}
.chip-label {
    font-size: 9px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Detail Panel (edge / junction / count site) ── */
#detail-panel {
    display: none;
    flex-direction: column;
    gap: 0;
}
#detail-panel.visible { display: flex; }

.detail-header {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
}
.detail-title {
    font-size: 14px;
    font-weight: 600;
    color: #e0e0e0;
    flex: 1;
}
.detail-close {
    background: none;
    border: none;
    color: #666;
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.detail-close:hover { background: rgba(255,255,255,0.08); color: #aaa; }

.detail-body {
    padding: 12px 14px;
    overflow-y: auto;
    flex: 1;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.detail-key {
    font-size: 11px;
    color: #777;
}
.detail-val {
    font-size: 12px;
    color: #ddd;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* ── Confidence badges ── */
.confidence-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.confidence-badge.HIGH {
    background: rgba(76,175,80,0.15);
    color: #81c784;
    border: 1px solid rgba(76,175,80,0.3);
}
.confidence-badge.MED {
    background: rgba(255,183,77,0.15);
    color: #ffb74d;
    border: 1px solid rgba(255,183,77,0.3);
}
.confidence-badge.LOW {
    background: rgba(158,158,158,0.15);
    color: #9e9e9e;
    border: 1px solid rgba(158,158,158,0.3);
}

/* ── Speed indicator bar ── */
.speed-bar {
    height: 6px;
    border-radius: 3px;
    background: rgba(255,255,255,0.06);
    overflow: hidden;
    margin-top: 4px;
}
.speed-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

/* ── Junction type badges ── */
.junction-type-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.junction-type-badge.signal {
    background: rgba(66,165,245,0.15);
    color: #64b5f6;
    border: 1px solid rgba(66,165,245,0.3);
}
.junction-type-badge.roundabout {
    background: rgba(171,71,188,0.15);
    color: #ce93d8;
    border: 1px solid rgba(171,71,188,0.3);
}
.junction-type-badge.give_way {
    background: rgba(255,183,77,0.15);
    color: #ffb74d;
    border: 1px solid rgba(255,183,77,0.3);
}

/* ── Sparkline ── */
.sparkline-container {
    width: 100%;
    height: 40px;
    margin-top: 8px;
}
.sparkline-container canvas {
    width: 100%;
    height: 100%;
}

/* ── Action buttons ── */
.detail-actions {
    display: flex;
    gap: 6px;
    padding: 10px 14px;
    border-top: 1px solid rgba(255,255,255,0.05);
}
.detail-btn {
    padding: 6px 12px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #aaa;
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.detail-btn:hover { background: rgba(255,255,255,0.1); color: #ddd; }
.detail-btn.primary {
    background: rgba(66,165,245,0.12);
    border-color: rgba(66,165,245,0.3);
    color: #90caf9;
}
.detail-btn.primary:hover {
    background: rgba(66,165,245,0.2);
}

/* ── Map Legend ── */
#map-legend {
    position: absolute;
    bottom: 24px;
    left: 12px;
    background: rgba(16,16,22,0.92);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 10px 14px;
    z-index: 800;
    backdrop-filter: blur(6px);
    min-width: 140px;
}
.legend-title {
    font-size: 10px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
    font-size: 11px;
    color: #aaa;
}
.legend-swatch {
    width: 24px;
    height: 4px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ── Panel toggle button ── */
#panel-toggle {
    position: absolute;
    top: 54px;
    left: 320px;
    z-index: 600;
    background: rgba(16,16,22,0.92);
    border: 1px solid rgba(255,255,255,0.08);
    border-left: none;
    border-radius: 0 6px 6px 0;
    padding: 8px 6px;
    color: #888;
    font-size: 14px;
    cursor: pointer;
    transition: left 0.2s, background 0.15s;
}
#panel-toggle:hover { background: rgba(30,30,40,0.95); color: #ccc; }
#panel-toggle.collapsed { left: 0; }

/* ── Loading overlay ── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5,5,15,0.82);
    backdrop-filter: blur(4px);
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }
.loading-card {
    background: rgba(20,20,35,0.96);
    border: 1px solid rgba(100,181,246,0.2);
    border-radius: 16px;
    padding: 36px 48px;
    text-align: center;
    min-width: 280px;
}
.loading-spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(100,181,246,0.15);
    border-top-color: #64b5f6;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg) } }
.loading-title { font-size: 14px; font-weight: 600; color: #e0e0e0; }
.loading-detail { font-size: 11px; color: #90a4ae; margin-top: 4px; }

/* ── Edge hover tooltip ── */
.edge-tooltip {
    font-size: 12px !important;
    background: rgba(16,16,22,0.95) !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    border-radius: 6px !important;
    padding: 6px 10px !important;
    color: #ddd !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important;
}
.edge-tooltip .tt-name { font-weight: 600; color: #fff; }
.edge-tooltip .tt-speed { color: #90caf9; }

/* ── Responsive ── */
@media (max-width: 768px) {
    #panel { width: 260px; min-width: 200px; }
    #panel-toggle { left: 260px; }
    #panel-toggle.collapsed { left: 0; }
}
