:root {
  --fondo: #f5f3f0;
  --superficie: #ffffff;
  --superficie-2: #efece8;
  --borde: #e2ddd6;
  --texto: #1f1b2e;
  --texto-2: #6b6577;
  --acento: #e0552b;
  --acento-texto: #ffffff;
  --acento-suave: #fde8e0;
  --ok: #1d8a5b;
  --ok-suave: #dcf3e8;
  --aviso: #b7791f;
  --aviso-suave: #fcefd6;
  --peligro: #c93a3a;
  --peligro-suave: #fbe1e1;
  --barra: #1f1b2e;
  --barra-texto: #b9b3c6;
  --sombra: 0 1px 2px rgba(31, 27, 46, .06), 0 4px 16px rgba(31, 27, 46, .06);
  --radio: 14px;
  --tabbar: 64px;
  --seguro-abajo: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #14121c;
    --superficie: #1f1c2a;
    --superficie-2: #2a2637;
    --borde: #363146;
    --texto: #f1eef7;
    --texto-2: #a19bb0;
    --acento: #ff7a4d;
    --acento-texto: #1a0f0a;
    --acento-suave: #3d2219;
    --ok: #4ccf92;
    --ok-suave: #173427;
    --aviso: #f0b44f;
    --aviso-suave: #3a2e14;
    --peligro: #ff7474;
    --peligro-suave: #3d1c1f;
    --barra: #0e0c14;
    --sombra: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--fondo); color: var(--texto);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
a { color: var(--acento); }
.oculto { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.tenue { color: var(--texto-2); }
.peq { font-size: .85rem; }

/* ---------- estructura ---------- */
.cabecera {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--fondo);
  border-bottom: 1px solid transparent;
}
.cabecera.con-borde { border-bottom-color: var(--borde); }
.cabecera h1 { font-size: 1.35rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cabecera .atras { margin-left: -8px; }
main {
  max-width: 820px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar) + var(--seguro-abajo) + 24px);
}
main.con-carrito { padding-bottom: calc(var(--tabbar) + var(--seguro-abajo) + 96px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + var(--seguro-abajo)); padding-bottom: var(--seguro-abajo);
  background: var(--barra);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--barra-texto); text-decoration: none; font-size: .72rem; font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.activa { color: #fff; }
.tabbar a.activa svg { color: var(--acento); }

/* ---------- controles ---------- */
.icono-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 12px; background: transparent; color: var(--texto);
}
.icono-btn:active { background: var(--superficie-2); }
.icono-btn svg { width: 24px; height: 24px; }

