:root {
  /* SparkLMS blue family. */
  --bg: #f6f9fe;
  --card: #ffffff;
  --ink: #0b2545;
  --muted: #4a5565;
  --line: #dbe9f2;
  --brand: #005acd;
  --brand-ink: #ffffff;
  --brand-soft: #dce8ff;
  --accent: #0093cb;
  --danger: #c81e1e;
  --ok: #12a566;
  --radius: 14px;
  color-scheme: light dark;
}
/* Pure dark: black and neutral greys; blue only as the accent. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #121212;
    --ink: #f2f2f2;
    --muted: #a3a3a3;
    --line: #2c2c2c;
    --brand: #5b9dff;
    --brand-ink: #000000;
    --brand-soft: #1f1f1f;
    --accent: #4cc3f0;
    --danger: #ff6b6b;
    --ok: #1fc985;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: 0.95rem; margin: 20px 0 6px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; }

.top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--card);
  position: sticky; top: 0; z-index: 2;
}
.logo { width: 34px; height: 34px; }
.brand { font-weight: 700; font-size: 1.1rem; flex: 1; }
.brand span { font-weight: 500; color: var(--muted); margin-left: 6px; font-size: 0.95rem; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }
#app { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { #app { grid-template-columns: 1fr; } }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 20px;
}
.narrow { max-width: 420px; margin: 60px auto; }
.detail .card:first-child { margin-top: 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

button {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 9px 14px;
  background: var(--brand); color: var(--brand-ink); cursor: pointer;
}
button:hover { opacity: 0.9; }
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.small { padding: 6px 10px; font-size: 0.9rem; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select {
  font: inherit; width: 100%; padding: 9px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
label { display: block; font-size: 0.85rem; color: var(--muted); }
label input, label select { margin-top: 4px; color: var(--ink); }
.stack > * { margin-top: 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 14px 0; }
.form-actions { display: flex; gap: 8px; align-items: end; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.inline input { flex: 1 1 180px; width: auto; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list li { border-radius: 10px; }
.list button.item {
  width: 100%; text-align: left; background: transparent; color: var(--ink);
  padding: 10px; border-radius: 10px; font-weight: 500;
}
.list button.item[aria-current="true"] { background: var(--brand-soft); color: var(--ink); box-shadow: inset 3px 0 0 var(--brand); }
.list .sub { display: block; font-size: 0.82rem; color: var(--muted); }
#deviceList li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented button { background: transparent; color: var(--ink); font-weight: 600; }
.segmented button[aria-checked="true"] { background: var(--brand); color: var(--brand-ink); }

.code-out {
  margin-top: 12px; padding: 14px; border-radius: 12px;
  border: 1px dashed var(--brand); background: var(--brand-soft);
}
.code-out .big { font: 700 1.8rem/1.2 ui-monospace, Menlo, monospace; letter-spacing: 0.12em; }
.code-out .key { font: 600 0.95rem ui-monospace, Menlo, monospace; word-break: break-all; }

.table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.table th { text-align: left; font-size: 0.8rem; color: var(--muted); font-weight: 600; padding: 6px 8px; }
.table td { padding: 10px 8px; border-top: 1px solid var(--line); vertical-align: top; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions button { margin-left: 6px; }
@media (max-width: 640px) {
  .table thead { display: none; }
  .table tr { display: block; padding: 8px 0; border-top: 1px solid var(--line); }
  .table td { display: block; border: 0; padding: 2px 0; }
  .table td.actions { text-align: left; margin-top: 6px; }
  .table td.actions button { margin: 0 6px 0 0; }
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 10px;
}

.school-switch { width: auto; max-width: 260px; }
.kv { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 12px; }
.big-code { font: 700 1.4rem ui-monospace, Menlo, monospace; letter-spacing: 0.12em; }

/* Drivers, readers, riders */
.drivers-head { margin-top: 22px; }
.driver-row, .device-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.driver-row .sub, .device-row .sub { display: block; font-size: 0.82rem; color: var(--muted); }
/* The sidebar is narrow: driver name on top, its buttons on one line below. */
.driver-row { flex-direction: column; align-items: stretch; }
.driver-row .actions { flex-wrap: nowrap; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--brand-soft); color: var(--ink); }
.pill.on_board { background: color-mix(in srgb, var(--ok) 22%, transparent); }
.pill.got_off { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* The hidden attribute always wins over display rules. */
[hidden] { display: none !important; }

/* Live map */
.map { height: 420px; border-radius: 12px; border: 1px solid var(--line); margin: 12px 0 4px; overflow: hidden; }
@media (max-width: 640px) { .map { height: 300px; } }
.follow { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 0.9rem; }
.follow input { width: auto; margin: 0; }
.bus-puck { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); border: 3px solid #fff;
  box-shadow: 0 2px 8px #0005; display: grid; place-items: center; }
.bus-puck svg { width: 14px; height: 14px; }
.stop-dot { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.stop-dot.school { border-color: var(--brand); width: 18px; height: 18px; }
@media (prefers-color-scheme: dark) {
  /* Dark tiles from the standard map: neutral, no blue tint. */
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9) saturate(0.6); }
  .leaflet-container { background: #000; }
  .leaflet-control-attribution { background: #121212cc !important; color: #a3a3a3; }
  .leaflet-control-attribution a { color: #a3a3a3; }
}
