/* Rides journal, ride detail and the shared-ride page (#189, design C 3.3
   and 3.4). Built from css/components.css; colours and type from
   css/tokens.css. Everything is scoped to the three views. */

:is(#view-rides, #view-ride-detail, #view-shared) {
  --ride-mono: 600 11.5px/1.3 var(--font-mono);
}
:is(#view-rides, #view-ride-detail, #view-shared) .page { max-width: var(--measure); }
:is(#view-rides, #view-ride-detail, #view-shared).page-view { padding: var(--s-5) var(--gutter) var(--s-8); }

/* roadbook eyebrow + tabular numbers */
:is(#view-rides, #view-ride-detail, #view-shared) .eyebrow {
  display: flex; align-items: center; gap: 10px; margin: 0;
  font: 600 12.5px/1.3 var(--font-mono); letter-spacing: var(--track-eyebrow); text-transform: uppercase;
  color: var(--accent-ink);
}
:is(#view-rides, #view-ride-detail, #view-shared) .eyebrow::before {
  content: ''; width: 22px; height: 0; border-top: 2px dashed currentColor; flex: none;
}
:is(#view-rides, #view-ride-detail, #view-shared) .eyebrow.plain::before { display: none; }
:is(#view-rides, #view-ride-detail, #view-shared) .num {
  font-family: var(--font-display); font-variant-numeric: tabular-nums; font-weight: 750; letter-spacing: -0.02em;
}
:is(#view-rides, #view-ride-detail, #view-shared) .faint { color: var(--text-3); }

/* route-shape thumbnails (js/views/rides.js shapeSvg) */
.shape { display: block; width: 100%; height: 100%; }
.shape-casing { fill: none; stroke: var(--surface); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.shape-line { fill: none; stroke: var(--shape); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.shape-start { fill: var(--surface); stroke: var(--shape); stroke-width: 2; }
.shape-end { fill: var(--accent); stroke: var(--shape); stroke-width: 1.5; }
.shape-empty path { fill: none; stroke: var(--text-3); stroke-width: 2; stroke-dasharray: 3 5; stroke-linecap: round; }

/* ---------- journal head ---------- */
.rides-head { display: grid; gap: var(--s-2); margin-bottom: var(--s-5); }
.rides-title-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.rides-title-row h1 { margin: 0; font-size: var(--fs-40); }
.rides-head .status { margin: 0; }

.stat-strip {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: var(--s-3) 0 0;
  border-block: 2px dashed var(--line);
}
.stat-strip > div { padding: 14px 16px 14px 0; min-width: 0; }
.stat-strip > div + div { padding-left: 16px; border-left: 1px solid var(--line); }
.stat-strip dt { font: var(--ride-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); }
.stat-strip dd { margin: 4px 0 0; font-size: var(--fs-28); line-height: 1.05; }
.stat-strip .stat-sub {
  display: block; margin: 4px 0 0; font-size: var(--fs-13); color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stat-strip a.stat-sub { color: var(--text-2); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.stat-strip a.stat-sub:hover { color: var(--accent-ink); }
@media (pointer: coarse), (max-width: 699px) {
  .stat-strip a.stat-sub { display: flex; align-items: center; min-height: var(--tap); margin: 0; }
}
@media (max-width: 699px) {
  .stat-strip { grid-template-columns: 1fr 1fr; }
  .stat-strip > div:nth-child(3) { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
  .stat-strip > div:nth-child(4) { border-top: 1px solid var(--line); }
  .stat-strip dd { font-size: var(--fs-22); white-space: nowrap; }
  /* Two narrow columns: the subline (recorded · imported) wraps, not clips. */
  .stat-strip .stat-sub { white-space: normal; }
}
@media (max-width: 359px) {
  .stat-strip dd { font-size: var(--fs-18); }
}

/* ---------- filters ---------- */
.rides-filters { display: grid; gap: 12px; margin-bottom: var(--s-5); min-width: 0; }
.year-chips {
  flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
  margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter);
}
.year-chips::-webkit-scrollbar { display: none; }
.rides-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.rides-search { position: relative; flex: 1 1 220px; min-width: 0; }
.rides-search .ic { position: absolute; left: 14px; top: 50%; translate: 0 -50%; color: var(--text-3); pointer-events: none; }
#view-rides .rides-search input,
#view-rides .rides-sort select {
  width: 100%; min-height: var(--tap); margin: 0; padding: 0 16px 0 42px;
  border: 1.5px solid var(--line-strong); border-radius: var(--r-pill);
  background: var(--surface); color: var(--text); font: 500 var(--fs-16)/1.2 var(--font-body);
}
#view-rides .rides-search input::placeholder { color: var(--text-3); }
.rides-sort { flex: 0 1 190px; min-width: 0; }
#view-rides .rides-sort select { padding: 0 36px 0 16px; font: 650 var(--fs-14)/1.2 var(--font-display); }

/* ---------- journal ---------- */
.journal-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: var(--s-6); align-items: start; }
.journal { min-width: 0; }
.season { position: sticky; top: calc(var(--topbar-h) + 24px); display: grid; gap: 8px; }
.season ol { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 2px dashed var(--line-strong); display: grid; }
.season a {
  display: flex; justify-content: space-between; gap: 8px; min-height: 36px; align-items: center;
  padding: 0 10px; border-radius: var(--r-1); text-decoration: none; color: var(--text);
}
.season a:hover { background: var(--surface-2); }
@media (max-width: 1023px) {
  .journal-wrap { grid-template-columns: minmax(0, 1fr); }
  .season { display: none; }
}

.year { border-top: 2px solid var(--text); margin-bottom: var(--s-5); scroll-margin-top: calc(var(--topbar-h) + 8px); }
.year-head {
  display: grid; grid-template-columns: auto minmax(0, 1fr) 240px auto; gap: 8px 20px;
  align-items: center; padding: 14px 0;
}
.year-num { margin: 0; font-size: var(--fs-40); line-height: 1; }
.year-sum { margin: 0; color: var(--text-2); font-size: var(--fs-14); }
.year-strip { height: 56px; min-width: 0; }
.bars { display: block; width: 100%; height: 100%; overflow: visible; }
.bar { fill: var(--line-strong); }
.bar-hi { fill: var(--accent); }
.bar-base { stroke: var(--line); }
.bar-label { fill: var(--text-2); font: 600 9px var(--font-display); }
.year-toggle .ic { transition: rotate .15s var(--ease); }
.year-toggle[aria-expanded='true'] .ic { rotate: 180deg; }
@media (max-width: 767px) {
  .year-head { grid-template-columns: auto minmax(0, 1fr); }
  .year-strip { grid-column: 1 / -1; order: 3; }
  .year-toggle { grid-column: 1 / -1; order: 4; justify-self: start; margin-top: 4px; }
}

.month { margin-top: var(--s-3); }
.month-head {
  position: sticky; top: var(--topbar-h); z-index: 3;
  display: flex; justify-content: space-between; align-items: baseline; gap: 4px 12px; flex-wrap: wrap;
  margin: 0; padding: 12px 0 10px; background: var(--bg); border-bottom: 1px solid var(--line);
  font-size: var(--fs-22);
}
.month-sum { font: 500 var(--fs-13)/1.3 var(--font-body); color: var(--text-2); letter-spacing: 0; }
.month-more { margin-top: 6px; }
.ride-list { list-style: none; margin: 0; padding: 0; }
.ride-list > li + li { border-top: 1px solid var(--line); }
.ride-row {
  display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 16px; align-items: center;
  padding: 12px 0; text-decoration: none; color: var(--text); border-radius: var(--r-2);
}
.ride-row:hover .ride-name { color: var(--accent-ink); }
.ride-shape {
  display: block; width: 72px; height: 72px; border-radius: var(--r-2);
  background: var(--surface); border: 1px solid var(--line); overflow: hidden;
}
.ride-main { display: grid; gap: 3px; min-width: 0; }
.ride-when { font: var(--ride-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); }
.ride-name { font: 700 var(--fs-18)/1.2 var(--font-display); letter-spacing: -0.015em; overflow-wrap: anywhere; }
.ride-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ride-stats {
  display: grid; grid-template-columns: repeat(4, auto); gap: 2px 18px;
  align-items: baseline; justify-items: end; text-align: right;
}
.ride-km { font-size: var(--fs-18); white-space: nowrap; }
.ride-sub { font-size: var(--fs-13); color: var(--text-2); white-space: nowrap; }
@media (max-width: 899px) {
  .ride-stats { grid-template-columns: auto; gap: 2px; }
  .ride-sub.hide-sm { display: none; }
}
@media (max-width: 420px) {
  .ride-row { grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; }
  .ride-shape { width: 56px; height: 56px; }
  .ride-name, .ride-km { font-size: var(--fs-16); }
}

/* the month's longest ride */
.hl {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); margin: 14px 0 6px;
  border-radius: var(--r-3); overflow: hidden; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line);
}
.hl-shape {
  display: block; min-height: 170px; background: var(--surface-2);
  background-image: radial-gradient(circle, var(--line) 1px, transparent 1.4px); background-size: 14px 14px;
}
.hl-shape .shape-line { stroke: var(--accent); stroke-width: 3.2; }
.hl-shape .shape-casing { stroke: var(--surface-2); stroke-width: 8; }
.hl-body { display: grid; gap: 6px; padding: 18px 20px; align-content: center; min-width: 0; }
.hl-name { font: 750 var(--fs-22)/1.15 var(--font-display); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.hl-num b { font-size: var(--fs-56); line-height: 1; }
.hl-num span { margin-left: 4px; font: 700 var(--fs-18) var(--font-display); color: var(--text-2); }
.hl-meta { color: var(--text-2); font-size: var(--fs-14); }
.hl:hover .hl-name { color: var(--accent-ink); }
@media (max-width: 599px) {
  .hl { grid-template-columns: minmax(0, 1fr); }
  .hl-shape { min-height: 0; aspect-ratio: 2 / 1; }
}

.nomatch { display: grid; gap: 12px; justify-items: start; padding: var(--s-6) 0; color: var(--text-2); }
.nomatch p { margin: 0; }

/* ---------- ride detail + shared ride ---------- */
:is(#view-ride-detail, #view-shared) .hidden { display: none; }
.ride-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: var(--s-3); }
.back-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding-right: 8px;
  color: var(--text-2); text-decoration: none; font: 650 var(--fs-14)/1.2 var(--font-display);
}
.back-link:hover { color: var(--accent-ink); }
.ride-pn { display: flex; gap: 8px; }

.ride-head { display: grid; gap: 10px; margin-bottom: var(--s-5); min-width: 0; }
.ride-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; }
.ride-head h1 { margin: 0; min-width: 0; font-size: var(--fs-56); line-height: 1.02; letter-spacing: -0.035em; overflow-wrap: anywhere; }
.ride-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ride-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin: 0; color: var(--text-2); font-size: var(--fs-14); }
.ride-meta a.badge { text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.ride-meta a.badge:hover { color: var(--accent-ink); }
.ride-meta .warn { color: var(--danger); }
@media (pointer: coarse), (max-width: 699px) {
  .ride-meta a.badge { min-height: var(--tap); padding-inline: 12px; }
  #view-shared .shared-by a { display: inline-flex; align-items: center; min-height: var(--tap); min-width: var(--tap); }
}

/* the ⋯ menu */
.menu-wrap { position: relative; }
.ride-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 200px;
  display: grid; padding: 6px; border-radius: var(--r-2);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-float);
}
.ride-menu[hidden] { display: none; }
.ride-menu button {
  appearance: none; display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 0 12px;
  border: 0; border-radius: var(--r-1); background: transparent; color: var(--text);
  font: 600 var(--fs-14)/1.2 var(--font-body); text-align: left; cursor: pointer;
}
.ride-menu button:hover, .ride-menu button:focus-visible { background: var(--surface-2); }
.ride-menu button.danger { color: var(--danger); }
.ride-menu hr { width: 100%; margin: 4px 0; border: 0; border-top: 1px solid var(--line); }

/* map card + kv stats */
.ride-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s-4); margin-bottom: var(--s-4); }
@media (max-width: 1023px) { .ride-grid { grid-template-columns: minmax(0, 1fr); } }
.ride-grid:has(> .ride-stats-card.hidden) { grid-template-columns: minmax(0, 1fr); }
.ride-map-card { display: grid; min-width: 0; border-radius: var(--r-3); overflow: hidden; border: 1px solid var(--line); background: var(--surface); }
.ride-map { position: relative; height: clamp(300px, 52vh, 520px); background: var(--surface-2); }
.map-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.map-legend.hidden { display: none; }
.seg-mini { display: inline-flex; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; color: var(--text-2); font-size: var(--fs-12); }
.legend > span { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 14px; height: 6px; border-radius: 3px; margin: 0; }