.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(--superficie); color: var(--texto);
  font-weight: 600; text-decoration: none; user-select: none;
}
.btn svg { width: 20px; height: 20px; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primario { background: var(--acento); border-color: var(--acento); color: var(--acento-texto); }
.btn.peligro { color: var(--peligro); border-color: var(--peligro-suave); background: var(--peligro-suave); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.grande { min-height: 56px; font-size: 1.1rem; border-radius: 14px; }
.btn.bloque { width: 100%; }
.btn.chico { min-height: 38px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.fila-botones { display: flex; gap: 10px; }
.fila-botones > * { flex: 1; }

.campo { display: block; margin-bottom: 14px; }
.campo > span { display: block; font-size: .85rem; font-weight: 600; color: var(--texto-2); margin-bottom: 6px; }
.campo small { display: block; color: var(--texto-2); margin-top: 4px; font-size: .8rem; }
.entrada {
  width: 100%; min-height: 50px; padding: 12px 14px;
  border: 1px solid var(--borde); border-radius: 12px; background: var(--superficie);
  font-size: 16px; /* evita el zoom de iOS */
}
.entrada:focus { outline: 2px solid var(--acento); outline-offset: -1px; border-color: transparent; }
textarea.entrada { min-height: 90px; resize: vertical; }
.dos-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.buscador { position: relative; margin: 4px 0 10px; }
.buscador svg { position: absolute; left: 14px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; color: var(--texto-2); pointer-events: none; }
.buscador .entrada { padding-left: 44px; border-radius: 999px; }
.buscador .limpiar { position: absolute; right: 4px; top: 50%; translate: 0 -50%; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 10px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--borde); background: var(--superficie); font-size: .9rem; font-weight: 500; white-space: nowrap;
}
.chip.activo { background: var(--texto); border-color: var(--texto); color: var(--fondo); }
.chip .cuenta { opacity: .6; margin-left: 4px; }

.segmentado { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--superficie-2); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.segmentado button { border: 0; background: transparent; min-height: 40px; border-radius: 9px; font-weight: 600; font-size: .9rem; color: var(--texto-2); }
.segmentado button.activo { background: var(--superficie); color: var(--texto); box-shadow: var(--sombra); }

.opciones { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.opcion {
  min-height: 52px; border-radius: 12px; border: 1.5px solid var(--borde); background: var(--superficie);
  font-weight: 600; font-size: .92rem; padding: 4px;
}
.opcion.activo { border-color: var(--acento); background: var(--acento-suave); color: var(--texto); }

/* ---------- tarjetas y listas ---------- */
.tarjeta { background: var(--superficie); border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px; margin-bottom: 12px; }
.tarjeta h2 { font-size: 1rem; margin-bottom: 12px; }
.lista { background: var(--superficie); border-radius: var(--radio); box-shadow: var(--sombra); overflow: hidden; margin-bottom: 12px; }
.lista > * + * { border-top: 1px solid var(--borde); }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px;
  width: 100%; text-align: left; border: 0; background: transparent; text-decoration: none; color: inherit;
}
button.item:active, a.item:active { background: var(--superficie-2); }
.item .cuerpo { flex: 1; min-width: 0; }
.item .titulo { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: .82rem; color: var(--texto-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .der { text-align: right; flex: none; }
.item .chevron { width: 18px; height: 18px; color: var(--texto-2); flex: none; }
.titulo-seccion { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-2); margin: 20px 4px 8px; display: flex; justify-content: space-between; }

.miniatura {
  width: 52px; height: 52px; border-radius: 10px; flex: none; object-fit: cover;
  background: var(--superficie-2); display: grid; place-items: center; color: var(--texto-2); overflow: hidden; border: 0; padding: 0;
}
.miniatura svg { width: 22px; height: 22px; }
.miniatura.poner-foto { border: 1.5px dashed var(--borde); background: transparent; }

.pastilla { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--superficie-2); color: var(--texto-2); white-space: nowrap; }
.pastilla.ok { background: var(--ok-suave); color: var(--ok); }
.pastilla.aviso { background: var(--aviso-suave); color: var(--aviso); }
.pastilla.peligro { background: var(--peligro-suave); color: var(--peligro); }

.vacio { text-align: center; padding: 48px 16px; color: var(--texto-2); }
.vacio svg { width: 56px; height: 56px; opacity: .5; margin-bottom: 8px; }
.vacio h3 { color: var(--texto); margin-bottom: 6px; }
.vacio .btn { margin-top: 16px; }

/* ---------- vender ---------- */
.rejilla { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .rejilla { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 760px) { .rejilla { grid-template-columns: repeat(4, 1fr); } }
.producto {
  position: relative; display: flex; flex-direction: column; text-align: left; padding: 0;
  border: 2px solid transparent; border-radius: var(--radio); background: var(--superficie); box-shadow: var(--sombra); overflow: hidden;
  transition: transform .12s;
}
.producto:active { transform: scale(.97); }
.producto.en-carrito { border-color: var(--acento); }
.producto .foto { aspect-ratio: 1; width: 100%; object-fit: cover; background: var(--superficie-2); display: grid; place-items: center; color: var(--texto-2); }
.producto .foto svg { width: 40px; height: 40px; opacity: .5; }
.producto .info { padding: 8px 10px 10px; }
.producto .nombre { font-size: .92rem; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.producto .precio { font-weight: 800; font-size: 1.05rem; margin-top: 4px; }
.producto .stock { position: absolute; top: 8px; left: 8px; }
.producto .en-carro {
  position: absolute; top: 8px; right: 8px; min-width: 30px; height: 30px; padding: 0 8px; border-radius: 999px;
  background: var(--acento); color: var(--acento-texto); font-weight: 800; display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.producto.agotado { opacity: .5; }
.producto.agotado:active { transform: none; }

.barra-carrito {
  position: fixed; z-index: 25; left: 12px; right: 12px;
  bottom: calc(var(--tabbar) + var(--seguro-abajo) + 10px);
  max-width: 796px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 18px;
  border: 0; border-radius: 16px; background: var(--acento); color: var(--acento-texto);
  box-shadow: 0 8px 24px rgba(224, 85, 43, .35); animation: subir .2s ease-out;
}
.barra-carrito .cuantos { font-weight: 600; flex: 1; text-align: left; }
.barra-carrito .total { font-weight: 800; font-size: 1.15rem; }
.barra-carrito .ir { background: rgba(255,255,255,.2); border-radius: 10px; padding: 8px 12px; font-weight: 700; }
@keyframes subir { from { transform: translateY(20px); opacity: 0; } }

.linea-carrito { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.linea-carrito + .linea-carrito { border-top: 1px solid var(--borde); }
.linea-carrito .cuerpo { flex: 1; min-width: 0; }
.contador { display: flex; align-items: center; background: var(--superficie-2); border-radius: 12px; }
.contador button { width: 40px; height: 40px; border: 0; background: transparent; font-size: 1.3rem; font-weight: 700; display: grid; place-items: center; }
.contador button svg { width: 18px; height: 18px; }
.contador span { min-width: 26px; text-align: center; font-weight: 700; }

.total-grande { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 0 6px; border-top: 2px solid var(--texto); margin-top: 8px; }
.total-grande strong { font-size: 1.8rem; }

/* ---------- producto ---------- */
.foto-grande { width: 100%; aspect-ratio: 1; max-height: 60vh; object-fit: contain; border-radius: var(--radio); background: var(--superficie-2); display: grid; place-items: center; color: var(--texto-2); margin-bottom: 12px; }
.foto-grande svg { width: 64px; height: 64px; opacity: .4; }
.datos { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dato { background: var(--superficie-2); border-radius: 12px; padding: 10px 12px; }
.dato span { display: block; font-size: .78rem; color: var(--texto-2); font-weight: 600; }
.dato strong { font-size: 1.15rem; }
.stock-grande { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stock-grande .cifra { font-size: 2.6rem; font-weight: 800; line-height: 1; }

.selector-foto { position: relative; display: grid; place-items: center; aspect-ratio: 4/3; border-radius: var(--radio); border: 2px dashed var(--borde); background: var(--superficie); color: var(--texto-2); margin-bottom: 16px; overflow: hidden; text-align: center; }
.selector-foto img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--superficie-2); }
.selector-foto svg { width: 40px; height: 40px; }
.selector-foto input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.selector-foto .quitar { position: absolute; top: 8px; right: 8px; z-index: 2; background: var(--superficie); box-shadow: var(--sombra); }

/* ---------- resumen ---------- */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.kpi { background: var(--superficie); border-radius: var(--radio); box-shadow: var(--sombra); padding: 14px; }
.kpi span { display: block; font-size: .8rem; color: var(--texto-2); font-weight: 600; }
.kpi strong { display: block; font-size: 1.35rem; margin-top: 4px; overflow-wrap: anywhere; }
.kpi.destacado { grid-column: 1 / -1; background: var(--barra); color: #fff; }
.kpi.destacado span { color: var(--barra-texto); }
.kpi.destacado strong { font-size: 2rem; }
.barras { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.barras .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.barras .b i { display: block; width: 100%; max-width: 22px; border-radius: 4px 4px 2px 2px; background: var(--acento); min-height: 2px; }
.barras .b i.cero { background: var(--borde); }
.barras .b.hoy i { background: var(--texto); }
.barras .b small { font-size: .65rem; color: var(--texto-2); }
.barra-h { height: 8px; border-radius: 4px; background: var(--superficie-2); overflow: hidden; margin-top: 6px; }
.barra-h i { display: block; height: 100%; background: var(--acento); border-radius: 4px; }

/* ---------- hojas y diálogos ---------- */
.fondo-hoja { position: fixed; inset: 0; z-index: 50; background: rgba(15, 12, 22, .5); animation: aparecer .15s; display: flex; align-items: flex-end; justify-content: center; }
.hoja {
  width: 100%; max-width: 620px; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--fondo); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(20px + var(--seguro-abajo)); animation: subir-hoja .22s ease-out;
}
.hoja .asa { width: 40px; height: 5px; border-radius: 3px; background: var(--borde); margin: 4px auto 12px; }
.hoja .titulo-hoja { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.hoja .titulo-hoja h2 { flex: 1; font-size: 1.25rem; }
@media (min-width: 700px) { .fondo-hoja { align-items: center; } .hoja { border-radius: 22px; } }
@keyframes aparecer { from { opacity: 0; } }
@keyframes subir-hoja { from { transform: translateY(40px); opacity: .5; } }

.fab {
  position: fixed; z-index: 24; right: 16px; bottom: calc(var(--tabbar) + var(--seguro-abajo) + 16px);
  width: 60px; height: 60px; border-radius: 18px; border: 0; background: var(--acento); color: var(--acento-texto);
  display: grid; place-items: center; box-shadow: 0 6px 20px rgba(224, 85, 43, .4);
}
.fab svg { width: 28px; height: 28px; }
@media (min-width: 860px) { .fab { right: calc(50% - 410px + 16px); } }

#toasts { position: fixed; z-index: 100; left: 16px; right: 16px; top: calc(env(safe-area-inset-top, 0px) + 12px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 480px; padding: 12px 18px; border-radius: 12px; background: var(--texto); color: var(--fondo); font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: bajar .2s ease-out; }
.toast.error { background: var(--peligro); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes bajar { from { transform: translateY(-16px); opacity: 0; } }

.exito { text-align: center; padding: 16px 0 8px; }
.exito .circulo { width: 84px; height: 84px; border-radius: 50%; background: var(--ok-suave); color: var(--ok); display: grid; place-items: center; margin: 0 auto 14px; animation: latir .4s ease-out; }
.exito .circulo svg { width: 44px; height: 44px; }
.exito h2 { font-size: 1.4rem; }
.exito .monto { font-size: 2.2rem; font-weight: 800; margin: 8px 0 20px; }
@keyframes latir { 0% { transform: scale(.5); } 70% { transform: scale(1.1); } }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .logo { width: 76px; height: 76px; border-radius: 22px; margin-bottom: 20px; }
.login h1 { font-size: 1.9rem; margin-bottom: 6px; }
.login p { color: var(--texto-2); margin: 0 0 28px; }
.login .error { color: var(--peligro); font-weight: 600; min-height: 1.4em; margin-bottom: 8px; }

/* ---------- importar ---------- */
.tabla-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.tabla { border-collapse: collapse; font-size: .82rem; min-width: 100%; }
.tabla th, .tabla td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--borde); white-space: nowrap; }
.tabla th { font-size: .72rem; text-transform: uppercase; color: var(--texto-2); }
.tabla tr.malo td { background: var(--peligro-suave); }
.pasos { counter-reset: paso; padding: 0; margin: 0 0 12px; list-style: none; }
.pasos li { counter-increment: paso; position: relative; padding-left: 36px; margin-bottom: 10px; }
.pasos li::before { content: counter(paso); position: absolute; left: 0; top: -1px; width: 24px; height: 24px; border-radius: 50%; background: var(--acento-suave); color: var(--acento); font-weight: 800; font-size: .8rem; display: grid; place-items: center; }

.cargando-pantalla { min-height: 100vh; display: grid; place-items: center; }
.girando { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--borde); border-top-color: var(--acento); animation: girar .8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
.aviso-caja { background: var(--aviso-suave); color: var(--texto); border-radius: 12px; padding: 12px 14px; font-size: .9rem; margin-bottom: 12px; }
.item > svg:not(.chevron) { width: 22px; height: 22px; color: var(--texto-2); flex: none; }

/* ---------- fotos de factura ---------- */
.miniaturas { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.miniaturas:empty { display: none; }
.mini-foto { position: relative; width: 84px; height: 84px; border-radius: 12px; overflow: hidden; background: var(--superficie-2); }
.mini-foto img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.mini-foto .icono-btn { position: absolute; top: 2px; right: 2px; width: 32px; height: 32px; border-radius: 50%; background: rgba(15, 12, 22, .6); color: #fff; }
.mini-foto .icono-btn svg { width: 16px; height: 16px; }
.galeria { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 10px; }
.galeria:empty { display: none; }
.mini-foto.grande { width: auto; height: auto; aspect-ratio: 3 / 4; }
.mini-foto.grande .icono-btn { top: 6px; right: 6px; }
.factura-opcional { margin-top: 8px; border-top: 1px solid var(--borde); padding-top: 10px; }
.factura-opcional summary { display: flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 600; cursor: pointer; list-style: none; }
.factura-opcional summary::-webkit-details-marker { display: none; }
.factura-opcional summary svg { width: 20px; height: 20px; color: var(--acento); }
a.kpi:active { transform: scale(.98); }
