/**
 * Route Map component — /routes/ hero interactive widget.
 *
 * LIGHT editorial treatment — matches the rest of the site (ivory/paper
 * surfaces, ink text, navy accent, brass eyebrows, Fraunces display) and the
 * "Route Legs" planner card from the Jet Supply CMS map prototype. Replaces the
 * earlier dark band, which read as foreign against the light routes page.
 *
 * All colour/type/space values come from tokens.css — never hardcoded hex.
 * Enqueued conditionally (route archive only) — NOT @import'd into main.css (D-26).
 *
 * BEM: .route-map (block), .route-map__el (element), .route-map--mod (modifier).
 *
 * @package JetSupply
 */

/* Self-contained box model — don't depend on a global reset being present. */
.route-map, .route-map *, .route-map *::before, .route-map *::after { box-sizing: border-box; }

/* ── Layout: outer frame ──────────────────────────────────────────────────── */

.route-map {
  position: relative;
  display: flex;
  flex-direction: column;
  color: var(--c-text);
}

@media (min-width: 900px) {
  .route-map { min-height: 640px; }
}

@media (min-width: 1200px) {
  .route-map { min-height: 680px; }
}

/* ── Map canvas ───────────────────────────────────────────────────────────── */

.route-map__canvas {
  order: -1;
  position: relative;
  z-index: 0;
  height: 320px;
  background:
    radial-gradient(130% 120% at 72% 18%, var(--c-paper), var(--c-ivory) 62%);
  border: var(--bw-hair) solid var(--c-rule);
  border-radius: var(--r-lg);
  overflow: hidden;
}

@media (min-width: 900px) {
  .route-map__canvas {
    position: absolute;
    inset: 0;
    height: auto;
    border: var(--bw-hair) solid var(--c-rule);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-base);
  }
}

.route-map__canvas .mapboxgl-map {
  width: 100%;
  height: 100%;
}

/* Keep the Mapbox WebGL canvas strictly below the floating planner. */
.route-map__canvas .mapboxgl-map,
.route-map__canvas .mapboxgl-canvas-container { z-index: 0; }
.route-map__canvas .mapboxgl-ctrl-group {
  border-radius: var(--r-md);
  box-shadow: var(--sh-base);
  border: var(--bw-hair) solid var(--c-rule);
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.route-map__sidebar {
  position: relative;
  z-index: 10;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  margin: -40px var(--s-3) 0;
  background-color: var(--c-paper);
  border: var(--bw-hair) solid var(--c-rule);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-modal);
  overflow-y: auto;
}

@media (min-width: 900px) {
  .route-map__sidebar {
    position: absolute;
    top: var(--s-4);
    left: var(--s-4);
    width: 320px;
    margin: 0;
    max-height: calc(100% - var(--s-4) * 2);
    overflow-y: auto;
    /* FULLY opaque (not backdrop-filter, not translucent): a frosted OR
       partially-transparent card over the Mapbox WebGL canvas triggers a
       Chromium bug where clicks pass THROUGH to the map and form fields can't
       be focused by mouse (Tab still works). A solid, fully-opaque bg is what
       keeps the float clickable — even 6% transparency (the old 94% color-mix)
       re-triggered the pass-through. */
    background-color: var(--c-paper);
  }
}

/* ── Segmented tab control (Route / Nearby) ───────────────────────────────── */

.route-map__tabs {
  display: flex;
  gap: var(--s-1);
  margin: var(--s-3);
  padding: var(--s-1);
  background-color: var(--c-ivory);
  border: var(--bw-hair) solid var(--c-rule);
  border-radius: var(--r-md);
  flex-shrink: 0;
}

.route-map__tab {
  flex: 1;
  padding: var(--s-2);
  font-family: var(--ff-sans);
  font-size: var(--fs-micro);
  font-weight: var(--fw-semi);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--c-text-soft);
  background: none;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-quiet),
              background-color var(--dur-fast) var(--ease-quiet);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .route-map__tab { transition: none; }
}

.route-map__tab.active {
  color: var(--c-ivory);
  background-color: var(--c-navy-900);
}

.route-map__tab:hover:not(.active) { color: var(--c-text); }

