/* ---------------------------------------------------------------------------
   Identidad Farmatodo (Toolkit 2024).

   Azul #002858 dominante, Process Blue #0084D0 de acento, fondo azul claro.
   El amarillo del toolkit NO se usa: esta reservado a descuentos.

   Se disena para un telefono en un muelle: zonas de toque grandes, contraste
   alto y nada que dependa de precision con el dedo. Quien usa esto puede tener
   guantes puestos y el sol de frente.
   --------------------------------------------------------------------------- */

:root {
  --azul: #002858;
  --azul-proc: #0084d0;
  --fondo: #ebf3fb;
  --superficie: #ffffff;
  --texto: #1a1a2e;
  --apagado: #64748b;
  --linea: #cbd9e8;
  --suave: #e4eef8;
  --alerta: #c0261c;
  --bien: #0f7b3e;

  --radio: 10px;
  /* 48px es el minimo de zona de toque que recomienda Google. Aqui se sube a
     56: el usuario va a estar de pie, con prisa y a veces con guantes. */
  --toque: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fondo);
  color: var(--texto);
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  font-size: 16px;            /* menos de 16 hace que iOS haga zoom al enfocar */
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ cabecera */

header {
  background: var(--azul);
  color: #fff;
  padding: 14px 16px 12px;
  /* El area de la barra de estado en pantalla completa. Sin esto, el titulo
     queda debajo del reloj del telefono. */
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
}

header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

header p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: #9fc3e4;
}

.acento { height: 3px; background: var(--azul-proc); }

/* ---------------------------------------------------------------- contenido */

main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--apagado);
  font-weight: 600;
  margin: 24px 0 8px;
}
h2:first-child { margin-top: 0; }

.tarjeta {
  background: var(--superficie);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  overflow: hidden;
}

/* ------------------------------------------------------------------- estado */

.estado {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 16px;
}

.luz {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--apagado);
}
.luz.bien     { background: var(--bien); }
.luz.mal      { background: var(--alerta); }
.luz.pensando { background: var(--azul-proc); animation: latir 1s infinite; }

@keyframes latir { 50% { opacity: 0.25; } }

/* Quien tenga activado "reducir movimiento" no deberia ver nada parpadear. */
@media (prefers-reduced-motion: reduce) {
  .luz.pensando { animation: none; }
}

.estado .titulo { font-weight: 600; }
.estado .detalle { font-size: 0.82rem; color: var(--apagado); }

/* --------------------------------------------------------------------- filas */

.fila {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid var(--linea);
  font-size: 0.9rem;
}

.fila dt { color: var(--apagado); margin: 0; flex: 0 0 auto; }
.fila dd {
  margin: 0;
  text-align: right;
  font-weight: 600;
  /* Un id o una URL larga no puede empujar el ancho de la pagina. */
  overflow-wrap: anywhere;
}

dl { margin: 0; }

/* ------------------------------------------------------------------- botones */

.boton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--toque);
  margin-top: 12px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radio);
  background: var(--azul);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.boton:active { background: var(--azul-proc); }
.boton[disabled] { opacity: 0.5; cursor: default; }

.boton.secundario {
  background: var(--superficie);
  color: var(--azul);
  border: 1px solid var(--linea);
}

/* -------------------------------------------------------------------- avisos */

.aviso {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radio);
  border-left: 4px solid var(--alerta);
  background: #fdf1f0;
  font-size: 0.86rem;
}

.aviso.ojo {
  border-left-color: var(--azul-proc);
  background: var(--suave);
}

.aviso code {
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.oculto { display: none !important; }

footer {
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 0.72rem;
  color: var(--apagado);
}

/* ------------------------------------------------------------------- vistas */

.vista { display: block; }
.vista.oculto { display: none; }

/* La barra de abajo y no de arriba: el pulgar llega ahi sin cambiar el agarre,
   y quien usa esto tiene la otra mano ocupada con la planilla. */
nav.barra {
  position: sticky;
  bottom: 0;
  display: flex;
  background: var(--superficie);
  border-top: 1px solid var(--linea);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

nav.barra button {
  flex: 1;
  min-height: var(--toque);
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--apagado);
  cursor: pointer;
  border-top: 3px solid transparent;
  padding: 0 4px;
}

nav.barra button.activa {
  color: var(--azul);
  border-top-color: var(--azul-proc);
}

.pastilla {
  display: inline-block;
  min-width: 20px;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--alerta);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1.5;
}
.pastilla.oculto { display: none; }

/* ---------------------------------------------------------- volver y titulo */

.cabecera-fila { display: flex; align-items: center; gap: 10px; }

.volver {
  border: 0;
  background: none;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  padding: 6px 10px 8px 0;
  margin-left: -4px;
  cursor: pointer;
  font-family: inherit;
}
.volver.oculto { display: none; }

/* --------------------------------------------------------------- lista olas */

.olas { display: flex; flex-direction: column; gap: 10px; }

