/* Better Moto Routing — night-ride dashboard theme.
   Brand knobs live in this :root block (mirrors BRAND_NAME in
   js/config.js): rename/recolor the product here. */

:root {
  --brand-accent: #ff8a2a;        /* warm headlight orange */
  --brand-accent-soft: #ff8a2a26; /* accent at ~15% for fills */
  --bg: #0d1117;                  /* asphalt */
  --bg-raised: #151c24;           /* panels, cards */
  --bg-inset: #0a0e13;            /* inputs, wells */
  --border: #2a3441;
  --text: #e9eef4;
  --muted: #8b98a6;
  --good: #4cc38a;
  --danger: #ff6b62;
  --danger-bg: #58201d;
  --info-bg: #1b3a5e;
  --nav-h: 56px;
  --panel-w: 380px;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin: 6px 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- top nav ---------- */

#topnav {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg-raised) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.brand-mark { color: var(--brand-accent); flex: none; }

.nav-links { display: flex; gap: 4px; flex: 1; min-width: 0; }
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 500;
  white-space: nowrap;
}
.nav-links a:hover { color: var(--text); background: var(--bg-inset); }
.nav-links a.active { color: var(--brand-accent); background: var(--brand-accent-soft); }

.nav-auth { display: flex; align-items: center; }
#nav-user {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
#nav-avatar { border-radius: 50%; border: 2px solid var(--brand-accent); display: block; }

main { padding-top: var(--nav-h); min-height: 100%; }

/* ---------- buttons + inputs ---------- */

