:root {
    --bg-deep: #0A0F1A;
    --panel: #111a2b;
    --panel-2: #0d1521;
    --border: #22304a;
    --cyan: #43d9c8;
    --cyan-dim: #2a6b64;
    --amber: #f2a93b;
    --amber-dim: #7a5a24;
    --red: #e85d5d;
    --green: #5ed48a;
    --text: #e7ecf3;
    --muted: #8b96ac;
    --mono: 'IBM Plex Mono', monospace;
    --sans: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--sans);
    background: var(--bg-deep);
    color: var(--text);
    overflow: hidden;
}

#app {
    position: relative;
    width: 100%;
    height: 100vh;
    min-height: 560px;
    background: var(--bg-deep);
}

/* ---------- KEY GATE ---------- */
#keyGate {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 30% 20%, #101c30 0%, #070b13 70%);
    z-index: 50;
    padding: 24px;
}

    #keyGate .card {
        width: 100%;
        max-width: 460px;
        background: linear-gradient(180deg, var(--panel), var(--panel-2));
        border: 1px solid var(--border);
        border-radius: 16px;
        padding: 32px 30px;
        box-shadow: 0 30px 80px rgba(0,0,0,.5);
    }

    #keyGate .eyebrow {
        font-family: var(--mono);
        letter-spacing: .14em;
        font-size: 11px;
        color: var(--cyan);
        text-transform: uppercase;
        margin-bottom: 10px;
    }

    #keyGate h1 {
        font-size: 22px;
        margin: 0 0 8px 0;
        font-weight: 700;
        letter-spacing: -.01em;
    }

    #keyGate p {
        color: var(--muted);
        font-size: 13.5px;
        line-height: 1.55;
        margin: 0 0 20px 0;
    }

    #keyGate a {
        color: var(--cyan);
        text-decoration: none;
        border-bottom: 1px solid var(--cyan-dim);
    }

        #keyGate a:hover {
            border-bottom-color: var(--cyan);
        }

    #keyGate code {
        background: #0a1220;
        border: 1px solid var(--border);
        padding: 1px 5px;
        border-radius: 4px;
        font-family: var(--mono);
        font-size: 11.5px;
    }

#keyInput {
    width: 100%;
    background: #0a1220;
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--mono);
    font-size: 13px;
    padding: 12px 14px;
    border-radius: 9px;
    outline: none;
    margin-bottom: 12px;
}

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

#keyGate button {
    width: 100%;
    background: var(--cyan);
    color: #04201d;
    border: none;
    font-family: var(--sans);
    font-weight: 700;
    font-size: 14px;
    padding: 12px 14px;
    border-radius: 9px;
    cursor: pointer;
    transition: filter .15s ease, transform .1s ease;
}

    #keyGate button:hover {
        filter: brightness(1.08);
    }

    #keyGate button:active {
        transform: scale(.99);
    }

    #keyGate button:focus-visible, #keyInput:focus-visible {
        outline: 2px solid var(--cyan);
        outline-offset: 2px;
    }

#gateError {
    margin-top: 14px;
    font-size: 12.5px;
    color: var(--red);
    font-family: var(--mono);
    display: none;
    line-height: 1.5;
}

#keyGate .demo-note {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
    line-height: 1.6;
}

/* ---------- MAIN APP ---------- */
#mapWrap {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
}

#map {
    position: absolute;
    inset: 0;
}

/* HUD top bar */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0;
    background: linear-gradient(180deg, rgba(10,15,26,.92), rgba(10,15,26,.75));
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    flex-wrap: wrap;
}

#backBtn {
    display: none;
    flex: none;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 600;
    background: rgba(67,217,200,.08);
    border: 1px solid var(--cyan-dim);
    color: var(--cyan);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-right: 16px;
}

    #backBtn:hover {
        background: rgba(67,217,200,.16);
    }

    #backBtn.show {
        display: inline-flex;
        align-items: center;
    }

#hud .title-block {
    display: flex;
    flex-direction: column;
    margin-right: 28px;
}

#hud .eyebrow {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .16em;
    color: var(--cyan);
    text-transform: uppercase;
}

