:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f9fafb; --text: #111827; --muted: #6b7280;
  --line: #e5e7eb; --accent: #2563eb; --accent-2: #dbeafe; --danger: #dc2626; --ok: #16a34a;
  --warn: #d97706; --stop: #2563eb; --off: #9ca3af; --shadow: 0 4px 18px rgba(0,0,0,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a21; --panel-2: #1d212a; --text: #e5e7eb; --muted: #9ca3af;
    --line: #2a2f3a; --accent: #3b82f6; --accent-2: #1e3a8a55; --shadow: 0 4px 18px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --panel: #171a21; --panel-2: #1d212a; --text: #e5e7eb; --muted: #9ca3af;
  --line: #2a2f3a; --accent: #3b82f6; --accent-2: #1e3a8a55; --shadow: 0 4px 18px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; }
a { color: var(--accent); cursor: pointer; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }

/* przyciski i pola */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px;
  padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { color: var(--text); width: 100%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { align-items: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.chk { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.login-box { background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 12px; }

/* nagłówek */
.top { height: 52px; display: flex; align-items: center; gap: 18px; padding: 0 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand svg { width: 22px; height: 22px; fill: var(--accent); }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 8px; }
nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
nav a { padding: 7px 11px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
nav a:hover { background: var(--panel-2); color: var(--text); }
nav a.active { background: var(--accent-2); color: var(--accent); font-weight: 600; }
.top-right { display: flex; align-items: center; gap: 10px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 3px #16a34a33; }

#app { height: 100%; display: flex; flex-direction: column; }
main { flex: 1; min-height: 0; }
.map-layout { display: flex; height: 100%; }
.side { width: 340px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto;
  display: flex; flex-direction: column; }
.side-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0; background: var(--panel); z-index: 2; }
.map-wrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }
.page { height: 100%; overflow: auto; padding: 18px; }
.page-inner { max-width: 1400px; margin: 0 auto; }

/* lista pojazdów */
.counts { display: flex; gap: 6px; flex-wrap: wrap; }
.count { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); cursor: pointer; }
.count.sel { border-color: var(--accent); color: var(--accent); }
.vlist { flex: 1; }
.vitem { display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 10px; padding: 9px 12px; border-bottom: 1px solid var(--line);
  cursor: pointer; align-items: center; }
.vitem:hover { background: var(--panel-2); }
.vitem.sel { background: var(--accent-2); }
.vitem .plate { font-weight: 600; }
.vitem .sub { grid-column: 2 / 4; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vitem .spd { font-variant-numeric: tabular-nums; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.st-moving { background: var(--ok); } .st-idle { background: var(--warn); } .st-stopped { background: var(--stop); }
.st-offline { background: var(--off); } .st-none { background: transparent; border: 1px dashed var(--off); }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: #16a34a55; } .badge.bad { color: var(--danger); border-color: #dc262655; }
.badge.warn { color: var(--warn); border-color: #d9770655; }

/* marker */
.vmarker { position: relative; }
.vmarker .arrow { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.vmarker .arrow svg { width: 14px; height: 14px; fill: #fff; }
.vmarker .lbl { position: absolute; left: 30px; top: 3px; background: var(--panel); color: var(--text); font-size: 11px; font-weight: 600;
  padding: 1px 5px; border-radius: 5px; box-shadow: 0 1px 3px rgba(0,0,0,.3); white-space: nowrap; }
.stop-marker { background: #2563eb; color: #fff; border-radius: 50%; width: 20px; height: 20px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.flag-marker { color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 700; border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.4); white-space: nowrap; }

/* panel szczegółów */
.detail { position: absolute; right: 12px; top: 12px; width: 330px; max-height: calc(100% - 24px); overflow: auto; z-index: 500;
  background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.detail-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.detail-head .plate { font-size: 18px; font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; padding: 12px 14px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.big-speed { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 14px; }
.x { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }

/* historia */
.sumgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.trip { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.trip:hover { background: var(--panel-2); }
.trip.sel { background: var(--accent-2); }
.trip .t1 { display: flex; justify-content: space-between; font-weight: 600; }
.trip.stop-row { color: var(--muted); background: var(--panel-2); font-size: 12px; }
.playback { position: absolute; left: 12px; right: 12px; bottom: 16px; z-index: 500; background: var(--panel); border-radius: 12px;
  box-shadow: var(--shadow); border: 1px solid var(--line); padding: 10px 14px; display: flex; gap: 12px; align-items: center; }
.playback input[type=range] { flex: 1; padding: 0; }
.playback .info { font-variant-numeric: tabular-nums; font-size: 13px; min-width: 260px; text-align: right; }
.legend { display: flex; gap: 8px; font-size: 11px; color: var(--muted); padding: 0 12px 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 3px; }

/* tabele */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: var(--panel-2); position: sticky; top: 0; font-weight: 600; color: var(--muted); z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--panel-2); }
tfoot td { font-weight: 700; background: var(--panel-2); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.wrap { white-space: normal; word-break: break-all; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding: 8px 0 0; }
.bars div { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; position: relative; min-width: 6px; }
.bars div span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.bars-lbl { display: flex; gap: 4px; font-size: 11px; color: var(--muted); }
.bars-lbl span { flex: 1; text-align: center; min-width: 6px; overflow: hidden; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs .btn.sel { background: var(--accent-2); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* modal / toasty */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 2000; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 14px; padding: 20px; width: min(620px, 100%); max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 3000; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 10px;
  padding: 9px 12px; box-shadow: var(--shadow); max-width: 340px; font-size: 13px; cursor: pointer; }
.toast.bad { border-left-color: var(--danger); } .toast.warn { border-left-color: var(--warn); } .toast.ok { border-left-color: var(--ok); }
.ev-icon { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.help { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 13px; }
.help code { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.leaflet-container { background: var(--bg); font: inherit; }

@media (max-width: 860px) {
  .top { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  nav { order: 3; width: 100%; flex-basis: 100%; }
  .map-layout { flex-direction: column-reverse; }
  .side { width: 100%; height: 42%; border-right: 0; border-top: 1px solid var(--line); }
  .detail { left: 8px; right: 8px; width: auto; top: 8px; max-height: 60%; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .page { padding: 12px 16px; }
  .playback { flex-wrap: wrap; } .playback .info { min-width: 0; text-align: left; }
}
