:root {
  --sidebar-width: 380px;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c1c1c;
  --muted: #6b7280;
  --border: #e4e6ea;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}

#app { position: relative; height: 100vh; width: 100%; overflow: hidden; }
#map { position: absolute; inset: 0; }

/* Push Leaflet controls clear of the floating menu / leaderboard buttons. */
.leaflet-top.leaflet-left { top: 56px; }
.leaflet-top.leaflet-right { top: 68px; }

/* ---- Floating map buttons ---- */
.map-btn {
  border: none;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  font-size: 16px;
  padding: 0 14px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.map-btn:hover { background: #f0f0f0; }

.menu-toggle {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1100;
  font-size: 20px;
  padding: 0;
  width: 44px;
  justify-content: center;
}

.topbar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1100;
  display: flex;
  gap: 8px;
}
.topbar .map-btn span { font-size: 14px; }

/* ---- Sidebar ---- */
.sidebar {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  max-width: 92vw;
  background: var(--bg);
  box-shadow: 2px 0 14px rgba(0, 0, 0, 0.15);
  transform: translateX(-105%);
  transition: transform 0.25s ease;
  z-index: 1200;
  overflow-y: auto;
  padding: 16px;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sidebar-header h1 { font-size: 20px; margin: 0; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
}
.icon-btn:hover { background: #e8e8e8; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* ---- Forms ---- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; margin-bottom: 4px; color: #333; }
.field em { color: var(--muted); font-style: normal; font-size: 12px; }

input[type=text],
input[type=password],
input[type=number],
select,
input[type=file] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
.row { display: flex; gap: 10px; }
.row .field { flex: 1; }

.owners {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 12px;
}
.owners legend { font-size: 13px; padding: 0 4px; color: #333; }
.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 14px; }
.check input { width: auto; }

button.primary,
button.secondary {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
}
button.primary { background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-hover); }
button.primary:disabled { opacity: 0.6; cursor: default; }
button.secondary { background: #fff; border-color: var(--border); color: var(--text); }
button.secondary:hover { background: #f0f0f0; }

.status { font-size: 13px; color: var(--danger); margin: 8px 0 0; min-height: 1em; }
.muted { color: var(--muted); font-size: 13px; }

/* ---- Legend ---- */
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 3px 0; }
.swatch { width: 18px; height: 4px; border-radius: 2px; display: inline-block; flex: none; }
.dash-sample {
  width: 18px;
  height: 0;
  border-top: 3px dashed #555;
  display: inline-block;
  flex: none;
}

/* ---- Rides list ---- */
.ride {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ride:last-child { border-bottom: none; }
.ride .ride-main { min-width: 0; flex: 1; }
.ride .ride-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ride .ride-meta { color: var(--muted); font-size: 12px; }
.ride-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.ride-actions a { color: var(--primary); text-decoration: none; font-size: 15px; }
.ride-actions a:hover { text-decoration: underline; }
.link-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 6px;
  line-height: 1;
}
.link-btn:hover { background: #eceef2; }

/* ---- Leaderboard modal ---- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 1250;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.4);
}
.modal.open { display: flex; }
.modal-card {
  background: #fff;
  border-radius: 14px;
  width: min(900px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
.modal-card.modal-small { width: min(460px, 100%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h2 { margin: 0; font-size: 20px; }

.leaderboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.lb-col h3 { margin: 0 0 8px; font-size: 15px; }
.lb-col table { width: 100%; border-collapse: collapse; font-size: 14px; }
.lb-col td { padding: 5px 4px; border-bottom: 1px solid var(--border); }
.lb-col td.rank { color: var(--muted); width: 22px; }
.lb-col td.value { text-align: right; font-variant-numeric: tabular-nums; }
.lb-col tr:first-child td { font-weight: 700; }
.lb-name { display: inline-flex; align-items: center; gap: 7px; }

/* ---- Overlay / toast / banners ---- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 1150;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1300;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.empty-state,
.config-banner {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  max-width: 90%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.empty-state { top: 70px; background: #fff; }
.config-banner { top: 16px; background: #fff3cd; border: 1px solid #ffe08a; color: #664d03; font-size: 13px; }

@media (max-width: 720px) {
  .leaderboard-grid { grid-template-columns: 1fr; }
  .topbar .map-btn span { display: none; }
  .topbar .map-btn { padding: 0 10px; }
}

/* ---- Snapshot & video modals ---- */
.media-body { display: flex; flex-direction: column; gap: 12px; }
.media-body canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #c6e2ff;
}
.media-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.media-controls .spacer { flex: 1; }
.media-controls button { width: auto; padding: 9px 16px; }
.field-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.field-inline input { width: 90px; padding: 7px 9px; }
.field-inline span { white-space: nowrap; }
