:root {
  --bosque: #1f3d2b;
  --bosque-2: #2c5a3e;
  --musgo: #5b8a63;
  --piedra: #f5f2ea;
  --piedra-2: #e8e3d6;
  --tinta: #18201b;
  --gris: #66706a;
  --blanco: #ffffff;
  --verde: #2f9e57;
  --ambar: #e3a21a;
  --rojo: #d23c2a;
  --agua: #2b7bd6;
  --sombra: 0 6px 24px rgba(20, 30, 24, .18);
  --radio: 16px;
  --nav-h: 64px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--tinta);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--piedra); }
button { font: inherit; cursor: pointer; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#mapa { position: fixed; inset: 0; z-index: 0; background: #dfe6dc; }

/* ---------- Barra superior ---------- */
.barra-sup {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 16px; right: 84px;
  display: flex; gap: 8px; z-index: 500; max-width: 560px;
}
.buscador { position: relative; flex: 1; }
.buscador input {
  width: 100%; height: 46px; border: 0; border-radius: 23px; padding: 0 16px 0 40px;
  background: var(--blanco); box-shadow: var(--sombra); font-size: 16px; outline: none;
}
.buscador .lupa { position: absolute; left: 15px; top: 11px; font-size: 20px; color: var(--gris); }
.resultados {
  position: absolute; top: 52px; left: 0; right: 0; background: var(--blanco);
  border-radius: 14px; box-shadow: var(--sombra); overflow: hidden; max-height: 55vh; overflow-y: auto;
}
.resultados button {
  display: flex; gap: 10px; align-items: center; width: 100%; padding: 11px 14px;
  border: 0; background: none; text-align: left; border-bottom: 1px solid var(--piedra-2);
}
.resultados button:hover { background: var(--piedra); }
.resultados small { color: var(--gris); margin-left: auto; white-space: nowrap; }

.btn-redondo {
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--blanco);
  box-shadow: var(--sombra); font-size: 20px; flex: none;
}
.btn-ubicar { position: fixed; right: 16px; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); z-index: 400; }
.btn-sos {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 16px; z-index: 500;
  width: 56px; height: 46px; border-radius: 23px; border: 0; background: var(--rojo); color: #fff;
  font-weight: 700; letter-spacing: .5px; box-shadow: 0 6px 20px rgba(210, 60, 42, .45);
}