/* ── Panel containers ────────────────────────────────────────────────────── */

.route-map__panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding: 0 var(--s-3) var(--s-3);
  overflow-y: auto;
}

.route-map__panel.hidden { display: none; }

/* ── Leg cards ────────────────────────────────────────────────────────────── */

.route-map__leg {
  background-color: #fff;
  border: var(--bw-hair) solid var(--c-rule);
  border-radius: var(--r-lg);
  padding: var(--s-3);
  box-shadow: var(--sh-quiet);
}

.route-map__leg-hd {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
}

.route-map__leg-label {
  font-family: var(--ff-sans);
  font-size: var(--fs-micro);
  font-weight: var(--fw-semi);
  letter-spacing: var(--tr-luxe);
  text-transform: uppercase;
  white-space: nowrap;
}

.route-map__leg-dist {
  flex: 1;
  display: none;
  font-family: var(--ff-mono);
  font-size: var(--fs-micro);
  color: var(--c-text-soft);
  text-align: right;
}

.route-map__leg-remove {
  width: 22px;
  height: 22px;
  margin-left: auto;
  border: none;
  background: none;
  color: var(--c-text-soft);
  cursor: pointer;
  font-size: var(--fs-body);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  transition: color var(--dur-fast) var(--ease-quiet),
              background-color var(--dur-fast) var(--ease-quiet);
}

.route-map__leg-remove:hover {
  color: var(--c-error);
  background-color: color-mix(in srgb, var(--c-error) 10%, transparent);
}

/* ── Field rows ───────────────────────────────────────────────────────────── */

.route-map__field-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--s-3);
}

/* Leg From/To are 4-char codes — size them to content, not full width. */
.route-map__leg .route-map__field { flex: 0 0 112px; }
.route-map__leg .route-map__ac-list { right: auto; min-width: 248px; }

/* FROM → TO connector arrow (added in renderLegs markup). */
.route-map__field-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  color: var(--c-silver-dim);
  font-size: var(--fs-h5);
  user-select: none;
}

.route-map__field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  position: relative;
}

.route-map__field-label {
  font-family: var(--ff-sans);
  font-size: var(--fs-micro);
  font-weight: var(--fw-medium);
  color: var(--c-text-soft);
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
}

.route-map__input {
  background-color: var(--c-ivory);
  border: var(--bw-hair) solid var(--c-rule);
  border-radius: var(--r-sm);
  color: var(--c-text);
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  padding: var(--s-2);
  width: 100%;
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-quiet),
              box-shadow var(--dur-fast) var(--ease-quiet);
}

/* Airport-code inputs read as flight data → mono, tracked, larger. */
/* Airport-code (leg) inputs read as flight data — mono. The Nearby box now
   takes city names too, so it stays in the sans base face. */
.route-map__input[data-rm-icao-input] {
  font-family: var(--ff-mono);
  font-size: var(--fs-small);
  letter-spacing: var(--tr-wide);
}

.route-map__input::placeholder { color: var(--c-silver); }

.route-map__input:focus {
  border-color: var(--c-navy-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c-navy-500) 14%, transparent);
}

/* ── Autocomplete list ────────────────────────────────────────────────────── */

.route-map__ac-list,
[data-rm-avoid-ac],
[data-rm-nearby-ac] {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: var(--s-1);
  z-index: 100;
  background-color: #fff;
  border: var(--bw-hair) solid var(--c-rule);
  border-radius: var(--r-md);
  box-shadow: var(--sh-modal);
  display: none;
  max-height: 240px;
  overflow-y: auto;
}

.route-map__ac-list.show,
[data-rm-avoid-ac].show,
[data-rm-nearby-ac].show { display: block; }

.route-map__ac-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-quiet);
}

.route-map__ac-item:hover,
.route-map__ac-item.hl { background-color: var(--c-ivory); }

.route-map__ac-icao {
  font-family: var(--ff-mono);
  font-size: var(--fs-caption);
  font-weight: var(--fw-semi);
  color: var(--c-navy-500);
  flex-shrink: 0;
  min-width: 44px;
}

.route-map__ac-name {
  color: var(--c-text-soft);
  font-size: var(--fs-caption);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Action row (Plot / Add leg / Clear) ─────────────────────────────────── */

.route-map__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  flex-shrink: 0;
}

