:root {
  --rojo: #D02527;
  --rojo-oscuro: #A81B1D;
  --rojo-suave: #FBE9E9;
  --navy: #1B2A4A;
  --navy-suave: #E8ECF4;
  --crema: #F5F1EB;
  --blanco: #FFFFFF;
  --texto: #1F2430;
  --texto-suave: #6B7280;
  --borde: #E6E1D8;
  --verde: #1F8A4C;
  --verde-suave: #E5F4EA;
  --ambar: #B7791F;
  --ambar-suave: #FBF1DD;
  --sombra: 0 4px 16px rgba(27, 42, 74, 0.08);
  --sombra-fuerte: 0 10px 30px rgba(27, 42, 74, 0.16);
  --radio: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--crema);
  color: var(--texto);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 800; }
p { margin: 0 0 .5rem; }
button, input, select, textarea { font: inherit; }

/* Barra superior */
.barra {
  background: var(--blanco);
  color: var(--navy);
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; z-index: 20;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--borde);
  box-shadow: 0 2px 10px rgba(27, 42, 74, 0.06);
}
.barra .marca { display: flex; align-items: center; gap: 10px; min-width: 0; }
.barra .logo-barra { height: 26px; width: auto; display: block; }
.barra .producto { font-weight: 800; font-size: 1rem; color: var(--navy); border-left: 1.5px solid var(--borde); padding-left: 10px; line-height: 1; }
.barra .usuario { font-size: .82rem; color: var(--texto-suave); text-align: right; line-height: 1.25; }
.barra .usuario b { color: var(--navy); }
.barra button { background: var(--navy-suave); color: var(--navy); border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 800; }

.contenedor { max-width: 640px; margin: 0 auto; padding: 18px 16px 110px; }
.contenedor.ancho { max-width: 1100px; }