/* ---------- Panel de capas ---------- */
.panel-flotante {
  position: fixed; top: calc(66px + env(safe-area-inset-top)); left: 16px; right: 16px; max-width: 380px;
  background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px 16px; z-index: 600;
  max-height: calc(100vh - 170px); overflow-y: auto;
}
.panel-flotante h3 { margin: 6px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--gris); }
.lista-opciones { display: grid; gap: 6px; margin-bottom: 10px; }
.lista-opciones label {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--piedra);
}
.lista-opciones label small { margin-left: auto; color: var(--gris); }
.info-acampada { background: #eef5ef; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.info-acampada summary { font-weight: 600; cursor: pointer; }
.nota { font-size: 12px; color: var(--gris); }

/* ---------- Navegación ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 700; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--bosque); display: flex;
}
.nav button { flex: 1; border: 0; background: none; color: rgba(255,255,255,.62); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; }
.nav button i { font-style: normal; font-size: 21px; filter: grayscale(.5); }
.nav button.activo { color: #fff; }
.nav button.activo i { filter: none; transform: translateY(-1px); }

/* ---------- Hoja inferior ---------- */
.hoja {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 650;
  background: var(--piedra); border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  height: 62vh; transition: transform .32s cubic-bezier(.2,.8,.2,1), height .32s;
  display: flex; flex-direction: column;
}
.hoja[data-estado="cerrada"] { transform: translateY(110%); }
.hoja[data-estado="mini"] { height: 132px; }
.hoja[data-estado="grande"] { height: calc(100vh - var(--nav-h) - 70px); }
.asa { border: 0; background: none; padding: 10px 0 6px; flex: none; }
.asa span { display: block; width: 44px; height: 5px; border-radius: 3px; background: #c9c2b2; margin: 0 auto; }
.hoja-contenido { overflow-y: auto; padding: 0 16px 24px; flex: 1; overscroll-behavior: contain; }
.seccion { display: none; }
.seccion.visible { display: block; }

@media (min-width: 900px) {
  .hoja {
    left: 16px; right: auto; width: 420px; top: 74px; bottom: calc(var(--nav-h) + 16px);
    height: auto !important; border-radius: 20px;
  }
  .hoja[data-estado="cerrada"] { transform: translateX(-120%); }
  .asa { display: none; }
  .hoja-contenido { padding-top: 16px; }
  .nav { left: 50%; right: auto; transform: translateX(-50%); bottom: 16px; border-radius: 20px; width: 460px; height: var(--nav-h); box-shadow: var(--sombra); padding: 0; }
  .hoja { bottom: calc(var(--nav-h) + 32px); }
  .btn-ubicar { bottom: 100px; }
  .barra-sup { left: 452px; }
  .hoja[data-estado="cerrada"] ~ .barra-sup { left: 16px; }
  .panel-flotante { left: auto; right: 16px; }
}

/* ---------- Componentes de las secciones ---------- */
.titulo-seccion { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 4px 0 12px; }
.titulo-seccion h2 { margin: 0; font-size: 22px; }
.titulo-seccion small { color: var(--gris); }
.tarjeta { background: var(--blanco); border-radius: var(--radio); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.tarjeta h3 { margin: 0 0 8px; font-size: 16px; }
.tarjeta p { margin: 6px 0; line-height: 1.45; }
.fila { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fila > * { flex: 1; min-width: 0; }
.campo { display: grid; gap: 4px; margin-bottom: 10px; font-size: 14px; }
.campo span { color: var(--gris); font-size: 13px; }
.campo input, .campo select { height: 42px; border: 1px solid var(--piedra-2); border-radius: 10px; padding: 0 10px; background: #fff; width: 100%; }
.check { display: flex; gap: 10px; align-items: center; padding: 7px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--bosque); flex: none; }

.btn { border: 0; border-radius: 12px; padding: 11px 14px; background: var(--piedra-2); font-weight: 600; text-align: center; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--tinta); }
.btn.primario { background: var(--bosque); color: #fff; }
.btn.verde { background: #25d366; color: #0b3d1e; }
.btn.rojo { background: var(--rojo); color: #fff; }
.btn.bloque { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--piedra); border-radius: 12px; padding: 9px 10px; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 12px; color: var(--gris); }

.perfil-alt { width: 100%; height: 110px; display: block; touch-action: none; }

.semaforo { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 14px; margin-bottom: 10px; }
.semaforo .luz { width: 44px; height: 44px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 0 rgba(0,0,0,.15); }
.semaforo b { font-size: 18px; display: block; }
.sem-0 { background: #e5f4ea; } .sem-0 .luz { background: var(--verde); }
.sem-1 { background: #fbf1d9; } .sem-1 .luz { background: var(--ambar); }
.sem-2 { background: #fbe3df; } .sem-2 .luz { background: var(--rojo); }
.motivos { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.motivos li { display: flex; gap: 8px; font-size: 14px; line-height: 1.35; }
.motivos li::before { content: ''; width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; flex: none; }
.motivos .n0::before { background: var(--verde); } .motivos .n1::before { background: var(--ambar); } .motivos .n2::before { background: var(--rojo); }

.tabla-horas { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla-horas th { text-align: left; color: var(--gris); font-weight: 500; padding: 4px 3px; }
.tabla-horas td { padding: 6px 3px; border-top: 1px solid var(--piedra-2); white-space: nowrap; }
.dias { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.dia { flex: none; border: 2px solid transparent; background: var(--blanco); border-radius: 14px; padding: 8px 12px; text-align: center; min-width: 86px; }
.dia.activo { border-color: var(--bosque); }
.dia .ico { font-size: 24px; }
.dia small { display: block; color: var(--gris); }
.alerta-roja { color: var(--rojo); font-weight: 600; }
.chip { display: inline-block; background: var(--piedra); border-radius: 999px; padding: 3px 10px; font-size: 12px; margin: 2px 4px 2px 0; }

.cat-mochila h4 { margin: 14px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--gris); }
.item-mochila { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--piedra-2); }
.item-mochila input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--bosque); flex: none; }
.item-mochila .nom { flex: 1; }
.item-mochila .porque { display: block; font-size: 12px; color: var(--gris); }
.item-mochila .peso { color: var(--gris); font-size: 13px; white-space: nowrap; }
.barra-peso { height: 10px; border-radius: 5px; background: var(--piedra-2); overflow: hidden; margin: 6px 0; }
.barra-peso div { height: 100%; background: var(--musgo); transition: width .3s; }

.lista-rutas button { display: flex; width: 100%; justify-content: space-between; border: 0; background: var(--piedra); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; text-align: left; }
.vacio { text-align: center; color: var(--gris); padding: 16px 8px; }
.proximamente { border: 2px dashed var(--piedra-2); background: transparent; box-shadow: none; }

/* ---------- Barra de dibujo ---------- */
.barra-dibujo {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 680;
  background: var(--bosque); color: #fff; border-radius: var(--radio); padding: 12px 14px; box-shadow: var(--sombra);
  max-width: 520px; margin: 0 auto;
}
.barra-dibujo .txt { font-size: 14px; margin-bottom: 8px; }
.barra-dibujo .acciones { display: flex; gap: 8px; }
.barra-dibujo button { flex: 1; border: 0; border-radius: 10px; padding: 10px; background: rgba(255,255,255,.15); color: #fff; font-weight: 600; }
.barra-dibujo button.primario { background: #fff; color: var(--bosque); }

/* ---------- Banner aviso ---------- */
.avisos-sup { position: fixed; top: calc(66px + env(safe-area-inset-top)); left: 16px; right: 16px; z-index: 550; max-width: 560px; display: grid; gap: 8px; pointer-events: none; }
.avisos-sup > * { pointer-events: auto; }
.banner { border-radius: 14px; padding: 10px 12px; font-size: 14px; box-shadow: var(--sombra); }
.banner-gris { background: #39423c; color: #fff; }
.banner-aviso {
  background: var(--bosque); color: #fff; border-radius: 14px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; box-shadow: var(--sombra);
}
.banner-aviso.vencido { background: var(--rojo); animation: latido 1.2s infinite; }
.banner-aviso .txt { flex: 1; font-size: 14px; }
.banner-aviso button { border: 0; border-radius: 10px; padding: 8px 10px; background: #fff; color: var(--tinta); font-weight: 600; }
@keyframes latido { 50% { box-shadow: 0 0 0 8px rgba(210,60,42,.25); } }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(15, 22, 18, .55); z-index: 900; display: flex; align-items: flex-end; justify-content: center; }
.modal-caja { background: var(--piedra); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); position: relative; }
@media (min-width: 600px) { .modal { align-items: center; } .modal-caja { border-radius: 22px; } }
.modal-cerrar { position: absolute; top: 12px; right: 12px; border: 0; background: var(--piedra-2); width: 34px; height: 34px; border-radius: 50%; }
.coords-grandes { font-size: 26px; font-weight: 700; text-align: center; letter-spacing: .5px; padding: 14px; background: #fff; border-radius: 14px; margin: 10px 0; font-variant-numeric: tabular-nums; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 90px); z-index: 1000; background: var(--tinta); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: var(--sombra); }

/* ---------- Marcadores ---------- */
.mk { display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); font-size: 14px; line-height: 1; }
.mk-refugio { background: #b4532a; width: 30px; height: 30px; }
.mk-libre { background: #8a6b4f; width: 26px; height: 26px; }
.mk-agua { background: var(--agua); width: 20px; height: 20px; font-size: 10px; }
.mk-agua.seca { background: #9aa4ad; }
.mk-cima { background: transparent; border: 0; box-shadow: none; width: auto; height: auto; flex-direction: column; font-size: 11px; font-weight: 600; color: var(--tinta); text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; white-space: nowrap; border-radius: 0; }
.mk-cima i { font-style: normal; color: #6b3d1f; font-size: 14px; }
.mk-camping { background: #2f8a5f; width: 26px; height: 26px; }
.mk-punto { background: var(--bosque); width: 16px; height: 16px; }
.mk-yo { background: var(--agua); width: 18px; height: 18px; box-shadow: 0 0 0 6px rgba(43,123,214,.25); }
.cluster { border-radius: 50%; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); font-size: 12px; }

.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-popup-content { margin: 12px 14px; font-family: inherit; font-size: 14px; min-width: 200px; }
.pop h4 { margin: 0 0 2px; font-size: 16px; }
.pop .sub { color: var(--gris); font-size: 13px; margin-bottom: 8px; }
.pop .acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.pop .acciones .btn { padding: 8px; font-size: 13px; }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-bottom.leaflet-right { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .leaflet-bottom.leaflet-right { bottom: 0; } }
.leaflet-top.leaflet-left { display: none; }

/* ---------- Comunidad ---------- */
.nav button span { font-size: 11px; }
.segmentado { display: flex; background: var(--piedra-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.segmentado button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px 6px; font-weight: 600; color: var(--gris); }
.segmentado button.activo { background: var(--blanco); color: var(--tinta); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.chip-activo { background: var(--bosque) !important; color: #fff; }
button.chip { cursor: pointer; font: inherit; font-size: 12px; }
.tarjeta-salida { display: block; width: 100%; text-align: left; border: 0; font: inherit; color: inherit; }
.tarjeta-salida:hover { box-shadow: 0 2px 10px rgba(0,0,0,.1); }
.mk-salida { background: #6b4fa0; width: 30px; height: 30px; }
.chat { max-height: 260px; overflow-y: auto; display: grid; gap: 6px; padding: 2px; }
.msj { background: var(--piedra); border-radius: 12px; padding: 7px 10px; font-size: 14px; max-width: 88%; justify-self: start; overflow-wrap: anywhere; }
.msj.mio { background: #dcefe1; justify-self: end; }
.msj small { display: block; color: var(--gris); font-size: 11px; margin-top: 2px; }
.tipos-parte { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0 12px; }
.tipos-parte label { cursor: pointer; }
.tipos-parte input { position: absolute; opacity: 0; pointer-events: none; }
.tipos-parte span { display: block; text-align: center; background: var(--blanco); border: 2px solid var(--piedra-2); border-radius: 12px; padding: 6px 2px; font-size: 11px; line-height: 1.5; }
.tipos-parte input:checked + span { border-color: var(--bosque); background: #eef5ef; }
.tipos-parte input:focus-visible + span { outline: 2px solid var(--bosque); outline-offset: 2px; }
textarea { font: inherit; width: 100%; }

/* ---------- Revisión: móvil, legal y funciones nuevas ---------- */
.campo input, .campo select, textarea, .chat input, #m-nuevo { font-size: 16px; }
a { color: var(--bosque-2); }
.acciones.tres { grid-template-columns: 1fr 1fr 1fr !important; }
.pop .acciones.tres { margin-top: 6px; }
.mk-cima.hecha { color: #8a5a00; }
.fila-ruta { display: flex; gap: 6px; margin-bottom: 6px; }
.fila-ruta > button:first-child { flex: 1; margin: 0; min-width: 0; }
.fila-ruta > button:first-child span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quitar { flex: none; width: 40px; border: 0; border-radius: 10px; background: var(--piedra); color: var(--gris); }
.lista-rutas .fila-ruta button:first-child { display: flex; justify-content: space-between; gap: 8px; border: 0; background: var(--piedra); border-radius: 10px; padding: 10px 12px; text-align: left; }
.legal-links { text-align: center; font-size: 13px; margin: 16px 0 4px; }
.aviso-cookies {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 800; max-width: 460px;
  background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra); padding: 12px 14px; display: flex; gap: 12px; align-items: center;
}
.aviso-cookies p { margin: 0; font-size: 13px; line-height: 1.4; flex: 1; }
.aviso-cookies .btn { flex: none; }
.barra-grabar { background: #1d3557; }
.grab-datos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; text-align: center; }
.grab-datos b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.grab-datos span { font-size: 11px; opacity: .75; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #7fb48a; outline-offset: 2px; }
@media (max-width: 360px) {
  .nav button span { font-size: 10px; }
  .nav button i { font-size: 19px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .barra-sup { right: 78px; left: 10px; }
  .btn-sos { right: 10px; width: 52px; }
  .hoja-contenido { padding: 0 12px 24px; }
  .aviso-cookies { flex-direction: column; align-items: stretch; }
}
@media (min-width: 900px) {
  .avisos-sup { left: 452px; }
  .aviso-cookies { left: 50%; right: auto; transform: translateX(-50%); width: 460px; bottom: 100px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.lista-rutas .quitar { width: 40px; flex: none; margin: 0; justify-content: center; padding: 0; }
.lista-rutas .fila-ruta button:first-child { width: auto; }
.tabla-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
