/* ==========================================================================
   Nueva venta — mismos tokens de app.css
   Teléfono: buscador arriba, resultados al centro, carrito fijo abajo (zona del pulgar).
   Ventana ancha: resultados a la izquierda y carrito como panel lateral fijo.
   ========================================================================== */

/* El modo venta ocupa toda la app: sin barra de marca ni navegación */
.app.is-venta .topbar, .app.is-venta .navbar { display: none; }
.app.is-venta .scroller { overflow: hidden; }

.venta {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  grid-template-areas: "head" "search" "banner" "results" "bar";
  background: var(--ground);
}
.venta[hidden] { display: none; }

.venta-head {
  grid-area: head;
  display: flex; align-items: center; gap: var(--s2);
  min-height: var(--tap-lg);
  padding: var(--s1) var(--s3) 0 var(--s1);
}
.venta-head-text { flex: 1; min-width: 0; }
.venta-head h1 { margin: 0; font-size: var(--fs-xl); font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
.venta-head h1:focus { outline: none; }
.venta-head h1:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.venta-status { margin: 0; font-size: var(--fs-sm); color: var(--ink-2); }
.venta-status.is-error { color: var(--crit); font-weight: 700; }
.net-pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 var(--s3); border-radius: var(--r-pill);
  background: var(--off-soft); font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
}
.net-pill svg.ic { width: 18px; height: 18px; }
/* Teléfono: el aviso grande ya lo explica; en el encabezado basta el ícono */
@container app (max-width: 479px) {
  .net-pill { padding: 0 var(--s2); }
  .net-pill-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

.venta-search {
  grid-area: search;
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s4) var(--s3);
}
.venta-search .search-field { min-height: var(--tap-lg); border-radius: var(--r-pill); background: var(--surface); }
.venta-search .search-field input { min-height: var(--tap-lg); }
.scan-cam { background: var(--ink); color: var(--surface); }
.scan-cam:active { background: var(--ink-2); }

.venta-banner { grid-area: banner; margin: 0 var(--s4) var(--s3); }
.venta-banner .banner-text { font-size: var(--fs-xs); }

.venta-results {
  grid-area: results;
  container: results / inline-size;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: var(--s4);
  scroll-padding-bottom: var(--s4);
}
.venta-results .results-meta { padding-top: 0; }
.venta-hint { margin: 0 var(--s4) var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r-md); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); font-size: var(--fs-sm); color: var(--ink-2); }
.venta-hint p { margin: 0; }
.venta-hint strong { color: var(--ink); }
.list-title { margin: var(--s2) var(--s4) var(--s1); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }

/* Filas de producto: toda la fila agrega; el botón de la derecha abre el teclado */
.pr-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-block: 1px solid var(--line); }
.pr { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; position: relative; }
.pr + .pr { border-top: 1px solid var(--line); }
/* Teléfono: el nombre usa todo el ancho (los nombres del inventario son largos y se
   distinguen al final: 6 X 70 / 6 X 75); precio y existencia van debajo */
