/* styles.css — mobile-first. Base rules target phones; min-width media queries
   progressively enhance to the dashboard grid. Dark and daylight cycling-
   computer palettes share one semantic token system. */

:root {
  color-scheme: dark;
  --bg: #0a0e14;
  --surface: #121821;
  --surface-2: #1a2230;
  --border: #5d6f86;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #22d3ee;
  --accent-text: #06222a;
  --headwind: #ff7a1a;
  --tailwind: #34d399;
  --crosswind: #f5b301;
  --error: #f87171;
  --route: #22d3ee;
  --map-marker-fill: #0a0e14;
  --radius: 12px;
  --space: 1rem;
  --display: "Chakra Petch", system-ui, sans-serif;
  --body: "Space Grotesk", system-ui, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #edf3f5;
  --surface: #ffffff;
  --surface-2: #dfe8ec;
  --border: #6f848f;
  --text: #14212b;
  --muted: #4a5b66;
  --accent: #006b7d;
  --accent-text: #ffffff;
  --headwind: #a93700;
  --tailwind: #006b4d;
  --crosswind: #806000;
  --error: #b42318;
  --route: #006b7d;
  --map-marker-fill: #ffffff;
}

* {
  box-sizing: border-box;
}

html {
  /* 16px+ base avoids iOS zoom-on-focus for form controls. */
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* Fluid containers — never wider than the viewport. */
.app-header,
.app-layout,
.app-footer {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding: var(--space);
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem var(--space);
  border-bottom: 1px solid var(--border);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.app-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1.25rem;
  text-transform: uppercase;
}
.app-title-accent {
  color: var(--accent);
}

/* Interactive targets are touch-friendly (>=44px). */
.units-toggle,
.theme-toggle,
.primary,
input {
  min-height: 44px;
  font: inherit;
}

.units-toggle {
  display: inline-flex;
  align-items: center;
  padding: 0 1rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--display);
  cursor: pointer;
  text-decoration: none;
}
a.units-toggle:hover {
  text-decoration: none;
  border-color: var(--accent);
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  padding: 0;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.theme-toggle:hover,
.units-toggle:hover {
  border-color: var(--accent);
}
.theme-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
}
.theme-toggle [data-theme-icon="light"] {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}
.theme-toggle [data-theme-icon="dark"] {
  fill: currentColor;
}
.theme-toggle [hidden] {
  display: none;
}
.theme-toggle:focus-visible,
.units-toggle:focus-visible,
.primary:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Intro — explains what the site does. */
.intro {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding: var(--space);
}
.intro-lead {
  margin: 0 0 0.5rem;
  font-family: var(--display);
  font-size: 1.35rem;
  line-height: 1.25;
  letter-spacing: 0.01em;
}
.intro-lead strong {
  color: var(--accent);
}
.intro-body {
  margin: 0 0 var(--space);
  max-width: 65ch;
  color: var(--muted);
}
.intro-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--display);
  font-size: 0.95rem;
}
.intro-steps li {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.intro-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
}

/* Mobile-first: single-column stack (controls -> map -> results). */
.app-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space);
}

.controls {
  display: grid;
  gap: 0.85rem;
  align-content: start;
}

.field {
  display: grid;
  min-width: 0;
  gap: 0.35rem;
}
.field label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 0 0.7rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input[type="file"] {
  padding: 0.5rem;
}

/* iOS Safari (WebKit bug 301648) miscalculates width: 100% for date/time
   inputs that carry their own horizontal padding, pushing them outside the
   card on iPhone. Keep those inputs padding-free and put the padding on a
   shell so the native control sizes correctly. */
.input-shell {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 44px;
  padding: 0 0.7rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.input-shell input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  align-self: stretch;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
}
.input-shell:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.input-shell input:focus-visible {
  outline: none;
}

.primary {
  padding: 0 1.1rem;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 8px;
  font-family: var(--display);
  font-weight: 600;
  cursor: pointer;
}
.primary:disabled,
.units-toggle:disabled,
.theme-toggle:disabled,
input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#status {
  margin: 0;
  min-height: 1.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}
#status[data-kind="ok"] {
  color: var(--tailwind);
}
#status[data-kind="error"] {
  color: var(--error);
}

.map {
  padding: 0;
  overflow: hidden;
}
/* Map-only wrapper so the legend stays anchored to the map even when the
   route notice below it is visible. */
.map-viewport {
  position: relative;
}
#map {
  width: 100%;
  height: 55vh;
  min-height: 300px;
  background: var(--surface-2);
}

/* On-map wind legend: static, bottom-left, clear of the zoom control
   (top-left) and attribution (bottom-right). */
