:root {
  --fondo: #f4f1ea;
  --papel: #ffffff;
  --tinta: #1d2424;
  --suave: #5f6b6a;
  --linea: #ddd7cb;
  --marca: #0f3d3e;
  --marca-2: #1f6f6b;
  --acento: #e0a526;
  --error: #b3261e;
  --aviso: #8a5a00;
  --radio: 14px;
  --sombra: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(15,61,62,.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--tinta);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fondo); min-height: 100dvh; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }

/* ---------- botones ---------- */
.btn {
  border: 1px solid var(--linea); background: var(--papel); border-radius: 10px;
  padding: .6rem .9rem; min-height: 44px; cursor: pointer; font-weight: 600;
}
.btn.primario { background: var(--marca); border-color: var(--marca); color: #fff; }
.btn.primario:disabled { background: #9fb3b1; border-color: #9fb3b1; }
.btn.grande { width: 100%; min-height: 52px; font-size: 1.05rem; }
.btn.texto { border: 0; background: none; color: var(--marca-2); padding: .4rem .5rem; }
.btn.icono { width: 48px; padding: 0; display: grid; place-items: center; background: var(--marca); color: #fff; border-color: var(--marca); }

/* ---------- login ---------- */
#v-login { min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem;
  background: radial-gradient(120% 80% at 0% 0%, #1f6f6b 0%, #0f3d3e 60%); }
.login { width: min(380px, 100%); background: var(--papel); border-radius: 20px; padding: 1.75rem 1.4rem;
  display: grid; gap: 1rem; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.marca { font-weight: 800; font-size: 1.7rem; letter-spacing: .04em; color: var(--marca); }
.marca span { font-weight: 400; color: var(--acento); }
label { display: grid; gap: .3rem; font-size: .85rem; color: var(--suave); font-weight: 600; }
input, select { border: 1px solid var(--linea); border-radius: 10px; padding: .7rem .8rem; background: #fff;
  min-height: 46px; font-size: 1rem; color: var(--tinta); width: 100%; }
input:focus, select:focus { outline: 2px solid var(--marca-2); outline-offset: 1px; }
.error { color: var(--error); margin: 0; font-weight: 600; }

/* ---------- venta ---------- */
#v-venta { max-width: 820px; margin: 0 auto; padding-bottom: 15rem; }
.barra { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem;
  background: var(--marca); color: #fff; position: sticky; top: 0; z-index: 5; }
.barra .btn.texto { color: #fff; }
.local { font-weight: 700; }
.vendedor { font-size: .8rem; opacity: .8; }
.opciones { display: flex; gap: .75rem; align-items: end; padding: .8rem 1rem 0; }
.sel { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--linea); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: none; padding: .6rem .8rem; min-height: 46px; font-weight: 600; color: var(--suave); }
.seg button.on { background: var(--marca); color: #fff; }

.buscador { position: relative; display: flex; gap: .5rem; padding: .8rem 1rem; position: sticky; top: 56px;
  z-index: 4; background: var(--fondo); }
.buscador input { flex: 1; }
.resultados { position: absolute; left: 1rem; right: 1rem; top: calc(100% - .4rem); margin: 0; padding: .3rem;
  list-style: none; background: #fff; border-radius: var(--radio); box-shadow: 0 10px 30px rgba(0,0,0,.18);
  max-height: 60vh; overflow: auto; }
.resultados li { padding: .7rem .75rem; border-radius: 10px; display: grid; grid-template-columns: 1fr auto; gap: .15rem .75rem; cursor: pointer; }
.resultados li:hover, .resultados li:focus { background: #eef5f4; outline: none; }
.resultados .d { font-weight: 600; }
.resultados .c { font-size: .8rem; color: var(--suave); }
.resultados .p { font-weight: 700; text-align: right; }
.resultados .s { font-size: .8rem; color: var(--suave); text-align: right; }

.lineas { display: grid; gap: .6rem; padding: 0 1rem; }
.vacio { text-align: center; color: var(--suave); padding: 2.5rem 1rem; }
.linea { background: var(--papel); border-radius: var(--radio); box-shadow: var(--sombra); padding: .85rem .9rem;
  display: grid; grid-template-columns: 1fr auto; gap: .35rem .75rem; border-left: 4px solid transparent; }
.linea.err { border-left-color: var(--error); }
.linea.warn { border-left-color: var(--acento); }
.linea .d { font-weight: 650; line-height: 1.25; }
.linea .c { font-size: .8rem; color: var(--suave); word-break: break-all; }
.linea .imp { text-align: right; font-weight: 750; font-variant-numeric: tabular-nums; }
.linea .ctrl { grid-column: 1 / -1; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.linea .msg { grid-column: 1 / -1; font-size: .85rem; font-weight: 600; }
.linea.err .msg { color: var(--error); }
.linea.warn .msg { color: var(--aviso); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--linea); border-radius: 10px; overflow: hidden; }
.stepper button { border: 0; background: #f2efe8; width: 42px; height: 40px; font-size: 1.2rem; font-weight: 700; }
.stepper input { border: 0; width: 56px; min-height: 40px; text-align: center; border-radius: 0; padding: 0; }
.precio { width: 130px; min-height: 40px; text-align: right; }
.pu { font-size: .85rem; color: var(--suave); }
.quitar { margin-left: auto; color: var(--error) !important; }

.totales { position: fixed; left: 0; right: 0; bottom: 0; background: var(--papel); border-top: 1px solid var(--linea);
  box-shadow: 0 -8px 24px rgba(0,0,0,.08); padding: .6rem 1rem calc(.8rem + env(safe-area-inset-bottom));
  max-width: 820px; margin: 0 auto; border-radius: 18px 18px 0 0; }
.fila-tot { display: flex; align-items: center; gap: .5rem; }
.chip { background: #fdf3dc; color: var(--aviso); border-radius: 999px; padding: .2rem .6rem; font-size: .8rem; font-weight: 700; }
.totales dl { display: grid; grid-template-columns: 1fr auto; margin: .2rem 0; font-size: .85rem; color: var(--suave); gap: .1rem .5rem; }
.totales dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.total-final { display: flex; justify-content: space-between; align-items: baseline; margin: .3rem 0 .6rem; }
.total-final strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; color: var(--marca); }
.nota { margin: .4rem 0 0; font-size: .8rem; color: var(--suave); text-align: center; }

/* ---------- dialogos ---------- */
.dlg { border: 0; border-radius: 18px; padding: 1.2rem; width: min(420px, calc(100% - 2rem)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(15, 30, 30, .55); }
.dlg form { display: grid; gap: .8rem; }
.dlg h3 { margin: 0; color: var(--marca); }
.dlg hr { border: 0; border-top: 1px solid var(--linea); width: 100%; margin: .2rem 0; }
.acciones { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.escaner { padding: 0; background: #000; width: min(520px, 100%); max-height: 100dvh; overflow: hidden; }
.escaner video { width: 100%; display: block; max-height: 70dvh; object-fit: cover; }
.escaner .mira { position: absolute; left: 12%; right: 12%; top: 28%; height: 22%; border: 3px solid var(--acento);
  border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; }
.escaner .ayuda { color: #fff; text-align: center; margin: .6rem; }
.escaner .btn { border-radius: 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16rem; background: var(--tinta); color: #fff;
  padding: .7rem 1rem; border-radius: 12px; z-index: 50; max-width: calc(100% - 2rem); box-shadow: var(--sombra); }
.toast.err { background: var(--error); }

@media (min-width: 720px) {
  .linea { grid-template-columns: 1fr 160px; }
}

/* ---------- cobro ---------- */
#v-cobro { max-width: 820px; margin: 0 auto; padding-bottom: 14rem; }
#v-cobro .barra { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; text-align: center; }
.cobro { padding: .8rem 1rem; display: grid; gap: .8rem; }
.a-cobrar { display: flex; justify-content: space-between; align-items: baseline; background: var(--papel);
  border-radius: var(--radio); padding: .9rem 1rem; box-shadow: var(--sombra); }
.a-cobrar strong { font-size: 1.5rem; color: var(--marca); font-variant-numeric: tabular-nums; }
.aviso { background: #fdf3dc; color: var(--aviso); border-radius: 10px; padding: .6rem .8rem; margin: 0; font-weight: 600; }
.bloque { background: var(--papel); border-radius: var(--radio); box-shadow: var(--sombra); padding: .4rem .9rem .9rem; }
.bloque summary { font-weight: 700; color: var(--marca); padding: .5rem 0; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.grid2 .full { grid-column: 1 / -1; }
.tit { margin: .4rem 0 0; color: var(--marca); }
.pagos { display: grid; gap: .6rem; }
.pago { background: var(--papel); border-radius: var(--radio); box-shadow: var(--sombra); padding: .8rem .9rem;
  display: grid; gap: .6rem; border-left: 4px solid var(--linea); }
.pago.ok { border-left-color: #2e7d32; }
.pago.pend { border-left-color: var(--acento); }
.pago.err { border-left-color: var(--error); }
.pago .cab { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.pago .fin { font-size: .9rem; color: var(--suave); }
.pago .fin strong { color: var(--texto, #000); font-size: 1rem; }
.pago .estado { font-weight: 700; font-size: .9rem; }
.pago.ok .estado { color: #2e7d32; }
.pago.pend .estado { color: var(--aviso); }
.pago.err .estado { color: var(--error); }
.pago .lapos { display: flex; gap: .5rem; flex-wrap: wrap; }
.pago .lapos .btn { flex: 1; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: gira .8s linear infinite; vertical-align: -2px; margin-right: .3rem; }
@keyframes gira { to { transform: rotate(360deg); } }
.falta { color: var(--error); font-weight: 700; }

.terminal { display: grid; gap: .3rem; padding: .8rem .9rem; font-weight: 700; color: var(--marca); }

/* ---------- factura ---------- */
#v-factura { max-width: 820px; margin: 0 auto; padding: 1rem; }
.acciones-fact { display: flex; gap: .5rem; justify-content: flex-end; margin-bottom: .8rem; flex-wrap: wrap; }
.factura { background: #fff; color: #000; border-radius: var(--radio); box-shadow: var(--sombra); padding: 1.2rem;
  font-size: .9rem; display: grid; gap: .8rem; }
.factura .f-cab { display: grid; grid-template-columns: 1fr auto 1fr; gap: .8rem; align-items: start; border-bottom: 2px solid #000; padding-bottom: .8rem; }
.factura .f-letra { border: 2px solid #000; width: 3.2rem; text-align: center; font-size: 2rem; font-weight: 800; line-height: 1.2; }
.factura .f-letra small { display: block; font-size: .6rem; font-weight: 600; }
.factura .f-der { text-align: right; }
.factura h4 { margin: 0 0 .2rem; font-size: 1.05rem; }
.factura p { margin: .1rem 0; }
.factura table { width: 100%; border-collapse: collapse; }
.factura th, .factura td { padding: .35rem .3rem; border-bottom: 1px solid #ddd; text-align: left; vertical-align: top; }
.factura td.n, .factura th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.factura .f-tot { display: grid; grid-template-columns: 1fr auto; gap: .2rem .8rem; justify-items: end; }
.factura .f-tot .g { font-size: 1.2rem; font-weight: 800; }
.factura .f-pie { display: grid; grid-template-columns: 110px 1fr; gap: .8rem; align-items: center; border-top: 2px solid #000; padding-top: .8rem; }
.factura .f-pie svg { width: 110px; height: 110px; }
.factura .f-transp { font-size: .8rem; border: 1px solid #000; padding: .4rem .5rem; }
.factura > *, .factura .f-cab > * { min-width: 0; overflow-wrap: anywhere; }
.factura th.n { white-space: normal; }
.factura table, .factura table * { overflow-wrap: normal; }
@media (max-width: 520px) {
  .factura { padding: .8rem; font-size: .8rem; }
  .factura th, .factura td { padding: .3rem .15rem; }
  .factura .f-cab { grid-template-columns: 1fr auto; }
  .factura .f-der { grid-column: 1 / -1; text-align: left; }
  .factura .f-tot .g { font-size: 1.05rem; }
}
@media print {
  @page { margin: 8mm; }
  body { background: #fff; }
  body > *:not(#v-factura) { display: none !important; }
  #v-factura { display: block !important; padding: 0; max-width: none; }
  .no-print { display: none !important; }
  .factura { box-shadow: none; border-radius: 0; padding: 0; }
}

/* ---------- cliente / buscador fp ---------- */
.cli { margin: .8rem 1rem 0; }
.cli-res { font-weight: 500; color: var(--suave); font-size: .85rem; margin-left: .4rem; }
.con-boton { display: flex; gap: .4rem; }
.con-boton input { flex: 1; min-width: 0; }
.con-boton .btn { padding: .4rem .6rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 600; color: var(--tinta); }
label.check input { width: auto; min-height: auto; }
.nota.izq { text-align: left; margin: .6rem 0 0; font-weight: 600; color: var(--marca-2); }
.selfp { width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; min-height: 46px; }
.selfp.vacio { color: var(--suave); font-weight: 500; }
.dlg-lista { display: none; }
.dlg-lista[open] { display: grid; gap: .6rem; max-height: 90dvh; grid-template-rows: auto auto 1fr auto; }
.lista-fp { list-style: none; margin: 0; padding: 0; overflow: auto; border: 1px solid var(--linea); border-radius: 10px; }
.lista-fp li { padding: .75rem .8rem; border-bottom: 1px solid var(--linea); cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
.lista-fp li:last-child { border-bottom: 0; }
.lista-fp li:hover, .lista-fp li:focus { background: #eef5f4; outline: none; }
.badge { font-size: .7rem; font-weight: 700; background: var(--marca); color: #fff; border-radius: 999px; padding: .1rem .5rem; align-self: center; }
.badge.gris { background: #9aa6a5; }

/* bonificaciones de combos */
.linea.combo { background: #eef7f1; border-left: 4px solid #2f8a57; }
.linea.combo .imp { color: #2f8a57; }

/* factura con plantilla KEYS */
.factura.keys { padding: 0; overflow: hidden; }
.factura iframe.f-keys { width: 100%; min-height: 70vh; border: 0; background: #fff; display: block; }

/* PROFP_ con cantidad automatica */
.linea.auto { border-left: 4px solid #2f8a57; }

/* ---------- ventas del local ---------- */
.barra-acc { display: flex; gap: .25rem; }
.filtros-vt { display: grid; grid-template-columns: 1fr 1fr auto; gap: .6rem; align-items: end; }
.filtros-vt label { display: grid; gap: .25rem; font-size: .85rem; color: var(--suave); }
.filtros-vt input { width: 100%; }
.filtros-rapidos { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .8rem; align-items: center; }
.filtros-rapidos .rapido { border: 1px solid var(--borde, #ddd); background: #fff; border-radius: 999px; padding: .35rem .8rem; font: inherit; cursor: pointer; }
.filtros-rapidos input[type=search] { flex: 1 1 14rem; min-width: 0; }
.vt-tot { display: flex; justify-content: space-between; align-items: center; }
.vt-tot strong { font-size: 1.2rem; }
.vt-lista { display: grid; gap: .6rem; }
.vt-vacio { text-align: center; color: var(--suave); padding: 1.5rem; }
.vt-item { background: #fff; border-radius: 12px; padding: .8rem 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.06); display: grid; gap: .45rem; }
.vt-item.anulada { opacity: .6; }
.vt-item.nc { border-left: 4px solid #b3261e; }
.vt-cab { display: flex; justify-content: space-between; gap: .8rem; align-items: flex-start; }
.vt-comp { font-weight: 700; }
.vt-meta { font-size: .82rem; color: var(--suave); }
.vt-total { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.vt-det summary { cursor: pointer; font-size: .85rem; color: var(--suave); }
.vt-det div { font-size: .85rem; padding: .3rem 0 0; }
.vt-pie { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .82rem; color: var(--suave); }
.vt-acc { display: flex; flex-wrap: wrap; gap: .4rem; }
.vt-acc .btn { padding: .45rem .8rem; font-size: .9rem; }
@media (max-width: 520px) { .filtros-vt { grid-template-columns: 1fr 1fr; } .filtros-vt button { grid-column: 1 / -1; } }

/* ---------- indicador de carga ---------- */
.cargando { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: rgba(20, 40, 38, .35); backdrop-filter: blur(1.5px); animation: aparecer .15s ease-out; }
.cargando[hidden] { display: none; }
.cargando-caja { background: #fff; border-radius: 16px; padding: 1.4rem 1.8rem; min-width: 14rem; max-width: 80vw;
  display: grid; justify-items: center; gap: .8rem; text-align: center; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.cargando-lenta { font-weight: 400; font-size: .85rem; color: var(--suave); }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid #dfe9e6; border-top-color: var(--marca);
  animation: girar .8s linear infinite; }
.cargando-barra { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 1001; overflow: hidden; background: rgba(18,64,60,.12); }
.cargando-barra[hidden] { display: none; }
.cargando-barra::after { content: ''; position: absolute; top: 0; bottom: 0; width: 35%; background: var(--marca);
  animation: barra 1s ease-in-out infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
@keyframes barra { from { left: -35%; } to { left: 100%; } }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }
@media print { .cargando, .cargando-barra { display: none !important; } }

/* ---------- stock (reportes del sistema) ---------- */
.rpt-tabs { display: flex; gap: .4rem; margin: 0 0 .7rem; }
.rpt-tab { flex: 1; border: 1px solid var(--linea); background: #fff; border-radius: 10px; padding: .6rem; font: inherit; font-weight: 600; cursor: pointer; color: var(--tinta); }
.rpt-tab.on { background: var(--marca); color: #fff; border-color: var(--marca); }
.rpt-filtros { display: grid; gap: .6rem; }
.rpt-campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .6rem; }
.rpt-campos label { display: grid; gap: .25rem; font-size: .85rem; color: var(--suave); }
.rpt-checks { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.rpt-checks label.check { font-weight: 500; font-size: .92rem; }
.rpt-tot { display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: baseline; }
.rpt-tot .rpt-fija { color: var(--suave); font-size: .85rem; }
.rpt-grupo { margin: .6rem .2rem 0; font-size: .95rem; color: var(--marca); }
.rpt-dest { text-align: right; white-space: nowrap; }
.rpt-dest small { display: block; font-size: .72rem; color: var(--suave); }
.rpt-dest strong { font-size: 1.35rem; }
.rpt-extra { display: flex; flex-wrap: wrap; gap: .2rem .9rem; font-size: .84rem; }
.rpt-extra em { font-style: normal; color: var(--suave); }
.rpt-item.alerta-roja { border-left: 4px solid #b3261e; }
.rpt-item.alerta-roja .rpt-dest strong { color: #b3261e; }
.rpt-item.alerta-naranja { border-left: 4px solid #e08a00; }
.rpt-item.alerta-naranja .rpt-dest strong { color: #c77700; }
.estrella { color: #e0a800; }
#rpt-mas { width: 100%; }
