*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* ── Design system (Orqestra) ─────────────────────
   Layered near-black surfaces, hairline white-alpha
   borders, teal accent, Inter + JetBrains Mono.      */
:root {
  --bg:          #0C0E14;
  --surface:     #10131A;   /* panels, sidebar, cards   */
  --surface-2:   #141820;   /* inputs, hover            */
  --surface-3:   #1C2130;   /* raised chips, tracks     */
  --border:      rgba(255,255,255,.06);
  --border-2:    rgba(255,255,255,.10);
  --text:        #F0F4FF;
  --text-muted:  #A8B4CC;
  --text-dim:    #5A6880;
  --text-faint:  #2E3A50;
  --accent:      #00D4AA;   /* teal                     */
  --accent-hover:#19E0BA;
  --accent-bg:   rgba(0,212,170,.12);
  --accent-bg-2: rgba(0,212,170,.06);
  --accent-ink:  #0C0E14;   /* text on teal             */
  --danger:      #FF4466;
  --danger-bg:   rgba(255,68,102,.12);
  --amber:       #F0A020;
  --amber-bg:    rgba(240,160,32,.10);
  --blue:        #4488FF;
  --blue-bg:     rgba(68,136,255,.12);
  --success:     #00D4AA;
  --success-bg:  rgba(0,212,170,.10);
  --radius:      8px;
  --sidebar:     228px;
  --fn:          'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --fm:          'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 var(--fn);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Brand mark ───────────────────────────────── */
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #0090A0);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 16px rgba(0,212,170,.25);
  flex-shrink: 0;
}
.brand-mark svg { width: 14px; height: 14px; }

/* ── Login ────────────────────────────────────── */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.4px;
  margin-bottom: 28px;
}

/* ── App shell ────────────────────────────────── */
#app-view {
  display: flex;
  height: 100vh;
  /* Mobile browsers (e.g. Brave on Android/DeX) count URL-bar chrome into
     100vh, pushing the sidebar footer off-screen; dvh tracks what's visible. */
  height: 100dvh;
}

/* ── Sidebar navigation ───────────────────────── */
#sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  overflow: hidden;
  transition: width .18s ease, padding .18s ease;
}
#sidebar.collapsed {
  width: 62px;
  padding: 14px 10px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 16px;
}
#sidebar.collapsed .sidebar-head { justify-content: center; padding: 4px 0 16px; }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex-shrink: 0;
}
.topbar-brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  white-space: nowrap;
}

/* Rail collapse / expand buttons */
.rail-btn {
  width: 26px; height: 26px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border-2);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color .12s, background .12s;
}
.rail-btn:hover { color: var(--text); background: var(--surface-2); }
.rail-btn svg { width: 14px; height: 14px; }

/* Hide labels/text when collapsed */
#sidebar.collapsed .topbar-brand-name,
#sidebar.collapsed .nav-text,
#sidebar.collapsed .nav-label,
#sidebar.collapsed #sidebar-collapse,
#sidebar.collapsed .current-user { display: none; }

/* Nav */
.sidebar-nav {
  flex: 1;
  /* Allow shrinking below content height so the nav scrolls in short windows
     instead of pushing the user/logout row out of the clipped sidebar. */
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  margin: 0 -4px;
  padding: 0 4px;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-group { margin-top: 12px; }
.nav-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
  padding: 0 10px 6px;
  white-space: nowrap;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  margin-bottom: 1px;
  border-radius: 7px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: color .12s, background .12s;
}
#sidebar.collapsed .nav-link { justify-content: center; padding: 9px; }
.nav-link:hover  { color: var(--text); background: var(--surface-2); }
.nav-link.active {
  color: var(--text);
  background: var(--accent-bg);
}
.nav-link.active::before {
  content: '';
  position: absolute;
  left: -4px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
.nav-link svg        { flex-shrink: 0; opacity: .75; }
.nav-link.active svg { opacity: 1; color: var(--accent); }

/* User row (sidebar footer) */
.sidebar-user {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 9px;
}
#sidebar.collapsed .sidebar-user { justify-content: center; padding-top: 12px; }
#sidebar.collapsed .sidebar-user .btn-icon { display: none; }

.user-avatar {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #0090A0);
  color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  text-transform: uppercase;
}

.current-user {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}
.current-user-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.current-user-email {
  font-family: var(--fm);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main column ──────────────────────────────── */
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#topbar {
  height: 54px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.2px;
  color: var(--text);
}

/* ── Main content ─────────────────────────────── */
#page-content {
  flex: 1;
  overflow-y: auto;
  padding: 30px 32px;
  background: var(--bg);
}
#page-content::-webkit-scrollbar { width: 3px; }
#page-content::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

