:root {
  --background: #fff;
  --page-background: #f4f4f1;
  --field-background: #f4f4f1;
  --strip-background: #fafaf8;
  --text: #17181c;
  --text-muted: #5f636b;
  --border: #e4e4e0;
  --border-subtle: #efefec;
  --hover-background: #f4f4f1;
  --selected-background: #eaf0fc;
  --link: #2f64d6;
  --shadow: 0 2px 10px rgba(23, 24, 28, 0.12);
  --font: Geist, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-numbers: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #1a1b1e;
    --page-background: #121315;
    --field-background: #24262a;
    --strip-background: #1f2023;
    --text: #f2f2f0;
    --text-muted: #a0a3aa;
    --border: #34363b;
    --border-subtle: #2a2c30;
    --hover-background: #24262a;
    --selected-background: #1f2e4a;
    --link: #7fa7f5;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  }
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  font: 14px/1.4 var(--font);
  background: var(--background);
  color: var(--text);
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
[hidden] {
  display: none !important;
}
.numbers {
  font-family: var(--font-numbers);
  font-variant-numeric: tabular-nums;
}

/* layout: sidebar on the left, map on the right (stacked on small screens, see the end of the file) */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}
#sidebar {
  width: 400px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--background);
}
#map-area {
  flex: 1;
  position: relative;
  background: var(--page-background);
}
#map {
  width: 100%;
  height: 100%;
}

/* search and filters */
/* the search and filters fold away under the title (closed by default on phones) */
#sidebar header {
  border-bottom: 1px solid var(--border);
}
#filter-section > summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 20px 12px;
  min-height: 44px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}
#filter-section > summary::-webkit-details-marker {
  display: none;
}
#filter-section > summary:hover {
  background: var(--strip-background);
}
#filter-section > summary:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: -2px;
}
.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chevron {
  flex: none;
  color: var(--text-muted);
  transition: transform 0.15s;
}
#filter-section[open] > summary .chevron {
  transform: rotate(90deg);
}
#rides-total {
  margin-left: auto;
}
.filter-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 24px;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
}
.filter-summary svg {
  flex: none;
}
#filter-summary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#filter-section[open] .filter-summary {
  display: none;
}
.filter-body {
  padding: 0 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}
#rides-total {
  font-size: 12px;
  color: var(--text-muted);
}
.search {
  position: relative;
  display: block;
}
.search svg {
  position: absolute;
  left: 12px;
  top: 12px;
  color: var(--text-muted);
  pointer-events: none;
}
#search {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 36px;
  background: var(--field-background);
  border: 1px solid transparent;
  border-radius: 10px;
  outline: none;
}
#search:focus {
  border-color: var(--link);
  background: var(--background);
}
.search kbd {
  position: absolute;
  right: 10px;
  top: 10px;
  font-family: var(--font-numbers);
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  background: var(--background);
}
#search:focus ~ kbd,
#search:not(:placeholder-shown) ~ kbd {
  display: none;
}
.filters {
  display: flex;
  gap: 8px;
}
.filters label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.date-filters {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
input[type="date"],
select {
  width: 100%;
  background: var(--background);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}
/* iOS Safari gives date fields a minimum width wider than their column, which made the whole page wider than the phone; without the native look they follow width: 100% */
input[type="date"] {
  display: block;
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  line-height: 32px;
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}
select[multiple] {
  padding: 3px;
  flex: 1;
  overflow-y: auto;
}
select[multiple] option {
  padding: 3px 7px;
  border-radius: 5px;
}
select[multiple] option:checked {
  background: var(--selected-background) linear-gradient(var(--selected-background), var(--selected-background));
  color: var(--text);
  font-weight: 600;
}
input[type="date"]:focus,
select:focus {
  border-color: var(--link);
}
.filter-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-top: -4px;
}
/* "Only rides with…": checkboxes folded away under their title */
#only-rides-with {
  flex: 1;
  min-width: 0;
}
#only-rides-with summary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  list-style: none;
  cursor: pointer;
  user-select: none;
}
#only-rides-with summary::-webkit-details-marker {
  display: none;
}
#only-rides-with summary:hover {
  color: var(--text);
}
#only-rides-with[open] .chevron {
  transform: rotate(90deg);
}
.checkbox-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 8px 0 0 18px;
}
.checkbox-filters label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}
.checkbox-filters input {
  margin: 0;
  accent-color: var(--link);
  cursor: pointer;
}
.label-with-info {
  display: flex;
  align-items: center;
  gap: 4px;
}
.info-button {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin: -3px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
.info-button:hover {
  color: var(--link);
  background: var(--hover-background);
}
#reset-filters {
  font-size: 12px;
  color: var(--link);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}
#reset-filters:disabled {
  visibility: hidden;
}

