/* Diseño plano (Flat + Swiss) para uso en bodega: una mano, guantes, luz variable.
   Marca provisional: azul #14365c + naranja #f5a524. Semáforo: verde = hecho, naranja = atención, rojo = error. */
:root {
  --azul: #14365c; --azul-2: #1f4f86; --naranja: #f5a524; --naranja-2: #fff3dc;
  --verde: #157347; --verde-2: #e3f4ea; --rojo: #b3261e;
  --fondo: #f1f4f8; --tarjeta: #fff; --texto: #14202e; --suave: #4d5a6a; --borde: #cfd7e1;
  --radio: 14px; --t: 160ms; font-size: 17px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Sin zoom por doble toque (tocar rápido +/− o Guardar no debe ampliar); el zoom con dos dedos sigue disponible. */
html, body, button, input, textarea { touch-action: manipulation; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.4; background: var(--fondo); color: var(--texto); }
main { max-width: 560px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* Barra superior */
header.barra { position: sticky; top: 0; z-index: 2; margin: 0 -16px 14px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
  background: var(--azul); color: #fff; display: flex; align-items: center; gap: 8px; border-bottom: 3px solid var(--naranja); }
header.barra:has(.icono) { padding-left: 4px; }
header.barra h1 { font-size: 1.1rem; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,255,255,.18); color: #fff; border-radius: 999px; padding: 6px 12px; font-size: .9rem; font-weight: 700; white-space: nowrap; }
.chip svg { width: 16px; height: 16px; fill: var(--naranja); stroke: var(--naranja); }
.chip:empty, .chip[hidden], #toast[hidden] { display: none; }
.chip.alerta { background: var(--naranja); color: #000; min-height: 44px; }

/* Botones */
button { font: inherit; border: 0; border-radius: var(--radio); min-height: 48px; padding: 0 18px; cursor: pointer; color: inherit;
  transition: transform var(--t), background-color var(--t), opacity var(--t); }
button:active:not(:disabled) { transform: scale(.97); }
:focus-visible { outline: 3px solid var(--azul-2); outline-offset: 2px; }
header.barra :focus-visible { outline-color: #fff; }
.primario { background: var(--naranja); color: #000; font-weight: 800; font-size: 1.1rem; width: 100%; min-height: 56px; margin-top: 16px; }
.primario:disabled { opacity: .5; }
/* Estados de carga: el botón se bloquea (evita dobles toques) y muestra que algo pasa. */
button.cargando { position: relative; overflow: hidden; pointer-events: none; opacity: 1 !important; }
button.cargando.llenar::before { content: ''; position: absolute; inset: 0; background: rgba(0, 0, 0, .16); transform-origin: left;
  animation: llenar .45s ease-out forwards; }
button.cargando.girando::after { content: ''; display: inline-block; width: 18px; height: 18px; margin-left: 10px; vertical-align: -3px;
  border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: girar .7s linear infinite; }
@keyframes llenar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes girar { to { transform: rotate(360deg); } }
.secundario { background: var(--tarjeta); border: 2px solid var(--azul); color: var(--azul); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.icono { background: transparent; color: #fff; min-width: 48px; padding: 0; display: inline-flex; align-items: center; justify-content: center; gap: 4px; font-weight: 700; }
.icono.texto { padding: 0 10px; font-size: .95rem; }
#btn-foto { width: 100%; }
#btn-foto::before { content: ""; width: 22px; height: 22px; background: currentColor;
  -webkit-mask: var(--ico-cam) center/contain no-repeat; mask: var(--ico-cam) center/contain no-repeat;
  --ico-cam: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z'/><circle cx='12' cy='13' r='4'/></svg>"); }

/* Formularios */
input, textarea { font: inherit; width: 100%; padding: 14px; border: 2px solid #7d8996; /* >= 3:1 sobre blanco */ border-radius: var(--radio); background: #fff; color: var(--texto); }
input:focus, textarea:focus { outline: none; border-color: var(--azul-2); box-shadow: 0 0 0 3px rgba(31,79,134,.25); }
select { font: inherit; width: 100%; padding: 14px; min-height: 52px; border: 2px solid #7d8996; border-radius: var(--radio); background: #fff; color: var(--texto); }
.tarjeta h3 { font-size: 1rem; margin: 14px 0 6px; }
input[type=search] { min-height: 52px; margin-bottom: 4px; }
label { display: block; font-weight: 700; margin: 16px 0 6px; font-size: .95rem; }
.error { color: var(--rojo); font-weight: 600; min-height: 1.4em; margin: 8px 0 0; }

/* Tarjetas y filas */
.tarjeta { background: var(--tarjeta); border-radius: var(--radio); padding: 16px; margin-bottom: 12px; border: 1px solid var(--borde); }
.sub { color: var(--suave); font-size: .88rem; margin: 2px 0 0; }
.resumen strong { font-size: 1.15rem; }
.resumen .pct { font-size: 2.2rem; line-height: 1; color: var(--azul); }
.meta { display: grid; gap: 2px; width: 100%; text-align: left; min-height: 64px; margin-bottom: 16px; padding: 14px 16px;
  background: var(--naranja-2); border: 2px solid var(--naranja); border-radius: var(--radio); }
.meta .titulo { font-weight: 800; font-size: 1.05rem; }
.meta .falta { font-weight: 700; color: var(--azul); }
.pie-resumen { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.enlace { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; background: none; font-weight: 700; color: var(--azul); white-space: nowrap; }
.enlace svg { width: 18px; height: 18px; stroke-width: 2; }
#hist .ronda2 { display: inline-block; margin-top: 4px; }
#buscar-todo { margin-bottom: 12px; }
.grupo-res { display: block; width: 100%; text-align: left; min-height: 48px; padding: 12px 4px 6px; background: none; font-weight: 800; color: var(--azul); }
.fila { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--tarjeta);
  border: 1px solid var(--borde); border-left: 5px solid var(--naranja); border-radius: var(--radio); padding: 14px 16px; margin-bottom: 8px; min-height: 64px; }
.fila:active:not(:disabled) { background: var(--naranja-2); }
.fila .info { flex: 1; min-width: 0; }
.fila .titulo { font-weight: 700; }
.fila.hecha { border-left-color: var(--verde); background: var(--verde-2); }
.fila.hecha:active { background: #cfeadb; }
.ok { display: inline-flex; align-items: center; gap: 4px; color: var(--verde); font-weight: 800; white-space: nowrap; }
.ok svg { width: 20px; height: 20px; stroke-width: 3; }
.con-foto { display: inline-flex; color: var(--azul); }
.con-foto svg { width: 20px; height: 20px; stroke-width: 2; }
.cuenta { font-weight: 800; color: var(--suave); white-space: nowrap; }
.vacio { text-align: center; color: var(--suave); padding: 32px 16px; }
.vacio svg { width: 40px; height: 40px; color: var(--borde); display: block; margin: 0 auto 8px; }
.barra-avance { display: block; height: 10px; border-radius: 99px; background: var(--borde); overflow: hidden; margin-top: 8px; }
.barra-avance > i { display: block; height: 100%; background: var(--verde); border-radius: 99px; transition: width .4s ease; }

/* Login */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 0; }
.login .marca { width: 64px; height: 64px; border-radius: 16px; background: var(--azul); color: var(--naranja); display: flex; align-items: center; justify-content: center; margin-bottom: 16px; border-bottom: 4px solid var(--naranja); }
.login .marca svg { width: 36px; height: 36px; }
.login h1 { color: var(--azul); margin: 0 0 4px; font-size: 1.7rem; }

/* Ficha: la cantidad manda */
.ficha-nombre { font-size: 1.25rem; font-weight: 800; margin: 4px 0 2px; line-height: 1.25; }
.cantidad { display: flex; gap: 8px; }
.cantidad input { text-align: center; font-size: 2.6rem; font-weight: 800; padding: 8px; min-height: 84px; border-color: var(--azul); color: var(--azul); }
.cantidad button { min-width: 72px; min-height: 84px; padding: 0; font-size: 2.2rem; font-weight: 700; line-height: 1; background: var(--azul); color: #fff; }
.foto { width: 100%; border-radius: var(--radio); margin-top: 8px; }
.ronda2 { background: var(--naranja); color: #000; border-radius: 6px; padding: 2px 8px; font-size: .8rem; font-weight: 800; }

/* Toast + gamificación */
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); text-align: center;
  background: var(--texto); color: #fff; padding: 14px 22px; border-radius: 999px; z-index: 10; font-weight: 700; animation: sube .25s ease-out; }
#toast.puntos { background: var(--verde); font-size: 1.15rem; animation: pop .45s cubic-bezier(.2,1.4,.4,1); }
#toast.fiesta { background: var(--naranja); color: #000; font-size: 1.15rem; border-radius: var(--radio); padding: 18px 26px; animation: pop .6s cubic-bezier(.2,1.4,.4,1); box-shadow: 0 0 0 6px rgba(245,165,36,.35); }
#toast .estrella { color: inherit; display: inline-block; vertical-align: -4px; margin-right: 4px; }
@keyframes sube { from { opacity: 0; transform: translate(-50%, 12px); } }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.6); } 100% { opacity: 1; transform: translate(-50%, 0) scale(1); } }
.fila.hecha .ok svg { animation: tilda .4s ease-out; }
@keyframes tilda { from { transform: scale(0); } }

#toast.aviso { background: var(--naranja); color: #000; }

/* Código de barras en la ficha */
.par-botones { display: flex; gap: 8px; margin-top: 8px; }
.par-botones button { flex: 1; min-height: 48px; padding: 0 8px; }
.par-botones svg { width: 20px; height: 20px; }

/* Escáner a pantalla completa */
.escaner { position: fixed; inset: 0; z-index: 20; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.escaner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.escaner .guia { position: absolute; left: 50%; top: 42%; width: min(80vw, 420px); height: min(34vw, 180px); min-height: 110px; transform: translate(-50%, -50%);
  border: 3px solid var(--naranja); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.escaner .hint { position: relative; color: #fff; font-weight: 700; text-align: center; margin: 0 0 8px; text-shadow: 0 1px 4px #000; }
.escaner .primario { position: relative; max-width: 420px; margin-top: 8px; background: #fff; }

/* Panel de supervisores */
.modo-panel main { max-width: 1100px; }
.modo-panel header.barra .chip { display: none; }
#panel-estado { margin: 0 0 10px; font-weight: 600; }
#panel-estado.alerta { color: var(--rojo); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; display: grid; gap: 4px; }
.kpi strong { font-size: 2rem; line-height: 1; color: var(--azul); }
.kpi span { color: var(--suave); font-size: .88rem; font-weight: 600; }
.cols { display: grid; gap: 12px; }
.cols .tarjeta { margin-bottom: 0; min-width: 0; }
.tarjeta h2 { font-size: 1.05rem; margin: 0 0 10px; color: var(--azul); }
.persona { padding: 8px 0; border-top: 1px solid var(--borde); }
.persona:first-of-type { border-top: 0; }
.persona .linea { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.est { border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 800; white-space: nowrap; }
.est.gris { background: #e4e8ee; color: var(--suave); }
.est.rojo { background: #fbe3e1; color: var(--rojo); }
.est.verde { background: var(--verde-2); color: var(--verde); }
.est.azul { background: #dce9f8; color: var(--azul-2); }
.tabla { overflow-x: auto; }
.tabla table { border-collapse: collapse; width: 100%; font-size: .85rem; }
.tabla th, .tabla td { text-align: left; padding: 6px 8px; border-top: 1px solid var(--borde); }
.reciente { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--borde); }
.reciente .info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
@media (min-width: 900px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .cols { grid-template-columns: 1fr 1fr; }
  .cols .ancho { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Líneas por marca en la ficha */
.mf { border: 1px solid var(--borde); border-left: 5px solid var(--azul); border-radius: var(--radio); padding: 8px; margin: 8px 0; }
.mf.con-error { border-color: var(--rojo); }
.mf.quitada { background: #eef0f3; border-left-color: var(--borde); color: var(--suave); }
.mf.quitada .mf-marca { text-decoration: line-through; }
.mf-nom { display: flex; align-items: center; gap: 8px; min-height: 28px; margin-bottom: 6px; }
.mf-marca { flex: 1; min-width: 0; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-aviso { font-size: .85rem; font-weight: 700; white-space: nowrap; }
.mf-nom input { min-height: 48px; padding: 8px 10px; }
.mf-ctl { display: flex; align-items: center; gap: 6px; }
.mf-ctl button { flex: none; min-width: 44px; min-height: 48px; padding: 0; font-size: 1.6rem; font-weight: 700; line-height: 1; background: var(--azul); color: #fff; }
.mf-ctl button:disabled { opacity: .45; }
.mf-ctl .mf-ico { background: var(--tarjeta); border: 2px solid var(--azul); color: var(--azul); display: inline-flex; align-items: center; justify-content: center; }
.mf-ctl .mf-ico.con-foto-ok { background: var(--verde-2); border-color: var(--verde); color: var(--verde); }
.mf-q { flex: 1; min-width: 0; text-align: center; font-size: 1.6rem; font-weight: 800; padding: 6px; min-height: 52px; border-color: var(--azul); color: var(--azul); }
.mf-q:disabled { background: transparent; border-color: var(--borde); color: var(--suave); }
.mf .mf-err { min-height: 0; margin: 4px 0 0; font-size: .9rem; }
.total-marcas { text-align: right; font-size: 1.1rem; padding: 4px 4px 0; }

/* Búsqueda en todo el catálogo, parecidos, chip "Mismo que" */
.fila.fuera { flex-wrap: wrap; border-left-color: var(--azul); }
.fila.fuera .secundario { min-height: 48px; width: 100%; }
.parecidos { background: var(--naranja-2); border-radius: var(--radio); padding: 10px 12px; margin: 10px 0; }
.parecido { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--borde); }
.parecido .info { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.parecido .secundario { min-height: 48px; padding: 0 12px; }
.chip-mismo { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--verde-2); border-radius: var(--radio); padding: 4px 4px 4px 12px; margin: 10px 0; font-weight: 700; }
.chip-mismo button { min-width: 48px; min-height: 48px; background: none; font-size: 1.4rem; }
.nuevos-alto { color: var(--rojo); font-weight: 800; }
