/* ============================================================
   STL Scanner — Dark Cockpit Theme
   1080p optimized, monospace, minimal chrome
   ============================================================ */

:root {
    --bg: #0a0a0a;
    --bg-panel: #0d0d0d;
    --bg-widget: #111111;
    --border: #1a1a1a;
    --border-bright: #333333;
    --green: #00ff44;
    --green-dim: #003311;
    --cyan: #00ccff;
    --cyan-dim: #003344;
    --yellow: #ffaa00;
    --yellow-dim: #332200;
    --red: #ff0000;
    --red-bg: #cc0000;
    --red-dim: #330000;
    --orange: #ff6600;
    --text: #cccccc;
    --text-dim: #555555;
    --text-bright: #ffffff;
    --font: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Source Code Pro', monospace;
}

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

html, body {
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---- App Shell ---- */
#app {
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* ---- Alert Banner ---- */
#alert-banner {
    width: 100%;
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.5px;
    z-index: 100;
}

#alert-banner.collapsed {
    display: none;
}

#alert-banner.alert-extreme,
#alert-banner.alert-severe {
    background: var(--red-bg);
    color: var(--text-bright);
    animation: flash-red 1s ease-in-out infinite;
}

#alert-banner.alert-moderate {
    background: #cc5500;
    color: var(--text-bright);
    animation: flash-orange 2s ease-in-out infinite;
}

#alert-banner.alert-minor {
    background: #886600;
    color: var(--text-bright);
}

@keyframes flash-red {
    0%, 100% { background: var(--red-bg); }
    50% { background: #ff2200; }
}

@keyframes flash-orange {
    0%, 100% { background: #cc5500; }
    50% { background: #ff7700; }
}

/* ---- Main 3-Column Grid ---- */
#main {
    display: grid;
    grid-template-columns: 28fr 40fr 32fr;
    gap: 4px;
    padding: 4px;
    min-height: 0;
    overflow: hidden;
}

/* ---- Panes ---- */
.pane {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 2px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pane::-webkit-scrollbar { width: 4px; }
.pane::-webkit-scrollbar-track { background: var(--bg); }
.pane::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }
.pane::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ---- Widgets ---- */
.widget {
    padding: 6px 8px;
    margin-bottom: 2px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.widget:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.widget-header {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.widget-body {
    color: var(--text);
    font-size: 12px;
}

.collapsed {
    display: none;
}

/* ---- Scanner Header ---- */
#scanner-hdr .widget-header {
    color: var(--green);
    font-size: 11px;
    letter-spacing: 2px;
}

.change-location-btn {
    color: var(--cyan);
    cursor: pointer;
    font-size: 10px;
    letter-spacing: 0;
    text-transform: none;
    margin-left: 8px;
}
.change-location-btn:hover {
    color: var(--text-bright);
}

/* ---- Channel List ---- */
#channel-list {
    padding: 4px 8px;
}

#audio-viz-container {
    padding: 0;
    display: none;
}
#audio-viz-container.has-audio {
    display: block;
}
#audio-viz {
    width: 100%;
    height: 60px;
    display: block;
    background: transparent;
}

.channel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 4px;
    border-radius: 2px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 11px;
}

.channel:hover {
    background: rgba(255, 255, 255, 0.04);
}

.channel.active {
    background: rgba(0, 255, 68, 0.06);
}

.ch-indicator {
    font-size: 10px;
    color: var(--text-dim);
    width: 12px;
    text-align: center;
}

.channel.active .ch-indicator {
    color: var(--green);
    text-shadow: 0 0 4px var(--green-dim);
}

.ch-num {
    font-weight: 600;
    width: 14px;
    text-align: right;
}

.ch-freq {
    font-size: 10px;
    width: 60px;
}

.ch-name {
    color: var(--text);
    font-size: 11px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Weather ---- */
.wx-current {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    font-size: 12px;
}

.wx-icon {
    font-size: 28px;
    grid-row: span 2;
    display: flex;
    align-items: center;
}

.wx-temp {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-bright);
}

.wx-desc {
    color: var(--text);
    font-size: 11px;
}

.wx-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 12px;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-dim);
}

.wx-detail-value {
    color: var(--text);
}

.wind-arrow {
    display: inline-block;
    transition: transform 0.3s;
}

/* ---- River Gauge ---- */
.river-level {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 1px;
}

