/* ==========================================================================
   Ruta de ida y vuelta — style.css

   Dirección visual: señalética de carretera.
   - Tinta (casi negra azulada) para estructura y texto.
   - Amarillo "poste kilométrico" solo para la acción principal.
   - Azul y rojo reservados para el mapa (ruta original / ruta generada),
     así el color de la interfaz nunca compite con el significado del mapa.
   - Tipografía: Barlow Semi Condensed para cifras y títulos (como los
     letreros de ruta), Barlow para texto corrido.

   Secciones:
     1. Variables y base
     2. Cabecera
     3. Layout (panel + mapa)
     4. Bloques, hechos y campos
     5. Botones, chips y pestañas
     6. Lecturas numéricas y barra de ruta
     7. Resultados (modo múltiple)
     8. Mensajes
     9. Mapa, leyenda y marcadores
    10. Responsive y accesibilidad
   ========================================================================== */

/* ---------- 1. Variables y base ---------- */
:root {
  --ink: #1b242b;
  --ink-soft: #3a4650;
  --muted: #64717b;
  --paper: #f4f6f5;
  --surface: #ffffff;
  --line: #dde2e0;
  --sign: #f5c400;          /* amarillo de señalización: acción principal */
  --sign-dark: #d9ab00;
  --route-blue: #2563eb;    /* = color de la ruta original en el mapa */
  --route-red: #dc2626;     /* = color de la ruta generada en el mapa */
  --ok: #1d7a4b;
  --warn: #9a6700;
  --danger: #b42318;

  --font-body: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;

  --header-h: 112px;
  --radius: 8px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

.num { font-variant-numeric: tabular-nums; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

[hidden] { display: none !important; }

/* ---------- 2. Cabecera ---------- */
.app-header {
  background: var(--ink);
  color: #fff;
  border-bottom: 4px solid var(--sign);
}

.app-header__inner {
  position: relative;   /* ancla el botón de apoyo */
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 24px 16px;
}

.app-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 3.4vw, 2.2rem);
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.app-subtitle {
  margin: 6px 0 0;
  max-width: 70ch;
  font-size: 0.95rem;
  color: #c3ccd2;
}

/* ---------- 3. Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  /* En escritorio el panel hace scroll por dentro y el mapa llena el resto. */
  height: calc(100dvh - var(--header-h));
  min-height: 560px;
}

.panel {
  min-width: 0;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 8px 24px 32px;
}

.map-pane {
  position: relative;
  min-height: 360px;
  background: #e6ebe8;
}

#map {
  position: absolute;
  inset: 0;
}

/* ---------- 4. Bloques, hechos y campos ---------- */
.block { padding: 20px 0; }
.block + .block,
.message + .controls,
.controls { border-top: 1px solid var(--line); }
.block--tab { border-top: 0; padding-top: 18px; }

.block__title {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
}

/* El fieldset se usa solo para deshabilitar todo en bloque */
.controls {
  margin: 0;
  padding: 0;
  min-width: 0;
  border: 0;
}
.controls:disabled { opacity: 0.45; }

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px;
  border: 2px dashed #b9c2c7;
  border-radius: var(--radius);
  background: var(--paper);
  transition: border-color 0.15s, background-color 0.15s;
}
.drop-zone.is-dragover {
  border-color: var(--ink);
  background: #fff8d6;
}
.drop-zone__text { margin: 0; font-weight: 500; }
.drop-zone__hint { margin: 0; font-size: 0.875rem; color: var(--muted); }

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin: 16px 0 0;
}
.facts__item { min-width: 0; }
.facts__item--wide { grid-column: 1 / -1; }
.facts dt { font-size: 0.8125rem; color: var(--muted); }
.facts dd {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}
.facts__item--wide dd { font-family: var(--font-body); font-size: 0.95rem; font-weight: 500; }

.field { display: block; }
.field__label { display: block; margin-bottom: 6px; font-weight: 500; }
.field__control {
  display: flex;
  align-items: stretch;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.field__control:focus-within { outline: 3px solid var(--sign); outline-offset: 2px; }
.field__control input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.75rem;
  color: var(--ink);
  outline: none;
}
.field__suffix {
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.125rem;
}

.hint { margin: 10px 0 0; font-size: 0.875rem; color: var(--muted); }
.hint--lead { margin: 0 0 14px; font-size: 0.9375rem; }
.hint.is-error { color: var(--danger); font-weight: 500; }

/* ---------- 5. Botones, chips y pestañas ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 20px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.0625rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background-color 0.12s, transform 0.12s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: 0.45; }

.btn--primary { background: var(--sign); color: var(--ink); }
.btn--primary:hover:not(:disabled) { background: var(--sign-dark); }

.btn--secondary { background: #fff; color: var(--ink); }
.btn--secondary:hover:not(:disabled) { background: var(--paper); }

.btn--small { min-height: 38px; padding: 6px 14px; font-size: 0.9375rem; }
.btn--reverse { margin-top: 14px; }

/* Casilla de verificación con nota */
.check { display: flex; align-items: flex-start; gap: 10px; margin-top: 14px; cursor: pointer; font-weight: 500; }
.check input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--ink); }
.check input:focus-visible { outline: 3px solid var(--sign); outline-offset: 2px; }
.check__note { display: block; margin-top: 2px; font-size: 0.8125rem; font-weight: 400; color: var(--muted); }

