:root {
  --azul: #005275;
  --azul-2: #0a6a94;
  --verde: #86BC25;
  --verde-osc: #5f8a14;
  --rojo: #c62828;
  --ambar: #e69500;
  --fondo: #f2f5f7;
  --tarjeta: #ffffff;
  --texto: #1b2830;
  --suave: #5d6f7a;
  --borde: #dbe3e8;
  --radio: 14px;
  --sombra: 0 1px 3px rgba(0, 40, 60, .12);
  --tab-alto: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0f171c;
    --tarjeta: #18242b;
    --texto: #e6edf1;
    --suave: #93a6b1;
    --borde: #2a3a44;
    --azul-2: #3aa0cf;
    --sombra: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(var(--tab-alto) + env(safe-area-inset-bottom) + 12px);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--azul-2); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 18px 0 8px; }

/* Barra superior */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--azul); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.top .titulo { font-weight: 700; font-size: 1.05rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .marca { width: 10px; height: 22px; border-radius: 3px; background: var(--verde); }
.top form { margin: 0; }
.top button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 8px; padding: 5px 10px; font-size: .85rem; }

main { padding: 14px 16px; max-width: 900px; margin: 0 auto; }

/* Pestañas abajo */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--tarjeta); border-top: 1px solid var(--borde);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; height: var(--tab-alto);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--suave); font-size: .72rem; font-weight: 600;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.on { color: var(--azul-2); }
.tabs a.escanear {
  color: #fff;
}
.tabs a.escanear span.bola {
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--verde); display: flex; align-items: center; justify-content: center;
  margin-top: -22px; box-shadow: 0 3px 10px rgba(0,0,0,.25);
}
.tabs a.escanear span.txt { color: var(--suave); }
.tabs a.escanear.on span.txt { color: var(--azul-2); }

