/* Lo comun de las apps de operario (fotos de carga, incidencias, devoluciones,
   inventario). Sistema "Precision Industrial": fondo frio, cabecera oscura
   con filo azul y controles grandes para manos con guantes. Cada app carga
   esta hoja y añade solo lo suyo. */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  height: 100vh; height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(165deg, #F2F4F7 0%, #E9ECF1 55%, #E4E8EE 100%);
  background-attachment: fixed;
  color: #161B22;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button, input, textarea { font: inherit; }
input, textarea { -webkit-user-select: text; user-select: text; max-width: 100%; min-width: 0; }
button { cursor: pointer; touch-action: manipulation; transition: transform .08s ease, filter .12s ease; }
button:active { transform: scale(.97); }
button:disabled { opacity: .5; }
img, video { max-width: 100%; }
.hidden { display: none !important; }
input.oculto { position: absolute; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ── Cabecera: volver a la izquierda, titulo y estado en el centro, salir ── */
.shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  flex: 0 0 auto; z-index: 5;
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top));
  background: #12161D; color: #fff; border-bottom: 2px solid #0f4c81; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.title { min-width: 0; text-align: center; }
.title b { display: block; font-size: 18px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title span { display: block; color: #aab4c2; font-size: 13px; margin-top: 3px; min-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title span.pendientes { color: #ffd27a; }
.ghost { min-height: 44px; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: 12px; padding: 8px 12px; font-weight: 800; }

/* En pantallas bajas, se puede bajar hasta el boton de foto. */
main.pantalla {
  flex: 1; min-height: 0; width: min(520px, 100%); margin: 0 auto;
  padding: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* La que si se desplaza (formularios largos). */
main.lista {
  flex: 1; min-height: 0; width: min(760px, 100%); margin: 0 auto;
  padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 10px;
}

/* ── Visor de camara con lectura de codigos a peticion ── */
.visor { flex: 1 0 110px; min-height: 110px; position: relative; background: #0b0f14; border-radius: 12px; overflow: hidden; }
.visor video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.visor .aviso-camara { position: absolute; inset: 0; display: none; place-items: center; text-align: center; color: #cfd6df; font-weight: 800; padding: 12px; }
.visor.sin-camara .aviso-camara { display: grid; }
.visor .flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.visor.dispara .flash { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
.lector { position: absolute; top: 8px; left: 8px; display: flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 999px; background: rgba(11,15,20,.72); color: #fff; font-size: 12px; font-weight: 800; letter-spacing: .04em; }
.lector::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #8a949f; }
.lector.activo::before { background: #3ddc84; box-shadow: 0 0 6px #3ddc84; }
button.lector { border: 1px solid rgba(255,255,255,.5); cursor: pointer; min-height: 44px; padding: 8px 12px; }
.visor.leida { outline: 4px solid #3ddc84; outline-offset: -4px; }
/* Hueco fijo de la ultima foto: siempre ocupa lo mismo, con o sin foto. */
.ultima { position: absolute; left: 8px; right: 8px; bottom: 8px; height: 56px; display: grid; grid-template-columns: 56px 1fr auto; gap: 8px; align-items: center; }
.ultima .mini { width: 56px; height: 56px; border-radius: 8px; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.35); overflow: hidden; }
.ultima .mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ultima .texto { color: #fff; font-weight: 800; font-size: 14px; line-height: 1.2; text-shadow: 0 1px 2px rgba(0,0,0,.8); min-width: 0; }
.ultima .texto small { display: block; font-weight: 700; font-size: 12px; color: #dfe6ee; }
.ultima .borrar { min-height: 40px; border: 0; border-radius: 10px; background: rgba(255,255,255,.92); color: #9f2f2f; font-weight: 900; padding: 0 12px; visibility: hidden; }
.ultima.con-foto .borrar { visibility: visible; }

/* ── Numero grande y linea de confirmacion (hueco fijo de dos lineas) ── */
.numero { display: grid; grid-template-columns: 1fr auto; align-items: center; min-height: 48px; padding: 0 4px; }
.cifra { font-size: 38px; font-weight: 900; line-height: 1; letter-spacing: .02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.cifra .propuesta { color: #9aa5b1; }
.cifra .vacio { color: #b7c0ca; }
.etiqueta { font-size: 13px; font-weight: 800; color: #707885; text-transform: uppercase; letter-spacing: .06em; text-align: right; white-space: nowrap; }
.confirma { min-height: 38px; max-height: 38px; font-size: 14px; line-height: 1.3; padding: 0 4px; color: #161B22; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.confirma.ok { color: #17633a; font-weight: 700; }
.confirma.aviso { color: #8a5a00; font-weight: 800; }
.confirma.error { color: #9f2f2f; font-weight: 800; }
.confirma.tenue { color: #707885; }

/* ── Tira de chips (jaulas, repartos, expediciones a rehacer) ── */
.tira { flex: 0 0 44px; display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: 2px; }
.tira::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-width: 66px; height: 40px; border-radius: 10px; border: 2px solid #C7CDD6; background: #FBFCFD; color: #161B22; font-weight: 800; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 0 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.con-foto, .chip.hecha { border-color: #17633a; background: #e9f7ef; }
.chip.en-cola { border-color: #8a5a00; background: #fff6e5; }
.chip.rechazada { border-color: #9f2f2f; background: #fdecec; }
.chip.actual { outline: 3px solid #0f4c81; outline-offset: -1px; }
.chip .marca { font-size: 13px; }
.tira .vacia { color: #707885; font-size: 13px; font-weight: 700; align-self: center; padding: 0 6px; white-space: nowrap; }

/* ── Teclado dibujado: nunca sale el del sistema ── */
.teclado { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tecla { min-height: 50px; font-size: 24px; font-weight: 800; border-radius: 10px; border: 2px solid #C7CDD6; background: #FBFCFD; color: #161B22; }
.tecla:active { border-color: #0f4c81; background: #eef4fa; }
.tecla.fn { font-size: 15px; font-weight: 900; background: #F5F6F8; }

/* ── Botones de disparo: tipo y foto en un toque ── */
.disparos { flex: 0 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.disparo { min-height: 68px; border: 0; border-radius: 12px; color: #fff; font-weight: 900; font-size: 16px; line-height: 1.1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 4px; }
.disparo small { font-size: 11px; font-weight: 700; opacity: .92; letter-spacing: .04em; }
.disparo.azul { background: #0f4c81; } .disparo.azul:active { background: #0b3a64; }
.disparo.verde { background: #229954; } .disparo.verde:active { background: #17703d; }
.disparo.verde-oscuro { background: #146b3a; } .disparo.verde-oscuro:active { background: #0e4f2b; }
.disparo.rojo { background: #b93a2b; } .disparo.rojo:active { background: #8f2a1e; }
.disparo.avisa, .hueco.avisa { animation: sacude .35s ease; }
@keyframes sacude { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* Interruptor Si/No de una sola fila (embalaje intacto, etc.). */
.interruptor { flex: 0 0 auto; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 6px; min-height: 44px; }
.interruptor .rotulo { font-weight: 800; font-size: 15px; padding-left: 4px; }
.interruptor button { min-width: 64px; min-height: 42px; border-radius: 10px; border: 2px solid #C7CDD6; background: #FBFCFD; font-weight: 900; color: #161B22; }
.interruptor button.on { border-color: #0f4c81; background: #0f4c81; color: #fff; }
.interruptor button.on.mal { border-color: #b93a2b; background: #b93a2b; }

/* ── Entrada por nombre: el ultimo que entro va el primero y en grande ── */
.login-wrap { height: 100vh; height: 100dvh; display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: calc(16px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom)); }
.login { width: min(420px, 100%); padding: 20px; background: #FBFCFD; border: 1px solid #C7CDD6; border-radius: 14px; box-shadow: 0 1px 2px rgba(22,27,34,.10); }
.login h1 { margin: 4px 0 12px; font-size: 1.45rem; }
.login p { margin: 0 0 20px; color: #6f7d8d; line-height: 1.45; }
.tag { color: #6f7d8d; font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.name-grid { display: grid; gap: 8px; max-height: 46vh; overflow-y: auto; overscroll-behavior: contain; margin-bottom: 12px; }
.name-btn { width: 100%; min-height: 58px; border: 2px solid #C7CDD6; border-radius: 12px; background: #fff; color: #161B22; font-size: 18px; font-weight: 800; padding: 12px 14px; text-align: left; }
.name-btn:active { border-color: #0f4c81; background: #eef4fa; }
.name-btn.ultimo { min-height: 76px; margin-bottom: 12px; border-color: #0f4c81; background: #0f4c81; color: #fff; font-size: 24px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.name-btn.ultimo small { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #cfe0f0; }
.name-btn.entrando { opacity: .7; }
.alert { min-height: 22px; font-weight: 700; font-size: 14px; }
.alert.error { color: #9f2f2f; }
.alert.ok { color: #17633a; }
.btn-lleno { display: grid; place-items: center; min-height: 58px; border-radius: 12px; color: white; background: #0f4c81; font-weight: 850; text-decoration: none; border: 0; width: 100%; }
/* La sesion caducada pide el nombre encima de lo que hay, sin vaciarlo. */
.op-capa { position: fixed; inset: 0; z-index: 50; background: rgba(18,22,29,.82); }
.op-capa .login-wrap { height: 100%; }
/* Capas de un solo gesto encima de una pantalla que se desplaza: la camara
   (foto de la ubicacion), el lector (escanear un codigo) y el numero. */
.op-hoja { position: fixed; inset: 0; z-index: 60; background: #12161D; display: flex; flex-direction: column; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom)); }
.op-hoja .op-titulo { color: #fff; font-weight: 900; font-size: 18px; text-align: center; min-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-hoja .op-texto { color: #aab4c2; font-size: 13px; font-weight: 700; text-align: center; min-height: 16px; }
.op-hoja .visor { flex: 1 1 0; min-height: 160px; }
.op-hoja .op-numero { flex: 0 0 auto; min-height: 64px; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: #FBFCFD; color: #161B22; font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.op-hoja .op-numero.vacio { color: #b7c0ca; }
.op-hoja .teclado { flex: 0 0 auto; }
.op-hoja .foto { flex: 0 0 auto; min-height: 64px; border: 0; border-radius: 12px; background: #229954; color: #fff; font-weight: 900; font-size: 19px; letter-spacing: .04em; }
.op-hoja .foto:active { background: #17703d; }
.op-hoja .op-cancelar { flex: 0 0 auto; min-height: 46px; border: 1px solid rgba(255,255,255,.35); border-radius: 12px; background: transparent; color: #fff; font-weight: 800; }

/* ── Inicio: cuatro botones grandes ── */
.inicio { flex: 1; display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; gap: 10px; padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); width: min(520px, 100%); margin: 0 auto; }
.inicio .tarjeta { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 1px solid #C7CDD6; border-radius: 16px; background: #FBFCFD; box-shadow: 0 1px 2px rgba(22,27,34,.10); color: #161B22; text-decoration: none; padding: 12px; min-height: 120px; }
.inicio .tarjeta:active { background: #eef4fa; }
.inicio .marca { width: 58px; height: 58px; border-radius: 14px; display: grid; place-items: center; color: #fff; font-size: 28px; }
.inicio .nombre { font-size: 18px; font-weight: 900; text-align: center; line-height: 1.1; }
.inicio .sub { font-size: 12px; color: #707885; font-weight: 700; text-align: center; }