/* totals of the shown rides */
#rides-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--strip-background);
}
#rides-summary b {
  display: block;
  font-family: var(--font-numbers);
  font-size: 16px;
  font-weight: 500;
}
#rides-summary span {
  font-size: 11px;
  color: var(--text-muted);
}

/* ride list, grouped by month (the rows are also used in the map popup) */
#ride-list {
  overflow-y: auto;
  flex: 1;
}
.month-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--background);
  border-bottom: 1px solid var(--border-subtle);
}
.month-header span {
  font-weight: 400;
  color: var(--text-muted);
  font-family: var(--font-numbers);
  font-size: 11px;
}
.ride-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  text-align: left;
  padding: 10px 20px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
}
.ride-row:hover {
  background: var(--hover-background);
}
.ride-row.selected {
  background: var(--selected-background);
}
.ride-row-top,
.ride-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.ride-title {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ride-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.ride-meta {
  color: var(--text-muted);
  font-size: 12px;
  align-items: center;
}
.ride-meta .numbers {
  flex: 1;
  min-width: 0;
}
.media-count {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.empty-list {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

/* map overlays: tracks/heatmap switch, and MapLibre's own controls */
.map-toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
}
/* the key to the open ride's steepness colors (in the toolbar's place, which is hidden while a ride is open):
   one column per band, swatch above its range, and the lift line last */
.map-legend {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(38px, auto);
  grid-template-rows: auto auto;
  gap: 4px 6px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--background);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.map-legend[hidden] {
  display: none;
}
.map-legend-title {
  grid-row: 1;
  grid-column: 1 / -1;
  font-weight: 600;
  color: var(--text);
}
.map-legend > span:not(.map-legend-title) {
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-family: var(--font-numbers);
  white-space: nowrap;
}
.map-legend i {
  display: block;
  height: 8px;
  border-radius: 2px;
}
.map-legend i.map-legend-lift {
  height: 0;
  margin: 3px 0 2.5px;
  border-top: 2.5px dashed;
  border-radius: 0;
}

.segmented {
  display: flex;
  padding: 3px;
  background: var(--background);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.segmented button {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  border: 0;
  border-radius: 7px;
  background: none;
  cursor: pointer;
}
.segmented button:hover {
  background: var(--hover-background);
}
.segmented button[aria-pressed="true"] {
  background: var(--text);
  color: var(--background);
  font-weight: 600;
}
.maplibregl-ctrl-group {
  border-radius: 10px !important;
  box-shadow: var(--shadow) !important;
  overflow: hidden;
}
.maplibregl-ctrl-group button {
  width: 36px;
  height: 36px;
}
/* MapLibre's own control icons are dark grey in light and dark mode, so the zoom to all rides icon is too */
.zoom-to-all-rides {
  color: #333;
}
.zoom-to-all-rides svg {
  display: block;
  margin: auto;
}

/* ride details */
#ride-details {
  display: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 20px 28px;
}
#ride-details.open {
  display: block;
}
.details-nav {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -20px 16px;
  padding: 10px 16px 10px 10px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}
.back-button {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 36px;
  padding: 0 10px 0 4px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-weight: 500;
  cursor: pointer;
}
.back-button:hover {
  background: var(--hover-background);
}
.ride-stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.ride-stepper span {
  margin-right: 4px;
}
.ride-stepper button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  cursor: pointer;
}
.ride-stepper button:hover:not(:disabled) {
  background: var(--hover-background);
}
.ride-stepper button:disabled {
  color: var(--border);
  cursor: default;
}
.ride-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--field-background);
  font-size: 12px;
}
#ride-details h2 {
  font-size: 26px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 8px 0 4px;
}
#ride-details > .ride-meta {
  font-size: 13px;
}
.ride-description {
  white-space: pre-wrap;
  margin: 14px 0 0;
}
.ride-highlights {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 18px 0 14px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.ride-highlights div {
  background: var(--background);
  padding: 10px 12px;
}
.ride-highlights b {
  display: block;
  font-family: var(--font-numbers);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.ride-highlights span {
  font-size: 12px;
  color: var(--text-muted);
}
.ride-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 0 0 20px;
  font-size: 13px;
}
.ride-stats div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
.ride-stats dt {
  color: var(--text-muted);
}
.ride-stats dd {
  margin: 0;
  font-family: var(--font-numbers);
  text-align: right;
}
.section-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 8px;
}
.media {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}
.media img,
.media video {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  background: var(--hover-background);
}
/* a video opens in the lightbox like a photo, with a play mark on its first frame */
.media-video {
  position: relative;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  display: block;
}
.media-video video {
  display: block;
  pointer-events: none;
}
.media-video .play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ride profile chart */
#ride-profile {
  margin: 0 0 24px;
}
.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
.profile-header .section-title {
  margin: 0;
}
.profile-position {
  font-size: 12px;
  color: var(--text-muted);
}
.profile-position b,
.profile-value b {
  color: var(--text);
  font-weight: 500;
  font-family: var(--font-numbers);
}
.profile-panels {
  display: flex;
  flex-direction: column;
  gap: 14px;
  touch-action: none;
}
.profile-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.profile-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
}
.profile-label i {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}
.profile-value {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-numbers);
}
#ride-profile svg {
  display: block;
  width: 100%;
  overflow: visible;
}
.profile-axis {
  margin-top: -8px;
}
#ride-profile .axis-label {
  fill: var(--text-muted);
  font-size: 10px;
  font-family: var(--font-numbers);
}
#ride-profile .grid-line {
  stroke: var(--border-subtle);
  stroke-width: 1;
}
#ride-profile .base-line {
  stroke: var(--border);
  stroke-width: 1;
}
#ride-profile .average-line {
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  opacity: 0.7;
}
#ride-profile .crosshair {
  stroke: var(--text);
  stroke-width: 1;
}
#ride-profile .cursor-dot {
  fill: var(--background);
  stroke-width: 2;
}

