/*
 * RGM Almacén — PWA
 * Modo oscuro fijo, botones grandes, pensada para usarse con un dedo.
 */

:root {
  --bg: #0B0F14;
  --bg-elev: #141B23;
  --bg-input: #1B242E;
  --borde: #263241;
  --txt: #E8EDF3;
  --txt-suave: #93A2B4;
  --verde: #16A34A;
  --verde-claro: #22C55E;
  --rojo: #DC2626;
  --rojo-claro: #EF4444;
  --ambar: #D97706;
  --azul: #2563EB;
  --oro: #C9A227;
  --alto-barra: 74px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(var(--alto-barra) + var(--safe-bottom)); }

.oculto { display: none !important; }

/* ---------- Barra superior ---------- */

.barra-sup {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--borde);
}

.barra-sup h1 { font-size: 1.05rem; margin: 0; font-weight: 700; }
.barra-sup .sub { font-size: .72rem; color: var(--txt-suave); }

.chip-conexion {
  font-size: .68rem;
  font-weight: 700;
  padding: .2rem .55rem;
  border-radius: 999px;
  background: rgba(220, 38, 38, .18);
  color: #FCA5A5;
  white-space: nowrap;
}

.chip-conexion.online { background: rgba(22, 163, 74, .18); color: #86EFAC; }

/* ---------- Contenido ---------- */

main { padding: 1rem; max-width: 720px; margin: 0 auto; }

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

.titulo-vista { font-size: 1.25rem; font-weight: 700; margin: 0 0 1rem; }

/* ---------- Formularios ---------- */

.campo { margin-bottom: 1.1rem; }

.campo > label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--txt-suave);
  margin-bottom: .4rem;
}

input, select, textarea {
  width: 100%;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--txt);
  background: var(--bg-input);
  border: 1px solid var(--borde);
  border-radius: 12px;
  padding: .9rem 1rem;
  outline: none;
  min-height: 52px;
}

input:focus, select:focus, textarea:focus { border-color: var(--azul); }
input:disabled { color: var(--txt-suave); background: #10161D; }
textarea { min-height: 84px; resize: vertical; }

.fila { display: flex; gap: .7rem; }
.fila > * { flex: 1; }

.hint { font-size: .74rem; color: var(--txt-suave); margin-top: .35rem; }

/* ---------- Buscador inteligente ---------- */

.buscador { position: relative; }

.buscador-fila { display: flex; gap: .5rem; }
.buscador-fila .buscador { flex: 1; }

.btn-camara {
  flex: 0 0 auto;
  width: 56px;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--borde);
  background: var(--bg-input);
  color: var(--txt);
  font-size: 1.4rem;
  cursor: pointer;
}

.sugerencias {
  position: absolute;
  z-index: 40;
  left: 0; right: 0;
  top: calc(100% + 4px);
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--borde);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
}

.sugerencia { padding: .8rem 1rem; border-bottom: 1px solid var(--borde); cursor: pointer; }
.sugerencia:last-child { border-bottom: none; }
.sugerencia:active { background: var(--bg-input); }
.sugerencia .cod { font-family: ui-monospace, SFMono-Regular, monospace; font-size: .78rem; color: var(--oro); }
.sugerencia .nom { font-size: .95rem; }
.sugerencia .meta { font-size: .72rem; color: var(--txt-suave); }
.sugerencia.vacio { color: var(--txt-suave); font-style: italic; cursor: default; }

/* ---------- Tarjeta de datos automáticos ---------- */

.tarjeta-datos {
  background: var(--bg-elev);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: .9rem 1rem;
  margin-bottom: 1.1rem;
}

.tarjeta-datos .par { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0; font-size: .9rem; }
.tarjeta-datos .par span:first-child { color: var(--txt-suave); }
.tarjeta-datos .par span:last-child { font-weight: 600; text-align: right; }

.foto-previa {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: 12px;
  margin-bottom: .8rem;
  background: var(--bg-input);
}

/* ---------- Avisos ---------- */

.aviso {
  border-radius: 12px;
  padding: .8rem 1rem;
  font-size: .86rem;
  line-height: 1.45;
  margin-bottom: 1.1rem;
}