.ola {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  min-height: var(--toque);
  padding: 0;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: var(--superficie);
  text-align: left;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
}

.ola:active { background: var(--suave); }

/* La etiqueta de la ola es lo unico que el operario ya sabe cuando llega al
   muelle: es su punto de entrada, asi que va grande y a la izquierda. */
.ola .etiqueta {
  flex: 0 0 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--azul);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 700;
}

.ola.cargado .etiqueta { background: var(--bien); }
.ola.no_salio .etiqueta { background: var(--apagado); }

.ola .cuerpo { flex: 1; padding: 10px 12px; min-width: 0; }
.ola .zona { font-weight: 600; font-size: 0.95rem; }
.ola .sub  { font-size: 0.8rem; color: var(--apagado); }

.ola .marca {
  display: inline-block;
  margin-top: 5px;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--suave);
  color: var(--azul);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.ola.cargado .marca { background: #dff2e6; color: var(--bien); }
.ola .marca.forzado { background: #fdf1f0; color: var(--alerta); }

/* ------------------------------------------------------------------ detalle */

.numero {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.pendiente { color: var(--apagado); font-weight: 400; font-style: italic; }

.vacio {
  padding: 28px 16px;
  text-align: center;
  color: var(--apagado);
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------- formulario */

.campo { margin-bottom: 14px; }

.campo > label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--apagado);
  font-weight: 600;
}

.campo input,
.campo select,
.campo textarea {
  width: 100%;
  min-height: var(--toque);
  padding: 10px 12px;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: var(--superficie);
  color: var(--texto);
  font-family: inherit;
  /* 16px exactos: por debajo, iOS hace zoom al enfocar y descoloca la pantalla
     entera cada vez que alguien toca un campo. */
  font-size: 16px;
}

.campo input:focus,
.campo select:focus {
  outline: 2px solid var(--azul-proc);
  outline-offset: -1px;
}

.campo input[readonly] {
  background: var(--suave);
  color: var(--apagado);
}

/* Los numeros de precinto se leen de una tira fisica y se comparan digito a
   digito. Tabular y espaciados, o se cuela un 8 por un 3. */
.campo input.numero {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.campo .pista {
  margin-top: 4px;
  font-size: 0.76rem;
  color: var(--apagado);
}

.campo.malo input,
.campo.malo select { border-color: var(--alerta); }
.campo.malo .pista { color: var(--alerta); }

.dos-columnas { display: flex; gap: 10px; }
.dos-columnas > * { flex: 1; min-width: 0; }

/* ------------------------------------------------------------ lista tiendas */

.tiendas { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }

.tienda {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: var(--superficie);
}

.tienda .orden {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--suave);
  color: var(--azul);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tienda .nombre { flex: 1; min-width: 0; font-size: 0.92rem; }
.tienda .nombre small { display: block; color: var(--apagado); font-size: 0.76rem; }

.tienda .quitar {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--alerta);
  font-size: 1.3rem;
  cursor: pointer;
  font-family: inherit;
}

/* --------------------------------------------------------------- resultados */

.resultados {
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: var(--superficie);
}

.resultados button {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--linea);
  background: none;
  text-align: left;
  font-family: inherit;
  font-size: 0.9rem;
  color: inherit;
  cursor: pointer;
}
.resultados button:last-child { border-bottom: 0; }
.resultados button:active { background: var(--suave); }
.resultados small { display: block; color: var(--apagado); font-size: 0.76rem; }

/* ------------------------------------------------------------------ errores */

.errores { margin: 0; padding-left: 20px; }
.errores li { margin: 3px 0; }

/* --------------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 40, 88, 0.55);
  display: flex;
  align-items: flex-end;
}
.modal.oculto { display: none; }

.modal .caja {
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--fondo);
  border-radius: 14px 14px 0 0;
  padding: 18px 16px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

.modal h3 { margin: 0 0 12px; font-size: 1rem; }

/* ---------------------------------------------------------------- evidencia */

.adjunto {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: var(--superficie);
}

.adjunto.obligatorio { border-left: 4px solid var(--azul-proc); }
.adjunto.listo { border-left: 4px solid var(--bien); }

.adjunto .vista-previa {
  flex: 0 0 56px;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  background: var(--suave) center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--apagado);
  font-size: 1.4rem;
}

.adjunto .texto { flex: 1; min-width: 0; }
.adjunto .texto strong { display: block; font-size: 0.9rem; }
.adjunto .texto small { color: var(--apagado); font-size: 0.78rem; }

.adjunto .tomar {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: var(--superficie);
  color: var(--azul);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

/* ------------------------------------------------------------------- firma */

canvas.firma {
  display: block;
  width: 100%;
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  background: #fff;
  /* Sin esto, arrastrar el dedo para firmar mueve la pagina entera. */
  touch-action: none;
}

.firma-pie {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.firma-pie .pista { flex: 1; }
.firma-pie .boton { width: auto; margin: 0; min-height: 44px; }
