/* La app del viaje. Colores de Telegram (themeParams → --tg-theme-*), con los nuestros si se abre fuera.
   Lo que se lee va en rem (crece con la letra del móvil); la barra de pestañas, con tope, como en iOS y Android. */
:root {
  color-scheme: light;
  --fondo: var(--tg-theme-bg-color, #ffffff);
  --fondo-2: var(--tg-theme-secondary-bg-color, #f1f2f5);
  --tarjeta: var(--tg-theme-section-bg-color, var(--fondo));
  --texto: var(--tg-theme-text-color, #111418);
  --boton-tg: var(--tg-theme-button-color, #2a7bc0);
  --enlace-tg: var(--tg-theme-link-color, #2a7bc0);
  --peligro-tg: var(--tg-theme-destructive-text-color, #d13b3b);
  /* AA garantizado: los grises y los azules de Telegram no siempre llegan a 4,5:1, así que se mezclan con el texto */
  --suave: #4b5260;
  --boton: #1f669f;
  --enlace: #1f669f;
  --peligro: #b02a2a;
  --borde: #d5d8de;
  --boton-texto: #ffffff;
  --guia: #b7791f;
  --comer: #c2410c;
  --parada: #1d6fa5;
  --hotel: #7e3ab0;
  --yo: #0f9d58;
  --radio: 14px;
  --sombra: 0 1px 2px rgb(0 0 0 / .08), 0 2px 10px rgb(0 0 0 / .06);
  --arriba: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
  --abajo: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --alto-barra: 64px;
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --suave: color-mix(in srgb, var(--texto) 74%, var(--fondo));
    --boton: color-mix(in srgb, var(--boton-tg) 62%, #000);
    --enlace: color-mix(in srgb, var(--enlace-tg) 64%, var(--texto));
    --peligro: color-mix(in srgb, var(--peligro-tg) 80%, var(--texto));
    --borde: color-mix(in srgb, var(--texto) 16%, var(--fondo));
  }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tema="claro"]) {
    color-scheme: dark;
    --fondo: var(--tg-theme-bg-color, #17212b);
    --fondo-2: var(--tg-theme-secondary-bg-color, #0e1621);
    --texto: var(--tg-theme-text-color, #f5f5f5);
    --boton-tg: var(--tg-theme-button-color, #5288c1);
    --enlace-tg: var(--tg-theme-link-color, #6ab3f3);
    --suave: #b8c0cc; --boton: #3d6e9f; --enlace: #8cc4f5; --peligro: #ff8a80; --borde: #33404d;
    --guia: #f0b429; --comer: #ff8a4c; --parada: #5cb3f0; --hotel: #c28dee; --yo: #34d07c;
  }
}
:root[data-tema="oscuro"] {
  color-scheme: dark;
  --fondo: var(--tg-theme-bg-color, #17212b);
  --fondo-2: var(--tg-theme-secondary-bg-color, #0e1621);
  --texto: var(--tg-theme-text-color, #f5f5f5);
  --boton-tg: var(--tg-theme-button-color, #5288c1);
  --enlace-tg: var(--tg-theme-link-color, #6ab3f3);
  --suave: #b8c0cc; --boton: #3d6e9f; --enlace: #8cc4f5; --peligro: #ff8a80; --borde: #33404d;
  --guia: #f0b429; --comer: #ff8a4c; --parada: #5cb3f0; --hotel: #c28dee; --yo: #34d07c;
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root[data-tema="oscuro"] {
    --suave: color-mix(in srgb, var(--texto) 76%, var(--fondo));
    --boton: color-mix(in srgb, var(--boton-tg) 66%, #000);
    --enlace: color-mix(in srgb, var(--enlace-tg) 70%, #fff);
    --peligro: color-mix(in srgb, var(--peligro-tg) 70%, #fff);
    --borde: color-mix(in srgb, var(--texto) 20%, var(--fondo));
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fondo-2); color: var(--texto);
  font: 400 1.0625rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--alto-barra) + var(--abajo));
  overscroll-behavior-y: none;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--enlace); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--enlace); outline-offset: 2px; border-radius: 6px; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.saltar { position: absolute; left: -999px; top: 0; z-index: 50; background: var(--fondo); padding: 12px; }
.saltar:focus { left: 8px; top: 8px; }
.suave { color: var(--suave); }
[hidden] { display: none !important; }

/* cabecera */
.cabecera {
  position: sticky; top: 0; z-index: 20; background: var(--fondo);
  padding: calc(10px + var(--arriba)) 16px 10px; border-bottom: 1px solid var(--borde);
}
.cabecera h1 { font-size: 1.25rem; line-height: 1.25; font-weight: 700; }
.cabecera p { font-size: .9375rem; }
.aviso-red {
  margin-top: 8px; padding: 8px 12px; border-radius: 10px; font-size: .9375rem;
  background: color-mix(in srgb, var(--guia) 18%, var(--fondo)); color: var(--texto);
}
main { outline: none; }
.vista { padding: 12px 16px 24px; }
.titulo-vista { font-size: 1.375rem; font-weight: 700; margin: 4px 0 12px; }

/* barra de pestañas (estructura: px con tope, como las barras del sistema) */
.pestanas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: var(--fondo); border-top: 1px solid var(--borde); padding-bottom: var(--abajo);
}
.pestanas button {
  flex: 1; min-height: var(--alto-barra); border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: min(.8125rem, 15px); font-weight: 600; color: var(--suave); padding: 6px 2px;
}
.pestanas button span { font-size: 22px; line-height: 1; }
.pestanas button[aria-current="page"] { color: var(--enlace); }
.pestanas button[aria-current="page"] span { transform: scale(1.08); }

/* chips (días, filtros, capas) */
.dias, .filtros, .capas { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.dias::-webkit-scrollbar, .filtros::-webkit-scrollbar, .capas::-webkit-scrollbar { display: none; }
.dias { display: grid; grid-template-columns: repeat(auto-fit, minmax(4.75rem, 1fr)); overflow: visible; }
.dias .chip { display: flex; flex-direction: column; align-items: center; gap: 2px; border-radius: 16px; padding: 8px 6px; white-space: normal; line-height: 1.2; }
.chip-icono { font-size: 1.25rem; }
.zona select { min-height: 44px; border-radius: 999px; border: 1.5px solid var(--borde); background: var(--tarjeta); padding: 8px 14px; font-weight: 600; }
.filtros { flex-wrap: wrap; overflow: visible; }
.chip {
  min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--borde);
  background: var(--tarjeta); color: var(--texto); font-weight: 600; font-size: 1rem; white-space: nowrap; cursor: pointer;
}
.chip[aria-selected="true"], .chip[aria-pressed="true"] { background: var(--boton); border-color: var(--boton); color: var(--boton-texto); }

/* tarjetas */
.tarjeta, .tarjetas > li {
  background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px 16px; margin: 0 0 12px;
}
.tarjetas { list-style: none; margin: 0; padding: 0; }
.tarjeta h3, .tarjetas h3 { font-size: 1.125rem; line-height: 1.3; font-weight: 700; }
.tarjeta p + p, .tarjetas p + p { margin-top: 6px; }
.etiqueta { display: inline-block; font-size: .875rem; font-weight: 700; padding: 2px 8px; border-radius: 6px;
  background: var(--fondo-2); color: var(--texto); margin: 0 6px 6px 0; }
.etiqueta.cerrado { background: color-mix(in srgb, var(--peligro) 16%, var(--fondo)); color: var(--peligro); }
.etiqueta.abierto { background: color-mix(in srgb, var(--yo) 16%, var(--fondo)); color: var(--texto); }

/* día */
.resumen-dia h3 { font-size: 1.25rem; }
.resumen-dia .marea { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--fondo-2); }
.horas { display: flex; gap: 8px; overflow-x: auto; margin: 10px -4px 0; padding: 4px; }
.hora { flex: 0 0 auto; min-width: 72px; text-align: center; padding: 8px 6px; border-radius: 12px; background: var(--fondo-2); font-size: .9375rem; }
.hora b { display: block; }
.plan { list-style: none; margin: 0; padding: 0; position: relative; }
.plan > li { display: grid; grid-template-columns: 3.6rem 1fr; gap: 0 10px; padding: 0 0 16px; position: relative; }
.plan > li::before { content: ""; position: absolute; left: 1.75rem; top: 2rem; bottom: 0; width: 2px; background: var(--borde); }
.plan > li:last-child::before { display: none; }
.plan .cuando { font-weight: 800; font-size: 1rem; padding-top: 2px; text-align: right; font-variant-numeric: tabular-nums; }
.plan .que { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 12px 14px; min-width: 0; }
.plan h3 { font-size: 1.0625rem; }
.plan .trayecto { font-size: .9375rem; margin-top: 2px; }
.plan .foto, .tarjetas .foto { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; margin-top: 10px; background: var(--fondo-2); display: block; }
details { margin-top: 6px; }
summary { cursor: pointer; color: var(--enlace); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 14px;
  border-radius: 12px; border: 0; background: var(--boton); color: var(--boton-texto); font-weight: 700; text-decoration: none; cursor: pointer;
  font-size: 1rem; text-align: center;
}
.boton.secundario { background: var(--fondo-2); color: var(--texto); border: 1.5px solid var(--borde); }
.boton.ancho { width: 100%; }
.boton:active { transform: scale(.98); }

/* mapa */
#v-mapa { padding: 8px 0 0; }
#v-mapa .capas { padding: 2px 16px 8px; }
.mapa { height: calc(100dvh - 210px - var(--arriba) - var(--abajo)); min-height: 320px; background: var(--fondo-2); }
.mapa-botones { position: absolute; right: 12px; bottom: 24px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.mapa-botones .boton { box-shadow: var(--sombra); }
.ficha {
  position: fixed; left: 8px; right: 8px; bottom: calc(var(--alto-barra) + var(--abajo) + 8px); z-index: 600;
  background: var(--tarjeta); border-radius: 18px; box-shadow: 0 6px 30px rgb(0 0 0 / .25); padding: 14px 16px 16px;
  max-height: 55vh; overflow: auto;
}
.ficha .cerrar { float: right; min-width: 44px; min-height: 44px; border: 0; background: var(--fondo-2); border-radius: 50%; font-size: 1.25rem; cursor: pointer; }
.zona-punto { display: flex; align-items: center; justify-content: center; }
.punto { display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 2px solid #fff;
  color: #fff; font-weight: 800; font-size: 13px; line-height: 1; box-shadow: 0 1px 4px rgb(0 0 0 / .35); width: 28px; height: 28px; }
.punto.guia { background: #8a5a12; width: 30px; height: 30px; }
.punto.comer { background: #b13a0a; font-size: 12px; width: 24px; height: 24px; }
.punto.parada { background: #175e8c; width: 24px; height: 24px; font-size: 12px; }
.punto.hotel { background: #6b2f98; width: 34px; height: 34px; font-size: 15px; }
.punto.yo { background: #0b7a43; width: 26px; height: 26px; box-shadow: 0 0 0 6px rgb(11 122 67 / .25); }
.lineas { white-space: pre-line; }
.leaflet-container { font: inherit; }
.leaflet-tile-container img.leaflet-tile { width: 256.5px !important; height: 256.5px !important; } /* sin costuras entre teselas */
:root[data-tema="oscuro"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
@media (prefers-color-scheme: dark) { :root:not([data-tema]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); } }
.leaflet-control-attribution { font-size: 11px; }

/* gastos */
.formulario { display: grid; gap: 10px; }
.formulario label { font-weight: 600; display: grid; gap: 4px; }
.formulario input, .formulario select {
  min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--borde); background: var(--fondo); width: 100%;
}
.fila-2 { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; }
@media (max-width: 360px) { .fila-2 { grid-template-columns: 1fr; } }
.total { font-size: 1.75rem; font-weight: 800; }
.movimientos { list-style: none; padding: 0; margin: 0; }
.movimientos li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.movimientos li:last-child { border-bottom: 0; }
.mensaje { margin-top: 8px; font-weight: 600; }

/* más */
.lista-mas { list-style: none; margin: 0; padding: 0; background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; }
.lista-mas button, .lista-mas a {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 16px; border: 0; background: none;
  text-align: left; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--texto); font-size: 1.0625rem;
}
.lista-mas li + li { border-top: 1px solid var(--borde); }
.lista-mas .icono { font-size: 1.375rem; width: 1.75rem; text-align: center; }
.lista-mas .detalle { display: block; font-weight: 400; font-size: .9375rem; color: var(--suave); }
.volver { margin-bottom: 12px; }
.consejos { margin: 0; padding-left: 1.2rem; }
.consejos li + li { margin-top: 8px; }
.sin-acceso { padding: 32px 20px; text-align: center; }
.sin-acceso h2 { font-size: 1.375rem; margin-bottom: 8px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
@media (min-width: 700px) { .vista { max-width: 720px; margin: 0 auto; } #v-mapa { max-width: none; } }
