/* =====================================================================
   ZEN CONTINUUM · capa de app (PWA)
   Se carga DESPUÉS de zen-continuum.css (que queda intacto, tal como se
   aprobó). Aquí no hay dirección de arte nueva: no se declara ni un HEX,
   ni un tamaño tipográfico, ni un componente. Solo se resuelve el shell:
   viewport real, área segura de iOS, scroll interno, foco táctil y las
   tres piezas de servicio (aviso de instalación, menú de demo, toast).

   Base de los wireframes: 390 × 844 fijos. Aquí: 360–430 px reales,
   100dvh, sin scroll horizontal y sin scroll de documento.
   ===================================================================== */

/* ---------- 1. RAÍZ: sin rebote ni scroll de documento ---------- */
:root {
  --seguro-top: env(safe-area-inset-top, 0px);
  --seguro-bottom: env(safe-area-inset-bottom, 0px);
  /* alto real de la nav: los 64 px del diseño + la barra de gestos (34 px) */
  --alto-nav: calc(64px + max(34px, var(--seguro-bottom)));
  --alto-pantalla: 100vh;
}

@supports (height: 100dvh) {
  :root { --alto-pantalla: 100dvh; }
}

html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--carbon-900);
  /* sin el zoom por doble toque: el primer toque responde ya */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 2. LA PANTALLA: 100dvh + área segura ---------- */
.screen {
  width: 100%;
  max-width: 100vw;
  height: var(--alto-pantalla);
  /* en standalone la barra de estado es real: se reserva el notch aquí */
  padding-top: var(--seguro-top);
  overflow: hidden;
}

/* statusbar dibujada en el wireframe: se oculta cuando iOS ya dibuja la suya */
@media all and (display-mode: standalone) {
  .statusbar { display: none; }
}
html.es-standalone .statusbar { display: none; }

/* ---------- 3. CONTENIDO CON SCROLL NATIVO ---------- */
.main {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.main::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* reserva exacta de la nav inferior: 16 + 64 + gestos = 114 px en iPhone */
.main--nav { padding-bottom: calc(16px + var(--alto-nav)); }

/* splash: centrado real (si no cabe, alinea arriba en vez de recortar) */
.main--centro { justify-content: center; padding-bottom: 0; }
@supports (justify-content: safe center) {
  .main--centro { justify-content: safe center; }
}

/* hilo de chat: crece desde abajo pero nunca recorta el primer mensaje */
.chat-hilo { justify-content: flex-start; }
.chat-hilo > .block { margin-top: auto; }
.scroll-inercia {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
}
.scroll-inercia::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* ---------- 4. NAV INFERIOR ANCLADA SOBRE LA BARRA DE GESTOS ---------- */
.nav {
  height: auto;
  padding-bottom: max(34px, var(--seguro-bottom));
}

/* ---------- 5. ESTADOS TÁCTILES REALES (:active en todo lo tocable) ---------- */
a, button, .tab, .chip, .card-programa, .fila-lista, .input, [data-demo] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
[data-demo] { cursor: pointer; }

.tab:active { background: rgba(216, 216, 209, 0.05); }
.chip:active,
.card-programa:active,
.fila-lista:active,
[data-demo]:active { opacity: 0.72; }
.card-programa:active { transform: scale(0.995); }
.card-programa { transition: transform var(--d-instant) var(--e-settle), opacity var(--d-fast) var(--e-settle); }

/* ---------- 6. ANCHO REAL 360–430 px (idéntico a 390) ---------- */
/* los media a sangre del wireframe medían 390 px fijos */
.media-full { width: 100%; }

/* el anillo del día: 196 px exactos a 390 y 168 px en el mínimo de 360 */
.anillo-heroe {
  width: clamp(168px, 50vw, 196px);
  height: clamp(168px, 50vw, 196px);
  flex: 0 0 auto;
}
.anillo-heroe svg { width: 100%; height: 100%; }

/* la gráfica de progreso se dibujó a 342 px (390 − gutter): escala al ancho real */
.grafico { display: block; width: 100%; height: auto; }

/* tres equipos de 104 px fijos = 332 px: no caben a 360 px */
.equipos > .equipo { width: auto; flex: 1 1 0; min-width: 0; }
.equipos > .equipo .nombre,
.equipos > .equipo .meta { overflow-wrap: anywhere; }

/* ningún hijo de una columna flex puede empujar el ancho */
.main > *,
.appbar > *,
.fila > * { min-width: 0; }

/* ---------- 7. TRANSICIÓN ENTRE PANTALLAS ----------
   320 ms, fade + 12 px de asentamiento vertical. Sin deslizamiento lateral.
   Cross-document view transitions (Safari 18+ / Chrome 126+); si el motor no
   las soporta, se usa la animación de entrada equivalente. */
@view-transition { navigation: auto; }

::view-transition-old(root) {
  animation: zen-salida 160ms var(--e-out) both;
}
::view-transition-new(root) {
  animation: zen-entrada 320ms var(--e-in) both;
}
@keyframes zen-entrada {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}
@keyframes zen-salida {
  from { opacity: 1; }
  to   { opacity: 0; }
}
html.sin-vt .screen { animation: zen-entrada 320ms var(--e-in) both; }

/* ---------- 8. PREFERENCIA DE MOVIMIENTO REDUCIDO ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 120ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 120ms !important;
  }
  .skel::after { animation: none !important; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 120ms !important; }
}

/* ---------- 9. ESCRITORIO: solo para revisar, con marco de teléfono ---------- */
@media (min-width: 560px) and (pointer: fine) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0B0A09; /* fondo de taller del design system, no un color nuevo */
  }
  .screen {
    width: min(430px, 100vw);
    height: min(932px, var(--alto-pantalla));
    outline: 1px solid var(--carbon-800);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  }
}

