/* Layout: fixed sidebar (stats + trip list) on the left, full-height map on the right.
   On phones the sidebar becomes a bottom sheet under the map. */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --text: #17201d;
  --muted: #5f6b67;
  --line: #dde3e1;
  --brand: #00a35c;
  --brand-ink: #ffffff;
  --danger: #c93a2f;

  /* One colour per activity, used on the map and in the list */
  --walk: #0e9384;
  --run: #e8590c;
  --bike: #3a5fd9;

  --radius: 14px;
  --shadow: 0 10px 30px rgba(16, 32, 26, 0.16);
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --surface: #182019;
    --surface-2: #212a25;
    --text: #e8eeeb;
    --muted: #97a39e;
    --line: #2b3530;
    --brand: #22c77a;
    --brand-ink: #08140e;
    --danger: #f07167;
    --walk: #2bc0ad;
    --run: #ff8a4c;
    --bike: #7d9bff;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-columns: 380px 1fr;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px 22px 18px;
  min-height: 0;
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__logo {
  width: 40px;
  height: 40px;
}

.brand__name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand__tagline {
  color: var(--muted);
  font-size: 13px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 14px 6px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat + .stat {
  border-left: 1px solid var(--line);
}

.stat__value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.sample-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--brand);
  font-weight: 700;
  white-space: nowrap;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.list-head__title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.filters {
  display: flex;
  gap: 4px;
}

.filter {
  border: 1px solid var(--line);
  background: none;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.filter.is-active {
  background: var(--text);
  border-color: var(--text);
  color: var(--surface);
}

/* ---------- Trip list ---------- */

.trips {
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 -6px;
  padding: 0 6px 6px;
  min-height: 0;
  flex: 1;
}

.trip {
  --c: var(--walk);
  position: relative;
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 0 12px;
  padding: 12px 12px 12px 0;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.trip--run {
  --c: var(--run);
}
.trip--bike {
  --c: var(--bike);
}

.trip::before {
  content: "";
  grid-row: 1 / span 2;
  background: var(--c);
  border-radius: 0 4px 4px 0;
}

.trip:hover,
.trip.is-active {
  border-color: var(--c);
}

.trip.is-active {
  transform: translateX(3px);
}

.trip__top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.trip__name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trip__meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.trip__type {
  color: var(--c);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.trip__numbers {
  grid-column: 2;
  display: flex;
  gap: 16px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.trip__num {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.trip__num b {
  font-size: 16px;
  font-weight: 800;
}

.trip__num span {
  font-size: 11px;
  color: var(--muted);
}

.trip__delete {
  grid-column: 3;
  grid-row: 1;
  background: none;
  border: none;
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.trip:hover .trip__delete,
.trip__delete:focus-visible {
  opacity: 1;
}

.trip__delete:hover {
  background: var(--surface-2);
  color: var(--danger);
}

.trip__confirm {
  grid-column: 2 / span 2;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  font-size: 13px;
}

.trip__confirm .btn {
  padding: 4px 12px;
  font-size: 13px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 14px;
}

.empty__title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.footer {
  font-size: 12px;
  color: var(--muted);
}

.footer a {
  color: inherit;
}

/* ---------- Map ---------- */

.map-wrap {
  position: relative;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
}

#map.is-drawing {
  cursor: crosshair;
}

.leaflet-container {
  font-family: var(--font);
}

/* Calmer basemap so the coloured routes stand out */
.leaflet-tile-pane {
  filter: saturate(0.55) contrast(0.95) brightness(1.03);
}

@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) saturate(0.5) brightness(0.85) contrast(0.9);
  }
}

.hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  white-space: nowrap;
}

.hint__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 163, 92, 0.5);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(0, 163, 92, 0);
  }
}

/* Route points while drawing */
.route-point {
  stroke-width: 2;
}

/* ---------- Floating panel ---------- */

.panel {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 600;
  width: min(460px, calc(100% - 32px));
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  animation: rise 0.2s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

.panel__live {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.panel__km {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.panel__unit {
  font-weight: 700;
  color: var(--muted);
}

.panel__points {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
}

.panel__help {
  font-size: 13px;
  color: var(--muted);
  margin: 6px 0 14px;
}

kbd {
  font-family: inherit;
  font-size: 12px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
}

.panel__actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.panel__actions .btn--primary {
  min-width: 110px;
}

.panel__form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel__summary {
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.panel__summary b {
  color: var(--text);
}

.panel__error {
  font-size: 13px;
  color: var(--danger);
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.field--small {
  flex: 0 0 120px;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field__label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.input {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
  min-width: 0;
}

.input:focus {
  outline: none;
  border-color: var(--brand);
}

.input-unit {
  position: relative;
  display: block;
}

.input-unit span {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

.input-unit .input {
  padding-right: 42px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  text-align: center;
  padding: 7px 0;
  border-radius: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--brand);
}

/* ---------- Buttons ---------- */

.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 700;
  font-size: 14px;
  transition: filter 0.15s, background 0.15s;
}

.btn--primary {
  background: var(--brand);
  color: var(--brand-ink);
}

.btn--primary:hover {
  filter: brightness(1.08);
}

.btn--primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: none;
}

.btn--ghost {
  background: var(--surface-2);
  color: var(--text);
}

.btn--ghost:hover {
  background: var(--line);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
}

/* ---------- Leaflet tweaks ---------- */

.leaflet-popup-content-wrapper {
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.leaflet-popup-tip {
  background: var(--surface);
}

.leaflet-popup-content {
  margin: 10px 14px;
  font-size: 13px;
  line-height: 1.45;
}

.popup__name {
  font-weight: 800;
  font-size: 14px;
}

.leaflet-bar a {
  background: var(--surface);
  color: var(--text);
  border-bottom-color: var(--line);
}

.leaflet-bar a:hover {
  background: var(--surface-2);
}

.locate-btn {
  font-size: 16px;
  line-height: 30px;
  text-align: center;
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Phone: map on top, list as a sheet below ---------- */

@media (max-width: 760px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 58vh 1fr;
  }

  .map-wrap {
    grid-row: 1;
  }

  .sidebar {
    grid-row: 2;
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    margin-top: -18px;
    padding: 18px 16px 12px;
    gap: 14px;
    overflow-y: auto;
  }

  .brand {
    display: none;
  }

  .trips {
    overflow: visible;
  }

  .trip__delete {
    opacity: 1;
  }

  .hint {
    font-size: 13px;
    left: 12px;
    right: 64px;
    transform: none;
    white-space: normal;
    border-radius: 12px;
  }

  .panel {
    bottom: 30px;
  }

  .field-row {
    flex-direction: column;
  }

  .field--small {
    flex-basis: auto;
  }
}
