:root {
    --bg: #0b1220;
    --panel: #121b2e;
    --panel-2: #17233a;
    --border: #24324d;
    --text: #e7edf7;
    --muted: #8ea0bd;
    --accent: #f6b23c;
    --accent-2: #3ca7f6;
    --track-line: #3a4a68;
    --green: #33d17a;
    --red: #ef4444;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: radial-gradient(1200px 600px at 20% -10%, #16233c 0%, var(--bg) 55%);
    color: var(--text);
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    background: linear-gradient(180deg, rgba(18,27,46,0.95), rgba(18,27,46,0.7));
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.topbar-kicker {
    display: block;
    font-size: 11px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 700;
    margin-bottom: 2px;
}

.topbar-title h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.field-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
}

select, input[type="range"] {
    accent-color: var(--accent);
}

select {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(180deg, #ffcf6b, var(--accent));
    color: #241a03;
    border-color: transparent;
}

.btn-ghost:hover { border-color: var(--accent-2); }

.stage {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    padding: 16px 24px 24px;
}

.board-wrap {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.board-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.clock {
    font-variant-numeric: tabular-nums;
    font-size: 22px;
    font-weight: 800;
    background: #000;
    color: var(--green);
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    min-width: 90px;
    text-align: center;
    letter-spacing: .05em;
}

.time-slider {
    flex: 1;
    min-width: 180px;
}

.board-canvas {
    background: #0d1626;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: auto;
}

.km-tooltip {
    position: fixed;
    z-index: 80;
    pointer-events: none;
    background: #0d1626;
    border: 1px solid var(--border);
    color: #e6edf7;
    font-size: 12px;
    line-height: 1.3;
    padding: 4px 9px;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0,0,0,.35);
    white-space: nowrap;
}
.km-tooltip[hidden] { display: none; }

.signal-node, .wesel-node, .peron-node { cursor: help; }

.peron-hover-mark {
    fill: rgba(60, 167, 246, 0.001);
    transition: fill .12s ease;
}
.peron-node:hover .peron-hover-mark {
    fill: rgba(60, 167, 246, 0.14);
}

.train-km-label {
    fill: #ffe9b3;
    font-size: 10px;
    font-weight: 400;
    text-anchor: middle;
}

#stationSvg {
    width: 100%;
    height: auto;
    display: block;
    transition: width .15s ease;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.zoom-controls .btn {
    padding: 6px 12px;
    font-size: 15px;
    line-height: 1;
}

.zoom-readout {
    font-size: 12px;
    color: var(--muted);
    min-width: 42px;
    text-align: center;
}

.notice-no-jadwal {
    margin: 0;
    padding: 8px 12px;
    background: rgba(246, 178, 60, 0.12);
    border: 1px solid rgba(246, 178, 60, 0.35);
    border-radius: 8px;
    color: var(--accent);
    font-size: 13px;
}

.btn:disabled,
select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.station-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 10px 24px 18px;
    border-top: 1px solid var(--border);
    background: rgba(18, 27, 46, 0.6);
}

.station-tab {
    padding: 8px 16px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.station-tab:hover {
    color: var(--text);
    border-color: var(--accent-2);
}

.station-tab.active {
    background: var(--accent);
    color: #241a03;
    border-color: transparent;
}

.board-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 12px;
    color: var(--muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot, .sig {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot-penumpang { background: var(--accent-2); }
.dot-komuter { background: #2dd4bf; }
.dot-barang { background: #f97316; }
.dot-dinas { background: #94a3b8; }
.sig-hijau { background: var(--green); box-shadow: 0 0 6px var(--green); }
.sig-merah { background: var(--red); box-shadow: 0 0 6px var(--red); }

.side-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 130px);
    overflow-y: auto;
}

.side-panel h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin: 12px 0 4px;
}

.side-panel h2:first-child { margin-top: 0; }

.train-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.train-card {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
}

.train-card .no-ka {
    font-weight: 800;
    color: var(--accent);
    margin-right: 6px;
}

.train-card .nama {
    color: var(--text);
}

.train-card .meta {
    color: var(--muted);
    margin-top: 2px;
}

.muted { color: var(--muted); font-size: 13px; }

/* SVG elements */
.track-line { stroke: var(--track-line); stroke-width: 3; fill: none; }
.track-label { fill: var(--muted); font-size: 13px; font-weight: 700; }
.station-box { fill: #17233a; stroke: var(--accent); stroke-width: 1.5; rx: 8; }
.station-box-label { fill: var(--accent); font-size: 16px; font-weight: 800; letter-spacing: .05em; }
.side-label { fill: var(--muted); font-size: 12px; font-style: italic; }

.signal-dot { stroke: #000; stroke-width: 1; }
.wesel-mark { fill: #56698f; }

.train-node text {
    fill: #06101f;
    font-size: 10px;
    font-weight: 800;
    text-anchor: middle;
    dominant-baseline: middle;
}

.train-node rect {
    stroke: rgba(0,0,0,.35);
    stroke-width: 1;
}

/* ---------------------------------------------------------------------
   Responsive (tablet & mobile)
   --------------------------------------------------------------------- */
@media (max-width: 900px) {
    .stage {
        grid-template-columns: 1fr;
    }

    .side-panel {
        max-height: none;
    }
}

@media (max-width: 600px) {
    .topbar {
        padding: 12px 16px;
        gap: 10px;
    }

    .topbar-title h1 {
        font-size: 16px;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .stage {
        padding: 12px 16px 16px;
        gap: 12px;
    }

    .board-wrap,
    .side-panel {
        padding: 10px;
        border-radius: 10px;
    }

    .board-toolbar {
        gap: 8px;
    }

    .clock {
        font-size: 18px;
        padding: 6px 10px;
        min-width: 72px;
    }

    .time-slider {
        min-width: 100%;
        order: 10;
    }

    .board-legend {
        gap: 10px;
        font-size: 11px;
    }

    .zoom-controls {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end;
        order: 9;
    }

    .station-tabs {
        padding: 8px 12px 14px;
        gap: 6px;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .station-tab {
        font-size: 12px;
        padding: 7px 12px;
    }
}

/* ------------------------------------------------------------------ */
/* Collision alert modal                                              */
/* ------------------------------------------------------------------ */
.collision-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(4, 7, 14, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.collision-overlay[hidden] { display: none; }

.collision-box {
    width: min(480px, 100%);
    background: var(--panel);
    border: 1px solid var(--red);
    border-radius: 14px;
    padding: 26px 28px;
    text-align: center;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.12), 0 20px 60px rgba(0, 0, 0, 0.5);
}

.collision-icon {
    font-size: 34px;
    line-height: 1;
    margin-bottom: 8px;
    color: var(--red);
    text-shadow: 0 0 14px rgba(239, 68, 68, 0.6);
}

.collision-box h2 {
    margin: 0 0 12px;
    color: var(--red);
    font-size: 18px;
}

.collision-box p {
    margin: 0 0 10px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

.collision-hint {
    color: var(--muted) !important;
    font-size: 12.5px !important;
}

.collision-actions {
    margin-top: 18px;
}

/* Train icon(s) currently flagged as colliding -- red pulsing outline,
   layered on top of the normal kategori fill color set in drawTrain(). */
.train-node.train-collision rect {
    stroke: var(--red);
    stroke-width: 2.5;
    animation: collision-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes collision-pulse {
    from { filter: drop-shadow(0 0 2px var(--red)); }
    to   { filter: drop-shadow(0 0 9px var(--red)); }
}