.aviso--ambar { background: rgba(217, 119, 6, .15); border: 1px solid rgba(217, 119, 6, .4); color: #FCD34D; }
.aviso--rojo  { background: rgba(220, 38, 38, .15); border: 1px solid rgba(220, 38, 38, .4); color: #FCA5A5; }
.aviso--verde { background: rgba(22, 163, 74, .15); border: 1px solid rgba(22, 163, 74, .4); color: #86EFAC; }

/* ---------- Menú inferior ---------- */

.barra-inf {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: flex;
  background: var(--bg-elev);
  border-top: 1px solid var(--borde);
  padding-bottom: var(--safe-bottom);
}

.barra-inf button {
  flex: 1;
  min-height: var(--alto-barra);
  border: none;
  background: transparent;
  color: var(--txt-suave);
  font-size: .74rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  cursor: pointer;
  padding: .4rem;
  position: relative;
}

.barra-inf button .icono { font-size: 1.5rem; line-height: 1; font-weight: 700; }
.barra-inf button.activo { color: var(--txt); }
.barra-inf button[data-vista="entrada"] .icono { color: var(--verde-claro); }
.barra-inf button[data-vista="salida"] .icono { color: var(--rojo-claro); }

.barra-inf .badge {
  position: absolute;
  top: 12px;
  right: 50%;
  transform: translateX(22px);
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--rojo);
  color: #fff;
  font-size: .64rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* Barra de formulario: sustituye al menú dentro de entrada/salida */
.barra-form { display: flex; gap: 0; }

.barra-form button {
  flex: 1;
  min-height: var(--alto-barra);
  border: none;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
}

.barra-form .btn-cancelar { background: var(--bg-input); color: var(--txt-suave); }
.barra-form .btn-guardar { background: var(--verde); color: #fff; }
.barra-form .btn-guardar.rojo { background: var(--rojo); }
.barra-form .btn-guardar:disabled { background: #374151; color: #6B7280; }

/* ---------- Botones ---------- */

.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  padding: 1rem;
  margin-bottom: .8rem;
}

.btn--primario { background: var(--azul); color: #fff; }
.btn--verde { background: var(--verde); color: #fff; }
.btn--rojo { background: var(--rojo); color: #fff; }
.btn--neutro { background: var(--bg-input); color: var(--txt); border: 1px solid var(--borde); }
.btn:disabled { background: #374151; color: #6B7280; }

/* ---------- Acceso ---------- */

.acceso {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
}

.acceso img { width: 118px; height: auto; margin-bottom: 1.6rem; }
.acceso h1 { font-size: 1.3rem; margin: 0 0 .4rem; }
.acceso p { color: var(--txt-suave); font-size: .9rem; margin: 0 0 1.8rem; line-height: 1.5; }
.acceso .caja { width: 100%; max-width: 380px; }
.acceso input { text-align: center; font-family: ui-monospace, SFMono-Regular, monospace; font-size: .9rem; }

/* ---------- Listas ---------- */

.lista { list-style: none; margin: 0; padding: 0; }

.item {
  background: var(--bg-elev);
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: .9rem 1rem;
  margin-bottom: .7rem;
}

.item .cab { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; }
.item .folio { font-family: ui-monospace, SFMono-Regular, monospace; font-weight: 700; color: var(--oro); }
.item .tipo { font-size: .68rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: var(--bg-input); color: var(--txt-suave); }
.item .det { font-size: .84rem; color: var(--txt-suave); margin-top: .3rem; }

.item--pendiente { border-left: 3px solid var(--ambar); }
.item--rechazado { border-left: 3px solid var(--rojo); }
.item--caducado { border-left: 3px solid #6B7280; opacity: .75; }

.vacio { text-align: center; color: var(--txt-suave); padding: 2.5rem 1rem; font-size: .92rem; }

/* ---------- Escáner ---------- */

.escaner {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #000;
  display: flex;
  flex-direction: column;
}

.escaner video { flex: 1; width: 100%; object-fit: cover; }

.escaner .marco {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 62vw; height: 62vw;
  max-width: 300px; max-height: 300px;
  border: 3px solid rgba(255, 255, 255, .85);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55);
}

.escaner .pie {
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  background: var(--bg-elev);
  display: flex;
  gap: .7rem;
}

.escaner .pie button { flex: 1; min-height: 52px; border-radius: 12px; border: none; font-weight: 700; font-size: .95rem; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--alto-barra) + var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  z-index: 95;
  max-width: 88vw;
  padding: .85rem 1.1rem;
  border-radius: 12px;
  font-size: .92rem;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .5);
  animation: subir .22s ease;
}

.toast--ok { background: var(--verde); color: #fff; }
.toast--error { background: var(--rojo); color: #fff; }
.toast--info { background: var(--bg-input); color: var(--txt); border: 1px solid var(--borde); }

@keyframes subir { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Ajustes ---------- */

.seccion { margin-bottom: 1.8rem; }
.seccion h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--txt-suave); margin: 0 0 .7rem; }

.dato { display: flex; justify-content: space-between; gap: 1rem; padding: .65rem 0; border-bottom: 1px solid var(--borde); font-size: .92rem; }
.dato:last-child { border-bottom: none; }
.dato span:first-child { color: var(--txt-suave); }
.dato span:last-child { font-weight: 600; text-align: right; }