.pr-add {
  display: grid; grid-template-columns: minmax(0, 1fr) 40px; align-items: center; gap: 6px var(--s3);
  grid-template-areas: "main badge" "side badge" "note note";
  width: 100%; min-height: 76px; padding: var(--s3) var(--s2) var(--s3) var(--s4);
  border: 0; background: transparent; color: inherit; text-align: left;
  touch-action: manipulation;
}
.pr-add:active { background: var(--surface-2); }
.pr-add[aria-disabled="true"] { opacity: .6; }
.pr-add:focus-visible, .pr-qty:focus-visible { outline-offset: -3px; border-radius: var(--r-md); }
.pr-main { grid-area: main; display: grid; gap: 2px; min-width: 0; }
.pr-main .p-name { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-weight: 700; line-height: 1.3; overflow-wrap: break-word; }
.pr-main .p-meta { margin: 0; }
.via { color: var(--accent-ink); font-weight: 700; }
.pr-side { grid-area: side; display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--s2); min-width: 0; }
.pr-side .pill { font-size: var(--fs-xs); padding: 2px 8px; }
.pr-badge { grid-area: badge; }
/* Lista ancha (tableta, escritorio): precio y existencia en su propia columna */
@container results (min-width: 560px) {
  .pr-add { grid-template-columns: minmax(0, 1fr) auto 40px; grid-template-areas: "main side badge" "note note note"; }
  .pr-side { display: grid; justify-items: end; }
  .pr-main .p-name { -webkit-line-clamp: 2; }
}
.pr-badge {
  width: 40px; height: 40px; border-radius: var(--r-pill);
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink);
  font-weight: 800; font-size: var(--fs-sm); font-variant-numeric: tabular-nums;
}
.pr-badge svg.ic { width: 22px; height: 22px; stroke-width: 2.5; }
.pr.in-cart .pr-badge { background: var(--accent); color: var(--on-accent); }
.pr-qty {
  width: var(--tap); height: var(--tap); margin-right: var(--s2);
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--ink-2);
  touch-action: manipulation;
}
.pr-qty:active { background: var(--surface-3); }
.pr.flash { animation: added .6s var(--ease); }
@keyframes added { 0% { background: var(--ok-soft); } 100% { background: transparent; } }
.pr.flash .pr-badge { animation: pop .35s var(--ease); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
.pr-skel { grid-template-columns: minmax(0, 1fr) 64px; gap: var(--s3); min-height: 76px; padding: var(--s3) var(--s4); }

/* Barra inferior del carrito (siempre visible en teléfono) */
.cart-bar {
  grid-area: bar;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s3); align-items: center;
  padding: var(--s3) var(--s4) calc(var(--s3) + var(--safe-bottom));
  background: var(--surface);
  box-shadow: var(--dock-shadow);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  position: relative; z-index: 2;
}
.cart-summary {
  display: flex; align-items: center; gap: var(--s3); flex: 1;
  min-height: var(--tap-lg); padding: 0 var(--s2) 0 var(--s1);
  border: 0; border-radius: var(--r-md); background: transparent; text-align: left; color: var(--ink);
  min-width: 0;
}
.cart-summary:active { background: var(--surface-2); }
.cart-ic { position: relative; width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--r-pill); background: var(--surface-2); flex: none; }
.cart-count {
  position: absolute; top: -4px; right: -6px; min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: var(--r-pill); background: var(--accent); color: var(--on-accent);
  font-size: var(--fs-xs); font-weight: 800; display: grid; place-items: center;
}
.cart-count.bump { animation: pop .35s var(--ease); }
.cart-sum { display: grid; min-width: 0; line-height: 1.25; }
.cart-sum strong { font-size: var(--fs-xl); font-weight: 800; }
.cart-sub { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-sm); color: var(--ink-2); }
.cart-sub-text { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-pay { min-height: var(--tap-lg); padding: 0 var(--s6); font-size: var(--fs-lg); border-radius: var(--r-lg); }
.btn-primary[aria-disabled="true"] { background: var(--surface-3); color: var(--ink-2); }

/* Contenido del carrito (pantalla completa en teléfono, panel en ventana ancha): ver css/cobro.css */
.cart-counts { margin: 0; font-size: var(--fs-sm); color: var(--ink-2); white-space: nowrap; }
.sheet-tall { height: calc(100% - 40px); max-height: none; }

/* Panel lateral (solo ventana ancha) */
.cart-panel { display: none; }
.cart-panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s4) var(--s2); }
.cart-panel-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 800; }

