/* Ride weather page (plan 0005 S2-T3). Ported from Ride Weather's styles.css
   with its own token block removed: every colour, radius and spacing value now
   comes from css/styles.css, so the page follows the shared theme. Only
   weather-page components live here. */

/* Mobile-first: controls, then map, then results. Two columns from 48rem. */
.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  padding-block-end: var(--space-8);
}

.panel {
  min-width: 0;
  padding: var(--space-4);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.controls {
  display: grid;
  gap: var(--space-3);
  align-content: start;
}

.controls .field {
  margin: 0;
}

/* Safari miscalculates width on padded date/time inputs (WebKit 301648), so the
   padding lives on the shell and the native control stays padding-free. */
.input-shell {
  display: flex;
  align-items: center;
}

.input-shell input {
  width: 100%;
  min-width: 0;
  min-height: 0;
  align-self: stretch;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
}

.input-shell:focus-within {
  outline: var(--focus-width) solid var(--focus);
  outline-offset: var(--space-1);
}

.input-shell input:focus-visible {
  outline: none;
}

.units-toggle[aria-pressed="true"] {
  background: var(--surface-2);
}

.controls-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.controls :disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#status {
  margin: 0;
  min-height: var(--space-6);
  color: var(--muted);
  font-size: var(--text-caption);
}

#status[data-kind="ok"] {
  color: var(--success);
}

#status[data-kind="error"] {
  color: var(--danger);
  font-weight: 650;
}

.map {
  display: flex;
  padding: 0;
  overflow: hidden;
  flex-direction: column;
}

.map-viewport {
  position: relative;
  display: grid;
  flex: 1;
}

#map {
  width: 100%;
  height: 55vh;
  min-height: 300px;
  background: var(--surface-2);
}

.map-placeholder {
  display: grid;
  min-height: var(--space-32);
  margin: 0;
  padding: var(--space-6);
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
}

.map-legend {
  padding: var(--space-2) var(--space-4);
  border-block-start: var(--border-width) solid var(--border);
  color: var(--text);
  font-size: 0.78rem;
}

.map-legend .map-legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
}

.map-legend-title {
  margin: 0 0 var(--space-1);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.map-legend-items {
  display: grid;
  margin: 0;
  padding: 0;
  gap: var(--space-1);
  list-style: none;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.map-legend-glyph {
  display: inline-flex;
  width: 20px;
  height: 20px;
  align-items: center;
  justify-content: center;
  flex: none;
}

.map-legend-glyph svg {
  display: block;
  width: 18px;
  height: 18px;
}

.map-legend-glyph--tailwind {
  color: var(--wind-tail);
}

.map-legend-glyph--headwind {
  color: var(--wind-head);
}

.map-legend-glyph--crosswind {
  color: var(--wind-cross);
}

.map-legend-note {
  margin: var(--space-2) 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.notice {
  margin: 0;
  padding: var(--space-2) var(--space-4);
  border-block-start: var(--border-width) solid var(--border);
  color: var(--warn);
  font-size: var(--text-caption);
}

.results {
  overflow-x: auto;
}

.results[aria-busy="true"] {
  opacity: 0.7;
}

.tz-note,
.muted {
  margin: 0 0 var(--space-2);
  color: var(--muted);
  font-size: var(--text-caption);
}

.loading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.loading::before {
  content: "";
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  white-space: nowrap;
}

.results-table th,
.results-table td {
  padding: var(--space-2) var(--space-3);
  border-block-end: var(--border-width) solid var(--border);
  text-align: start;
}

.results-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.results-table tbody th {
  color: var(--text);
  font-weight: 650;
}

.results-table tbody tr:hover,
.results-table tbody tr:hover th {
  background: var(--surface-2);
}

/* Keep the point label visible while the table scrolls sideways. */
.results-table tbody th,
.results-table thead th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
}

.results-table thead th:first-child {
  z-index: 2;
}

.results-table td {
  font-variant-numeric: tabular-nums;
}

.results-table sup {
  color: var(--accent);
  font-size: 0.7em;
}

.ride-summary {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
}

.ride-summary li {
  display: grid;
  min-width: 7.5rem;
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  gap: var(--space-1);
}

.ride-summary-label {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ride-summary-value {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.cond {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.cond svg,
.pop-cond svg {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--accent);
}

/* Map markers: rotated wind arrows whose colour, arrowhead fill and label all
   carry the category, on an opaque disc so tile pixels never sit behind them. */
.route-marker-shell {
  border: 0;
  background: transparent;
}

.route-marker {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: var(--bg);
  color: var(--accent);
}

.route-marker svg {
  display: block;
  width: 18px;
  height: 18px;
}

.route-marker--headwind {
  color: var(--wind-head);
}

.route-marker--tailwind {
  color: var(--wind-tail);
}

.route-marker--crosswind {
  color: var(--wind-cross);
}

.route-marker--sample {
  color: var(--accent);
}

.wind {
  display: inline-block;
  padding: var(--space-1) var(--space-2);
  border: var(--border-width) solid currentColor;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 650;
}

.wind--headwind {
  color: var(--wind-head);
}

.wind--tailwind {
  color: var(--wind-tail);
}

.wind--crosswind {
  color: var(--wind-cross);
}

.pop-head {
  margin-block-end: var(--space-1);
  font-weight: 650;
}

.pop-cond {
  display: flex;
  align-items: center;
  margin-block-end: var(--space-1);
  gap: var(--space-2);
}

.pop-grid {
  display: grid;
  align-items: center;
  grid-template-columns: auto 1fr;
  gap: var(--space-1) var(--space-3);
}

.pop-grid span {
  color: var(--muted);
  font-size: 0.8rem;
}

.pop-grid b {
  font-variant-numeric: tabular-nums;
}

.pop-dim {
  color: var(--muted);
}

/* Attribution for the two external data sources, next to the results. */
.attribution {
  margin: var(--space-3) 0 0;
  color: var(--muted);
  font-size: var(--text-caption);
}

@media (min-width: 48rem) {
  .app-layout {
    grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr);
  }

  /* The results panel (not the inner .results div) is the grid item to span. */
  .app-layout > .results-panel {
    grid-column: 1 / -1;
  }

  #map {
    height: 60vh;
  }

  .map-legend-host {
    position: absolute;
    left: var(--space-3);
    bottom: var(--space-6);
    z-index: 1000;
    max-width: min(230px, calc(100% - var(--space-6)));
  }

  .map-legend {
    padding: var(--space-2) var(--space-3);
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-results);
    font-size: 0.8rem;
  }

  .map-legend .map-legend-items {
    display: grid;
  }
}

@media (min-width: 75rem) {
  #map {
    height: 68vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading::before {
    animation: none;
  }
}

/* Leaflet chrome follows the active theme through the shared tokens. */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  border: var(--border-width) solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

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

.leaflet-container a.leaflet-popup-close-button {
  color: var(--muted);
}

.leaflet-bar a,
.leaflet-container .leaflet-control-attribution {
  background: var(--surface);
  color: var(--text);
}

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

/* Leaflet's attribution links are tappable, so they get a 24 px target instead
   of relying on the inline-in-prose exception. The container and link colours are
   re-stated with `.leaflet-container` specificity because Leaflet's own stylesheet
   paints a near-white semi-transparent panel that would leave the light-theme link
   colour and the dark-theme text below 4.5:1. */
.leaflet-control-attribution a {
  display: inline-flex;
  min-height: 1.5rem;
  align-items: center;
  color: var(--accent-ink);
}
