:root {
  --fondo: #f4f6f4; --superficie: #ffffff; --texto: #18201b; --suave: #5d6b62; --borde: #dde3de;
  --marca: #1f7a4d; --marca-texto: #ffffff; --alerta: #b26a00; --mal: #c0392b; --ok: #1f7a4d; --pend: #fff7e0;
  --radio: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --fondo: #101411; --superficie: #1a201c; --texto: #e7ece8; --suave: #9aa79f; --borde: #2c352f; --marca: #3aa872; --pend: #2b2716; --alerta: #f0a63a; --mal: #ff6b5b; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fondo); color: var(--texto); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input { font: inherit; color: inherit; }
button { background: var(--superficie); border: 1px solid var(--borde); border-radius: 10px; padding: .6rem .9rem; min-height: 44px; cursor: pointer; }
button.primario { background: var(--marca); color: var(--marca-texto); border-color: var(--marca); font-weight: 600; }
button.peligro { color: var(--mal); border-color: var(--mal); background: transparent; }
button.icono { min-width: 44px; padding: .4rem; background: transparent; border: none; font-size: 1.1rem; }
button.enlace { background: none; border: none; color: var(--marca); padding: 0; min-height: 0; text-decoration: underline; }
button.ancho { width: 100%; margin-top: .5rem; }
input { width: 100%; padding: .65rem .75rem; border: 1px solid var(--borde); border-radius: 10px; background: var(--superficie); min-height: 44px; }
label { display: block; margin: .6rem 0; color: var(--suave); font-size: .9rem; }
label input { margin-top: .25rem; color: var(--texto); font-size: 1rem; }
label.check { display: flex; gap: .5rem; align-items: center; }
label.check input { width: auto; min-height: 0; margin: 0; }
h1, h2, h3 { margin: .2rem 0; line-height: 1.2; }
h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
small { display: block; color: var(--suave); font-size: .82rem; }
.mal { color: var(--mal); } .alerta { color: var(--alerta); } .ok { color: var(--ok); }

#app { max-width: 720px; margin: 0 auto; padding-bottom: 84px; }
.barra { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: .55rem 16px; background: var(--marca); color: var(--marca-texto); }
.barra .sync { min-height: 32px; padding: .2rem .7rem; border-radius: 99px; border: none; font-size: .85rem; background: rgba(255,255,255,.18); color: inherit; }
.barra .sync.alerta { background: #f0a63a; color: #222; } .barra .sync.mal { background: #c0392b; color: #fff; }
main { padding: 12px 16px; }
.pestanas { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--superficie); border-top: 1px solid var(--borde); padding-bottom: env(safe-area-inset-bottom); }
.pestanas button { flex: 1; border: none; border-radius: 0; background: none; display: flex; flex-direction: column; align-items: center; font-size: .72rem; padding: .35rem 0; position: relative; color: var(--suave); min-height: 56px; }
.pestanas button span { font-size: 1.25rem; }
.pestanas button.on { color: var(--marca); font-weight: 700; }
.badge { position: absolute; top: 4px; right: calc(50% - 22px); background: var(--mal); color: #fff; font-style: normal; font-size: .68rem; border-radius: 99px; padding: 0 .38rem; }

.fila { display: flex; gap: .5rem; align-items: center; margin: .5rem 0; flex-wrap: wrap; }
.fila > input { flex: 1; min-width: 0; }
.fila.entre { justify-content: space-between; }
.pegajosa { position: sticky; top: 50px; z-index: 4; background: var(--fondo); padding: .4rem 0; margin: -.4rem 0 .4rem; }
.seg { display: inline-flex; border: 1px solid var(--borde); border-radius: 10px; overflow: hidden; }
.seg button { border: none; border-radius: 0; background: var(--superficie); }
.seg button.on { background: var(--marca); color: var(--marca-texto); }

.lista { list-style: none; margin: 0; padding: 0; }
.item, .bloque { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: .65rem .75rem; margin: .45rem 0; }
.item { display: flex; justify-content: space-between; gap: .6rem; align-items: center; }
.item > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.item[data-sku], .item[data-acc], .item[data-c] { cursor: pointer; }
.der { text-align: right; white-space: nowrap; }
.acciones { display: flex; gap: .3rem; align-items: center; flex-shrink: 0; }
.acciones button { min-height: 38px; padding: .3rem .6rem; }
.pend { background: var(--pend); }
.pend::after { content: "por subir"; font-size: .7rem; color: var(--alerta); }
.bloque.pend::after { display: block; }
.lineas { margin: .4rem 0; padding-left: 1.1rem; }
.lineas li { margin: .15rem 0; }
.lineas small { display: inline; }
.fotos { display: flex; gap: .4rem; flex-wrap: wrap; }
.fotos button { min-height: 36px; padding: .2rem .6rem; }
.grupo { margin: 1rem 0 .2rem; display: flex; align-items: center; gap: .4rem; }
.pill { background: var(--borde); border-radius: 99px; padding: 0 .5rem; font-size: .8rem; }
.chip { border-radius: 99px; padding: .1rem .6rem; font-size: .8rem; border: 1px solid currentColor; }
.chip.enviado { color: var(--alerta); } .chip.aprobado { color: var(--ok); } .chip.rechazado { color: var(--mal); }
.vacio { color: var(--suave); text-align: center; padding: 1rem; }
.nota { color: var(--suave); font-size: .88rem; }
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: .8rem 1rem; margin: .7rem 0; }
.pie { color: var(--suave); text-align: center; font-size: .8rem; }
.ficha { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; margin: .8rem 0; }
.ficha dt { color: var(--suave); } .ficha dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.botones { display: grid; gap: .5rem; }
.producto-sel { width: 100%; text-align: left; font-weight: 600; }

.ingreso { padding: 24px 16px; }
details.tarjeta summary { cursor: pointer; color: var(--suave); }
details[open].tarjeta summary { margin-bottom: .5rem; }
.ingreso h1 { color: var(--marca); text-align: center; margin: 1rem 0; }

.dlg { border: none; border-radius: 16px 16px 0 0; padding: 0 16px 16px; width: 100%; max-width: 720px; max-height: 92vh; margin: auto auto 0; background: var(--fondo); color: var(--texto); overflow-y: auto; }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg header { position: sticky; top: 0; background: var(--fondo); display: flex; justify-content: space-between; align-items: center; padding: .8rem 0 .4rem; z-index: 1; }
.escaner { position: relative; background: #000; border-radius: var(--radio); overflow: hidden; aspect-ratio: 4 / 3; }
.escaner-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.escaner-marco { position: absolute; inset: 30% 10%; border: 3px solid rgba(255,255,255,.85); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.25); }
.foto-grande { width: 100%; border-radius: var(--radio); }

.aviso { position: fixed; left: 16px; right: 16px; bottom: 90px; z-index: 50; background: #18201b; color: #fff; padding: .75rem 1rem; border-radius: 12px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; max-width: 688px; margin: 0 auto; }
.aviso.visible { opacity: 1; transform: none; }
.aviso.error { background: #c0392b; }

.reporte table { width: 100%; border-collapse: collapse; font-size: .85rem; margin: .3rem 0 1rem; }
.reporte th, .reporte td { border-bottom: 1px solid var(--borde); padding: .3rem; text-align: left; }
.reporte h1 { font-size: 1.1rem; }


/* ---------- v0.4 ---------- */
/* Escáner dentro de la APK: la cámara va DETRÁS de la web, así que todo se vuelve transparente menos la capa. */
html.escaneando, html.escaneando body { background: transparent !important; }
html.escaneando #app, html.escaneando .aviso, html.escaneando dialog:not(.dlg-capa) { visibility: hidden; }
html.escaneando dialog::backdrop { background: transparent; }
.dlg-capa { border: 0; padding: 0; margin: 0; width: 100vw; max-width: none; height: 100vh; height: 100dvh; max-height: none; background: transparent; color: #fff; }
.dlg-capa::backdrop { background: transparent; }
.capa-escaner { display: flex; flex-direction: column; justify-content: space-between; height: 100%; }
.capa-escaner header, .capa-escaner footer { background: rgba(0,0,0,.62); padding: .7rem 16px; display: flex; flex-direction: column; gap: .4rem; }
.capa-escaner header { flex-direction: row; justify-content: space-between; align-items: center; padding-top: max(.7rem, env(safe-area-inset-top)); }
.capa-escaner footer { padding-bottom: max(.9rem, env(safe-area-inset-bottom)); }
.capa-escaner button { color: #fff; background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.3); }
.capa-escaner button.primario { background: var(--marca); }
.capa-escaner input { background: rgba(0,0,0,.4); color: #fff; border-color: rgba(255,255,255,.35); }
.capa-escaner #esc-msg { margin: 0; font-size: 1.05rem; min-height: 2.6em; }
.capa-escaner #esc-msg.mal { color: #ff8a7d; }
.escaner-marco-nativo { margin: 0 8%; height: 26vh; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.28); }

/* Dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: .5rem; margin: .5rem 0; }
.kpi { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: .55rem .6rem; text-align: left; min-height: 0; display: block; width: 100%; }
.kpi b { display: block; font-size: 1.45rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi small { font-size: .78rem; }
.kpi.mal b { color: var(--mal); } .kpi.alerta b { color: var(--alerta); } .kpi.ok b { color: var(--ok); }
.saludo { margin: .3rem 0 .2rem; }
.tienda { opacity: .85; font-weight: 400; font-size: .85rem; margin-left: .4rem; }

/* Cíclicos */
.progreso { height: 8px; background: var(--borde); border-radius: 99px; overflow: hidden; margin: .35rem 0; }
.progreso i { display: block; height: 100%; background: var(--marca); }
.num { font-variant-numeric: tabular-nums; }
.linea-c { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; align-items: center; }
.linea-c .cifras { display: flex; gap: .7rem; font-size: .85rem; color: var(--suave); }
.linea-c .cifras b { color: var(--texto); }
.linea-c .contar { display: flex; gap: .3rem; }
.linea-c .contar button { min-width: 44px; padding: .2rem .5rem; font-weight: 700; }
.dif-pos { color: var(--alerta); } .dif-neg { color: var(--mal); } .dif-cero { color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0; }
.chip.neutro { color: var(--suave); }
textarea { width: 100%; min-height: 7rem; padding: .6rem; border: 1px solid var(--borde); border-radius: 10px; background: var(--superficie); color: var(--texto); font: inherit; }
select { font: inherit; color: var(--texto); background: var(--superficie); border: 1px solid var(--borde); border-radius: 10px; padding: .45rem .5rem; min-height: 40px; }
.tabla { width: 100%; border-collapse: collapse; font-size: .85rem; }
.tabla th, .tabla td { border-bottom: 1px solid var(--borde); padding: .35rem .3rem; text-align: left; }
.tabla td.n, .tabla th.n { text-align: right; font-variant-numeric: tabular-nums; }

@media print {
  body.imprimiendo #app, body.imprimiendo .aviso, body.imprimiendo .no-imprimir, body.imprimiendo .dlg header { display: none !important; }
  body.imprimiendo .dlg { position: static; max-height: none; overflow: visible; background: #fff; color: #000; }
  body.imprimiendo .dlg::backdrop { background: none; }
}
#q-ciclico { flex: 1 1 100%; }

/* v0.5.1: listas que no aplastan el texto. Si las acciones no caben al lado, bajan a su propia fila. */
.item { flex-wrap: wrap; }
.item > div:first-child { flex: 1 1 11rem; }
.item > .acciones { flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.item > .der { margin-left: auto; }
.linea-c { grid-template-columns: minmax(0, 1fr) auto; }
.linea-c .cifras { flex-wrap: wrap; gap: .2rem .7rem; }
.kpi small { overflow-wrap: anywhere; }
.dlg { overflow-x: hidden; }
.tabla td small { display: block; }
.item > .acciones { flex-shrink: 1; max-width: 100%; }
.acciones select { max-width: 100%; }

/* Promociones del encarte (v0.6) */
.promo-tag { color: var(--alerta); font-weight: 600; }
button.promo-boton { border: 2px solid var(--alerta); color: var(--texto); font-weight: 600; text-align: left; margin: 0 0 .6rem; overflow-wrap: anywhere; }
.tarjeta.promo { border-left: 4px solid var(--alerta); }
.promo-cab { display: flex; justify-content: space-between; align-items: baseline; gap: .6rem; }
.promo-cab h3 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.promo-precio { font-weight: 700; white-space: nowrap; color: var(--marca); }
.promo-precio s { display: block; color: var(--suave); font-weight: 400; font-size: .8rem; text-align: right; }
.promo-grupo { border-top: 1px solid var(--borde); margin-top: .6rem; padding-top: .4rem; }
.promo-grupo > p { margin: .2rem 0; }
.promo-grupo.rol-amarre b, .promo-grupo.rol-incluye b { color: var(--marca); }
.promo-grupo.rol-cambio b { color: var(--alerta); }
.promo-grupo details summary { color: var(--suave); cursor: pointer; font-size: .88rem; }
.item.actual { outline: 2px solid var(--marca); }
.sin-stock { color: var(--mal); }

/* Foto dentro de la app (v0.6.1) */
.dlg-foto { background: #000; }
.capa-foto .foto-video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }
.capa-foto #foto-msg.mal { color: #ff8a7d; }

/* v0.8: fotos de producto (tambo.pe o del admin) y miniaturas de fotos */
.ico-prod { flex: none; width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: #fff; border: 1px solid var(--borde); }
.ico-prod.vacio { background: var(--fondo); border-style: dashed; opacity: .5; }
.ico-prod.chico { width: 26px; height: 26px; border-radius: 5px; vertical-align: middle; margin-right: .35rem; display: inline-block; }
.lineas .ico-prod.chico.vacio { display: none; }
.lineas li { display: flex; align-items: center; flex-wrap: wrap; gap: 0 .3rem; }
.lineas li .icono { min-height: 32px; min-width: 36px; margin-left: auto; }
.foto-prod { display: block; max-width: 100%; max-height: 200px; margin: .3rem auto .6rem; object-fit: contain; background: #fff; border-radius: var(--radio); }
button.mini { flex: none; padding: 0; min-height: 0; border: 0; background: none; border-radius: 8px; overflow: hidden; }
.miniatura { display: block; width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--fondo); border: 1px solid var(--borde); }
.miniatura.sin { opacity: .35; }
.fotos .miniatura { width: 84px; height: 84px; }
.fotos button.mini { min-height: 0; padding: 0; }
.con-ico { display: flex; gap: .6rem; align-items: center; min-width: 0; }
.con-ico > div { min-width: 0; }
tr.tocable { cursor: pointer; }
/* v0.10: listas de escaneo, códigos para la caja, compartir */
textarea.texto-compartir { width: 100%; font: .9rem/1.35 ui-monospace, Consolas, monospace; padding: .6rem; border: 1px solid var(--borde); border-radius: 10px; background: var(--superficie); color: var(--texto); }
a.boton { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .6rem .9rem; border-radius: 10px; border: 1px solid var(--borde); text-decoration: none; color: inherit; font-weight: 600; }
a.boton.whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.item .contar { display: flex; align-items: center; gap: .3rem; flex: none; }
.item .contar button { min-width: 40px; padding: .2rem .4rem; font-weight: 700; }
.item .contar b { min-width: 1.6rem; text-align: center; }
.dlg-codigos { background: #fff; color: #000; }
.codigo-caja { background: #fff; color: #000; text-align: center; padding: 1rem .5rem 1.2rem; border-bottom: 1px dashed #bbb; }
.codigo-caja svg.barras { display: block; width: 100%; max-width: 420px; height: 110px; margin: 0 auto .3rem; }
.codigo-caja b { display: block; font: 600 1.1rem ui-monospace, Consolas, monospace; letter-spacing: .08em; }
.codigo-caja small { color: #444; }
.foto-mini { position: relative; display: inline-block; }
.foto-mini .quitar-foto { position: absolute; top: -6px; right: -6px; min-height: 0; width: 26px; height: 26px; padding: 0; border-radius: 50%; background: var(--mal); color: #fff; border: 2px solid var(--superficie); font-size: .8rem; line-height: 1; }
label select { width: 100%; padding: .6rem .75rem; border: 1px solid var(--borde); border-radius: 10px; background: var(--superficie); color: var(--texto); min-height: 44px; font: inherit; margin-top: .25rem; }
.item:has(> .ico-prod), .item:has(> button.mini) { flex-wrap: nowrap; }
.item:has(> .ico-prod) > div:first-of-type, .item:has(> button.mini) > div:first-of-type { flex: 1 1 auto; min-width: 0; }