/* ── Home dashboard ───────────────────────────── */
/* On very wide screens, condense to 75% (centered) rather than
   stretching the full content width. */
.dash { margin-inline: auto; }
@media (min-width: 1500px) { .dash { width: 75%; max-width: 1700px; } }

.dash-greeting { margin-bottom: 24px; }
.dash-greeting-label {
  font-family: var(--fm);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .8px;
  margin-bottom: 6px;
}
.dash-greeting-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
}
.dash-greeting-text span { color: var(--accent); }

/* Hero: greeting beside the Network Health summary. */
.dash-hero {
  display: flex;
  gap: 12px;
  align-items: stretch;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.dash-hero .dash-greeting { flex: 1 1 260px; margin-bottom: 0; align-self: center; }

.dash-health {
  flex: 0 0 300px;
  align-self: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
@media (max-width: 880px) { .dash-health { flex-basis: 100%; } }

.hs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.hs-row:last-child { margin-bottom: 0; }
.hs-label { font-size: 12.5px; color: var(--text-muted); }
.hs-val {
  font-family: var(--fm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dash-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}
.dash-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px)  { .dash-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px)  { .dash-grid, .dash-grid-3 { grid-template-columns: 1fr; } }

.dash-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color .15s;
}
.dash-card:hover { border-color: var(--border-2); }
.dash-card.hi { border-color: rgba(0,212,170,.25); background: var(--accent-bg-2); }
.dash-card.ri { border-color: rgba(255,68,102,.25); background: var(--danger-bg); }
.dash-card.wa { border-color: rgba(240,160,32,.25); background: var(--amber-bg); }
.dash-card.bl { border-color: rgba(68,136,255,.25); background: var(--blue-bg); }

.dash-card-label {
  font-family: var(--fm);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 10px;
}
.dash-card.hi .dash-card-label { color: rgba(0,212,170,.6); }
.dash-card.ri .dash-card-label { color: rgba(255,68,102,.6); }
.dash-card.wa .dash-card-label { color: rgba(240,160,32,.6); }
.dash-card.bl .dash-card-label { color: rgba(68,136,255,.6); }

.dash-card-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -1.2px;
  line-height: 1;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}
.dash-card.hi .dash-card-value { color: var(--accent); }
.dash-card.ri .dash-card-value { color: var(--danger); }
.dash-card.wa .dash-card-value { color: var(--amber); }
.dash-card.bl .dash-card-value { color: var(--blue); }

.dash-card-sub {
  font-size: 12px;
  color: var(--text-dim);
  min-height: 15px;
}

/* Thin accent strip along the bottom of a card. */
.dash-card-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; }

.dash-section-title {
  font-family: var(--fm);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .9px;
  margin: 26px 0 12px;
}

.dash-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.dash-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
@media (max-width: 880px) { .dash-split { grid-template-columns: 1fr; } }

.dash-panel-title {
  font-family: var(--fm);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .9px;
  margin-bottom: 18px;
}