/* Tarjetas y listas */
.card { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px; margin-bottom: 12px; border: 1px solid var(--borde); }
.lista { background: var(--tarjeta); border-radius: var(--radio); border: 1px solid var(--borde); overflow: hidden; margin-bottom: 12px; }
.lista > a, .lista > div.item { display: flex; gap: 12px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--borde); color: inherit; }
.lista > *:last-child { border-bottom: 0; }
.lista .grow { flex: 1; min-width: 0; }
.lista .nombre { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista .sub { color: var(--suave); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; background: var(--fondo); flex: none; display: flex; align-items: center; justify-content: center; color: var(--suave); font-size: .7rem; }
.cifra { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.cifra small { color: var(--suave); font-weight: 500; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--suave); font-size: .82rem; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .74rem; font-weight: 700; background: var(--fondo); color: var(--suave); border: 1px solid var(--borde); }
.b-entrada, .b-almacen, .b-devolucion { background: #e8f4d6; color: #3f6b00; border-color: #cfe5a8; }
.b-salida, .b-tecnico { background: #e0eef5; color: #005275; border-color: #bcd9e7; }
.b-consumo, .b-instalada { background: #efe6f7; color: #5b2a86; border-color: #dccbeb; }
.b-ajuste, .b-obra { background: #fff2d9; color: #8a5a00; border-color: #f0dcae; }
.b-baja, .b-rma, .b-error { background: #fde3e3; color: #a31515; border-color: #f3c2c2; }
.b-enviado { background: #e8f4d6; color: #3f6b00; }
.b-pendiente { background: #fff2d9; color: #8a5a00; }
.bajo { color: var(--rojo); }

/* Formularios */
label { display: block; font-size: .85rem; color: var(--suave); margin: 10px 0 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=date], select, textarea {
  width: 100%; font-size: 16px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--borde); background: var(--tarjeta); color: var(--texto);
}
input:focus, select:focus { outline: 2px solid var(--azul-2); outline-offset: 0; }
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; color: var(--texto); font-size: .95rem; }
.check input { width: 22px; height: 22px; }
.fila { display: flex; gap: 10px; }
.fila > * { flex: 1; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 16px; font-size: 1rem; font-weight: 700;
  background: var(--azul); color: #fff; cursor: pointer; text-align: center;
}
.btn.verde { background: var(--verde); color: #10240a; }
.btn.rojo { background: var(--rojo); }
.btn.gris { background: var(--fondo); color: var(--texto); border: 1px solid var(--borde); }
.btn.bloque { width: 100%; }
.btn.peq { padding: 7px 11px; font-size: .85rem; border-radius: 9px; }
.btn:disabled { opacity: .5; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.buscador { display: flex; gap: 8px; margin-bottom: 10px; }
.buscador input { flex: 1; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; }
.chips a { flex: none; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--borde); background: var(--tarjeta); color: var(--texto); font-size: .85rem; }
.chips a.on { background: var(--azul); color: #fff; border-color: var(--azul); }

.flash { padding: 11px 14px; border-radius: 12px; margin-bottom: 10px; font-weight: 600; }
.flash.ok { background: #e8f4d6; color: #335800; }
.flash.error { background: #fde3e3; color: #8f1111; }

.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabla th, .tabla td { padding: 8px 6px; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: top; }
.tabla th { color: var(--suave); font-size: .78rem; text-transform: uppercase; }
.scroll-x { overflow-x: auto; }
.muted { color: var(--suave); }
.vacio { text-align: center; color: var(--suave); padding: 24px 10px; }

/* ---------- Escáner ---------- */
.modos { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 10px; }
.modos button {
  border: 1px solid var(--borde); background: var(--tarjeta); color: var(--texto);
  border-radius: 11px; padding: 9px 2px; font-size: .74rem; font-weight: 700;
}
.modos button.on { color: #fff; border-color: transparent; }
.modos button[data-modo=entrada].on { background: var(--verde-osc); }
.modos button[data-modo=salida].on { background: var(--azul); }
.modos button[data-modo=consumo].on { background: #6a3a99; }
.modos button[data-modo=devolucion].on { background: #2e7d32; }
.modos button[data-modo=ajuste].on { background: var(--ambar); }
.destino { margin-bottom: 10px; }
.destino .fila { margin-top: 6px; }
.visor-wrap { position: relative; border-radius: var(--radio); overflow: hidden; background: #000; margin-bottom: 10px; min-height: 60px; }
#visor { width: 100%; }
#visor video { width: 100% !important; display: block; }
.visor-wrap .marco { position: absolute; inset: 0; pointer-events: none; }
.manual { display: flex; gap: 8px; margin-bottom: 10px; }
.manual input { flex: 1; }
#resultado:empty { display: none; }
.res-art { display: flex; gap: 12px; align-items: center; }
.res-art img, .res-art .thumb { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; }
.res-art .nombre { font-weight: 700; font-size: 1.05rem; }
.stock-grande { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.pregunta { font-weight: 700; margin: 14px 0 8px; }
.numeros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.numeros button {
  font-size: 1.35rem; font-weight: 800; padding: 14px 0; border-radius: 12px;
  border: 1px solid var(--borde); background: var(--fondo); color: var(--texto);
}
.numeros button.on { background: var(--azul); color: #fff; border-color: var(--azul); }
.cant-fila { display: flex; gap: 8px; margin-top: 8px; align-items: stretch; }
.cant-fila input { flex: 1; font-size: 1.3rem; font-weight: 700; text-align: center; }
.cant-fila .paso { width: 56px; font-size: 1.4rem; font-weight: 800; border-radius: 12px; border: 1px solid var(--borde); background: var(--fondo); color: var(--texto); }
.aviso { padding: 10px 12px; border-radius: 11px; background: #fff2d9; color: #6b4600; font-weight: 600; margin: 10px 0; }
.aviso.error { background: #fde3e3; color: #8f1111; }
.aviso.ok { background: #e8f4d6; color: #335800; }
.sesion .item { font-size: .9rem; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tab-alto) + env(safe-area-inset-bottom) + 14px);
  z-index: 40; padding: 14px 16px; border-radius: 14px; font-weight: 700;
  background: #1f3b12; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.3);
  transform: translateY(20px); opacity: 0; transition: .2s; pointer-events: none;
}
.toast.ver { transform: none; opacity: 1; }
.toast.error { background: #8f1111; }
.offline { display: none; background: var(--rojo); color: #fff; text-align: center; font-weight: 700; padding: 6px; font-size: .85rem; }
body.sin-red .offline { display: block; }
.instalar { display: none; }
.instalar.ver { display: block; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px 16px; background: var(--azul); }
.login-wrap .card { width: 100%; max-width: 380px; }
.login-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.3rem; margin-bottom: 8px; }
.login-logo .marca { width: 12px; height: 28px; border-radius: 3px; background: var(--verde); }

/* ---------- Impresión etiquetas ---------- */
.etiquetas-hoja { display: flex; flex-wrap: wrap; gap: 3mm; }
.etiqueta { width: 62mm; height: 29mm; border: 1px dashed #bbb; border-radius: 2mm; padding: 1.5mm; display: flex; gap: 2mm; align-items: center; background: #fff; color: #000; page-break-inside: avoid; break-inside: avoid; }
.etiqueta svg { width: 25mm; height: 25mm; flex: none; }
.etiqueta .txt { min-width: 0; font-size: 8.5pt; line-height: 1.2; }
.etiqueta .txt b { display: block; font-size: 9.5pt; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.etiqueta .cod { font-family: monospace; font-size: 10pt; font-weight: 700; margin-top: 1mm; }
@media print {
  .no-print, .top, .tabs { display: none !important; }
  body { background: #fff; padding: 0; }
  main { padding: 0; max-width: none; }
  .etiqueta { border-color: transparent; }
  @page { margin: 6mm; }
}

/* ---------- v2: escáner en ventana, hoja inferior, bandeja ---------- */
.escaner-capa { position: fixed; inset: 0; z-index: 60; background: rgba(0,15,25,.92); display: flex; align-items: flex-start; justify-content: center; padding: calc(env(safe-area-inset-top) + 14px) 16px 16px; overflow-y: auto; }
.escaner-caja { width: 100%; max-width: 520px; }
#escaner-visor { width: 100%; border-radius: 14px; overflow: hidden; background: #000; min-height: 40px; }
#escaner-visor video { width: 100% !important; display: block; }
.hoja-fondo { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.hoja { width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; background: var(--tarjeta); color: var(--texto); border-radius: 20px 20px 0 0; padding: 10px 16px calc(env(safe-area-inset-bottom) + 16px); box-shadow: 0 -6px 24px rgba(0,0,0,.25); }
.hoja-asa { width: 44px; height: 5px; border-radius: 3px; background: var(--borde); margin: 0 auto 12px; }
.foto-linea { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; display: block; flex: none; }
.card.linea { padding: 12px; }
.con-badge { position: relative; display: inline-flex; }
.contador { position: absolute; top: -6px; right: -12px; background: var(--rojo); color: #fff; border-radius: 99px; font-size: .68rem; padding: 1px 6px; font-style: normal; }
.b-hecha { background: #e8f4d6; color: #3f6b00; border-color: #cfe5a8; }
.b-rechazada { background: #fde3e3; color: #a31515; border-color: #f3c2c2; }
.b-abierto { background: #fff2d9; color: #8a5a00; }
.lista > label.item { cursor: pointer; }
.grow { flex: 1; min-width: 0; }
