:root {
  --verde: #1F6F43;
  --verde-oscuro: #17573A;
  --verde-suave: #E3F0E8;
  --ambar: #B7791F;
  --ambar-suave: #FDF3E1;
  --rojo: #C53030;
  --rojo-suave: #FDECEC;
  --fondo: #F4F6F3;
  --tarjeta: #FFFFFF;
  --texto: #1D2621;
  --texto-2: #5B6B62;
  --borde: #DCE3DE;
  --sombra: 0 1px 2px rgba(20, 40, 30, .06), 0 2px 8px rgba(20, 40, 30, .06);
  --radio: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --verde: #3FA36B;
    --verde-oscuro: #2F8656;
    --verde-suave: #183626;
    --ambar: #E3A84A;
    --ambar-suave: #3A2C14;
    --rojo: #F07171;
    --rojo-suave: #3D1C1C;
    --fondo: #101613;
    --tarjeta: #18211C;
    --texto: #E6EEE9;
    --texto-2: #9DB0A5;
    --borde: #2A3A31;
    --sombra: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ── Barra superior ── */
.barra {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--verde); color: #fff;
}
.barra-titulo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.barra-titulo strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra-titulo span { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.atras, .menu {
  background: rgba(255, 255, 255, .14); border: 0; color: #fff; border-radius: 10px;
  min-height: 40px; padding: 0 12px; cursor: pointer;
}
.atras { font-size: 26px; line-height: 1; padding: 0 14px 4px; }

main { padding: 16px 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 720px; margin: 0 auto; }

/* ── Bloques ── */
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.tarjeta {
  background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 14px; margin-bottom: 12px;
}
.muted { color: var(--texto-2); font-size: 14px; }
.fila { display: flex; align-items: center; gap: 10px; }
.fila > .crece { flex: 1; min-width: 0; }
.vacio { text-align: center; color: var(--texto-2); padding: 32px 12px; }
.vacio h1 { color: var(--texto); }

/* ── Botones ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--borde);
  background: var(--tarjeta); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--texto);
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primario { background: var(--verde); border-color: var(--verde); color: #fff; }
.btn-primario:active { background: var(--verde-oscuro); }
.btn-peligro { color: var(--rojo); border-color: var(--rojo); }
.btn-bloque { width: 100%; }
.barra-accion {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--tarjeta); border-top: 1px solid var(--borde);
}
.barra-accion .btn { width: 100%; max-width: 688px; display: flex; margin: 0 auto; }

/* ── Menú de inicio ── */
.opciones { display: grid; gap: 12px; }
.opcion {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 16px; cursor: pointer; min-height: 76px;
}
.opcion .ico {
  flex: none; width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: var(--verde-suave); color: var(--verde); font-size: 22px;
}
.opcion b { display: block; font-size: 17px; }
.contador.rojo { background: var(--rojo-suave); color: var(--rojo); }
.contador {
  margin-left: auto; min-width: 30px; height: 30px; padding: 0 9px; border-radius: 15px;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  background: var(--ambar-suave); color: var(--ambar);
}

/* ── Formularios ── */
label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 15px; }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--borde); background: var(--tarjeta);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--verde); outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
.error { color: var(--rojo); margin-top: 10px; font-weight: 600; }

/* ── Estado ── */
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--verde-suave); color: var(--verde);
}
.chip.transito { background: var(--ambar-suave); color: var(--ambar); }
.chip.novedad { background: var(--rojo-suave); color: var(--rojo); }
.chip.gris { background: var(--borde); color: var(--texto-2); }

/* ── Líneas de recepción ── */
.linea { padding: 12px 0; border-top: 1px solid var(--borde); }
.linea:first-child { border-top: 0; padding-top: 0; }
.linea .ref { font-size: 13px; color: var(--texto-2); }
.linea .nombre { font-weight: 600; }
.cantidad { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.cantidad button {
  width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--borde);
  background: var(--tarjeta); font-size: 22px; cursor: pointer;
}
.cantidad input { width: 96px; text-align: center; font-weight: 700; font-size: 18px; }
.cantidad .desp { margin-left: auto; text-align: right; font-size: 13px; color: var(--texto-2); }
.linea.diferencia { background: var(--rojo-suave); margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
.linea select { margin-top: 8px; }

/* ── Firma ── */
.firma {
  position: relative; border: 2px dashed var(--borde); border-radius: var(--radio);
  background: #fff; touch-action: none; height: 180px; overflow: hidden;
}
.firma canvas { width: 100%; height: 100%; display: block; }
.firma .pista {
  position: absolute; inset: 0; display: grid; place-items: center; color: #9AA8A0;
  pointer-events: none; font-size: 15px;
}
.firma-pie { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.firma-pie button { background: none; border: 0; color: var(--verde); font-weight: 600; cursor: pointer; padding: 8px 0; }

/* ── Listas ── */
.item { display: flex; gap: 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--borde); }
.item:first-child { border-top: 0; }
.item .crece { flex: 1; min-width: 0; }
.item .crece b, .item .crece span { display: block; overflow: hidden; text-overflow: ellipsis; }
.item .num { font-weight: 700; font-variant-numeric: tabular-nums; }
.num.neg { color: var(--rojo); }
button.item { width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; cursor: pointer; }

.ultima { border-color: var(--verde); margin-top: 12px; }
details > summary { cursor: pointer; padding: 4px 0; }

/* ── Escáner ── */
.escaner { position: relative; border-radius: var(--radio); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.escaner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.escaner .mira {
  position: absolute; left: 12%; right: 12%; top: 38%; bottom: 38%;
  border: 3px solid rgba(255, 255, 255, .9); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
}
.buscar { display: flex; gap: 8px; }
.buscar input { flex: 1; }
.buscar .btn { flex: none; }

/* ── Precios ── */
.precios { width: 100%; border-collapse: collapse; font-size: 15px; }
.precios td { padding: 8px 0; border-top: 1px solid var(--borde); }
.precios td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 12px; }
.precios tr:first-child td { border-top: 0; }

/* ── Aviso flotante ── */
.aviso {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 88px); z-index: 20;
  max-width: 560px; margin: 0 auto; padding: 14px 16px; border-radius: 12px;
  background: var(--texto); color: var(--fondo); box-shadow: 0 6px 24px rgba(0, 0, 0, .25); font-weight: 600;
}
.aviso.error { background: var(--rojo); color: #fff; }

/* ── Login ── */
.login { max-width: 400px; margin: 8vh auto 0; }
.logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 14px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login .muted { text-align: center; margin-bottom: 18px; }

.cargando { display: grid; place-items: center; padding: 40px; color: var(--texto-2); }