.route-map__btn {
  padding: var(--s-2) var(--s-3);
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  font-weight: var(--fw-semi);
  letter-spacing: var(--tr-wide);
  border-radius: var(--r-md);
  border: var(--bw-hair) solid transparent;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-quiet),
              color var(--dur-fast) var(--ease-quiet),
              border-color var(--dur-fast) var(--ease-quiet);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .route-map__btn { transition: none; }
}

/* Primary = ink fill, ivory text. The decisive CTA. */
.route-map__btn--primary {
  flex: 1 1 100%;
  background-color: var(--c-navy-900);
  color: var(--c-ivory);
}

.route-map__btn--primary:hover { background-color: var(--c-navy-700); }

.route-map__btn--primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Ghost = hairline outline, share a row. */
.route-map__btn--ghost {
  flex: 1;
  background: none;
  color: var(--c-text-soft);
  border-color: var(--c-rule);
}

.route-map__btn--ghost:hover {
  color: var(--c-text);
  border-color: var(--c-silver-dim);
}

/* ── Status line ──────────────────────────────────────────────────────────── */

.route-map__status {
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  color: var(--c-text-soft);
  padding: var(--s-1) 0;
  line-height: var(--lh-snug);
  flex-shrink: 0;
}

.route-map__status--error { color: var(--c-error); }

/* ── Distance result card ────────────────────────────────────────────────── */

.route-map__dist-box {
  background-color: var(--c-navy-900);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  flex-shrink: 0;
  color: var(--c-ivory);
}

.route-map__dist-box.hidden { display: none; }

.route-map__dist-label {
  font-family: var(--ff-sans);
  font-size: var(--fs-micro);
  color: var(--c-silver);
  letter-spacing: var(--tr-luxe);
  text-transform: uppercase;
  margin-bottom: var(--s-2);
}

.route-map__dist-total {
  font-family: var(--ff-serif);
  font-size: var(--fs-small);
  font-weight: var(--fw-regular);
  letter-spacing: var(--tr-snug);
  color: var(--c-ivory);
  line-height: var(--lh-tight);
  margin-bottom: var(--s-1);
}

.route-map__dist-gc {
  font-family: var(--ff-mono);
  font-size: var(--fs-caption);
  color: var(--c-silver);
  margin-bottom: var(--s-1);
}

.route-map__dist-time {
  font-family: var(--ff-sans);
  font-size: var(--fs-small);
  color: var(--c-silver);
}

/* ── Avoid-countries section ─────────────────────────────────────────────── */

.route-map__avoid {
  border-top: var(--bw-hair) solid var(--c-rule);
  padding-top: var(--s-3);
  flex-shrink: 0;
}

.route-map__avoid-label {
  font-family: var(--ff-sans);
  font-size: var(--fs-micro);
  font-weight: var(--fw-semi);
  color: var(--c-text-soft);
  letter-spacing: var(--tr-luxe);
  text-transform: uppercase;
  margin-bottom: var(--s-2);
}

.route-map__avoid-row {
  display: flex;
  gap: var(--s-2);
  position: relative;
}

.route-map__avoid-row .route-map__input { flex: 1; }

.route-map__avoid-row .route-map__btn { flex: 0 0 auto; padding: var(--s-2) var(--s-4); }

.route-map__avoid-row [data-rm-avoid-ac] { top: 100%; left: 0; right: 0; }

.route-map__avoid-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-3);
}

.route-map__avoid-tags:empty { margin-top: 0; }

/* Avoid chips — burgundy "excluded" register, used sparingly. */
.route-map__avoid-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-1) var(--s-3);
  background-color: color-mix(in srgb, var(--c-error) 9%, #fff);
  border: var(--bw-hair) solid color-mix(in srgb, var(--c-error) 26%, transparent);
  border-radius: var(--r-sm);
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  color: var(--c-error);
}

.route-map__avoid-tag-x {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: var(--fs-small);
  line-height: 1;
  padding: 0;
  opacity: 0.65;
  transition: opacity var(--dur-fast) var(--ease-quiet);
}

