:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #6b7785;
  --line: #e2e7ec;
  --brand: #13294b;
  --accent: #1f6feb;
  --moving: #1a9e5c;
  --idle: #e0a100;
  --parked: #3b6ea8;
  --offline: #9aa4ae;
  --danger: #c0392b;
  --radius: 10px;
  --topbar: 52px;
  --footer: 30px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; }
body > main { flex: 1 0 auto; }
.topbar, .powered { flex: none; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  height: var(--topbar);
  display: flex; align-items: center; gap: 24px;
  padding: 0 16px;
  background: var(--brand); color: #fff;
}
.brand { color: #fff; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { color: #c9d4e3; padding: 6px 10px; border-radius: 6px; font-size: 14px; }
.topbar nav a.on, .topbar nav a:hover { color: #fff; background: rgba(255,255,255,.12); }
.who { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; color: #c9d4e3; white-space: nowrap; }
.who a { color: #c9d4e3; padding: 6px 8px; border-radius: 6px; }
.who a:hover, .who a.on { color: #fff; background: rgba(255,255,255,.12); }
.who form { margin: 0; }
button.link { background: none; border: 0; color: #fff; cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* ---------------------------------------------------------------- forms */
button, input, select { font: inherit; }
button:not(.link):not(.step) {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600;
}
input, select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--ink);
}

/* ---------------------------------------------------------------- login */
.login { display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 360px;
        box-shadow: 0 6px 24px rgba(19,41,75,.08); display: grid; gap: 14px; }
.card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.card input { width: 100%; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

/* ---------------------------------------------------------------- map layouts */
body > main.live, body > main.history { flex: 1 1 0; min-height: 0; }
.live, .history { display: grid; grid-template-columns: 340px 1fr; }
.map { height: 100%; min-height: 300px; }
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.panel-head { padding: 16px; border-bottom: 1px solid var(--line); display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; }
.updated, .reg { font-size: 12px; color: var(--muted); margin-left: auto; }
.back { font-size: 13px; width: 100%; }

.vehicles { list-style: none; margin: 0; padding: 0; flex: 1; }
.vehicles li { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid;
               grid-template-columns: 14px 1fr auto; gap: 4px 10px; align-items: center; }
.vehicles li:hover, .vehicles li.sel { background: #f0f5fc; }
.vehicles .name { font-weight: 600; }
.vehicles .sub { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }
.vehicles .speed { font-size: 13px; font-variant-numeric: tabular-nums; }
.vehicles .hist { font-size: 12px; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--offline); }
.dot.moving { background: var(--moving); }
.dot.idle { background: var(--idle); }
.dot.parked { background: var(--parked); }
.dot.offline, .dot.no-device { background: var(--offline); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; padding: 12px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.legend .dot { margin-right: 4px; vertical-align: -1px; }

/* vehicle marker: arrow rotated to heading */
.vmark { width: 30px; height: 30px; display: grid; place-items: center; }
.vmark svg { width: 30px; height: 30px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); }
.vmark .lbl { position: absolute; top: 30px; left: 50%; transform: translateX(-50%); white-space: nowrap;
              background: #fff; border-radius: 4px; padding: 1px 5px; font-size: 11px; font-weight: 600;
              box-shadow: 0 1px 3px rgba(0,0,0,.25); }

/* ---------------------------------------------------------------- history */
.daypick { display: flex; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.daypick input { flex: 1; }
.step { background: #fff; border: 1px solid var(--line); border-radius: 8px; width: 38px; cursor: pointer; font-size: 18px; color: var(--ink); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.history h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 16px 8px; }
.trips { list-style: none; margin: 0; padding: 0 0 16px; }
.trips li { padding: 10px 16px; border-top: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.trips li:hover, .trips li.sel { background: #f0f5fc; }
.trips .t { font-weight: 600; font-variant-numeric: tabular-nums; }
.trips .d { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- admin */
.admin { padding: 24px 16px; max-width: 1100px; margin: 0 auto; }
.admin h1 { font-size: 22px; margin-bottom: 8px; }
.admin > p { max-width: 70ch; }
.flash { background: #e8f5ee; color: #155d36; padding: 10px 14px; border-radius: 8px; }
.table-wrap { overflow-x: auto; background: var(--panel); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(19,41,75,.06); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
tr.unassigned td:first-child { box-shadow: inset 3px 0 var(--idle); }
.assign { display: flex; gap: 6px; }
.assign select { min-width: 200px; }

/* ---------------------------------------------------------------- footer */
.powered { height: var(--footer); display: flex; align-items: center; justify-content: center; gap: .3em;
           font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); }
.powered a { color: var(--ink); font-weight: 600; }

/* ---------------------------------------------------------------- admin: clients */
.admin.narrow { max-width: 560px; }
.admin h2 { font-size: 16px; margin-bottom: 12px; }
.flash.bad { background: #fdecea; color: #8a1f15; }
.small { font-size: 13px; }
.sections { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.box { background: var(--panel); border-radius: var(--radius); padding: 20px; box-shadow: 0 2px 10px rgba(19,41,75,.06); min-width: 0; }
.box.wide { grid-column: 1 / -1; }
.stack { display: grid; gap: 12px; }
.stack label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.stack label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--ink); }
.stack label.check input { margin-top: 3px; }
.stack button { justify-self: start; }
textarea { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
input[type=color] { width: 64px; height: 38px; padding: 2px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.inline-form input:not([size]) { flex: 1; min-width: 160px; }
.table-wrap.flat { box-shadow: none; border: 1px solid var(--line); }
.preview { color: #fff; font-weight: 700; padding: 12px 16px; border-radius: 8px; margin-bottom: 14px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
ul.plain .right { margin: 0 0 0 auto; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef1f4; color: var(--muted); white-space: nowrap; }
.pill.ok { background: #e8f5ee; color: #155d36; }
.pill.wait { background: #fff6dc; color: #7a5a00; }
.pill.bad { background: #fdecea; color: #8a1f15; }
button.link { color: var(--accent); }
.topbar button.link { color: #fff; }
button.link.danger { color: var(--danger); }
td.actions { display: flex; gap: 14px; }
td.actions form { margin: 0; }
tr.off td { color: var(--muted); }
.tempkey { background: #fff6dc; border: 1px solid #f0d98a; border-radius: var(--radius); padding: 16px; display: grid; gap: 8px; margin: 12px 0; }
.tempkey code.big { font-size: 1.25em; font-weight: 700; letter-spacing: .04em; }

/* ---------------------------------------------------------------- phones */
@media (max-width: 760px) {
  .topbar { gap: 12px; }
  .who .org { display: none; }
  .topbar { height: auto; min-height: var(--topbar); flex-wrap: wrap; padding: 8px 10px; row-gap: 4px; }
  .topbar nav { order: 3; width: 100%; }
  .topbar nav:has(a:only-child) { display: none; }
  .who a { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
  .brand { font-size: 15px; }
  .sections { grid-template-columns: 1fr; }
  .live, .history { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  .map { grid-row: 1; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); }
}