.btn {
  appearance: none;
  padding: 9px 16px;
  min-height: 40px; /* touch-friendly */
  background: #222b36;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: #2b3643; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--brand-accent);
  border-color: var(--brand-accent);
  color: #1a1006;
  font-weight: 700;
}
.btn-primary:hover { background: #ffa052; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger-bg); border-color: var(--danger); color: #ffc9c5; }
.btn-danger:hover { background: #6e2a26; }
.btn-block { width: 100%; }
.btn-lg { padding: 13px 26px; font-size: 17px; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 13px; }

input[type="text"], input[type="number"], input[type="search"], input[type="url"], select {
  width: 100%;
  padding: 9px 10px;
  min-height: 40px;
  margin: 4px 0 2px;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
input:focus, select:focus, .btn:focus-visible {
  outline: 2px solid var(--brand-accent);
  outline-offset: 1px;
}
label { display: block; margin-top: 10px; color: var(--muted); font-size: 13px; font-weight: 600; }

.status {
  padding: 9px 12px;
  margin: 0 0 10px;
  border-radius: 8px;
  font-size: 13.5px;
}
.status.error { background: var(--danger-bg); border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); }
.status.info { background: var(--info-bg); border: 1px solid #3478c666; }

/* ---------- landing ---------- */

#view-landing {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}
.hero { text-align: center; padding: 64px 8px 40px; }
.hero h1 {
  font-size: clamp(34px, 6vw, 56px);
  margin: 0 0 16px;
  background: linear-gradient(100deg, var(--text) 40%, var(--brand-accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  max-width: 620px;
  margin: 0 auto 28px;
  color: var(--muted);
  font-size: 18px;
}
.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin-top: 32px;
}
.feature-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 8px;
}
.feature-card h3 { margin: 0 0 8px; font-size: 16px; color: var(--brand-accent); }
.feature-card p { color: var(--muted); font-size: 14px; }

/* ---------- map views (planner + ridden) ---------- */

.map-view {
  position: relative;
  height: calc(100dvh - var(--nav-h));
  overflow: hidden;
}
.map { position: absolute; inset: 0; }

.panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--panel-w);
  max-width: 100%;
  overflow-y: auto;
  padding: 14px 16px 40px;
  background: color-mix(in srgb, var(--bg-raised) 94%, transparent);
  backdrop-filter: blur(6px);
  border-right: 1px solid var(--border);
  z-index: 10;
  overscroll-behavior: contain;
}
.panel-toggle {
  position: absolute;
  z-index: 11;
  top: 10px;
  left: calc(var(--panel-w) + 10px);
  padding: 8px 12px;
  min-height: 40px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  transition: left 0.15s ease;
}
.map-view.panel-closed .panel { display: none; }
.map-view.panel-closed .panel-toggle { left: 10px; }

.field-group { margin: 14px 0; }
.field-group > label:first-child { margin-top: 0; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg-btn {
  flex: 1;
  padding: 9px 6px;
  min-height: 40px;
  background: transparent;
  color: var(--muted);
  border: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.active { background: var(--brand-accent-soft); color: var(--brand-accent); }

/* waypoint list */
.wp-list { list-style: none; margin: 6px 0; padding: 0; }
.wp-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.wp-list li:last-child { border-bottom: none; }
.wp-tag {
  flex: none;
  min-width: 46px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
span.wp-tag { background: var(--bg-inset); color: var(--muted); }
span.wp-tag.start { background: #173b26; color: var(--good); }
span.wp-tag.end { background: var(--danger-bg); color: #ff9d96; }
button.wp-tag { cursor: pointer; font: inherit; font-size: 11px; font-weight: 700; min-height: 28px; }
button.wp-tag.break { background: #14334f; color: #7db4ec; }
button.wp-tag.via { background: #46350c; color: #e8c25a; }
.wp-coords { flex: 1; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.wp-remove {
  flex: none;
  width: 34px; height: 34px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
.wp-remove:hover { color: var(--danger); border-color: var(--danger); }

/* result stats */
.stats-strip {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}
.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.stat-value { font-size: 17px; font-weight: 700; color: var(--brand-accent); }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

details summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 6px 0; }
#plan-instructions-list { margin: 6px 0 0; padding-left: 20px; }
#plan-instructions-list li {
  margin: 5px 0;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
#plan-instructions-list li:last-child { border-bottom: none; }
.instruction-dist { display: block; color: var(--muted); font-size: 11.5px; }

/* planner: alternatives toggle + promote list */
.check-row {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer;
}
.check-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand-accent); }
#plan-alts > label { margin-top: 12px; }
#plan-alts-list { list-style: none; margin: 6px 0 0; padding: 0; }
#plan-alts-list li {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 7px 6px; border-bottom: 1px solid var(--border); font-size: 13px;
}
#plan-alts-list li:last-child { border-bottom: none; }
#plan-alts-list li:hover { background: var(--bg-inset); }
#plan-alts-list .alt-swatch {
  display: inline-block; width: 12px; height: 0; border-radius: 1px;
  border-top: 3px dashed #9ea7b3; flex: none;
}
#plan-alts-list .alt-delta { margin-left: auto; color: var(--muted); font-size: 12px; }

/* planner: elevation/curviness profile chart docked over the map bottom */
#plan-profile-panel {
  position: absolute;
  left: calc(var(--panel-w) + 12px);
  right: 12px;
  bottom: 12px;
  z-index: 9; /* above the map canvas, below the side panel (10) */
  padding: 6px 10px 8px;
  background: color-mix(in srgb, var(--bg-raised) 93%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: left 0.15s ease;
}
.map-view.panel-closed #plan-profile-panel { left: 12px; }
#plan-profile-head { display: flex; align-items: center; gap: 10px; }
#plan-profile-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700;
}
#plan-profile-readout { color: var(--text); font-size: 12px; min-width: 14em; }
#plan-profile-legend { flex: 1; text-align: right; margin: 0; font-size: 12px; }
#plan-profile-legend .legend-swatch {
  width: 14px; height: 3px; margin: 0 4px 0 10px; vertical-align: middle;
}
.legend-curv { background: var(--brand-accent); }
.legend-elev { background: #539bf5; }
#plan-profile-toggle {
  margin: 0; padding: 0 8px; min-height: 24px; font: inherit; font-size: 12px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
#plan-profile-toggle:hover { color: var(--text); }
#plan-profile-svg { display: block; width: 100%; height: 150px; cursor: crosshair; }
#plan-profile-no-elev { margin: 2px 0 0; }
.pc-grid { stroke: var(--border); stroke-width: 1; }
.pc-label { fill: var(--muted); font-size: 10px;
            font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pc-curv-label { fill: #d29455; }
.pc-elev-label { fill: #84b5f7; }
.pc-curv-line { stroke: var(--brand-accent); stroke-width: 1.5; fill: none; }
.pc-elev-line { stroke: #539bf5; stroke-width: 1.5; fill: none; }
.pc-cursor { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 2; }
.profile-hover-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--brand-accent);
  box-shadow: 0 0 4px #00000088;
}

/* ---------- page views (rides + account) ---------- */

.page-view { padding: 24px 16px 64px; }
.page { max-width: 760px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page h2 { margin: 8px 0 12px; }

.doc-list { list-style: none; margin: 14px 0; padding: 0; }
.doc-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin: 8px 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.doc-list li.selected { border-color: var(--brand-accent); }
.doc-main { flex: 1; min-width: 0; cursor: pointer; }
.doc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { color: var(--muted); font-size: 12.5px; }
.doc-swatch { flex: none; width: 12px; height: 12px; border-radius: 3px; }
.doc-actions { display: flex; gap: 6px; flex: none; }
/* "ridden N times" pill on My Rides rows (route_id back-links). */
.ridden-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--brand-accent);
  background: var(--brand-accent-soft);
  border-radius: 999px;
  vertical-align: 1px;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 14px 0;
}
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.account-id { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
#account-avatar { border-radius: 50%; border: 2px solid var(--brand-accent); }
.account-login { font-weight: 700; font-size: 17px; }

/* track details popup (MapLibre) */
.maplibregl-popup-content {
  background: var(--bg-raised) !important;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: 13.5px/1.45 system-ui, sans-serif;
  min-width: 220px;
}
.maplibregl-popup-tip { border-top-color: var(--bg-raised) !important; border-bottom-color: var(--bg-raised) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; }
.popup-title { font-weight: 700; margin: 0 0 4px; padding-right: 14px; }
.popup-meta { color: var(--muted); margin: 0 0 8px; }
.popup-spark { display: block; width: 100%; height: auto; margin: 0 0 8px; opacity: 0.9; }
.popup-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- ride detail ---------- */

.detail-map {
  position: relative;
  height: 340px;
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.detail-toolbar { margin: 10px 0; }
.detail-toolbar .spacer { flex: 1; }
.detail-modes { flex: none; }
.detail-modes .seg-btn { padding: 7px 14px; min-height: 34px; }
.legend {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}
.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: -1px;
}
.stats-wrap { flex-wrap: wrap; }
.stats-wrap .stat { flex: 1 1 110px; }

/* --- ride sharing (detail view share box + public shared-ride page) --- */
.share-box { margin: 10px 0; }
.share-url { flex: 1 1 240px; min-width: 0; }
.share-note-error { color: var(--danger); }
.shared-badge {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chart-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0;
}
.chart-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.chart-value { color: var(--text); font-weight: 500; min-height: 1em; }
.chart-card svg { display: block; width: 100%; height: auto; }

/* ---------- stats view ---------- */

.stats-records { list-style: none; margin: 0; padding: 0; }
.stats-records li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.stats-records li:last-child { border-bottom: none; padding-bottom: 0; }
.stats-record-label {
  flex: 1 1 170px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stats-record-value { font-weight: 700; color: var(--brand-accent); white-space: nowrap; }
.stats-record-ride {
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.stats-record-ride:hover { text-decoration: underline; color: var(--brand-accent); }

.stats-chart svg { display: block; width: 100%; height: auto; }
.stats-bar { fill: var(--brand-accent); }
.stats-bar-hit { fill: transparent; }
.stats-bar-group:hover .stats-bar { fill: var(--text); }
.stats-axis-label { fill: var(--muted); font-size: 10px; }

.stats-source-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.stats-source-label { flex: 0 0 160px; color: var(--muted); font-size: 13px; }
.stats-source-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.stats-source-fill { height: 100%; background: var(--brand-accent); }
.stats-source-count { flex: none; min-width: 2ch; text-align: right; font-weight: 700; }

/* ---------- dialog ---------- */

dialog {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  max-width: 420px;
  width: calc(100vw - 40px);
}
dialog::backdrop { background: rgba(4, 6, 9, 0.7); }
dialog h3 { margin-top: 0; }
.dialog-actions { justify-content: flex-end; margin-top: 14px; }

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  :root { --panel-w: 100%; }
  #topnav { gap: 8px; padding: 0 10px; }
  .brand-name { display: none; }
  .nav-links a { padding: 8px 9px; font-size: 14px; }
  #nav-login-name { display: none; }

  /* Panels become a bottom sheet over the map so the map stays visible
     while riders poke at options with a gloved thumb. */
  .panel {
    top: auto;
    height: 58%;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
  }
  .panel-toggle {
    top: auto;
    bottom: calc(58% + 10px);
    left: 10px !important;
    transition: bottom 0.15s ease;
  }
  .map-view.panel-closed .panel-toggle { bottom: 10px; }

  /* The plan profile chart rides above the bottom sheet, like the toggle. */
  #plan-profile-panel {
    left: 10px !important;
    right: 10px;
    bottom: calc(58% + 58px);
    transition: bottom 0.15s ease;
  }
  .map-view.panel-closed #plan-profile-panel { bottom: 58px; }
}