/* Full-width progress bars (orq .prog style). */
.dash-progs { display: flex; flex-direction: column; gap: 16px; }
.dash-prog-h { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 7px; }
.dash-prog-l { font-size: 13px; color: var(--text-muted); }
.dash-prog-v { font-family: var(--fm); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dash-prog-track { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.dash-prog-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }

.dash-bars { display: flex; flex-direction: column; gap: 12px; }
.dash-bars-empty { color: var(--text-dim); font-size: 13px; }

/* Recent activity feed (orq decision-log style). */
.dash-feed { display: flex; flex-direction: column; }
.feed-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.feed-item:first-child { padding-top: 0; }
.feed-item:last-child { border-bottom: none; padding-bottom: 0; }
.feed-item .badge { margin-top: 1px; flex-shrink: 0; }
.feed-main { min-width: 0; }
.feed-body { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.feed-ts { font-family: var(--fm); font-size: 10.5px; color: var(--text-dim); margin-top: 2px; }

.dash-bar-row {
  display: grid;
  grid-template-columns: 110px 1fr 52px;
  align-items: center;
  gap: 12px;
}
.dash-bar-label { font-size: 12.5px; color: var(--text-muted); }
.dash-bar-track { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; }
.dash-bar-fill { height: 100%; border-radius: 3px; transition: width .4s ease; }
.dash-bar-val {
  font-family: var(--fm);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Page header ──────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.page-title { font-size: 20px; font-weight: 700; letter-spacing: -.5px; }

/* ── Toolbar ──────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  /* Filter-heavy pages (trips) outgrow one line — controls flow onto more
     rows instead of overflowing or squeezing. */
  flex-wrap: wrap;
  row-gap: 8px;
}

/* ── Table ────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}

table { width: 100%; border-collapse: collapse; }

thead { background: var(--bg); }

th {
  padding: 10px 16px;
  text-align: left;
  font-family: var(--fm);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
}

tbody tr { background: transparent; transition: background .08s; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tr.row-clickable { cursor: pointer; }

.col-id { width: 56px; color: var(--text-dim); font-family: var(--fm); font-size: 12px; }
.col-cb { width: 40px; }

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--fn);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s, color .12s;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger  {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--border-2);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn-sm  { padding: 5px 11px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* Space stacked full-width buttons in the login card. */
#login-view .btn-full + .btn-full { margin-top: 10px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  background: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-dim);
  transition: background .12s, color .12s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ── Forms ────────────────────────────────────── */
.field { margin-bottom: 14px; }

.field:last-child { margin-bottom: 0; }

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input::placeholder { color: var(--text-dim); }
input:focus, select:focus {
  border-color: rgba(0,212,170,.35);
  box-shadow: 0 0 0 3px rgba(0,212,170,.06);
}
select option { background: var(--surface-2); }
input[type="checkbox"] { width: auto; accent-color: var(--accent); cursor: pointer; }

input[type="search"] {
  max-width: 280px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235A6880' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  padding-left: 32px;
}

/* ── Modal ────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(3px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  width: 460px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  max-height: calc(100dvh - 64px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 15px; font-weight: 600; }

.modal-body { padding: 20px; overflow-y: auto; }

/* Wide variant with a map pane beside the form */
.modal.modal-wide { width: 1400px; }
.modal-body-map { display: flex; gap: 18px; align-items: stretch; flex-wrap: wrap; }
.modal-body-map #modal-form { flex: 0 0 560px; min-width: 0; }

/* Full-width stops row beneath the form + map pair (moved there by
   setupFormMap for trips). Wide plans scroll inside the row, not the page. */
.trip-plan-row { flex: 1 1 100%; min-width: 0; }
.trip-plan-row .table-wrap { overflow-x: auto; }
.modal-map {
  flex: 1;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}
.modal-map .leaflet-container { width: 100%; height: 100%; background: var(--surface-2); }

/* Polygon editor */
.poly-vtx {
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  cursor: move;
}
.polygon-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.polygon-count { font-size: 12px; color: var(--text-dim); }
.polygon-help  { margin: 6px 0 0; font-size: 11px; color: var(--text-dim); line-height: 1.4; }
.btn.btn-sm { padding: 5px 11px; font-size: 12px; }

/* Text input with an inline action button (e.g. geocode "Search") */
.input-with-btn { display: flex; gap: 8px; align-items: stretch; }
.input-with-btn input { flex: 1; min-width: 0; }
.input-with-btn .btn { flex: 0 0 auto; white-space: nowrap; }

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

/* ── Badges ───────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-family: var(--fm);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-admin  { background: var(--blue-bg); color: var(--blue); }
.badge-viewer { background: var(--surface-3); color: var(--text-dim); }

.badge-status-new      { background: var(--blue-bg);   color: var(--blue); }
.badge-status-routed   { background: var(--amber-bg);  color: var(--amber); }
.badge-status-picked   { background: var(--amber-bg);  color: var(--amber); }
.badge-status-dropped  { background: rgba(68,136,255,.12); color: #76d3ea; }
.badge-status-noshow   { background: var(--danger-bg); color: var(--danger); }
.badge-status-done     { background: var(--accent-bg); color: var(--accent); }
.badge-status-inroute  { background: var(--amber-bg);  color: var(--amber); }
.badge-status-canceled { background: var(--surface-3); color: var(--text-dim); }

/* ── Toast ────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  max-width: 300px;
  backdrop-filter: blur(8px);
  animation: toast-in .18s ease;
}

.toast-success { background: var(--success-bg); border: 1px solid rgba(0,212,170,.3); color: var(--accent); }
.toast-error   { background: var(--danger-bg); border: 1px solid rgba(255,68,102,.3); color: var(--danger); }

@keyframes toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Misc ─────────────────────────────────────── */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 14px; }

.otp-hint { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.otp-hint span { color: var(--text); }

/* ── Tag input (attribute multi-select) ───────── */
.tag-input {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  padding: 4px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  cursor: text;
}

.tag-input:focus-within { border-color: rgba(0,212,170,.35); box-shadow: 0 0 0 3px rgba(0,212,170,.06); }

.passenger-filter { width: 200px; flex: 0 0 auto; }

/* Driver/vehicle toolbar comboboxes (client-side filtered — see setupListFilter). */
.list-filter { width: 180px; flex: 0 0 auto; }

/* Cross-record links: routed job → its trip, trip's job chips → reservations. */
.cell-link { color: var(--accent); text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.link-field { padding: 6px 0; font-size: 13px; }
.tag-chip-open { margin-left: 2px; font-size: 12px; }

.tag-chips { display: contents; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 10px;
  background: var(--surface-3);
  border-radius: 5px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.tag-chip-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.tag-chip-remove:hover { color: var(--danger); }

.tag-search {
  flex: 1;
  min-width: 80px;
  border: none !important;
  background: transparent !important;
  outline: none !important;
  box-shadow: none !important;
  padding: 2px 0 !important;
  font-size: 13px;
  color: var(--text);
  width: auto !important;
}

.tag-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  max-height: 200px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

.tag-option {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.tag-option:hover { background: var(--surface-2); }

/* ── Attribute chips (table cell) ─────────────── */
.attr-chip {
  display: inline-block;
  padding: 1px 7px;
  background: var(--surface-3);
  border-radius: 5px;
  font-size: 11px;
  color: var(--text-dim);
  margin: 1px 2px 1px 0;
}

/* ── Select-all bar ───────────────────────────── */
#select-all-bar {
  font-size: 12px;
  color: var(--text-dim);
  padding: 0 2px 10px;
}

#select-all-bar a {
  color: var(--accent);
  text-decoration: none;
}

#select-all-bar a:hover { text-decoration: underline; }

/* ── Search toolbar ───────────────────────────── */
.toolbar input[type="text"] {
  width: 240px;
}

.site-filter-select {
  width: auto;
  min-width: 140px;
}

/* Date-range filter inputs — narrower than the search box (whose 240px width
   the .toolbar input[type="text"] rule would otherwise impose). */
.toolbar input[type="text"].date-filter-input {
  width: 185px;
}

/* Date/time input with the 📅 picker tucked inside the input's right edge
   (like a native calendar icon), not as a separate framed button. `.dt-field`
   is the full-width form wrapper; `.date-filter` is the inline toolbar wrapper. */
.dt-field    { position: relative; }
.date-filter { position: relative; display: inline-flex; align-items: center; }

/* Leave room on the right so the value never sits under the icon. */
.dt-field input[type="text"],
.date-filter .date-filter-input { padding-right: 32px; }

/* The calendar button: no border/background of its own — just the icon,
   overlaid on the input's right edge and vertically centred. */
.dt-picker-btn {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: .6;
  transition: opacity .15s;
}
.dt-picker-btn:hover { opacity: 1; }

/* Small grey record-id suffix in an edit-modal title (non-jobs/trips modules). */
.modal-title-id {
  margin-left: 6px;
  font-size: .72em;
  font-weight: 400;
  color: var(--text-dim);
}

/* Read-only display field (e.g. record id shown in the form, never submitted). */
.readonly-field {
  color: var(--text-muted);
  background: var(--surface-3);
  cursor: default;
}

/* ── Location group (address + lat/lon, framed together) ── */
.geo-group {
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.geo-group .input-with-btn input,
.geo-coords input { background: var(--surface); }
.geo-coords { display: flex; gap: 6px; }
.geo-coords input { flex: 1; min-width: 0; font-size: 12px; }

/* ── Trip jobs editor (chips) + plan table ─────── */
.tj-editor { display: flex; flex-direction: column; gap: 10px; }
.tj-search { position: relative; }
.tj-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.attr-display { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--text-dim); }

/* Inline passenger quick-create (job form): framed like the location group. */
.passenger-quickcreate {
  margin-top: 6px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.passenger-quickcreate input { background: var(--surface); }
.pqc-actions { display: flex; gap: 8px; }
.tag-option-new { color: var(--accent); font-weight: 500; border-top: 1px solid var(--border); }
.tj-chips:empty { display: none; }
.tj-preview-empty { color: var(--text-dim); font-size: 12px; }

/* ⓘ hover details in the trip plan table. The bubble is a fixed-position
   singleton appended to <body> (see app.js) so table overflow can't clip it. */
.info-tip {
  cursor: help;
  color: var(--text-dim);
  font-size: 11px;
  margin-left: 3px;
  user-select: none;
}
.info-tip:hover { color: var(--accent); }
.info-tooltip {
  position: fixed;
  z-index: 100;
  max-width: 320px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-line;
  pointer-events: none;
}

.trip-plan table { font-size: 12px; }
.trip-plan th, .trip-plan td { padding: 6px 8px; white-space: nowrap; }
.trip-plan td:nth-child(2) { white-space: normal; }

/* Numbered stop marker on the trip route map. */
.trip-stop-marker {
  background: var(--accent, #1f6feb);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

/* The native date/time picker that backs the 📅 button: kept in the DOM and
   rendered (so showPicker() is allowed to open) but invisible. Not
   display:none — some browsers refuse showPicker() on an unrendered element.
   Parked under the icon so the popup opens beneath it; pointer-events:none so
   the click falls through to the button. */
.dt-picker-native {
  position: absolute;
  right: 5px;
  bottom: 0;
  width: 24px;
  height: 24px;
  opacity: 0;
  padding: 0;
  border: 0;
  margin: 0;
  pointer-events: none;
}

/* ── Sortable columns ─────────────────────────── */
th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover { color: var(--text-muted); }

th.sorted { color: var(--text); }

.sort-icon {
  font-size: 10px;
  opacity: .5;
  margin-left: 2px;
}

th.sorted .sort-icon { opacity: 1; color: var(--accent); }

/* ── Pagination ───────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.pagination-info {
  font-family: var(--fm);
  font-size: 11.5px;
  color: var(--text-dim);
}

.page-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.page-gap {
  font-size: 12px;
  color: var(--text-dim);
  padding: 0 2px;
}

/* ── Import page ──────────────────────────────── */
.import-intro {
  color: var(--text-muted);
  font-size: 13px;
  max-width: 760px;
  margin: 0 0 16px;
  line-height: 1.55;
}
.import-intro code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--fm);
  font-size: 12px;
}

.import-drop {
  border: 1.5px dashed var(--border-2);
  border-radius: 10px;
  background: var(--surface);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: border-color .15s, background .15s;
}
.import-drop:hover, .import-drop.dragover {
  border-color: var(--accent);
  background: var(--surface-2);
}
.import-drop-inner strong { color: var(--text); }

.import-panel { margin-top: 20px; }

.import-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.import-row label { font-size: 13px; color: var(--text-muted); }
.import-confidence { font-size: 12px; color: var(--text-dim); }
.import-reasoning {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 14px;
  line-height: 1.5;
}

.import-sample { color: var(--text-dim); font-size: 12.5px; }
.import-note   { color: var(--danger); font-size: 12px; }
.import-map { min-width: 160px; }

.import-actions { margin-top: 16px; }

.import-progress { padding: 24px 4px; }
/* Centered full-screen overlay shown while an import runs. */
.import-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(3px);
  z-index: 1000;
}
.import-overlay-card {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  padding: 28px 32px;
  width: min(440px, 90vw);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .6);
}
.import-progress-label { font-size: 13px; color: var(--text); margin-bottom: 10px; }
.progress-track {
  height: 8px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .2s ease;
}
.import-progress-count { margin-top: 8px; font-family: var(--fm); font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.import-summary {
  display: flex;
  gap: 18px;
  align-items: baseline;
  margin: 20px 0 12px;
  flex-wrap: wrap;
}
.import-stat { font-size: 13px; color: var(--text-dim); }
.import-stat strong { color: var(--text); font-family: var(--fm); font-size: 16px; margin-right: 4px; }
.import-stat.muted { color: var(--text-dim); }

.import-bad { background: var(--danger-bg); }

.import-skipped {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.import-skipped summary { cursor: pointer; color: var(--text); }
.import-skipped ul { margin: 8px 0 0; padding-left: 18px; }
.import-skipped li { margin: 2px 0; }

/* ── Analytics ────────────────────────────────── */
.analytics { display: flex; flex-direction: column; min-height: calc(100% - 8px); }

.analytics-feed { flex: 1; display: flex; flex-direction: column; gap: 16px; padding-bottom: 16px; }

.analytics-empty { color: var(--text-dim); margin-top: 4px; }
.analytics-empty p { margin-bottom: 12px; }
.analytics-examples { display: flex; flex-wrap: wrap; gap: 8px; }
.analytics-example {
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text);
  border-radius: 20px; padding: 6px 14px; font-size: 12.5px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.analytics-example:hover { background: var(--surface-3); border-color: rgba(0,212,170,.3); }

.analytics-msg { max-width: 900px; }
.analytics-user {
  align-self: flex-end; background: var(--accent); color: var(--accent-ink);
  font-weight: 500;
  padding: 9px 14px; border-radius: 14px 14px 4px 14px;
  white-space: pre-wrap; max-width: 75%;
}
.analytics-assistant { align-self: stretch; }

.analytics-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 18px;
}
.analytics-card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.analytics-explain { color: var(--text-dim); margin-bottom: 12px; }
.analytics-chart { position: relative; height: 340px; }
.analytics-map { height: 380px; border-radius: 8px; overflow: hidden; }
.analytics-map .leaflet-container { width: 100%; height: 100%; background: var(--surface-2); }
.analytics-popup-title { font-weight: 600; margin-bottom: 4px; }
.analytics-popup .k { color: var(--text-dim); margin-right: 4px; }
.analytics-output .table-wrap { overflow-x: auto; }
.analytics-note { color: var(--text-dim); font-size: 12px; margin-top: 8px; }
.analytics-error { color: var(--danger); }
.analytics-loading { color: var(--text-dim); display: flex; align-items: center; gap: 8px; }

.analytics-sql { margin-top: 12px; }
.analytics-sql summary { cursor: pointer; color: var(--text-dim); font-size: 12px; }
.analytics-sql pre {
  margin-top: 8px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; overflow-x: auto;
  font: 12px/1.5 var(--fm);
  white-space: pre-wrap; word-break: break-word;
}

.analytics-input {
  position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 0; background: var(--bg); border-top: 1px solid var(--border);
}
.analytics-input textarea {
  flex: 1; resize: none; max-height: 160px;
  background: var(--surface); border: 1px solid var(--border-2); color: var(--text);
  border-radius: var(--radius); padding: 10px 12px; font: inherit; font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}
.analytics-input textarea:focus { outline: none; border-color: rgba(0,212,170,.35); box-shadow: 0 0 0 3px rgba(0,212,170,.06); }

.spinner {
  width: 14px; height: 14px; display: inline-block;
  border: 2px solid var(--surface-3); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