#hud h1 {
    font-size: 16px;
    margin: 2px 0 0 0;
    font-weight: 700;
}

.stat {
    display: flex;
    flex-direction: column;
    padding: 0 18px;
    border-left: 1px solid var(--border);
}

    .stat .label {
        font-family: var(--mono);
        font-size: 9.5px;
        letter-spacing: .1em;
        color: var(--muted);
        text-transform: uppercase;
    }

    .stat .value {
        font-family: var(--mono);
        font-size: 16px;
        font-weight: 600;
        margin-top: 3px;
    }

        .stat .value.cyan {
            color: var(--cyan);
        }

        .stat .value.amber {
            color: var(--amber);
        }

.hud-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.updatedLabel {
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--muted);
    white-space: nowrap;
}

#refreshBtn {
    flex: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: rgba(255,255,255,.04);
    color: var(--text);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease;
}

    #refreshBtn:hover {
        background: rgba(255,255,255,.09);
    }

    #refreshBtn:disabled {
        cursor: default;
        opacity: .6;
    }

    #refreshBtn.spinning {
        animation: fleetSpin .8s linear infinite;
    }

@keyframes fleetSpin {
    to {
        transform: rotate(360deg);
    }
}

#statusBadge {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--cyan-dim);
    color: var(--cyan);
    background: rgba(67,217,200,.08);
    transition: all .25s ease;
    white-space: nowrap;
}

    #statusBadge.stopped {
        border-color: var(--amber-dim);
        color: var(--amber);
        background: rgba(242,169,59,.1);
    }

    #statusBadge .dot {
        display: inline-block;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: currentColor;
        margin-right: 7px;
        box-shadow: 0 0 8px currentColor;
    }

/* Fleet panel (left) */
#fleetPanel {
    position: absolute;
    top: 82px;
    left: 16px;
    bottom: 96px;
    z-index: 10;
    width: 260px;
    background: rgba(17,26,43,.88);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

#fleetList {
    overflow-y: auto;
    padding: 8px;
    flex: 1;
}

    #fleetList::-webkit-scrollbar {
        width: 6px;
    }

    #fleetList::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 4px;
    }

.carCard {
    display: flex;
    gap: 10px;
    padding: 11px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 6px;
    transition: background .15s ease, border-color .15s ease;
    align-items: flex-start;
}

    .carCard:hover {
        background: rgba(255,255,255,.04);
        border-color: var(--border);
    }

    .carCard.selected {
        background: rgba(67,217,200,.1);
        border-color: var(--cyan-dim);
    }

    .carCard .statusDot {
        flex: none;
        width: 10px;
        height: 10px;
        border-radius: 50%;
        margin-top: 4px;
        box-shadow: 0 0 6px currentColor;
    }

    .carCard .info {
        min-width: 0;
        flex: 1;
    }

    .carCard .name {
        font-family: var(--mono);
        font-size: 13px;
        font-weight: 700;
        display: flex;
        justify-content: space-between;
        gap: 6px;
    }

        .carCard .name .statLabel {
            font-size: 9.5px;
            font-weight: 600;
            letter-spacing: .06em;
            text-transform: uppercase;
            opacity: .85;
        }

    .carCard .job {
        font-size: 11.5px;
        color: var(--muted);
        margin-top: 3px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .carCard .noFix {
        font-size: 10.5px;
        color: var(--muted);
        font-family: var(--mono);
        margin-top: 3px;
        font-style: italic;
    }

.emptyState, .loadingState, .errorState {
    padding: 16px 12px;
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.6;
}

.errorState {
    color: var(--red);
}

/* Sidebar */
#sidebar {
    position: absolute;
    top: 82px;
    right: 16px;
    bottom: 96px;
    z-index: 10;
    width: 290px;
    background: rgba(17,26,43,.88);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

    #sidebar .sb-head {
        padding: 14px 16px 10px 16px;
        border-bottom: 1px solid var(--border);
    }

        #sidebar .sb-head .eyebrow {
            font-family: var(--mono);
            font-size: 10px;
            letter-spacing: .14em;
            color: var(--muted);
            text-transform: uppercase;
        }

        #sidebar .sb-head h2 {
            font-size: 14px;
            margin: 4px 0 0 0;
            font-weight: 700;
        }