.river-flow {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

.river-stage {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 2px 6px;
    border-radius: 2px;
    display: inline-block;
    margin-top: 4px;
}

.river-normal { color: var(--green); }
.river-action { color: var(--yellow); background: var(--yellow-dim); }
.river-minor { color: var(--orange); background: rgba(255, 102, 0, 0.15); }
.river-moderate { color: var(--red); background: var(--red-dim); }
.river-major { color: var(--text-bright); background: var(--red-bg); animation: flash-red 1s infinite; }

#river-canvas {
    display: block;
    width: 100%;
    height: 120px;
    margin-top: 6px;
}

/* ---- Map ---- */
#map-container {
    width: 100%;
    height: 200px;
    background: var(--bg);
    border-radius: 2px;
}

/* ---- Radar Canvas ---- */
#radar-canvas {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg);
    border-radius: 2px;
}

/* ---- Camera Grid ---- */
.cam-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 4px;
}

.cam-cell {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 2px;
    overflow: hidden;
    aspect-ratio: 16/9;
    cursor: pointer;
}

.cam-cell:hover {
    border-color: var(--cyan);
}

.cam-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text);
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 6px;
    z-index: 2;
}

.cam-cell video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ---- Intel Header ---- */
#intel-hdr .widget-header {
    color: var(--cyan);
    font-size: 11px;
    letter-spacing: 2px;
}

/* ---- Badges ---- */
.badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 1px 5px;
    border-radius: 2px;
    vertical-align: middle;
    margin-left: 4px;
}

.badge-closed { background: var(--red-bg); color: var(--text-bright); }
.badge-work { background: var(--orange); color: #000; }
.badge-delay { background: var(--yellow); color: #000; }
.badge-fatal { background: var(--red-bg); color: var(--text-bright); animation: flash-red 1.5s infinite; }
.badge-injury { background: #cc4400; color: var(--text-bright); }
.badge-new { background: var(--cyan); color: #000; }
.badge-live { background: var(--green); color: #000; }
.badge-stale { background: var(--text-dim); color: var(--bg); }

/* ---- Staleness Indicators ---- */
.staleness {
    font-size: 9px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
}

.stale-ok { color: var(--green); }
.stale-warn { color: var(--yellow); }
.stale-error { color: var(--red); animation: pulse-dim 2s infinite; }

@keyframes pulse-dim {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ---- Travel Times ---- */
.travel-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
}
.travel-row:last-child { border-bottom: none; }
.travel-route { color: var(--text); }
.travel-time { font-weight: 600; color: var(--green); }
.travel-time.delayed { color: var(--yellow); }
.travel-time.severe { color: var(--red); }

/* ---- Traffic Incidents ---- */
.incident-row {
    padding: 3px 0;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
}
.incident-row:last-child { border-bottom: none; }
.incident-type { font-weight: 600; color: var(--yellow); }
.incident-location { color: var(--text); }
.incident-time { color: var(--text-dim); font-size: 10px; }

/* ---- News Feed ---- */
.news-item {
    padding: 3px 0;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    cursor: default;
}
.news-item:last-child { border-bottom: none; }
.news-title { color: var(--text); }
.news-source { color: var(--text-dim); font-size: 10px; }
.news-time { color: var(--text-dim); font-size: 10px; }

/* ---- Earthquakes ---- */
.quake-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 0;
    font-size: 11px;
}
.quake-mag { font-weight: 700; min-width: 32px; }
.quake-mag.mag-low { color: var(--green); }
.quake-mag.mag-med { color: var(--yellow); }
.quake-mag.mag-high { color: var(--red); }

/* ---- AQI ---- */
.aqi-value { font-size: 20px; font-weight: 700; }
.aqi-good { color: var(--green); }
.aqi-moderate { color: var(--yellow); }
.aqi-unhealthy { color: var(--orange); }
.aqi-very-unhealthy { color: var(--red); }
.aqi-hazardous { color: #cc00cc; }

/* ---- Gas Prices ---- */
#gas-chart canvas {
    display: block;
    width: 100%;
    height: 80px;
}

/* ---- Marquee ---- */
#marquee {
    background: var(--bg);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 3px 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: 11px;
    color: var(--cyan);
    letter-spacing: 0.5px;
}

#marquee-content {
    display: inline-block;
    animation: marquee-scroll 60s linear infinite;
    padding-left: 100%;
}

@keyframes marquee-scroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-100%); }
}

/* ---- Stats Bar ---- */
#stats-bar {
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 3px 12px;
    font-size: 10px;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    white-space: nowrap;
    overflow: hidden;
}

