/* Default theme: Slate (dark). Switched via data-theme on <html>. */
:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --line: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --btn-text: #04293f;
    --input-bg: #0b1220;
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #ef4444;
}

:root[data-theme="light"] {
    --bg: #f1f5f9;
    --panel: #ffffff;
    --line: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --accent: #0284c7;
    --btn-text: #ffffff;
    --input-bg: #ffffff;
    --ok: #16a34a;
    --warn: #d97706;
    --bad: #dc2626;
}

:root[data-theme="dracula"] {
    --bg: #282a36;
    --panel: #343746;
    --line: #44475a;
    --text: #f8f8f2;
    --muted: #6272a4;
    --accent: #bd93f9;
    --btn-text: #282a36;
    --input-bg: #21222c;
    --ok: #50fa7b;
    --warn: #f1fa8c;
    --bad: #ff5555;
}

:root[data-theme="nord"] {
    --bg: #2e3440;
    --panel: #3b4252;
    --line: #4c566a;
    --text: #eceff4;
    --muted: #8e99ab;
    --accent: #88c0d0;
    --btn-text: #2e3440;
    --input-bg: #272c36;
    --ok: #a3be8c;
    --warn: #ebcb8b;
    --bad: #bf616a;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

header {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

header h1 { font-size: 18px; margin: 0; }
/* The build, beside the name: readable when looked for, not competing with the tabs. */
header h1 .ver { margin-left: 8px; font-size: 12px; font-weight: 400; color: var(--muted); }
header a { color: var(--accent); text-decoration: none; }
/* Page tabs: aligned to the header's bottom edge, active tab underlined in accent. */
header nav.tabs { display: flex; gap: 4px; align-self: stretch; align-items: stretch; margin-bottom: -14px; }
/* A checkbox sitting in the tab strip: same height and weight as a tab, but not a link. */
header nav.tabs .tab-check { display: flex; align-items: center; gap: 6px; padding: 0 12px;
    color: var(--muted); font-weight: 600; font-size: 14px; margin: 0; cursor: pointer;
    user-select: none; }
header nav.tabs .tab-check input { width: auto; margin: 0; cursor: pointer; }
header .header-right { margin-left: auto; display: flex; gap: 16px; align-items: center; }
header .header-right select { width: auto; padding: 5px 8px; font-size: 13px; }
header .header-right .logout { margin: 0; padding: 5px 12px; font-size: 13px; white-space: nowrap; }
/* The selected route, shown as a blue badge centered between the tabs and the right controls. */
header .header-route { flex: 1 1 auto; min-width: 0; display: flex; justify-content: center; }
header .header-route .route-badge { background: #2563eb; color: #fff; font-weight: 600;
    font-size: 14px; padding: 4px 12px; border-radius: 6px; max-width: 100%;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tab {
    display: flex;
    align-items: center;
    padding: 0 16px;
    color: var(--muted);
    font-weight: 600;
    font-size: 14px;
    border-bottom: 3px solid transparent;
}
.tab:hover { color: var(--text); border-bottom-color: var(--line); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

h2 { border-bottom: 1px solid var(--line); padding-bottom: 6px; }

a { color: var(--accent); }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px;
    margin-bottom: 20px;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: rgba(56, 189, 248, 0.06); }

.btn {
    display: inline-block;
    background: var(--accent);
    color: var(--btn-text);
    border: none;
    border-radius: 7px;
    padding: 8px 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
}
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.danger { background: var(--bad); color: #fff; }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; }

form.inline { display: inline; }

input, textarea, select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    padding: 9px 11px;
    font-size: 14px;
}
label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--input-bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.SUCCESS { background: rgba(34,197,94,.15); color: var(--ok); }
.badge.FAILED { background: rgba(239,68,68,.15); color: var(--bad); }
.badge.RUNNING { background: rgba(245,158,11,.15); color: var(--warn); }

.flash-ok { border-left: 4px solid var(--ok); }
.flash-err { border-left: 4px solid var(--bad); }

.muted { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

/* Vehicle-positions fetch control: button + rate dropdown + polling spinner. */
.vp-control { display: inline-flex; align-items: center; gap: 8px; }
.vp-control select { width: auto; padding: 6px 8px; font-size: 13px; }
.spinner {
    display: inline-block; width: 15px; height: 15px;
    border: 2px solid var(--line); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 16px; }

/* ---- TSP signals -----------------------------------------------------
   Named intersections loaded from the TSP signals file are drawn as labelled
   dots so the corridor reads as a list of places, not anonymous OSM nodes. */
.tsp-signal { background: none; border: none; }
.tsp-signal .dot { width: 12px; height: 12px; border-radius: 50%;
                       background: #ef4444; border: 2px solid #fff;
                       box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.tsp-signal .code { position: absolute; left: 16px; top: -3px; font-size: 11px;
                        font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.9);
                        white-space: nowrap; }
