:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #16202b;
  --muted: #5b6875;
  --line: #d9e0e6;
  --brand: #0f5c63;
  --brand-ink: #ffffff;
  --accent: #d98a1c;
  --ok: #1f7a45;
  --warn: #9a6400;
  --bad: #b3261e;
  --moving: #1f7a45;
  --stationary: #2f6fb3;
  --offline: #8a949e;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b;
    --surface: #181f26;
    --surface-2: #1f2830;
    --ink: #e6ebef;
    --muted: #9aa6b1;
    --line: #2c3742;
    --brand: #4fb3ba;
    --brand-ink: #0b1a1c;
    --accent: #f0a93b;
    --ok: #57c285;
    --warn: #e2b04a;
    --bad: #ef7a72;
    --moving: #57c285;
    --stationary: #6aa8ec;
    --offline: #7b8793;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brand); }
code, pre { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: 13px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
h1 { font-size: 26px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 6px; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1em; margin: 8px 0; }
.ok { color: var(--ok); min-height: 1em; margin: 8px 0; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent); align-self: center;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .2px; white-space: nowrap; }
.brand-sub { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 14px 0 0; padding: 8px 12px 12px; }
legend { font-weight: 600; font-size: 13px; padding: 0 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
.check input { width: auto; }
.check.spaced { margin-top: 34px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-inline { display: flex; gap: 8px; flex-wrap: wrap; }

.login { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}
.card.subtle { background: var(--surface-2); }
.card summary { cursor: pointer; font-weight: 600; }

.tabs {
  display: flex; gap: 2px; padding: 0 16px; background: var(--surface);
  border-bottom: 1px solid var(--line); overflow-x: auto;
}
.tab {
  font: inherit; background: none; border: 0; border-bottom: 3px solid transparent;
  padding: 12px 14px; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.banner {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
}
.panel { padding: 16px 20px 32px; flex: 1; }

.split { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.map-wrap { position: sticky; top: 12px; }
.map { height: 560px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-2); }
.small-map { height: 240px; }
.list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.list-head h2 { margin: 0; }
.list-head select { width: auto; }
.empty { padding: 18px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat b { display: block; font-size: 24px; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 13px; }

.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: grid; gap: 6px;
}
.item.clickable { cursor: pointer; }
.item.clickable:hover, .item.selected { border-color: var(--brand); }
.item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.badge.moving { color: var(--moving); border-color: var(--moving); }
.badge.stationary { color: var(--stationary); border-color: var(--stationary); }
.badge.no_recent_position { color: var(--warn); border-color: var(--warn); }
.badge.offline, .badge.never_seen, .badge.cancelled, .badge.revoked, .badge.expired, .badge.inactive { color: var(--offline); border-color: var(--offline); }
.badge.active, .badge.arrived, .badge.valid { color: var(--ok); border-color: var(--ok); }

.bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.steps { padding-left: 20px; margin: 0 0 8px; }
.steps li { margin: 4px 0; }
.secret, .code {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0;
}
.reveal { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; }

.foot { padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface); }

.leaflet-container { font: inherit; }
.pin-label { font-weight: 600; }

label.inline { display: inline; margin: 0 6px 0 0; }
.track-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 10px; }
.track-bar select { width: auto; }
.track-info { display: grid; gap: 4px; margin-bottom: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); font-size: 13px; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 2px solid var(--offline); margin-left: 6px; }
.legend .dot.start { background: #ffffff; margin-left: 0; }
.legend .dot.end { background: var(--moving); border-color: var(--moving); }
.legend .line { width: 18px; height: 4px; border-radius: 2px; background: var(--moving); display: inline-block; margin-left: 6px; }

@media (max-width: 600px) {
  .tabs { flex-wrap: wrap; overflow-x: visible; padding: 0 8px; }
  .tab { padding: 10px 10px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--line); padding: 6px 0; }
  .table td { border: 0; padding: 2px 12px; overflow-wrap: anywhere; }
  .table td::before { content: attr(data-label) ": "; color: var(--muted); font-weight: 600; }
}

.pager { margin-top: 10px; }
.panel.loading form, .panel.loading .list, .panel.loading .table-wrap { opacity: .45; pointer-events: none; }
.panel.loading::before { content: "Loading..."; display: block; margin-bottom: 10px; color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .trips-split > :last-child { order: -1; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .map-wrap { position: static; }
  .map { height: 380px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { padding: 12px 16px 24px; }
  .topbar { padding: 10px 16px; }
  .banner { margin: 12px 16px 0; }
}
@media (max-width: 420px) {
  .row { grid-template-columns: minmax(0, 1fr); }
  .check.spaced { margin-top: 8px; }
}