.stat-item { display: inline-flex; align-items: center; gap: 4px; }
.stat-label { color: var(--text-dim); }
.stat-value { color: var(--green); font-weight: 500; }
.stat-sep { color: var(--border-bright); margin: 0 4px; }

/* ---- Canvas (generic) ---- */
canvas { display: block; width: 100%; }

/* ---- Utility ---- */
.text-green { color: var(--green); }
.text-cyan { color: var(--cyan); }
.text-yellow { color: var(--yellow); }
.text-red { color: var(--red); }
.text-dim { color: var(--text-dim); }
.text-bright { color: var(--text-bright); }
.mono { font-family: var(--font); }
.bold { font-weight: 700; }
.uppercase { text-transform: uppercase; letter-spacing: 1px; }
.glow-green { text-shadow: 0 0 6px var(--green-dim); }
.glow-cyan { text-shadow: 0 0 6px var(--cyan-dim); }
.glow-red { text-shadow: 0 0 6px var(--red-dim); }

/* ---- Camera Modals ---- */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-content {
    background: #111; border: 1px solid #333; border-radius: 8px;
    width: 75vw; max-height: 90vh; overflow: hidden;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 16px; background: #0d0d0d; border-bottom: 1px solid #222;
    color: #00ccff; font-weight: bold;
}
.modal-close { cursor: pointer; color: #888; font-size: 24px; }
.modal-close:hover { color: #fff; }
#cam-modal-video { width: 100%; display: block; }

.allcams-content { width: 95%; max-width: 1800px; }
#allcams-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 4px; padding: 8px;
}
#allcams-grid .cam-cell { position: relative; }
#allcams-grid video { width: 100%; aspect-ratio: 16/9; background: #000; }
#allcams-grid .cam-label {
    position: absolute; top: 0; left: 0; padding: 2px 6px;
    background: rgba(0,0,0,0.7); color: #00ccff; font-size: 10px;
}

.all-cams-btn {
    float: right; cursor: pointer; color: #00ccff; font-size: 11px;
}
.all-cams-btn:hover { color: #fff; }

/* ---- Location Modal ---- */
.location-content {
    width: 420px;
    max-width: 90vw;
}

.location-body {
    padding: 16px;
}

.location-desc {
    color: var(--text-dim);
    margin-bottom: 12px;
    font-size: 12px;
    line-height: 1.5;
}

#location-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border-bright);
    color: var(--text-bright);
    font-family: var(--font);
    font-size: 12px;
    border-radius: 4px;
    outline: none;
}

#location-input:focus {
    border-color: var(--cyan);
}

.location-input-wrap {
    position: relative;
}

#location-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #1a1a1a;
    border: 1px solid var(--border-bright);
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 220px;
    overflow-y: auto;
    z-index: 10;
    display: none;
}

#location-suggestions.visible {
    display: block;
}

.suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

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

.suggestion-item:hover,
.suggestion-item.active {
    background: rgba(0, 204, 255, 0.1);
}

.suggestion-name {
    color: var(--text-bright);
}

.suggestion-detail {
    color: var(--text-dim);
    font-size: 10px;
}

#location-status {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-dim);
    min-height: 16px;
}

.location-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

#location-submit {
    padding: 8px 20px;
    background: var(--green);
    color: #000;
    border: none;
    border-radius: 4px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

#location-submit:hover {
    background: #00cc33;
}

#location-submit:disabled {
    background: var(--text-dim);
    cursor: wait;
}

.btn-secondary {
    padding: 8px 20px;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border-bright);
    border-radius: 4px;
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
}

.btn-secondary:hover {
    color: var(--text);
    border-color: var(--text-dim);
}

/* ---- Responsive: Tablet ---- */
@media (max-height: 900px) {
    html, body { font-size: 11px; }
    .widget { padding: 4px 6px; }
}

@media (max-width: 1024px) {
    #main {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }
    #pane-scanner { order: 1; }
    #pane-intel { order: 2; }
    #pane-center { order: 3; grid-column: 1 / -1; }
}

