:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #f59e0b;
  --bad: #dc2626;
  --panel-w: 360px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
#map { position: absolute; inset: 0 0 0 var(--panel-w); }
button, select, input { font: inherit; }
button {
  border: 1px solid var(--line); background: #f8fafc; border-radius: 8px;
  padding: 6px 10px; cursor: pointer; color: var(--text);
}
button:hover { background: #eef2f7; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
input[type=text], input[type=password], select {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; width: 100%; background: #fff;
}
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.row input { flex: 1; }
.file-btn {
  display: inline-block; margin: 0; border: 1px solid var(--line); background: #f8fafc;
  border-radius: 8px; padding: 6px 10px; cursor: pointer; color: var(--text); font-size: 16px;
}
h4 { margin: 16px 0 6px; }

/* panel */
.panel {
  position: absolute; left: 0; top: 0; bottom: 0; width: var(--panel-w);
  background: var(--panel); z-index: 1000; display: flex; flex-direction: column;
  box-shadow: 2px 0 12px rgba(0,0,0,.15);
}
.grip { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; border: 0; border-radius: 0; background: none; padding: 12px 6px;
  border-bottom: 2px solid transparent; color: var(--muted);
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.badge { background: var(--line); border-radius: 10px; padding: 0 7px; font-size: 12px; }
.tab { display: none; padding: 8px 12px 24px; overflow-y: auto; flex: 1; }
.tab.active { display: block; }
body:not(.admin) .admin-only { display: none !important; }

/* rider list */
.list { list-style: none; padding: 0; margin: 0; }
.rider {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 8px; border-radius: 10px; cursor: pointer;
}
.rider:hover { background: #f1f5f9; }
.rider.selected { background: #e0ecff; }
.rider .dot {
  width: 34px; height: 34px; border-radius: 50%; color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; grid-row: span 2; background-size: cover; background-position: center;
}
.rider .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rider .meta { font-size: 12px; color: var(--muted); grid-column: 2 / 4; }
.rider .metrics { font-size: 13px; grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.rider .status { font-size: 12px; white-space: nowrap; }
.rider .actions { grid-column: 3; display: flex; gap: 4px; }
.rider .actions button { padding: 2px 6px; font-size: 12px; }
.st-live { color: var(--ok); }
.st-stale { color: var(--warn); }
.st-off { color: var(--muted); }
.st-bad { color: var(--bad); }

.route-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; }
.route-item .swatch { width: 14px; height: 4px; border-radius: 2px; }
.route-item .info { flex: 1; min-width: 0; }
.route-item .info div:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-item button { padding: 2px 6px; font-size: 12px; }

.stats { display: flex; gap: 14px; font-size: 14px; margin: 6px 0; flex-wrap: wrap; }
.stats b { font-size: 18px; }
.elev { width: 100%; height: 110px; background: #f8fafc; border-radius: 8px; touch-action: none; }

/* map overlays */
.fab-col { position: absolute; right: 10px; bottom: 30px; z-index: 900; display: flex; flex-direction: column; gap: 8px; }
.fab {
  width: 44px; height: 44px; border-radius: 50%; background: #fff; border: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); font-size: 20px; padding: 0;
}
.conn, .route-hint {
  position: absolute; top: 10px; left: calc(var(--panel-w) + 60px); right: 60px; z-index: 900;
  background: #fef3c7; border-radius: 8px; padding: 8px 12px; font-size: 14px; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.route-hint { background: #dbeafe; }

/* rider marker */
.rider-icon { background: none; border: 0; }
.rider-pin {
  position: relative; width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff;
  color: #fff; font-weight: 700; font-size: 12px; display: grid; place-items: center;
  box-shadow: 0 1px 6px rgba(0,0,0,.45); background-size: cover; background-position: center;
}
.rider-pin.stale { opacity: .55; filter: grayscale(.6); }
.rider-pin .lbl {
  position: absolute; top: 34px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: rgba(255,255,255,.92); color: #0f172a; font-size: 11px; font-weight: 600;
  padding: 1px 5px; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
body.no-labels .rider-pin .lbl { display: none; }
.wp-icon { background: #fff; border: 3px solid #2563eb; border-radius: 50%; }
.wp-icon.first { border-color: #16a34a; }
.wp-icon.last { border-color: #dc2626; }

/* mobile: bottom sheet */
@media (max-width: 760px) {
  :root { --sheet-h: 42vh; }
  #map { inset: 0 0 var(--sheet-h) 0; }
  body.sheet-min #map { bottom: 64px; }
  .panel {
    top: auto; width: 100%; height: var(--sheet-h); border-radius: 14px 14px 0 0;
    box-shadow: 0 -2px 12px rgba(0,0,0,.2); padding-bottom: env(safe-area-inset-bottom);
  }
  body.sheet-min .panel { height: 64px; }
  .grip { display: block; height: 18px; cursor: pointer; }
  .grip::after { content: ""; display: block; width: 44px; height: 5px; border-radius: 3px; background: #cbd5e1; margin: 7px auto 0; }
  .fab-col { bottom: calc(var(--sheet-h) + 14px); }
  body.sheet-min .fab-col { bottom: 80px; }
  .conn, .route-hint { left: 10px; right: 60px; }
}