.ride-stats-card {
  display: grid; align-self: start; align-content: start; min-width: 0;
  padding: 6px 20px; border-radius: var(--r-3); background: var(--surface); border: 1px solid var(--line);
}
.kv { margin: 0; display: grid; grid-template-columns: 1fr 1fr; }
.kv > div { display: grid; align-content: center; min-width: 0; padding: 14px 0; border-bottom: 1px solid var(--line); }
.kv > div:nth-child(odd) { padding-right: 12px; }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.kv.kv-odd > div:nth-last-child(2) { border-bottom: 1px solid var(--line); }
.kv dt { font: var(--ride-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); }
.kv dd { margin: 4px 0 0; font-size: var(--fs-22); line-height: 1.1; overflow-wrap: anywhere; }
.kv .kv-hero dd { font-size: var(--fs-28); }
@media (max-width: 1023px) and (min-width: 600px) {
  .kv { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .kv > div, .kv.kv-odd > div:nth-last-child(2) { border-bottom: 0; }
}

/* charts: one row per series, one crosshair, one readout */
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 8px; }
.h-sm { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: var(--fs-18); }
.charts { display: grid; gap: 6px; margin-bottom: var(--s-4); min-width: 0; }
.charts.hidden { display: none; }
.readout { font-size: var(--fs-13); color: var(--text-2); font-variant-numeric: tabular-nums; min-height: 1.3em; }
.chart-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; align-items: center; }
.chart-row + .chart-row { border-top: 1px solid var(--line); padding-top: 6px; }
.chart-label { margin: 0; font: 650 var(--fs-13)/1.3 var(--font-display); color: var(--text-2); letter-spacing: 0; }
.chart { min-width: 0; cursor: crosshair; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; border-radius: var(--r-1); }
.chart svg:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (max-width: 599px) {
  .chart-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
}

/* the ride's share sheet (O8, js/views/ride_detail.js) */
.share-sheet { display: grid; gap: 12px; }
.share-expiry { display: grid; gap: 4px; margin: 0; font-size: var(--fs-13); color: var(--text-2); }
.share-expiry select {
  min-height: var(--tap); margin: 0; padding: 0 12px; border: 1.5px solid var(--line-strong); border-radius: var(--r-2);
  background: var(--surface); color: var(--text); font: 500 var(--fs-16)/1.2 var(--font-body);
}
.share-sheet > .btn { justify-self: start; }
.share-link { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; width: 100%; }
.share-sheet .share-url { flex: 1 1 220px; border-radius: var(--r-2); font: 500 var(--fs-14)/1.45 var(--font-mono); }
.share-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.share-note { margin: 0; color: var(--text-2); font-size: var(--fs-14); }
.share-note:empty { display: none; }
.share-note-error { color: var(--danger); }
.dlg-share .dlg-head .info-btn { margin-inline-start: -4px; margin-inline-end: auto; }

/* shared page */
#view-shared .shared-by a { color: var(--accent-ink); }
#view-shared > .page > .status { margin-bottom: var(--s-3); }