/* Teclado de cantidad */
.qty-prod { display: grid; gap: 2px; margin: 0 0 var(--s3); }
.qty-prod strong { font-size: var(--fs-md); line-height: 1.3; }
.qty-prod span { font-size: var(--fs-sm); color: var(--ink-2); }
.qty-display-wrap { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); padding: var(--s2) var(--s4); border-radius: var(--r-md); background: var(--ground); box-shadow: inset 0 0 0 1px var(--line-strong); }
.qty-display {
  width: 100%; min-width: 0; min-height: 56px; border: 0; background: transparent; outline: none;
  font-size: 2.25rem; font-weight: 800; letter-spacing: -0.02em; text-align: right; color: var(--ink);
}
.qty-display.is-fresh { color: var(--ink-2); }
.qty-display-wrap:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.qty-display.nudge, .qty-display-wrap .nudge { animation: nudge .25s; }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.qty-calc { margin: 0; white-space: nowrap; font-weight: 700; color: var(--ink-2); }
.qty-warn { display: flex; gap: var(--s2); align-items: flex-start; margin: var(--s2) 0 0; font-size: var(--fs-sm); color: var(--warn); font-weight: 600; }
.qty-warn svg.ic { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.field-error { margin: var(--s2) 0 0; font-size: var(--fs-sm); color: var(--crit); font-weight: 700; }
.quick { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--s2); margin: var(--s3) 0 var(--s2); }
.quick-btn {
  min-height: var(--tap); border-radius: var(--r-md); border: 1px solid var(--line-strong); background: var(--surface);
  font-weight: 800; font-size: var(--fs-sm); color: var(--ink); touch-action: manipulation;
}
.quick-btn:active { background: var(--surface-3); }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
.key {
  min-height: 56px; border: 0; border-radius: var(--r-md); background: var(--surface-2); color: var(--ink);
  font-size: 1.5rem; font-weight: 700; display: grid; place-items: center; touch-action: manipulation;
}
.key:active { background: var(--surface-3); }
.qty-more { margin: var(--s3) 0 0; }
/* Secciones plegables: la fila completa es tocable, muestra el valor actual y un chevrón que gira */
.disclosure > summary {
  list-style: none;
  display: flex; align-items: center; gap: var(--s2);
  min-height: var(--tap); padding: var(--s1) 0;
  cursor: pointer; font-weight: 700; color: var(--ink); font-size: var(--fs-sm);
  touch-action: manipulation;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.disc-label { flex: 0 1 auto; min-width: 0; }   /* con el texto grande pasa a otra línea; el valor se acorta antes */
.disc-value { flex: 1; min-width: 0; text-align: right; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.disclosure > summary svg.disc-ic { width: 20px; height: 20px; flex: none; color: var(--ink-2); transition: transform .2s var(--ease); }
.disclosure[open] > summary svg.disc-ic { transform: rotate(180deg); }
.disc-label + svg.disc-ic { margin-left: auto; }

/* Teléfonos angostos: la barra del carrito cede espacio al total y al aviso */
@container app (max-width: 359px) {
  .cart-bar { gap: var(--s2); padding-inline: var(--s3); }
  .cart-summary { gap: var(--s2); }
  .cart-sub-u { display: none; }
  .cart-pay { padding: 0 var(--s4); }
  .pr-add { padding-left: var(--s3); gap: 6px var(--s2); }
}
.qty-more .field { margin-top: var(--s1); }
#sheet-qty .sheet-actions { margin-top: var(--s4); }
#sheet-qty .sheet-actions .btn-primary { flex: 2 1 auto; min-height: var(--tap-lg); font-size: var(--fs-lg); border-radius: var(--r-lg); }

/* Cobrar */
.pay-total { text-align: center; padding: var(--s2) 0 var(--s4); }
.pay-total .amount { justify-content: center; }
.pay-total .amount:focus { outline: none; }
.pay-total .amount:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.pay-meta { margin: var(--s1) 0 0; color: var(--ink-2); font-size: var(--fs-sm); }
.fs { border: 0; margin: 0 0 var(--s4); padding: 0; display: grid; gap: var(--s1); }
.fs legend { padding: 0; margin-bottom: var(--s2); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.opt { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink-2); }
#cobrar-form .field { margin-bottom: var(--s2); }
#cobrar-form .chips { margin: 0 0 var(--s2); }
.pay-change { margin: var(--s1) 0 0; font-weight: 800; font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn-xl { min-height: 64px; font-size: var(--fs-xl); border-radius: var(--r-lg); }
.btn-xl svg.ic { width: 24px; height: 24px; }
#cobrar-form .note { margin: 0 0 var(--s3); }

/* Venta registrada */
.venta .venta-done { display: none; }
.venta.is-done { grid-template-areas: "head" "done"; grid-template-rows: auto minmax(0, 1fr); }
.venta.is-done .venta-search, .venta.is-done .venta-banner, .venta.is-done .venta-results,
.venta.is-done .cart-bar, .venta.is-done .cart-panel { display: none; }
.venta.is-done .venta-done { display: block; grid-area: done; overflow-y: auto; padding: var(--s4); }
.done-card { max-width: 480px; margin: 0 auto; display: grid; justify-items: center; gap: var(--s2); text-align: center; }
.done-icon { width: 72px; height: 72px; border-radius: var(--r-pill); background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; animation: pop .4s var(--ease); }
.done-icon svg.ic { width: 40px; height: 40px; stroke-width: 2.5; }
.done-card h2 { margin: var(--s2) 0 0; font-size: var(--fs-2xl); font-weight: 800; }
.done-card h2:focus { outline: none; }
.done-card h2:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.done-meta { margin: 0; color: var(--ink-2); font-size: var(--fs-sm); }
.done-sync { display: flex; gap: var(--s2); align-items: center; margin: var(--s1) 0 var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-md); background: var(--off-soft); font-size: var(--fs-sm); text-align: left; }
.done-sync[data-state="ok"] { background: var(--ok-soft); }
.done-sync[data-state="warn"] { background: var(--warn-soft); }
.done-sync[data-state="sync"] svg { animation: spin 1.1s linear infinite; }
.done-sync svg.ic { width: 20px; height: 20px; flex: none; }
.done-actions { display: grid; gap: var(--s3); width: 100%; }
.done-detail { width: 100%; text-align: left; margin-top: var(--s2); }
.done-detail > summary { font-size: var(--fs-md); }

/* Escaneo continuo */
.vscan-tools { display: flex; align-items: center; gap: var(--s2); }
.vscan-tools .help { flex: 1; margin: 0; }
#vscan-torch[aria-pressed="true"] { background: var(--warn-soft); color: var(--warn); }
.vscan-log { list-style: none; margin: var(--s3) 0; padding: 0; display: grid; gap: var(--s1); }
.vscan-log li { display: flex; gap: var(--s2); align-items: center; padding: var(--s2) var(--s3); border-radius: var(--r-md); font-size: var(--fs-sm); background: var(--ok-soft); }
.vscan-log li.warn { background: var(--warn-soft); }
.vscan-log li.err { background: var(--crit-soft); }
.vscan-log li svg.ic { width: 18px; height: 18px; flex: none; }

/* Avisos con acción y de advertencia: con el aviso, en css/app.css */

/* La CTA de la Home muestra "Continuar venta" si hay borrador */
.cta-text { display: grid; line-height: 1.15; text-align: left; }
.cta-sub { font-size: var(--fs-sm); font-weight: 600; opacity: .92; }

/* En el modo venta los avisos van sobre la barra del carrito; con una hoja abierta, arriba */
.app-host:has(.app.is-venta) .toasts { bottom: calc(88px + var(--safe-bottom)); }
.app-host.has-sheet:has(.app.is-venta) .toasts { top: calc(64px + var(--safe-top)); bottom: auto; }

.pr-note { grid-area: note; display: block; font-size: var(--fs-xs); font-weight: 700; color: var(--warn); }
.pr-note[hidden] { display: none; }
.bar-warn { flex: none; display: inline-flex; align-items: center; gap: 2px; padding: 0 6px 0 4px; border-radius: var(--r-pill); background: var(--warn-soft); color: var(--warn); font-weight: 800; line-height: 1.5; }
.bar-warn svg.ic { width: 16px; height: 16px; }
.bar-disc { flex: none; font-weight: 800; color: var(--ok); }


/* ---------- Ventana ancha: carrito como panel fijo ---------- */
@container app (min-width: 840px) {
  .app.is-venta { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "main"; }
  .venta {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas: "head cart" "search cart" "banner cart" "results cart";
  }
  .venta-head { padding: var(--s3) var(--s4) 0 var(--s4); }
  .venta-search { padding: var(--s3) var(--s6) var(--s3); }
  .venta-banner { margin-inline: var(--s6); }
  .venta-results .pr-list { margin-inline: var(--s6); border-radius: var(--r-md); border: 1px solid var(--line); overflow: hidden; }
  .venta-hint, .list-title, .venta-results .results-meta { margin-inline: var(--s6); }
  .venta-results .results-meta { padding-inline: 0; }
  .cart-bar { display: none; }
  .cart-panel {
    grid-area: cart; display: flex; flex-direction: column; min-height: 0;
    background: var(--surface); border-left: 1px solid var(--line);
  }
  .venta.is-done { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "done"; }
  .app-host:has(.app.is-venta) .toasts { bottom: var(--s6); right: calc(420px + var(--s6)); left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .pr.flash { animation: none; background: var(--ok-soft); }
}
@media (forced-colors: active) {
  .pr-badge, .key, .quick-btn, .cart-count { border: 1px solid CanvasText; }
}