.map-legend-host {
  position: absolute;
  left: 0.75rem;
  bottom: 1.6rem;
  z-index: 1000;
  max-width: min(230px, calc(100% - 1.5rem));
}
.map-legend {
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.3);
  color: var(--text);
  font-size: 0.8rem;
}
.map-legend-title {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.map-legend-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}
.map-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.map-legend-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: none;
}
.map-legend-glyph svg {
  display: block;
  width: 18px;
  height: 18px;
}
.map-legend-glyph--tailwind {
  color: var(--tailwind);
}
.map-legend-glyph--headwind {
  color: var(--headwind);
}
.map-legend-glyph--crosswind {
  color: var(--crosswind);
}
.map-legend-note {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.notice {
  margin: 0;
  padding: 0.6rem var(--space);
  font-size: 0.85rem;
  color: var(--crosswind);
  border-top: 1px solid var(--border);
}

.results {
  overflow-x: auto;
}
.results[aria-busy="true"] {
  opacity: 0.7;
}
.tz-note {
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
}
.loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.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 {
  animation: reveal 0.3s ease both;
}
@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
.muted {
  color: var(--muted);
  margin: 0;
}

/* Readable prose column (privacy page). */
.prose {
  max-width: 68ch;
  margin-inline: auto;
}
.prose h2 {
  font-family: var(--display);
  margin-top: 0;
}
.prose h3 {
  font-family: var(--display);
  margin-top: 1.6rem;
  color: var(--accent);
}
.prose p,
.prose li {
  color: var(--text);
}
.prose code {
  padding: 0.05rem 0.35rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9em;
}

/* Results table — dense, scannable, horizontally scrollable on small screens. */
.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: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.results-table thead th {
  position: sticky;
  top: 0;
  font-family: var(--display);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface);
}
.results-table tbody th {
  font-family: var(--display);
  font-weight: 600;
  color: var(--text);
}
.results-table tbody tr:hover {
  background: var(--surface-2);
}
.results-table td {
  font-variant-numeric: tabular-nums;
}
.results-table .dim {
  color: var(--muted);
}
.results-table sup {
  color: var(--accent);
  font-size: 0.7em;
}

/* Condition icon + label. */
.cond {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.cond svg,
.pop-cond svg {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--accent);
}

/* Map markers: rotated wind arrows. Colour AND arrowhead fill state carry the
   head/tail/cross category (filled = tailwind, outline = headwind, half =
   crosswind), so direction never depends on colour alone. The badge is rotated
   by the blows-toward bearing via an inline transform on the inner span. */
.route-marker-shell {
  background: transparent;
  border: 0;
}
.route-marker {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  color: var(--route);
  background: var(--map-marker-fill);
  border: 2px solid currentColor;
  border-radius: 50%;
}
.route-marker svg {
  display: block;
  width: 18px;
  height: 18px;
}
.route-marker--headwind {
  color: var(--headwind);
}
.route-marker--tailwind {
  color: var(--tailwind);
}
.route-marker--crosswind {
  color: var(--crosswind);
}
.route-marker--sample {
  color: var(--route);
}

/* Head/tail/crosswind badge. */
.wind {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-family: var(--display);
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid currentColor;
}
.wind--headwind {
  color: var(--headwind);
}
.wind--tailwind {
  color: var(--tailwind);
}
.wind--crosswind {
  color: var(--crosswind);
}

/* Map popup detail. */
.pop-head {
  font-family: var(--display);
  margin-bottom: 0.3rem;
}
.pop-cond {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.pop-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.75rem;
  align-items: center;
}
.pop-grid span {
  color: var(--muted);
  font-size: 0.8rem;
}
.pop-grid b {
  font-variant-numeric: tabular-nums;
}
.pop-dim {
  color: var(--muted);
}

.app-footer {
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}
.app-footer p {
  margin: 0.25rem 0;
}
.sep {
  margin: 0 0.4rem;
  opacity: 0.5;
}

/* Tablet and up: two-column dashboard, results spanning the width. */
@media (min-width: 48rem) {
  .app-layout {
    grid-template-columns: minmax(280px, 340px) 1fr;
  }
  .results {
    grid-column: 1 / -1;
  }
  #map {
    height: 60vh;
  }
}

/* Wide desktop: larger title, taller map. */
@media (min-width: 75rem) {
  .app-title {
    font-size: 1.5rem;
  }
  #map {
    height: 68vh;
  }
}

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

/* Leaflet chrome follows the active page theme. */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.leaflet-container {
  font-family: var(--body);
}
.leaflet-container a.leaflet-popup-close-button {
  color: var(--muted);
}
.leaflet-bar a,
.leaflet-control-attribution {
  color: var(--text);
  background: var(--surface);
}
.leaflet-bar a:hover,
.leaflet-bar a:focus {
  color: var(--accent);
  background: var(--surface-2);
}
