:root {
  --bg: #0d1410;
  --surface: #141e17;
  --surface-2: #1c2920;
  --border: #2a3d2f;
  --text-1: #e8f0e4;
  --text-2: #9ab89a;
  --text-3: #5a7a5e;
  --accent: #34d064;
  --danger: #e5484d;
}
html[data-theme="light"] {
  --bg: #f4f7f2;
  --surface: #ffffff;
  --surface-2: #e9f1e7;
  --border: #d3e0d1;
  --text-1: #142114;
  --text-2: #3c5a3e;
  --text-3: #7a967c;
  --accent: #1d9e48;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-1);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.layout { display: flex; height: 100vh; }
.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
  overflow-y: auto;
  transition: margin-left .2s ease;
}
.sidebar.collapsed { margin-left: -264px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; border-bottom: 1px solid var(--border); }
.logo {
  background: var(--accent);
  color: #08130b;
  font-weight: 800;
  border-radius: 8px;
  padding: 4px 8px;
}
.brand-name { font-weight: 700; flex: 1; }
.collapse-btn { background: none; border: none; color: var(--text-2); font-size: 20px; cursor: pointer; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 600;
}
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: var(--surface-2); color: var(--text-1); }
.nav-item.active { background: var(--surface-2); color: var(--accent); border: 1px solid var(--border); }
.nav-start { color: var(--text-1); }
.staff { margin-top: 8px; }
.staff-label, .footer-label { color: var(--text-3); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 0 12px; }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.theme-toggle { display: flex; gap: 8px; padding: 0 8px; }
.theme-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  font-weight: 700;
}
.theme-btn.active { color: var(--accent); border-color: var(--accent); }
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 700;
}
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); display: inline-block; }
.logout { color: var(--danger); text-decoration: none; padding: 0 12px; }
.legal { color: var(--text-2); text-decoration: none; padding: 0 12px; font-size: 13px; }
.map-wrap { position: relative; flex: 1;  }
#map { width: 100%; height: 100%;   overflow: hidden; }
.layer-toggles {
  position: absolute;
  top: 22px;
  left: 22px;
  background: rgba(13, 20, 16, .9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-1);
  z-index: 10;
}
html[data-theme="light"] .layer-toggles { background: rgba(255, 255, 255, .92); }
.layer-toggles input { accent-color: #2563eb; }
.maplibregl-ctrl-attrib { font-size: 11px; }
/* Bustimes-style popup card, themed via vars. */
.bus-popup-card .maplibregl-popup-content {
  background: var(--surface) !important;
  color: var(--text-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 180px;
  max-width: 250px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
.bus-popup-card .maplibregl-popup-tip { border-top-color: var(--surface) !important; }
.bus-popup-card.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--surface) !important; }
.bus-popup-card.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--surface) !important; }
.bus-popup-card.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--surface) !important; }
.bus-popup-card.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--surface) !important; }
.bus-popup-card .maplibregl-popup-close-button {
  color: var(--text-2) !important;
  font-size: 16px;
  line-height: 1;
  padding: 6px 8px;
}
.bus-popup-card .maplibregl-popup-close-button:hover { color: var(--text-1) !important; }
.bus-popup .bus-row { margin: 1px 0; }
.bus-popup .bus-title { font-weight: 400; padding-right: 20px; }
.bus-popup a.bus-vehicle { color: var(--accent); text-decoration: none; font-weight: 600; }
.bus-popup a.bus-vehicle:hover { text-decoration: underline; }
.bus-popup .ridden {
  display: inline-block;
  margin-top: 6px;
  padding: 1px 10px;
  border-radius: 999px;
  background: rgba(52, 208, 100, .16);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.bus-popup .bus-log-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--accent);
  color: #08130b;
  font-weight: 800;
  font-size: 13px;
  text-align: center;
  text-decoration: none;
}
.bus-popup .bus-log-btn:hover { filter: brightness(1.08); }
/* Live bus markers, same pattern as bustimes.org: a rotated wrapper holds
   the livery-coloured service pill plus a direction arrow. */
.bus-marker {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.vehicle-marker {
  border: 1px solid var(--surface);
  text-align: center;
  color: #000;
  fill: currentColor;
  text-anchor: middle;
  paint-order: stroke;
  stroke-width: 2px;
  background: #fff;
  width: 26px;
  height: 18px;
  margin: 1px;
  line-height: 16px;
  display: block;
  overflow: hidden;
}
svg.vehicle-marker {
  padding: 0;
}
.bus-marker .arrow,
.bus-arrow {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid #fff;
  margin-left: -1px;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, .6));
  background: #000;
  border-left-color: #fff;
}
.bus-popup { font: 13px/1.4 system-ui, sans-serif; }
/* Live train markers: a delay-coloured chevron pill holding the headcode,
   rotated to the direction of travel (matches Signalbox map style). */
.train-marker {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.train-pill {
  color: #111;
  font: 700 11px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: 3.5px 5px;
  white-space: nowrap;
}
.train-arrow {
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 7px solid #9ca3af;
  margin-left: 0;
}
