/* Estilos solo para móvil (sin adaptaciones a escritorio) */
:root {
  --fondo: #f2f3f5; --tarjeta: #fff; --texto: #1d2330; --suave: #6b7280;
  --acento: #0b5cad; --ok: #127a3a; --no: #b42318; --borde: #e3e6ea;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 16px;
  background: var(--fondo); color: var(--texto);
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  position: sticky; top: 0; z-index: 10;
  background: var(--acento); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
}
header h1 { margin: 0; font-size: 1.1rem; }
header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
header h1 a { color: inherit; text-decoration: none; display: block; }
header h1 .sub { font-weight: 500; opacity: .75; }
#tiempo { font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; opacity: .9; white-space: nowrap; }

main { display: grid; gap: 10px; padding: 10px 0; }
section { background: var(--tarjeta); padding: 12px; }

/* Búsqueda */
form { display: flex; gap: 8px; margin-top: 10px; }
input {
  flex: 1; min-width: 0; height: 48px; padding: 0 12px;
  font-size: 16px; /* evita el zoom automático de iOS */
  border: 1px solid var(--borde); border-radius: 10px; background: #fff;
}
button {
  height: 48px; padding: 0 16px; font-size: 1rem; font-weight: 600;
  border: 0; border-radius: 10px; background: var(--acento); color: #fff;
}
button:active { opacity: .8; }
.btn-lupa { width: 52px; padding: 0; flex: none; display: flex; align-items: center; justify-content: center; }
.btn-lupa svg { width: 24px; height: 24px; }
button.secundario { width: 100%; background: #e8eef7; color: var(--acento); display: flex; align-items: center; justify-content: center; gap: 8px; }
button.secundario svg { width: 20px; height: 20px; flex: none; }

/* Visor de cámara: franja panorámica; el vídeo completo queda centrado y recortado */
#visor { position: relative; aspect-ratio: 16 / 9; margin-bottom: 8px; border-radius: 10px; overflow: hidden; background: #000; }
#lector { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); }
#lector video { width: 100%; height: auto; display: block; }
/* Línea guía para apuntar al código */
#visor::after {
  content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: 2px;
  background: rgba(255, 59, 48, .85); box-shadow: 0 0 6px rgba(255, 59, 48, .9); pointer-events: none; z-index: 2;
}
/* Filete verde al leer un código */
#visor::before {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  border: 5px solid transparent; border-radius: 10px; transition: border-color .4s ease-out;
}
#visor.leido::before { border-color: #22c55e; transition: none; }
#visor.leido::after { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
#btn-sonido {
  position: absolute; z-index: 4; left: 50%; bottom: 8px; transform: translateX(-50%);
  height: auto; padding: 6px 12px; font-size: .8rem; font-weight: 600; white-space: nowrap;
  background: rgba(0, 0, 0, .65); color: #fff; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 6px;
}
#btn-sonido svg { width: 16px; height: 16px; flex: none; }
#btn-sonido[hidden] { display: none; }
#mensaje { margin: 8px 0 0; min-height: 1.2em; font-size: .9rem; color: var(--suave); text-align: center; }
#mensaje.error { color: var(--no); }
#mensaje:empty { display: none; }
#mensaje .ejemplo { color: var(--acento); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* Ficha */
#r-foto-wrap { margin: -12px -12px 12px; background: #fff; border-bottom: 1px solid var(--borde); }
#r-foto { display: block; width: 100%; height: 220px; object-fit: contain; padding: 8px; }
h2 { margin: 0 0 10px; font-size: 1.05rem; line-height: 1.3; }
h3 { margin: 16px 0 6px; font-size: .9rem; color: var(--suave); text-transform: uppercase; letter-spacing: .03em; }
.ficha { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0; }
.ficha div { background: var(--fondo); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.ficha dt { font-size: .7rem; color: var(--suave); text-transform: uppercase; letter-spacing: .03em; }
.ficha dd { margin: 2px 0 0; font-size: 1rem; font-weight: 600; overflow-wrap: anywhere; }
.ficha .destacado { grid-column: 1 / -1; background: #e8f4ec; display: flex; justify-content: space-between; align-items: center; }
.ficha .destacado dd { font-size: 1.8rem; margin: 0; color: var(--ok); }
.tachado { display: block; text-decoration: line-through; color: var(--suave); font-weight: 400; font-size: .8rem; }

/* Tabla de tallas */
.tabla-wrap { overflow-x: auto; margin: 0 -12px; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--borde); text-align: center; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 12px; }
th:last-child, td:last-child { padding-right: 12px; }
th { font-size: .7rem; color: var(--suave); text-transform: uppercase; background: #fafbfc; }
tr.actual { background: #fff7d6; font-weight: 700; }
tr.clic:active { background: #e8eef7; }
td.cero { color: #b8bec7; }
td.total { font-weight: 700; }
.ficha .destacado.sin-stock { background: #fdecea; }
.ficha .destacado.sin-stock dd { color: var(--no); }

/* Evitar que la tabla ensanche la página */
main > section { min-width: 0; }
th { white-space: normal; font-size: .6rem; line-height: 1.2; padding: 8px 4px; vertical-align: bottom; }
td { padding: 10px 4px; }
th:first-child, td:first-child { padding-left: 12px; }
th:last-child, td:last-child { padding-right: 12px; }

/* Stock del producto por almacén */
.ficha .almacenes { grid-column: 1 / -1; }
.ficha .almacenes ul { list-style: none; margin: 4px 0 0; padding: 0; }
.ficha .almacenes li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--borde); font-weight: 500; font-size: .95rem; }
.ficha .almacenes li:last-child { border-bottom: 0; }
.ficha .almacenes li.principal { font-weight: 700; }
.ficha .almacenes li.cero b { color: #b8bec7; }
.ficha .almacenes li.total { font-weight: 700; border-top: 2px solid var(--borde); }

/* ===== Recuento de inventario (estilo "Recuento en curso") ===== */
:root { --marino: #0f2747; --azul-borde: #3b8ff0; }
main { padding: 10px; }
.panel { background: #fff; border-radius: 18px; padding: 16px 14px; box-shadow: 0 2px 10px rgba(15, 39, 71, .08); }

.titulo-recuento { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.icono-titulo { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: #dbeafe; color: var(--acento); box-shadow: inset 0 0 0 1px #bfdbfe; }
.icono-titulo svg { width: 26px; height: 26px; }
.titulo-recuento h2 { margin: 0; font-size: 1.45rem; font-weight: 800; color: var(--marino); letter-spacing: -.01em; }

.btn-info { margin-left: auto; flex: none; width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: 50%; background: #eef2f7; color: var(--marino); }
.btn-info svg { width: 24px; height: 24px; }
.btn-info[aria-expanded="true"] { background: var(--acento); color: #fff; }

/* Una columna: icono + valor */
.datos-recuento { display: grid; gap: 2px; padding: 6px 12px; margin-bottom: 12px; background: #eef2f7; border-radius: 10px; color: var(--marino); animation: desplegar .15s ease-out; }
.datos-recuento[hidden] { display: none; }
@keyframes desplegar { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dato { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: .95rem; }
.dato + .dato { border-top: 1px solid #d8e0ea; }
.dato svg { width: 20px; height: 20px; flex: none; color: #4b5d78; }
.dato b { font-weight: 700; }
.dato select { flex: 1; min-width: 0; height: 36px; border: 0; background: transparent; font: inherit; font-size: 16px; font-weight: 700; color: var(--marino); padding: 0; }

.escanear { display: flex; gap: 8px; margin: 0; }
.btn-codigo { flex: none; width: 52px; height: 52px; padding: 0; display: grid; place-items: center; background: #fff; color: var(--marino); border: 1.5px solid #c9d6e8; border-radius: 10px; }
.btn-codigo svg { width: 28px; height: 28px; }
.btn-codigo.activa { background: var(--acento); color: #fff; border-color: var(--acento); }
.escanear input { height: 52px; border: 2px solid var(--azul-borde); border-radius: 10px; font-size: 16px; box-shadow: 0 0 0 3px rgba(59, 143, 240, .12); }
.escanear input::placeholder { color: #8a97a8; }

.tabla-recuento { margin: 12px -4px 0; border-radius: 12px; overflow: hidden; border: 1px solid #dde3ea; }
.tabla-recuento table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .85rem; }
.tabla-recuento th { background: var(--marino); color: #fff; font-size: .68rem; font-weight: 700; text-transform: none; letter-spacing: 0; padding: 10px 6px; text-align: left; white-space: nowrap; vertical-align: middle; }
.tabla-recuento th:nth-child(1) { width: 50px; }
.tabla-recuento th:nth-child(2) { width: 22%; }
.tabla-recuento th:nth-child(4) { width: 13%; }
.tabla-recuento th:nth-child(5) { width: 46px; }
.tabla-recuento th:nth-child(4), .tabla-recuento th:nth-child(5) { width: 15.5%; text-align: center; padding-left: 2px; padding-right: 2px; font-size: .62rem; border-left: 1px solid rgba(255,255,255,.15); }
.tabla-recuento th:nth-child(6) { width: 30px; }
.tabla-recuento td { padding: 10px 6px; border-top: 1px solid #e5e9ef; vertical-align: middle; text-align: left; white-space: normal; color: var(--marino); }
.tabla-recuento td.ref { font-weight: 800; font-size: .7rem; word-break: break-all; padding-left: 2px; }
.tabla-recuento td.foto { padding: 6px 4px 6px 6px; }
.miniatura { display: block; width: 40px; height: 40px; padding: 0; border: 1px solid #dde3ea; border-radius: 8px; background: #fff; overflow: hidden; }
.miniatura img { width: 100%; height: 100%; object-fit: contain; display: block; }
.miniatura.vacia { background: #eef2f7 url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23a3b0c2" stroke-width="1.6"><rect x="3" y="5" width="18" height="14" rx="2"/><circle cx="9" cy="10" r="1.6"/><path d="M4 18l5-5 4 4 3-3 4 4"/></svg>') center / 22px no-repeat; }
.tabla-recuento td.contado { padding: 4px 3px; }
.tabla-recuento td.contado button { display: block; width: 100%; height: 26px; padding: 0; border-radius: 6px; background: #e8eef7; color: var(--acento); font-size: 1.1rem; font-weight: 700; line-height: 1; }
.tabla-recuento td.contado input { height: 30px; margin: 2px 0; }
.tabla-recuento td.art { font-size: .78rem; line-height: 1.25; }
.tabla-recuento td.num { text-align: center; font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; border-left: 1px solid #e5e9ef; padding: 4px 2px; }
.tabla-recuento td.num input { width: 100%; height: 36px; padding: 0; border: 0; border-radius: 6px; background: transparent; text-align: center; font: inherit; color: inherit; -moz-appearance: textfield; }
.tabla-recuento td.num input:focus { background: #eef5ff; outline: 2px solid var(--azul-borde); }
.tabla-recuento td.num input::-webkit-outer-spin-button, .tabla-recuento td.num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tabla-recuento td.estado { text-align: center; padding: 4px; border-left: 1px solid #e5e9ef; }
.tabla-recuento td.estado svg { width: 22px; height: 22px; display: block; margin: auto; }
.tabla-recuento tr.no-encontrado td.art, .tabla-recuento tr.error td.art { color: var(--no); font-weight: 600; }
.tabla-recuento tr.pendiente td.art { color: var(--suave); }
.tabla-recuento tr.nueva td { animation: nueva 1.2s ease-out; }
@keyframes nueva { from { background: #fff7d6; } to { background: transparent; } }
.girando { display: block; width: 18px; height: 18px; margin: auto; border-radius: 50%; border: 2.5px solid #cbd5e1; border-top-color: var(--acento); animation: girar .8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
#vacio { margin: 0; padding: 18px 12px; text-align: center; color: var(--suave); font-size: .88rem; }

.resumen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.resumen div { background: #eef2f7; border-radius: 10px; padding: 8px; text-align: center; color: var(--marino); }
.resumen b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.resumen span { white-space: nowrap; font-size: .68rem; color: var(--suave); text-transform: uppercase; letter-spacing: .03em; }
.acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.acciones button { height: 42px; font-size: .85rem; }
.acciones .peligro { grid-column: 1 / -1; background: #fdecea; color: var(--no); }
.acciones button:disabled { opacity: .45; }
#visor { margin-bottom: 10px; }
#mensaje { margin-top: 8px; }

/* Foto ampliada */
.foto-grande { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(10, 20, 35, .72); }
.foto-grande[hidden] { display: none; }
.foto-grande-caja { position: relative; width: 100%; max-width: 420px; background: #fff; border-radius: 16px; padding: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.35); animation: aparecer .18s ease-out; }
@keyframes aparecer { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
.foto-grande img { display: block; width: 100%; max-height: 60vh; object-fit: contain; border-radius: 10px; background: #fff; }
.foto-grande .fg-texto { display: grid; gap: 2px; margin-top: 10px; color: var(--marino); text-align: center; }
.foto-grande .fg-texto b { font-size: 1rem; }
.foto-grande .fg-texto span { font-size: .8rem; color: var(--suave); }
.foto-grande .cerrar { position: absolute; top: 8px; right: 8px; z-index: 1; width: 36px; height: 36px; padding: 0; display: grid; place-items: center; border-radius: 50%; background: rgba(15, 39, 71, .85); color: #fff; }
.foto-grande .cerrar svg { width: 18px; height: 18px; }

/* Ajuste de la pausa entre lecturas (ms) */
.ajuste-ms { display: flex; align-items: center; gap: 10px; }
.ajuste-ms b { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.ajuste-ms button { width: 32px; height: 32px; padding: 0; border-radius: 8px; background: #fff; color: var(--acento); font-size: 1.15rem; font-weight: 700; line-height: 1; box-shadow: inset 0 0 0 1px #c9d6e8; }
.ajuste-ms button:disabled { opacity: .4; }

/* Filas compactas: que cada línea ocupe lo mínimo */
.tabla-recuento td { padding-top: 5px; padding-bottom: 5px; }
.tabla-recuento td.foto { padding: 4px 3px 4px 6px; }
.miniatura { width: 34px; height: 34px; border-radius: 6px; }
.miniatura.vacia { background-size: 18px; }
.tabla-recuento td.art { font-size: .72rem; line-height: 1.2; }
.art-txt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tabla-recuento td.contado { padding: 3px 3px; }
.tabla-recuento td.contado button { height: 20px; font-size: .95rem; border-radius: 5px; }
.tabla-recuento td.contado input { height: 22px; margin: 1px 0; font-size: .95rem; }
.tabla-recuento td.num { font-size: .95rem; }
.tabla-recuento td.estado svg { width: 20px; height: 20px; }
.art-icono { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; vertical-align: middle; }
.art-icono svg { width: 18px; height: 18px; }
.art-icono.no { background: #fdecea; color: var(--no); }
.art-icono.red { background: #fff4e0; color: #9a5b00; }
.art-icono.espera { color: var(--suave); font-weight: 700; }

/* Aspa roja = borrar la línea */
.tabla-recuento td.estado .borrar { display: block; width: 28px; height: 28px; margin: auto; padding: 2px; background: transparent; border-radius: 50%; }
.tabla-recuento td.estado .borrar:active { background: #fdecea; }
#mensaje .ejemplo { color: var(--acento); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
