:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #142235; --muted: #5b6b80; --line: #dde3ea;
  --brand: #0f2742; --primary: #1d6fe0; --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --idle: #8a96a6;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d1520; --panel: #16212f; --ink: #e8eef6; --muted: #9aabbf; --line: #2a3a4e; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1.4em; }
a { color: var(--primary); }
input, textarea, button { font: inherit; color: inherit; }
input, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
input[type=number] { width: 80px; }
textarea { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
label { display: inline-flex; align-items: center; gap: 6px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.grow { flex: 1; }
.grow input { flex: 1; }
.pill { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--brand); }
.login-card { background: var(--panel); padding: 28px; border-radius: 16px; width: min(92vw, 340px); display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; }
.login-card label { display: grid; text-align: left; gap: 4px; }

.top { height: 56px; display: flex; align-items: center; gap: 18px; padding: 0 16px; background: var(--brand); color: #fff; }
.top .muted { color: #b8c4d4; }
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
nav button { background: transparent; border: 0; color: #c9d4e3; padding: 8px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; font-weight: 600; }
nav button.active { background: rgba(255,255,255,.14); color: #fff; }
.user { display: flex; gap: 10px; align-items: center; }
.user .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }

.tab.live { position: absolute; top: 56px; bottom: 0; left: 0; right: 0; display: flex; }
.side { width: 320px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 12px; }
#map { flex: 1; }
.counts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.count { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.count b { display: block; font-size: 22px; }
.live-item { border: 1px solid var(--line); border-left: 4px solid var(--idle); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; }
.live-item:hover { background: var(--bg); }
.live-item .name { font-weight: 700; }
.st-en-ruta { border-left-color: var(--ok) !important; } .st-fuera-de-ruta { border-left-color: var(--bad) !important; }
.st-sin-conexion { border-left-color: var(--warn) !important; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; color: #fff; background: var(--idle); white-space: nowrap; }
.badge.en-ruta { background: var(--ok); } .badge.fuera-de-ruta { background: var(--bad); } .badge.sin-conexion { background: var(--warn); } .badge.baja { background: #555; }

.page { max-width: 1200px; margin: 0 auto; padding: 18px 16px 40px; }
.page h2 { margin: 6px 0 4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 14px 0; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.warn-cell { color: var(--warn); font-weight: 700; }
.mini-map { height: 360px; border-radius: 10px; margin: 10px 0; border: 1px solid var(--line); }
.code-result { display: flex; gap: 20px; align-items: center; margin-top: 12px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.code-result .code { font-size: 34px; font-weight: 800; letter-spacing: .12em; font-family: ui-monospace, Menlo, monospace; }
.code-result svg { width: 140px; height: 140px; background: #fff; padding: 6px; border-radius: 8px; }
.stale { background: #fff4e5; color: #8a4b00; border: 1px solid #f3c98b; border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
@media (prefers-color-scheme: dark) { .stale { background: #3a2a10; color: #f6c97d; border-color: #6b4d1c; } }
.car-icon { width: 26px; height: 26px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111c; color: #fff; padding: 10px 16px; border-radius: 20px; opacity: 0; transition: .25s; pointer-events: none; z-index: 5000; }
#toast.show { opacity: 1; }
@media (max-width: 760px) {
  .tab.live { flex-direction: column-reverse; }
  .side { width: auto; height: 40%; border-right: 0; border-top: 1px solid var(--line); }
  .brand span, .user span { display: none; }
}
select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; max-width: 420px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; margin: 10px 0; }
.history { display: grid; gap: 12px; }
#history-table tr[data-v] { cursor: pointer; }
#history-table tr[data-v]:hover { background: var(--bg); }
.report-ok { color: var(--ok); font-weight: 700; } .report-warn { color: var(--warn); font-weight: 700; } .report-bad { color: var(--bad); font-weight: 700; }
.report ul { margin: 6px 0 10px; padding-left: 20px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.kv b { color: var(--muted); font-weight: 600; }
.badge.en-parada, .badge.buscando-la-ruta, .badge.sin-senal-gps { background: #6b7280; }
.st-en-parada, .st-buscando-la-ruta, .st-sin-senal-gps { border-left-color: #6b7280 !important; }
.nowrap { white-space: nowrap; }