/* ---------- 10. CAMPO REAL (misma piel que .input .placeholder) ---------- */
.campo-real {
  width: 100%;
  min-width: 0;
  background: none;
  border: 0;
  outline: none;
  font-family: var(--f-text);
  font-size: 16px; /* ≥16 px evita el zoom automático de iOS al enfocar */
  line-height: 22px;
  color: var(--salvia-100);
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}
.campo-real::placeholder { color: var(--t-3); opacity: 1; }
.campo-real:focus-visible { outline: none; }
.input:focus-within {
  border-color: var(--salvia-100);
  box-shadow: 0 0 0 2px rgba(216, 216, 209, 0.14);
}

/* ---------- 11. BOTÓN Y HOJA DE DEMO ----------
   El botón vive en el margen izquierdo (--gutter = 24 px de aire en todo el
   sistema): x 0–15 px, centrado en vertical. No pisa ningún contenido. */
.demo-btn {
  position: fixed;
  left: -22px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 55;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  width: 34px;
  height: 42px;
  padding: 0 5px 0 0;
  border: 1px solid var(--hairline);
  border-left: 0;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: rgba(20, 18, 15, 0.78);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: border-color var(--d-fast) var(--e-settle), background var(--d-fast) var(--e-settle);
}
.demo-btn i {
  display: block;
  width: 2px;
  height: 2px;
  border-radius: var(--r-full);
  background: var(--t-3);
}
.demo-btn:active { border-color: var(--borde-control); background: var(--carbon-800); }
.demo-btn:active i { background: var(--t-1); }
.demo-btn[hidden] { display: none; }

.demo-hoja {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(20, 18, 15, 0.72);
  animation: zen-fundido var(--d-fast) var(--e-out) both;
}
.demo-hoja[hidden] { display: none; }
@keyframes zen-fundido { from { opacity: 0; } to { opacity: 1; } }

.demo-panel {
  background: var(--carbon-800);
  border-top: 1px solid var(--hairline);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 18px var(--gutter) calc(16px + var(--seguro-bottom));
  max-height: 86%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: zen-entrada var(--d-slow) var(--e-settle) both;
}

.demo-cab {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--hairline);
}
.demo-lista {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}
.demo-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 44px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 15px;
  line-height: 20px;
  color: var(--t-1);
  touch-action: manipulation;
}
.demo-item:active { opacity: 0.7; }
.demo-item .punto {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--lima-400);
  flex: 0 0 6px;
}
.demo-item .punto--vacio { background: var(--carbon-700); }
.demo-pie {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
}
.demo-accion {
  font-size: 13px;
  line-height: 18px;
  color: var(--t-2);
  text-decoration: underline;
  text-decoration-color: var(--carbon-700);
  text-underline-offset: 3px;
  padding: 6px 0;
  touch-action: manipulation;
}
.demo-accion:active { color: var(--t-0); }

/* ---------- 12. AVISO "AÑADIR A PANTALLA DE INICIO" ---------- */
.aviso-a2hs {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--seguro-bottom));
  z-index: 60;
  background: var(--carbon-800);
  border: 1px solid var(--borde-control);
  border-radius: var(--r-sm);
  padding: 16px 16px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  animation: zen-entrada var(--d-base) var(--e-in) both;
}
html.con-nav .aviso-a2hs { bottom: calc(var(--alto-nav) + 12px); }
.aviso-a2hs[hidden] { display: none; }
.aviso-a2hs .aviso-cab {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.aviso-a2hs .aviso-pasos {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.aviso-a2hs .aviso-paso {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  line-height: 18px;
  color: var(--t-2);
}
.aviso-a2hs .aviso-cerrar {
  margin-top: 12px;
  width: 100%;
}

/* ---------- 13. TOAST (componente del design system, sin cambios) ---------- */
.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--alto-nav) + 14px);
  z-index: 65;
  display: flex;
  justify-content: center;
  padding: 0 20px;
  pointer-events: none;
}
html:not(.con-nav) .toast-host { bottom: calc(24px + var(--seguro-bottom)); }
.toast-host .toast {
  max-width: 340px;
  animation: zen-entrada var(--d-base) var(--e-in) both;
}
.toast-host .toast.saliendo { animation: zen-salida var(--d-fast) var(--e-out) both; }

/* ---------- 14. CTA ANCLADO AL PIE ---------- */
/* Los paddings en línea del wireframe ya se reescribieron a max(…, env(…)).
   A 360 px hay CTAs cuyo texto salta a dos líneas: el botón acompaña en alto
   en vez de recortar la etiqueta. A 390 px el resultado es idéntico (56 px). */
.push > .btn {
  height: auto;
  min-height: 56px;
  padding-top: 14px;
  padding-bottom: 14px;
}
.push > .btn--sm { min-height: 48px; }
/* si el contenido desborda, el CTA no queda pegado a la última fila;
   a 390 px el margen automático absorbe este aire y nada se mueve */
.push > .btn:first-child { margin-top: var(--s6); }