/* Etiquetas de kilómetro sobre la ruta generada */
.km-icon { background: transparent; border: 0; }
.km-mark {
  display: inline-block;
  transform: translate(-50%, -50%);
  padding: 0 6px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.6875rem;
  line-height: 16px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.legend__check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.legend__check input { margin: 0; accent-color: var(--ink); }
.legend__check input:focus-visible { outline: 3px solid var(--sign); outline-offset: 2px; }
.btn[aria-pressed="true"],
.btn--secondary[aria-pressed="true"]:hover:not(:disabled) { background: var(--ink); color: #fff; }

.btn.is-busy { position: relative; pointer-events: none; opacity: 0.7; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1 1 150px; }

.btn:focus-visible,
.chip:focus-visible,
.tab:focus-visible,
.result__btn:focus-visible {
  outline: 3px solid var(--route-blue);
  outline-offset: 2px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Chip de distancia: sirve como <button> (modo simple) y como <label> con checkbox (modo múltiple) */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.0625rem;
  cursor: pointer;
  user-select: none;
}
button.chip:hover { background: var(--paper); }
.chip.is-active { background: var(--ink); color: #fff; }

.chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.chip:has(input:checked) { background: var(--ink); color: #fff; }
.chip:has(input:focus-visible) { outline: 3px solid var(--route-blue); outline-offset: 2px; }
.chip.is-unavailable {
  border-style: dashed;
  border-color: #aab4ba;
  color: #8a959c;
  background: transparent;
  cursor: not-allowed;
  text-decoration: line-through;
}
.chip.is-unavailable input { cursor: not-allowed; }

.tabs { display: flex; gap: 0; margin-top: 18px; border-bottom: 2px solid var(--line); }
.tab {
  appearance: none;
  flex: 1;
  padding: 10px 8px;
  margin-bottom: -2px;
  border: 0;
  border-bottom: 4px solid transparent;
  background: transparent;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--sign); }

/* ---------- 6. Lecturas numéricas y barra de ruta ---------- */
.route-bar {
  position: relative;
  height: 12px;
  margin-top: 20px;
  border-radius: 6px;
  background: var(--route-blue);
  opacity: 0.9;
  overflow: hidden;
}
/* La parte "recorrida" en la ida se pinta en rojo, igual que en el mapa */
.route-bar__fill {
  height: 100%;
  width: 0;
  background: var(--route-red);
  border-radius: 6px 0 0 6px;
  transition: width 0.25s ease;
}
.route-bar__caption { margin: 6px 0 0; font-size: 0.8125rem; color: var(--muted); }

.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.readout {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-left: 4px solid var(--ink);
  background: var(--paper);
}
.readout--wide { grid-column: 1 / -1; }
.field--compact .field__control input { font-size: 1.25rem; }
.field--compact .field__suffix { font-size: 1rem; }
.readout__label { font-size: 0.8125rem; color: var(--muted); }
.readout__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.75rem;
  line-height: 1.1;
}

/* ---------- 7. Resultados (modo múltiple) ---------- */
.results { list-style: none; margin: 18px 0 0; padding: 0; }
.result {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.result:last-child { border-bottom: 1px solid var(--line); }
.result.is-selected { box-shadow: inset 4px 0 0 var(--route-red); padding-left: 12px; }
.result__label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.75rem;
  line-height: 1;
}
.result__detail { display: flex; flex-direction: column; font-size: 0.875rem; color: var(--ink-soft); }
.result__actions { display: flex; gap: 6px; }
.result__btn {
  appearance: none;
  padding: 6px 12px;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
}
.result__btn:hover { background: var(--paper); }

/* ---------- 8. Mensajes ---------- */
.message {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-left: 4px solid var(--ink);
  background: var(--paper);
  font-size: 0.9375rem;
}
.message p { margin: 0; }
.message p + p { margin-top: 6px; }
.message--error   { border-left-color: var(--danger); background: #fdeceb; color: #6e1710; }
.message--warn    { border-left-color: var(--warn);   background: #fff6dc; color: #5c3d00; }
.message--success { border-left-color: var(--ok);     background: #e6f4ec; color: #0f4a2b; }

/* ---------- 9. Mapa, leyenda y marcadores ---------- */
.legend {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 500; /* por encima de los paneles de Leaflet */
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  max-width: calc(100% - 80px);   /* deja libres los botones de zoom */
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
  font-size: 0.8125rem;
  font-weight: 500;
}
.legend li { display: flex; align-items: center; gap: 6px; }
.legend__line { width: 22px; height: 5px; border-radius: 3px; }
.legend__line--original  { background: var(--route-blue); }
.legend__line--generated { background: var(--route-red); }

/* Marcadores del mapa (divIcon de Leaflet) */
.pin-icon { background: transparent; border: 0; }
.pin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1;
}
.pin--start { background: #16803c; }
.pin--turn  { background: var(--route-red); }
.pin--legend { width: 20px; height: 20px; border-width: 2px; font-size: 0.6875rem; box-shadow: none; }

/* ---------- 10. Responsive y accesibilidad ---------- */
/* Escritorio: el cuerpo ocupa justo la pantalla y el mapa toma lo que sobra bajo la
 * cabecera, sin importar cuánto mida ésta (así el perfil flotante nunca queda fuera). */
@media (min-width: 861px) {
  body { display: flex; flex-direction: column; height: 100dvh; }
  .layout { flex: 1 1 0; height: auto; min-height: 0; }
}

@media (max-width: 860px) {
  :root { --header-h: 0px; }

  .layout {
    display: block;
    height: auto;
    min-height: 0;
  }
  .panel {
    overflow: visible;
    border-right: 0;
    padding: 4px 16px 24px;
  }
  .map-pane {
    height: 68dvh;
    min-height: 380px;
  }
  .app-header__inner { padding: 14px 16px 12px; }
  .app-subtitle { font-size: 0.875rem; }
}

@media (max-width: 420px) {
  .readouts { grid-template-columns: 1fr; }
  .result { grid-template-columns: 52px 1fr; }
  .result__actions { grid-column: 1 / -1; }
  .result__btn { flex: 1; }
}

/* ---------- Perfil de elevación (flotante sobre el mapa) ---------- */
.profile {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 28px;           /* deja libre la atribución del mapa */
  z-index: 500;           /* por encima de los paneles de Leaflet */
  max-width: 620px;
  padding: 8px 12px 10px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}
.profile__head { display: flex; align-items: baseline; gap: 10px; }
.profile__title { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 0.9375rem; white-space: nowrap; }
.profile__caption { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8125rem; color: var(--muted); }
.profile__toggle {
  appearance: none;
  padding: 2px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.profile__toggle:focus-visible { outline: 3px solid var(--sign); outline-offset: 2px; }
.profile__body { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 4px; }
.profile__chart { flex: 1 1 240px; min-width: 0; }
.profile__svg { display: block; width: 100%; height: auto; }
.profile__axis, .profile__grid { stroke: var(--line); stroke-width: 1; }
.profile__grid { stroke-dasharray: 3 3; }
.profile__area { fill: var(--ink); fill-opacity: 0.12; }
.profile__line { fill: none; stroke: var(--ink); stroke-width: 1.75; stroke-linejoin: round; }
.profile__label { fill: var(--muted); font-size: 9px; font-family: var(--font-body); }
.profile__stats { display: grid; grid-template-columns: auto auto; gap: 4px 16px; flex: 0 0 auto; margin: 0; }
.profile__stats dt { font-size: 0.75rem; color: var(--muted); }
.profile__stats dd { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 1rem; }
.profile__empty { margin: 0; font-size: 0.875rem; color: var(--muted); }
@media (max-width: 520px) {
  .profile__stats { grid-template-columns: repeat(4, auto); width: 100%; justify-content: space-between; gap: 4px 8px; }
  .profile__stats dd { font-size: 0.9375rem; }
}

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

/* ---------- 11. Firma, "Insertar en tu web" y modo incrustado ---------- */
.app-byline {
  margin: 10px 0 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--sign);
}

.embed { padding: 16px 0; border-top: 1px solid var(--line); }
.embed summary {
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.125rem;
}
.embed summary:focus-visible { outline: 3px solid var(--route-blue); outline-offset: 2px; }
.embed[open] summary { margin-bottom: 10px; }
.embed__row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 500; }
.embed__row input {
  width: 96px;
  padding: 6px 10px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 6px;
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.embed__code {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  line-height: 1.45;
  resize: vertical;
}

.credit { padding-top: 16px; border-top: 1px solid var(--line); }
.credit p { margin: 0; }
.credit__name { font-family: var(--font-display); font-weight: 600; font-size: 1.0625rem; }
.credit__note { margin-top: 2px; font-size: 0.8125rem; color: var(--muted); }

/* Modo incrustado (?embed=1): sin cabecera ni bloque de inserción; se conserva la firma */
.is-embed { --header-h: 0px; }
.is-embed .app-header,
.is-embed .embed { display: none; }

/* Selector de unidad (km | mi) */
.unit-row { display: flex; align-items: center; gap: 8px; padding: 14px 0 10px; }
.unit-row__label { margin-right: 4px; font-size: 0.8125rem; color: var(--muted); }

/* Botón de apoyo (corazón): enlaza a un mensaje de Instagram */
.donate {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.donate:focus-visible { outline: 3px solid var(--sign); outline-offset: 2px; }
.donate__icon { flex: none; }
.donate--header {
  position: absolute;
  top: 18px;
  right: 24px;
  border: 2px solid var(--sign);
  color: var(--sign);
}
.donate--header:hover { background: var(--sign); color: var(--ink); }
.donate--footer {
  margin-top: 10px;
  border: 2px solid var(--ink);
  color: var(--ink);
}
.donate--footer:hover { background: var(--ink); color: #fff; }
@media (max-width: 860px) {
  .donate--header { position: static; margin-top: 10px; }
}
@media (prefers-reduced-motion: reduce) { .donate { transition: none; } }