#stopList {
    overflow-y: auto;
    padding: 8px;
    flex: 1;
}

    #stopList::-webkit-scrollbar {
        width: 6px;
    }

    #stopList::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 4px;
    }

.stopCard {
    display: flex;
    gap: 10px;
    padding: 11px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 6px;
    transition: background .15s ease, border-color .15s ease;
}

    .stopCard:hover {
        background: rgba(255,255,255,.04);
        border-color: var(--border);
    }

    .stopCard.active {
        background: rgba(242,169,59,.1);
        border-color: var(--amber-dim);
    }

    .stopCard .badge {
        flex: none;
        width: 26px;
        height: 26px;
        border-radius: 50%;
        background: var(--amber);
        color: #221604;
        font-family: var(--mono);
        font-weight: 700;
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .stopCard.start .badge {
        background: var(--green);
    }

    .stopCard.end .badge {
        background: var(--red);
    }

    .stopCard .info {
        min-width: 0;
    }

    .stopCard .name {
        font-size: 12.5px;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .stopCard .meta {
        font-family: var(--mono);
        font-size: 10.5px;
        color: var(--muted);
        margin-top: 3px;
    }

    .stopCard .dur {
        font-family: var(--mono);
        font-size: 10.5px;
        color: var(--amber);
        margin-top: 2px;
        font-weight: 600;
    }

    .stopCard.start .dur, .stopCard.end .dur {
        color: var(--green);
    }

/* Timeline / scrubber */
#timeline {
    position: absolute;
    left: 292px;
    right: 322px;
    bottom: 16px;
    z-index: 10;
    background: rgba(17,26,43,.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px 14px 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,.35);
}

    #timeline.disabled {
        opacity: .5;
        pointer-events: none;
    }

    #timeline .tl-top {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 10px;
    }

#playBtn {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--cyan-dim);
    background: rgba(67,217,200,.1);
    color: var(--cyan);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}

    #playBtn:hover {
        background: rgba(67,217,200,.18);
    }

.speedBtn {
    font-family: var(--mono);
    font-size: 11px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 5px 9px;
    border-radius: 7px;
    cursor: pointer;
}

    .speedBtn.active {
        color: var(--cyan);
        border-color: var(--cyan-dim);
        background: rgba(67,217,200,.08);
    }

#clockLabel {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--text);
    margin-left: auto;
}

#barTrack {
    position: relative;
    height: 26px;
    border-radius: 6px;
    overflow: hidden;
    background: #0a1220;
    border: 1px solid var(--border);
    cursor: pointer;
}

.seg {
    position: absolute;
    top: 0;
    bottom: 0;
}

    .seg.drive {
        background: linear-gradient(180deg, var(--cyan), var(--cyan-dim));
    }

    .seg.stop {
        background: linear-gradient(180deg, var(--amber), var(--amber-dim));
    }

#playhead {
    position: absolute;
    top: -4px;
    bottom: -4px;
    width: 2px;
    background: #fff;
    box-shadow: 0 0 8px #fff, 0 0 14px var(--cyan);
    pointer-events: none;
}

    #playhead::before {
        content: '';
        position: absolute;
        top: -5px;
        left: 50%;
        transform: translateX(-50%);
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 6px solid #fff;
    }

#errorBanner {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    background: #2a1414;
    border: 1px solid #7a2c2c;
    color: #ffb4b4;
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 10px 16px;
    border-radius: 10px;
    display: none;
    max-width: 520px;
    text-align: center;
    line-height: 1.5;
}

@media (max-width: 1050px) {
    #fleetPanel {
        position: absolute;
        left: 16px;
        right: 16px;
        top: 82px;
        bottom: auto;
        height: 130px;
        width: auto;
    }

    #sidebar {
        position: absolute;
        left: 16px;
        right: 16px;
        top: auto;
        bottom: 180px;
        height: 130px;
        width: auto;
    }

    #timeline {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }

    .stat {
        padding: 0 10px;
    }

    #hud .title-block {
        margin-right: 14px;
    }
}