/* ---- Responsive: Mobile ---- */
@media (max-width: 768px) {
    html, body {
        height: auto;
        overflow: auto;
        font-size: 13px;
        -webkit-text-size-adjust: 100%;
    }

    #app {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    #main {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 0;
        overflow: visible;
    }

    .pane {
        overflow-y: visible;
        border: none;
        border-bottom: 2px solid var(--border-bright);
        border-radius: 0;
    }

    /* -- Widgets -- */
    .widget {
        padding: 10px 12px;
        margin-bottom: 0;
        border-bottom: 1px solid var(--border);
    }

    .widget-header {
        font-size: 11px;
        margin-bottom: 6px;
        padding: 2px 0;
    }

    .widget-body {
        font-size: 13px;
    }

    /* -- Scanner header -- */
    #scanner-hdr .widget-header {
        font-size: 13px;
        padding: 6px 0;
        flex-wrap: wrap;
        gap: 4px;
    }

    .change-location-btn {
        font-size: 12px;
    }

    /* -- Channels -- */
    #channel-list {
        padding: 6px 12px;
    }

    .channel {
        padding: 8px 4px;
        font-size: 13px;
        gap: 10px;
    }

    .ch-freq { font-size: 12px; width: 70px; }
    .ch-name { font-size: 13px; }

    /* -- Weather -- */
    .wx-icon { font-size: 36px; }
    .wx-temp { font-size: 28px; }
    .wx-desc { font-size: 13px; }
    .wx-details { font-size: 13px; gap: 4px 16px; margin-top: 8px; }

    /* -- Camera grid: 2x1 on mobile -- */
    .cam-container {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto;
        gap: 4px;
    }

    .cam-cell {
        aspect-ratio: 16/9;
    }

    .cam-label {
        font-size: 10px;
        padding: 3px 8px;
    }

    /* -- Radar scope -- */
    #radar-canvas {
        max-height: 350px;
    }

    /* -- Map -- */
    #map-container {
        height: 250px;
    }

    /* -- River chart -- */
    #river-canvas {
        height: 100px;
    }

    /* -- Travel times -- */
    .travel-row {
        padding: 6px 0;
        font-size: 13px;
    }

    /* -- Incidents -- */
    .incident-row {
        padding: 8px 0;
        font-size: 13px;
    }

    /* -- News -- */
    .news-item {
        padding: 8px 0;
        font-size: 13px;
    }

    /* -- Quakes -- */
    .quake-row {
        padding: 6px 0;
        font-size: 13px;
    }

    /* -- Badges (bigger tap targets) -- */
    .badge {
        font-size: 10px;
        padding: 2px 6px;
    }

    /* -- Marquee -- */
    #marquee {
        font-size: 12px;
        padding: 6px 0;
    }

    /* -- Stats bar -- */
    #stats-bar {
        font-size: 11px;
        padding: 6px 12px;
        flex-wrap: wrap;
        gap: 8px;
        white-space: normal;
    }

    /* -- Modals -- */
    .modal-content {
        width: 95vw;
        max-height: 95vh;
        border-radius: 4px;
    }

    #cam-modal-video {
        max-height: 60vh;
    }

    #allcams-grid {
        grid-template-columns: 1fr 1fr;
        gap: 4px;
        padding: 4px;
    }

    .allcams-content {
        width: 98vw;
    }

    /* -- Location modal -- */
    .location-content {
        width: 95vw;
    }

    #location-input {
        font-size: 16px; /* prevents iOS zoom on focus */
        padding: 12px;
    }

    .location-actions {
        flex-direction: column;
    }

    #location-submit, .btn-secondary {
        padding: 12px 20px;
        font-size: 14px;
        width: 100%;
        text-align: center;
    }

    .suggestion-item {
        padding: 12px;
        font-size: 14px;
    }

    .suggestion-detail {
        font-size: 12px;
    }

    /* -- Collapsible sections on mobile -- */
    .mobile-section-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
        background: var(--bg-panel);
        border-bottom: 1px solid var(--border-bright);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-section-header .section-title {
        font-size: 12px;
        font-weight: 600;
        letter-spacing: 1.5px;
        text-transform: uppercase;
    }

    .mobile-section-header .section-arrow {
        font-size: 14px;
        color: var(--text-dim);
        transition: transform 0.2s;
    }

    .mobile-section-header.collapsed .section-arrow {
        transform: rotate(-90deg);
    }

    /* Alert banner -- */
    #alert-banner {
        font-size: 14px;
        padding: 10px 12px;
    }
}

/* ---- Responsive: Small phones ---- */
@media (max-width: 400px) {
    html, body { font-size: 12px; }

    .cam-container {
        grid-template-columns: 1fr;
    }

    #allcams-grid {
        grid-template-columns: 1fr;
    }

    .wx-temp { font-size: 24px; }
    .wx-icon { font-size: 30px; }
}
