:root {
  --bg: #F3F2F7;
  --card: #fff;
  --tx: #1f2937;
  --mut: #6b7280;
  --naranja: #EE6B41;
  --naranja-osc: #d9582f;
  --menta: #5FD6BD;
  --menta-osc: #1f9d86;
  --navy: #27254F;
  --ok: #16a34a;
  --warn: #d97706;
  --borde: #e8e7f0;
  --sombra: 0 2px 10px rgba(39, 37, 79, .07);
  --sombra-fuerte: 0 8px 22px rgba(238, 107, 65, .32);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--tx);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}
.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px max(18px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}
h1 { font-size: 30px; line-height: 1.15; color: var(--navy); margin: 10px 0 4px; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 21px; line-height: 1.2; color: var(--navy); margin: 0 0 8px; font-weight: 800; letter-spacing: -.01em; }
.sub { color: var(--mut); font-size: 14px; line-height: 1.5; }
.centrado { text-align: center; }
/* Pantallas cortas (bienvenida, autorización, resultado) centradas en medio
   del teléfono en vez de pegadas arriba - pedido explícito del usuario. Las
   pantallas largas (grilla, cámara) se quedan arriba y hacen scroll normal. */
.centrada {
  min-height: calc(100vh - 40px);
  min-height: calc(100dvh - 40px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
}
/* Solo títulos/subtítulos centrados - el texto de las casillas de
   autorización y el contenido de las cards se queda alineado a la
   izquierda (centrarlo también se veía mal con texto de varias líneas). */
.centrada > h1, .centrada > .sub, .centrada > h2, .centrada > .tag { text-align: center; }
.centrada > .tag { align-self: center; }
.destacado { color: var(--naranja); font-weight: 700; }
.ilustracion { width: 52%; max-width: 190px; margin: 14px auto 10px; display: block; }
.card {
  background: var(--card);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--sombra);
  border: 1px solid var(--borde);
  overflow-wrap: anywhere;
}
.card.centro { text-align: center; }
button {
  font: inherit; font-size: 16px; border: 0; border-radius: 99px;
  padding: 15px 18px; font-weight: 700; cursor: pointer; width: 100%;
  min-height: 52px; transition: transform .1s ease, box-shadow .15s ease, opacity .15s ease;
}
button:active:not(:disabled) { transform: scale(.98); }
.p { background: linear-gradient(135deg, var(--naranja), var(--naranja-osc)); color: #fff; box-shadow: var(--sombra-fuerte); }
.o { background: #fff; color: var(--menta-osc); border: 2px solid var(--menta); }
button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
button:focus-visible, label.chk input:focus-visible { outline: 3px solid rgba(95, 214, 189, .6); outline-offset: 2px; }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row > button { flex: 1; }
/* Visor en vivo: caja fija 3:4 (antes se veía con el ratio crudo del
   sensor, descuadrado) - solo encuadre visual, antes de capturar.
   canvas.prev SÍ es la foto real ya recortada 9:16/16:9 por
   congelarCuadro() en camara.js - se muestra con su proporción real, sin
   forzar otra distinta, para no mentirle al usuario sobre qué se envía. */
video { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 14px; background: #000; display: block; }
canvas.prev { width: 100%; height: auto; border-radius: 14px; background: #000; display: block; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; color: #fff; }
.kv { font-size: 14px; line-height: 1.65; }
.hide { display: none !important; }
.note { font-size: 12px; color: var(--mut); margin-top: 6px; }
label.chk {
  display: flex; gap: 12px; align-items: flex-start;
  margin: 10px 0; padding: 12px; font-size: 14px; line-height: 1.5;
  background: #faf9fd; border: 1px solid var(--borde); border-radius: 14px; cursor: pointer;
}
label.chk input { width: 22px; height: 22px; margin-top: 1px; flex-shrink: 0; accent-color: var(--naranja); }
label.chk:has(input:checked) { background: #fff3ed; border-color: rgba(238, 107, 65, .45); }
#btnAceptar { margin-top: 8px; }
.tag {
  display: inline-block; font-size: 11px; letter-spacing: .1em; background: #fff3ed;
  color: var(--naranja); padding: 5px 14px; border-radius: 99px; font-weight: 800;
  border: 1px solid rgba(238, 107, 65, .25); margin-bottom: 4px;
}

.grid9 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.casilla {
  aspect-ratio: 3/4;
  min-width: 0;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  border: 2px dashed rgba(95, 214, 189, .9);
  background: linear-gradient(160deg, #f4fdfb, #e7f8f4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  color: var(--menta-osc);
  box-shadow: var(--sombra);
  transition: transform .1s ease;
}
.casilla:active { transform: scale(.97); }
.casilla.obligatoria {
  border-color: rgba(238, 107, 65, .8);
  background: linear-gradient(160deg, #fff7f3, #ffece4);
  color: var(--naranja);
}
.casilla img { width: 100%; height: 100%; object-fit: cover; display: block; }
.casilla .icono-casilla {
  width: 46px; height: 46px; padding: 10px; border-radius: 99px;
  background: #fff; box-shadow: 0 2px 8px rgba(39, 37, 79, .1); color: inherit;
}
.casilla .icono-casilla svg { width: 100%; height: 100%; display: block; }
.casilla .etiqueta { font-size: 12px; font-weight: 700; line-height: 1.2; text-align: center; color: var(--navy); padding: 0 6px; }
.casilla .check {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px; border-radius: 99px;
  background: var(--ok); color: #fff; border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
/* Botón de enviar siempre a la mano mientras se hace scroll en la grilla. */
#s2 #btnEnviar {
  position: sticky; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 5;
}

.overlay {
  position: fixed; inset: 0; background: rgba(15,15,40,.55);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 18px; z-index: 10;
}
.modalCard { background: #fff; border-radius: 22px; padding: 22px; max-width: 420px; width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.3); text-align: center; }
.modalCard .kv { font-size: 16px; font-weight: 600; color: var(--navy); }

.spinner {
  width: 44px; height: 44px; margin: 0 auto 12px;
  border: 4px solid var(--bg); border-top-color: var(--naranja);
  border-radius: 99px; animation: girar 0.8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }
.check {
  width: 92px; height: 92px; margin: 0 auto 14px;
  border-radius: 99px; background: var(--menta); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 46px; font-weight: 700;
}

/* Enlace único del siniestro */
.aviso-tag {
  background: var(--navy); color: rgba(255,255,255,.8);
  border-radius: 16px; padding: 12px 16px; text-align: center;
  font-size: 13px; margin: 6px 0 14px; box-shadow: var(--sombra);
}
.aviso-tag b { display: block; font-size: 22px; letter-spacing: .04em; color: #fff; margin-top: 2px; }
.err-icono { font-size: 44px; color: var(--warn); line-height: 1; margin-bottom: 8px; }

@media (max-width: 360px) {
  h1 { font-size: 26px; }
  .grid9 { gap: 8px; }
  .casilla .icono-casilla { width: 40px; height: 40px; padding: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  button, .casilla { transition: none; }
  .casilla.siembra { animation: none; }
}

/* Fecha de siembra: casilla ancha al inicio de la grilla (obligatoria, late suave hasta que se completa) */
.casilla.siembra {
  grid-column: 1 / -1; aspect-ratio: auto; flex-direction: row; justify-content: flex-start;
  gap: 14px; padding: 14px 16px; text-align: left; overflow: visible;
  border-style: solid; border-width: 2px;
  animation: latido 2.8s ease-in-out infinite;
}
.casilla.siembra .icono-casilla { flex-shrink: 0; }
.casilla.siembra .etiqueta { padding: 0; text-align: left; font-size: 14px; }
.casilla.siembra .detalle { font-size: 12px; font-weight: 500; color: var(--mut); margin-top: 2px; }
.casilla.siembra.lista { animation: none; border-color: rgba(95, 214, 189, .9); background: linear-gradient(160deg, #f4fdfb, #e7f8f4); color: var(--menta-osc); }
.casilla.siembra .check { top: 50%; right: 14px; transform: translateY(-50%); }
@keyframes latido {
  0%, 100% { box-shadow: var(--sombra), 0 0 0 0 rgba(238, 107, 65, 0); }
  50% { box-shadow: var(--sombra), 0 0 0 6px rgba(238, 107, 65, .16); }
}

/* Calendario de la fecha de siembra */
.modalCard.cal { padding: 18px; }
.cal-pregunta { font-size: 17px; font-weight: 800; color: var(--navy); margin-bottom: 12px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-titulo { font-size: 15px; font-weight: 700; color: var(--navy); text-transform: capitalize; }
.cal-flecha { width: 40px; min-height: 40px; height: 40px; padding: 0; font-size: 22px; line-height: 1; background: #fff3ed; color: var(--naranja); box-shadow: none; }
.cal-flecha:disabled { opacity: .3; }
.cal-sem, .cal-dias { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-sem span { font-size: 11px; font-weight: 700; color: var(--mut); padding: 4px 0; }
.cal-dia { min-height: 0; width: 100%; aspect-ratio: 1; padding: 0; font-size: 14px; font-weight: 600; color: var(--tx); background: transparent; border-radius: 99px; box-shadow: none; }
.cal-dia:disabled { opacity: .25; }
.cal-dia.hoy { border: 1.5px solid var(--menta); }
.cal-dia.sel { background: linear-gradient(135deg, var(--naranja), var(--naranja-osc)); color: #fff; }
.cal-hueco { aspect-ratio: 1; }
.cal-sel { font-size: 14px; font-weight: 600; color: var(--menta-osc); margin: 12px 0 2px; min-height: 22px; }

/* Resumen de autorizaciones cerradas tras el envío */
ul.cierre { list-style: none; margin: 14px 0 10px; padding: 12px 14px; text-align: left; background: #f1fbf8; border: 1px solid rgba(95, 214, 189, .5); border-radius: 14px; }
ul.cierre li { font-size: 14px; font-weight: 600; color: var(--navy); padding: 4px 0; display: flex; align-items: center; gap: 10px; }
ul.cierre .ok { width: 22px; height: 22px; border-radius: 99px; background: var(--ok); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; }