.route-map__avoid-tag-x:hover { opacity: 1; }

.route-map__avoid-empty {
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  color: var(--c-silver);
}

/* ── Nearby panel ─────────────────────────────────────────────────────────── */

[data-rm-panel="nearby"] .route-map__field--ac { margin-bottom: var(--s-4); }

/* Nearby search row: the input takes the space, the Search button hugs its
   label (without this it inherits the full-width primary-button flex). */
#rm-nearby-input { flex: 1; min-width: 0; }
[data-rm-panel="nearby"] .route-map__btn { flex: 0 0 auto; }

.route-map__nearby-origin {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--ff-sans);
  font-size: var(--fs-small);
  color: var(--c-text);
  margin-bottom: var(--s-3);
}

.route-map__nearby-origin.hidden { display: none; }

.route-map__nearby-pin-icon {
  width: 16px;
  height: 16px;
  fill: var(--c-navy-500);
  flex-shrink: 0;
}

/* Radius slider */
.route-map__radius-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}

.route-map__radius-label {
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  color: var(--c-text-soft);
  white-space: nowrap;
}

.route-map__radius-slider {
  flex: 1;
  accent-color: var(--c-navy-900);
  cursor: pointer;
}

.route-map__radius-value {
  font-family: var(--ff-mono);
  font-size: var(--fs-small);
  color: var(--c-text);
  min-width: 48px;
  text-align: right;
}

/* Result header */
.route-map__nearby-header {
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  color: var(--c-text-soft);
  margin-bottom: var(--s-2);
}

.route-map__nearby-empty {
  font-family: var(--ff-sans);
  font-size: var(--fs-small);
  color: var(--c-text-soft);
  padding: var(--s-3) 0;
}

.route-map__nearby-empty--error { color: var(--c-error); }

/* Scrollable result list */
.route-map__nearby-scroll {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  max-height: 320px;
  overflow-y: auto;
  padding-right: var(--s-1);
}

/* Individual nearby card */
.route-map__nearby-card {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3);
  background-color: #fff;
  border: var(--bw-hair) solid var(--c-rule);
  border-radius: var(--r-md);
  box-shadow: var(--sh-quiet);
  transition: border-color var(--dur-fast) var(--ease-quiet);
}

.route-map__nearby-card:hover { border-color: var(--c-silver-dim); }

.route-map__nearby-rank {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--c-navy-900);
  color: var(--c-ivory);
  font-family: var(--ff-sans);
  font-size: 11px;
  font-weight: var(--fw-semi);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.route-map__nearby-info { flex: 1; min-width: 0; }

.route-map__nearby-name {
  font-family: var(--ff-sans);
  font-size: var(--fs-small);
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.route-map__nearby-meta {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}

.route-map__nearby-icao {
  font-family: var(--ff-mono);
  font-size: var(--fs-caption);
  font-weight: var(--fw-semi);
  color: var(--c-navy-500);
}

.route-map__nearby-city {
  font-family: var(--ff-sans);
  font-size: var(--fs-caption);
  color: var(--c-text-soft);
}

.route-map__nearby-dists {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: 2px;
}

.route-map__nearby-nm {
  font-family: var(--ff-mono);
  font-size: var(--fs-caption);
  color: var(--c-text-soft);
}

/* Longest-runway readout on each nearby card (metres, from airports data [6]). */
.route-map__nearby-rwy {
  font-family: var(--ff-mono);
  font-size: var(--fs-caption);
  color: var(--c-text-soft);
}
.route-map__nearby-rwy::before {
  content: '·';
  margin-right: var(--s-2);
  color: var(--c-silver);
}

/* "CITY" tag on a Mapbox place suggestion in the Nearby typeahead. */
.route-map__ac-city {
  color: var(--c-warning);
  font-size: 9px;
  font-weight: var(--fw-semi);
  letter-spacing: var(--tr-extra);
}

/* ── Marker (via JS inline style) ────────────────────────────────────────── */
.route-map__marker { cursor: pointer; }

/* ── noscript fallback ────────────────────────────────────────────────────── */
.route-map__noscript {
  padding: var(--s-7) var(--s-5);
  text-align: center;
  color: var(--c-text-soft);
}