/* Tarjetas */
.tarjeta {
  background: var(--blanco);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 18px;
  margin-bottom: 14px;
}
.tarjeta.roja { background: var(--rojo); color: #fff; box-shadow: var(--sombra-fuerte); }
.tarjeta.navy { background: var(--navy); color: #fff; }
.tarjeta.verde { background: var(--verde-suave); border: 1px solid #C9E8D4; }
.tarjeta.ambar { background: var(--ambar-suave); border: 1px solid #F1DFB5; }
.tarjeta.suave { background: var(--navy-suave); box-shadow: none; }
.tarjeta .etiqueta { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; opacity: .7; margin-bottom: 4px; }
.tarjeta .grande { font-size: 2.6rem; font-weight: 900; letter-spacing: -.02em; line-height: 1; }
.tarjeta .sub { font-size: .9rem; opacity: .8; margin-top: 6px; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 14px 18px;
  font-weight: 800; font-size: 1rem; cursor: pointer;
  background: var(--navy); color: #fff;
  box-shadow: 0 2px 0 rgba(0,0,0,.08);
  transition: transform .05s ease, filter .15s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.rojo { background: var(--rojo); }
.btn.blanco { background: #fff; color: var(--navy); }
.btn.suave { background: var(--navy-suave); color: var(--navy); box-shadow: none; }
.btn.verde { background: var(--verde); }
.btn.fantasma { background: transparent; color: var(--navy); box-shadow: none; padding: 10px 12px; }
.btn.bloque { width: 100%; }
.btn.grande { padding: 18px 20px; font-size: 1.1rem; border-radius: 18px; }
.btn.chico { padding: 8px 12px; font-size: .9rem; border-radius: 10px; }
.fila-botones { display: flex; gap: 10px; flex-wrap: wrap; }
.fila-botones .btn { flex: 1; }

/* Formularios */
.campo { margin-bottom: 14px; }
.campo label { display: block; font-weight: 800; font-size: .88rem; margin-bottom: 6px; color: var(--navy); }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 13px 14px; border: 1.5px solid var(--borde); border-radius: 12px;
  background: #fff; color: var(--texto); outline: none;
}
.campo input:focus, .campo select:focus, .campo textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(27,42,74,.12); }
.campo textarea { min-height: 110px; resize: vertical; }
.campo .ayuda { font-size: .82rem; color: var(--texto-suave); margin-top: 5px; }
.campo.codigo input { text-transform: uppercase; letter-spacing: .12em; font-size: 1.25rem; text-align: center; font-weight: 800; }
.grilla-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Listas */
.lista { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: #fff; border-radius: 14px; padding: 14px 16px; box-shadow: var(--sombra);
  display: flex; align-items: center; gap: 12px;
}
.item.plano { box-shadow: none; border: 1px solid var(--borde); }
.item .cuerpo { flex: 1; min-width: 0; }
.item .titulo { font-weight: 800; }
.item .detalle { font-size: .86rem; color: var(--texto-suave); }
.item .accion { flex-shrink: 0; }
.item.pulsable { cursor: pointer; }
.item.apilado { flex-direction: column; align-items: stretch; }
.item.pulsable:active { filter: brightness(.97); }

.chequeo {
  width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--navy-suave); color: var(--navy); font-weight: 900; flex-shrink: 0;
}
.chequeo.ok { background: var(--verde); color: #fff; }
.chequeo.alerta { background: var(--ambar-suave); color: var(--ambar); }

.pildora {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800;
  background: var(--navy-suave); color: var(--navy);
}
.pildora.ok { background: var(--verde-suave); color: var(--verde); }
.pildora.alerta { background: var(--rojo-suave); color: var(--rojo); }
.pildora.ambar { background: var(--ambar-suave); color: var(--ambar); }

/* Progreso */
.progreso { height: 10px; border-radius: 999px; background: rgba(255,255,255,.3); overflow: hidden; margin-top: 10px; }
.progreso > div { height: 100%; background: #fff; border-radius: 999px; transition: width .3s ease; }
.tarjeta:not(.roja):not(.navy) .progreso { background: var(--navy-suave); }
.tarjeta:not(.roja):not(.navy) .progreso > div { background: var(--navy); }

/* Alerta pulsante */
@keyframes latido { 0%,100% { box-shadow: 0 10px 30px rgba(208,37,39,.25); } 50% { box-shadow: 0 10px 40px rgba(208,37,39,.55); } }
.tarjeta.alarma { background: var(--rojo); color: #fff; animation: latido 1.4s ease-in-out infinite; }

/* Pestañas (panel) */
.pestanas {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--borde);
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.pestanas button {
  background: transparent; border: 0; color: var(--texto-suave); font-weight: 800; font-size: .75rem;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px; border-radius: 10px; flex: 1;
}
.pestanas button span.ico { font-size: 1.25rem; }
.pestanas button.activa { color: var(--rojo); background: var(--rojo-suave); }

/* Modal */
.modal-fondo {
  position: fixed; inset: 0; background: rgba(27,42,74,.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 640px; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow: auto; box-shadow: var(--sombra-fuerte);
}
.modal h2 { margin-bottom: 12px; }
.modal .cerrar { position: absolute; right: 16px; top: 12px; }

/* Escáner */
.escaner { position: relative; background: #000; border-radius: 16px; overflow: hidden; aspect-ratio: 3/4; max-height: 60vh; }
.escaner video { width: 100%; height: 100%; object-fit: cover; }
.escaner .guia {
  position: absolute; left: 10%; right: 10%; top: 38%; height: 24%;
  border: 3px solid rgba(255,255,255,.9); border-radius: 12px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,.35);
}
.escaner .guia::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: var(--rojo); }

/* Tabla (panel) */
.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabla th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--texto-suave); padding: 8px 10px; border-bottom: 1px solid var(--borde); }
.tabla td { padding: 10px; border-bottom: 1px solid var(--borde); vertical-align: top; }
.tabla tr:last-child td { border-bottom: 0; }
.desplazable { overflow-x: auto; }

/* Fotos */
.miniatura { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--navy-suave); flex-shrink: 0; }
.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.galeria img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; }

/* Avisos */
.aviso { padding: 12px 14px; border-radius: 12px; font-size: .92rem; margin-bottom: 12px; }
.aviso.error { background: var(--rojo-suave); color: var(--rojo-oscuro); }
.aviso.ok { background: var(--verde-suave); color: var(--verde); }
.aviso.info { background: var(--navy-suave); color: var(--navy); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700;
  box-shadow: var(--sombra-fuerte); z-index: 100; max-width: 90vw; text-align: center;
}
.toast.error { background: var(--rojo); }

.vacio { text-align: center; color: var(--texto-suave); padding: 24px 10px; }
.separador { height: 1px; background: var(--borde); margin: 16px 0; }
.centrado { text-align: center; }
.muted { color: var(--texto-suave); }
.pequeno { font-size: .85rem; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.codigo-sitio { font-size: 1.9rem; letter-spacing: .15em; word-break: break-all; font-weight: 900; color: var(--navy); text-align: center; padding: 10px 0 4px; }

/* Pantalla de acceso */
.acceso { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 28px 20px; max-width: 460px; margin: 0 auto; }
.acceso .logo { text-align: center; margin-bottom: 26px; }
.acceso .logo .logo-acceso { width: 210px; max-width: 70%; height: auto; display: block; margin: 0 auto 14px; }
.acceso .logo .marca { font-size: 1.5rem; font-weight: 900; color: var(--navy); letter-spacing: .02em; }
.acceso .logo p { color: var(--texto-suave); }
.enlace { background: none; border: 0; color: var(--navy); font-weight: 800; text-decoration: underline; cursor: pointer; padding: 0; }

.cargando { text-align: center; padding: 60px 20px; color: var(--texto-suave); font-weight: 700; }

@media (min-width: 720px) {
  .contenedor { padding-top: 26px; }
  .modal-fondo { align-items: center; }
  .modal { border-radius: 22px; }
}

/* Estado de red */
.banda-red { font-size: .82rem; font-weight: 700; padding: 8px 16px; text-align: center; }
.banda-red.sin { background: var(--ambar-suave); color: var(--ambar); }
.banda-red.pend { background: var(--navy-suave); color: var(--navy); }

/* Etiquetas QR */
#impresion { display: none; }
.previa-qr { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.etiqueta-qr { border: 1.5px dashed #BBB; border-radius: 10px; padding: 10px; text-align: center; background: #fff; }
.etiqueta-qr svg { width: 110px; height: 110px; display: block; margin: 0 auto 6px; }
.etiqueta-qr .eq-nombre { font-weight: 800; font-size: .95rem; line-height: 1.2; }
.etiqueta-qr .eq-sub { font-size: .8rem; color: var(--texto-suave); }
.etiqueta-qr .eq-pie { font-size: .7rem; color: var(--texto-suave); margin-top: 6px; text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; justify-content: center; gap: 6px; }
.etiqueta-qr .eq-logo { height: 12px; width: auto; }
@media print {
  body > *:not(#impresion) { display: none !important; }
  body { background: #fff; padding: 0; }
  #impresion { display: block; }
  .hoja-qr { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8mm; padding: 8mm; }
  .etiqueta-qr { border: 1px dashed #999; border-radius: 3mm; padding: 6mm; page-break-inside: avoid; break-inside: avoid; }
  .etiqueta-qr svg { width: 48mm; height: 48mm; }
  .etiqueta-qr .eq-nombre { font-size: 13pt; }
  .etiqueta-qr .eq-sub { font-size: 10pt; color: #444; }
  .etiqueta-qr .eq-pie { font-size: 8pt; color: #666; }
  .etiqueta-qr .eq-logo { height: 5mm; }
}

/* Línea de auditoría (cliente) */
.linea { position: relative; padding-left: 4px; }
.linea::before { content: ""; position: absolute; left: 96px; top: 8px; bottom: 8px; width: 2px; background: var(--borde); }
.evento { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; position: relative; }
.evento .hora { width: 74px; flex-shrink: 0; font-weight: 800; font-size: .8rem; white-space: nowrap; color: var(--navy); text-align: right; padding-top: 4px; }
.evento .punto { width: 30px; height: 30px; border-radius: 50%; background: #fff; border: 2px solid var(--borde); display: flex; align-items: center; justify-content: center; font-size: .9rem; flex-shrink: 0; z-index: 1; }
.evento.marca .punto, .evento.fin_ok .punto { border-color: var(--verde); }
.evento.fin_incompleto .punto { border-color: var(--ambar); }
.evento.observacion .punto { border-color: var(--navy); }
.evento.entrada .punto { border-color: var(--verde); }
.evento .cuerpo { flex: 1; background: #fff; border-radius: 12px; padding: 8px 12px; box-shadow: var(--sombra); min-width: 0; }
.evento .titulo { font-weight: 800; font-size: .92rem; }
.evento .detalle { font-size: .82rem; color: var(--texto-suave); }

.evento details summary { list-style: none; cursor: pointer; }
.evento details summary::-webkit-details-marker { display: none; }
.evento .ver-puntos { display: inline-block; margin-top: 4px; font-size: .78rem; font-weight: 800; color: var(--navy); }
.evento details[open] .ver-puntos { display: none; }
.evento .hijos { margin-top: 8px; border-top: 1px solid var(--borde); padding-top: 6px; }
.evento .hijo { font-size: .85rem; padding: 4px 0; }

/* Acuerdo de prestación de servicios */
.ac-marco { border: 1px solid var(--borde); border-radius: 12px; background: #fff; max-height: 55vh; overflow: auto; padding: 4px; }
.acuerdo-doc { font-family: "Nunito", system-ui, sans-serif; color: #1F2430; font-size: .86rem; line-height: 1.5; padding: 14px 16px; background: #fff; }
.acuerdo-doc + .acuerdo-doc { border-top: 2px dashed var(--borde); }
.acuerdo-doc p { margin: 0 0 9px; text-align: justify; }
.ac-cab img { height: 30px; width: auto; }
.ac-titulo { text-align: center; font-size: 1.05rem; color: var(--navy); margin: 10px 0 2px; letter-spacing: .02em; }
.ac-sub { text-align: center; font-weight: 800; color: var(--rojo); margin-bottom: 12px; font-size: .85rem; }
.hueco { color: #9AA0A6; letter-spacing: -1px; }
.ac-firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 18px 0 8px; text-align: center; font-size: .8rem; }
.ac-firma img { height: 64px; max-width: 100%; object-fit: contain; display: block; margin: 0 auto; }
.ac-vacia { height: 64px; }
.ac-linea { border-top: 1px solid #1F2430; margin: 2px 6px 4px; }
.ac-nombre { font-weight: 800; }
.ac-fecha { margin-top: 10px; }
.pad-firma { width: 100%; height: 170px; border: 2px dashed var(--navy); border-radius: 12px; background: #FBFAF7; touch-action: none; display: block; }
.firma-actual { height: 70px; max-width: 100%; display: block; margin-bottom: 4px; background: #fff; border: 1px solid var(--borde); border-radius: 8px; padding: 4px; }
@media print {
  .hoja-acuerdos .acuerdo-doc { font-size: 10.5pt; padding: 12mm 14mm; page-break-after: always; break-after: page; border: 0; }
  .hoja-acuerdos .acuerdo-doc:last-child { page-break-after: auto; break-after: auto; }
  .ac-cab img { height: 12mm; }
  .ac-firma img { height: 20mm; }
}