/* stats per bike */
#bike-stats {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--background);
  color: var(--text);
  box-shadow: var(--shadow);
}
#bike-stats::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
.dialog-content {
  padding: 6px 20px 18px;
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.dialog-header h2 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}
.dialog-close {
  width: 36px;
  height: 36px;
  margin-right: -10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.dialog-close:hover {
  background: var(--hover-background);
  color: var(--text);
}
.numbers-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.numbers-table th,
.numbers-table td {
  padding: 7px 0 7px 12px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: right;
  white-space: nowrap;
}
.numbers-table td {
  font-family: var(--font-numbers);
  font-variant-numeric: tabular-nums;
}
.numbers-table thead th {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  border-bottom-color: var(--border);
}
.numbers-table th:first-child {
  padding-left: 0;
  text-align: left;
}
.numbers-table tbody th {
  font-weight: 600;
}
.numbers-table tbody th span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}
.numbers-table tfoot th,
.numbers-table tfoot td {
  font-weight: 600;
  border-bottom: 0;
  border-top: 1px solid var(--border);
}

/* full-screen photo or video, with its caption below */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
#lightbox.open {
  display: flex;
}
#lightbox figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
/* fill the screen whatever size the browser thinks the picture is, keeping its proportions */
#lightbox img,
#lightbox video {
  width: 95vw;
  height: 95vh;
  object-fit: contain;
}
/* with a caption, the picture sits right above it, also on a phone where it is far wider than tall */
#lightbox.with-caption img,
#lightbox.with-caption video {
  height: calc(95vh - 4em);
  object-position: center bottom;
}
#lightbox [hidden] {
  display: none;
}
#lightbox figcaption {
  color: #fff;
  font-size: 15px;
  line-height: 1.4;
  max-width: min(95vw, 700px);
  text-align: center;
  white-space: pre-line;
}
#lightbox figcaption:empty {
  display: none;
}

/* map popup listing the rides under a click */
.maplibregl-popup-content {
  background: var(--background);
  color: var(--text);
  padding: 0 0 6px;
  border-radius: 10px;
  box-shadow: var(--shadow);
}
/* MapLibre colours the popup's tip white, so match it to the popup in dark mode too */
.maplibregl-popup-anchor-top .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
  border-bottom-color: var(--background);
}
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
  border-top-color: var(--background);
}
.maplibregl-popup-anchor-left .maplibregl-popup-tip {
  border-right-color: var(--background);
}
.maplibregl-popup-anchor-right .maplibregl-popup-tip {
  border-left-color: var(--background);
}
.maplibregl-popup-content .ride-row {
  border: 0;
  padding: 6px 12px;
}
.popup-header {
  display: flex;
  color: var(--text-muted);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.popup-header span {
  flex: 1;
  padding: 8px 12px 6px;
}
/* close button as tall as the header */
.popup-header button {
  border: 0;
  background: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  padding: 0 12px;
  cursor: pointer;
  border-top-right-radius: 10px;
}
.popup-header button:hover {
  background: var(--hover-background);
  color: var(--text);
}
.popup-ride-list {
  overflow-y: auto;
  overscroll-behavior: contain;
}

@media (max-width: 700px) {
  #app {
    flex-direction: column-reverse;
  }
  #sidebar {
    width: 100%;
    height: 50%;
    border-right: 0;
    border-top: 1px solid var(--border);
  }
  #filter-section > summary {
    padding: 10px 14px;
  }
  h1 {
    font-size: 20px;
  }
  .filter-body {
    padding: 0 14px 12px;
    gap: 8px;
  }
  .search kbd {
    display: none;
  }
  /* iOS Safari zooms into any field with text smaller than 16px when it gets focus */
  #search,
  input[type="date"],
  select {
    font-size: 16px;
  }
  #rides-summary {
    padding: 8px 14px;
  }
  .month-header,
  .ride-row {
    padding-left: 14px;
    padding-right: 14px;
  }
}
