/* ==========================================================================
   Inventario — mismos tokens de app.css
   Teléfono: lista a pantalla completa (sin la barra de marca); la ficha ocupa toda
   la pantalla con sus acciones abajo, en la zona del pulgar.
   Ventana ancha: lista a la izquierda y ficha a la derecha.
   Estados: ícono + texto (nunca solo color); los negativos llevan signo.
   ========================================================================== */

.app.is-inv .scroller { overflow: hidden; }
@container app (max-width: 839px) {
  .app.is-inv .topbar { display: none; }
  .app.is-ficha .navbar { display: none; }
}

.inv { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); background: var(--ground); }
.inv-list { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.inv-list > * { flex: none; }
.inv-list > .inv-results { flex: 1 1 auto; }

/* Encabezado */
.inv-head { display: flex; align-items: center; gap: var(--s2); min-height: var(--tap-lg); padding: var(--s1) var(--s3) 0 var(--s1); }
.inv-head-text { flex: 1; min-width: 0; }
.inv-head h1 { margin: 0; font-size: var(--fs-xl); font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; }
.inv-head h1:focus, .ficha-top h1:focus { outline: none; }
.inv-head h1:focus-visible, .ficha-top h1:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.inv-sub { margin: 0; font-size: var(--fs-sm); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-bodega { flex: 0 1 auto; max-width: 46%; padding: 0 var(--s2) 0 var(--s3); gap: 4px; }
.inv-bodega > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-bodega svg.ic { width: 18px; height: 18px; }

/* Búsqueda */
.inv-search { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s4) var(--s2); }
.inv-search .search-field { min-height: var(--tap-lg); border-radius: var(--r-pill); background: var(--surface); }
.inv-search .search-field input { min-height: var(--tap-lg); }

/* Filtros rápidos: una fila que se desliza (no ocupa alto en teléfonos de 360 px) */
.inv-chips {
  /* position: lo que va oculto para lectores de pantalla (absoluto) queda dentro de la fila y no la hace desbordar */
  position: relative; display: flex; gap: var(--s2); overflow-x: auto; overscroll-behavior-x: contain;
  padding: var(--s1) var(--s4) var(--s2);
  scroll-snap-type: x proximity; scroll-padding-inline: var(--s4);
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
          mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
}
.inv-chips::-webkit-scrollbar { display: none; }
.fchip { flex: none; scroll-snap-align: start; gap: 6px; padding: 0 var(--s3); }
.fchip svg.ic { width: 20px; height: 20px; }
.fchip-n { font-weight: 800; font-variant-numeric: tabular-nums; }
.fchip[aria-pressed="true"]::before, .chip-radio input:checked + .chip::before { content: "✓"; font-weight: 800; margin-right: 2px; }
.fchip-negativo svg { color: var(--crit); }
.fchip-sin svg { color: var(--ink); }
.fchip-bajo svg { color: var(--warn-icon); }
.fchip-disponible svg { color: var(--ok); }
.fchip[aria-pressed="true"] svg { color: currentColor; }
.fchip-more { border-style: dashed; }
.inv-chips .fchip:last-child { margin-right: var(--s4); }

.inv-active { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding: 0 var(--s4) var(--s2); }
.chip-x { gap: 6px; padding: 0 var(--s2) 0 var(--s3); background: var(--surface-2); border-color: transparent; }
.chip-x svg.ic { width: 18px; height: 18px; }
.btn-sm { min-height: var(--tap); padding: 0 var(--s3); font-size: var(--fs-sm); }

.inv-banner { display: grid; gap: var(--s2); padding: 0 var(--s4) var(--s2); }
.inv-banner .banner-text { font-size: var(--fs-xs); }
.banner[data-kind="auth"] { background: var(--ok-soft); }
.banner[data-kind="auth"] > svg { color: var(--ok); }

/* Resultados */
.inv-results { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: var(--s6); scroll-padding-block: var(--s4); }
.inv-results .results-meta { padding: var(--s2) var(--s4) var(--s2); }
.inv-results > .state-box, .inv-ficha .state-box { margin: var(--s2) var(--s4); background: var(--surface); border-radius: var(--r-md); box-shadow: inset 0 0 0 1px var(--line); }
.inv-hint {
  display: flex; gap: var(--s2); align-items: flex-start;
  margin: var(--s2) var(--s4) 0; padding: var(--s2) var(--s3);
  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);
}
.inv-hint p { margin: 0; }
.inv-hint strong { color: var(--ink); }
.inv-hint svg.ic { width: 20px; height: 20px; flex: none; color: var(--ink); margin-top: 1px; }
.inv-pad { padding: 0 var(--s4); }
.inv-more { display: flex; justify-content: center; padding: var(--s4); }
.inv-more .muted { font-weight: 400; color: var(--ink-2); }

.inv-rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border-block: 1px solid var(--line); }
.inv-rows > li + li .inv-row, .inv-rows > li + li.inv-skel { border-top: 1px solid var(--line); }
.inv-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "main chev" "foot foot";
  align-items: center; gap: 6px var(--s2);
  min-height: 80px; padding: var(--s3) var(--s2) var(--s3) var(--s4);
  text-decoration: none; color: inherit;
}
.inv-row:active { background: var(--surface-2); }
.inv-row:focus-visible { outline-offset: -3px; border-radius: var(--r-md); }
.inv-row[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 4px 0 0 var(--accent); }
.inv-row-main { grid-area: main; display: grid; gap: 2px; min-width: 0; }
.inv-row-main .p-name { -webkit-line-clamp: 2; }
.inv-row-main .p-meta { margin: 0; overflow-wrap: anywhere; }
.inv-row > .chev { grid-area: chev; }
.inv-row-foot { grid-area: foot; display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--s2); min-width: 0; padding-right: var(--s2); }
.inv-stock { font-weight: 700; font-size: var(--fs-sm); white-space: nowrap; }
.inv-price { margin-left: auto; font-size: var(--fs-md); }
.inv-skel { display: grid; gap: var(--s2); padding: var(--s3) var(--s4); min-height: 80px; }

/* Estados de stock */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px 2px 6px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 800; line-height: 1.5; white-space: nowrap;
}
.badge svg.ic { width: 16px; height: 16px; stroke-width: 2.4; }
.b-disponible { background: var(--ok-soft); color: var(--ok); }
.b-bajo { background: var(--warn-soft); color: var(--warn); }
.b-sin { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.b-negativo { background: var(--crit-soft); color: var(--crit); }
.badge-lg { font-size: var(--fs-sm); padding: 4px 12px 4px 8px; }
.badge-lg svg.ic { width: 20px; height: 20px; }

.tag { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.tag svg.ic { width: 16px; height: 16px; }
.tag-pend { color: var(--warn); }
.tag-sug { padding: 0 8px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--ink-2); vertical-align: 1px; }
.muted-i { color: var(--ink-2); font-weight: 400; }

/* ---------- Ficha ---------- */
.inv-ficha { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; height: 100%; background: var(--ground); }
.ficha-head { display: flex; align-items: center; gap: var(--s2); min-height: var(--tap-lg); padding: var(--s1) var(--s3) 0 var(--s1); }
.ficha-kicker { margin: 0; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); }
.ficha-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-padding-block: var(--s4); }
.ficha-body { display: flex; flex-direction: column; gap: var(--s3); max-width: 720px; margin-inline: auto; padding: 0 var(--s4) var(--s6); }
.ficha-top h1 { margin: var(--s1) 0 0; font-size: var(--fs-xl); font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; }
.f-codes { margin: var(--s1) 0 0; display: flex; flex-wrap: wrap; gap: 2px var(--s3); font-size: var(--fs-sm); color: var(--ink-2); }
.f-code .code { color: var(--ink); }
.f-badges { margin: var(--s2) 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.f-demo { display: flex; gap: var(--s2); align-items: flex-start; margin: var(--s2) 0 0; padding: var(--s2) var(--s3); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-xs); font-weight: 600; }
.f-demo svg.ic { width: 18px; height: 18px; flex: none; }
.ficha-empty { display: grid; justify-items: center; gap: var(--s2); padding: var(--s8) var(--s5); text-align: center; color: var(--ink-2); }
.ficha-empty svg.ic { width: 40px; height: 40px; }
.ficha-empty .state-title { color: var(--ink); }

.fcard { background: var(--surface); border-radius: var(--r-md); box-shadow: inset 0 0 0 1px var(--line); padding: var(--s2) var(--s4) var(--s4); }
.fcard-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); min-height: var(--tap); }
.f-big { margin: 0; font-size: 2.25rem; font-weight: 800; line-height: 1.1; letter-spacing: -0.02em; }
.f-unit { font-size: var(--fs-lg); font-weight: 700; color: var(--ink-2); letter-spacing: 0; }
.f-eq { margin: var(--s1) 0 0; font-size: var(--fs-sm); color: var(--ink-2); }
.f-eq strong { color: var(--ink); }
.f-sub { color: var(--ink-2); font-weight: 400; font-size: var(--fs-sm); }
.f-io { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); margin: var(--s3) 0; }
.io {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "ic l" "ic n" "sub sub";
  column-gap: var(--s2); padding: var(--s3); border-radius: var(--r-md); background: var(--ground);
}
.io-ic { grid-area: ic; margin-top: 2px; }
.io-in .io-ic { color: var(--ok); }
.io-out .io-ic { color: var(--ink); }
.io-l { grid-area: l; font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.io-n { grid-area: n; font-size: var(--fs-xl); font-weight: 800; line-height: 1.2; }
.io-sub { grid-area: sub; margin-top: 2px; font-size: var(--fs-xs); color: var(--ink-2); }
.f-kv { margin: 0; }
.f-warn {
  display: flex; gap: var(--s2); align-items: flex-start;
  margin: var(--s3) 0 0; padding: var(--s2) var(--s3); border-radius: var(--r-md);
  background: var(--warn-soft); color: var(--ink); font-size: var(--fs-sm); font-weight: 600;
}
.f-warn svg.ic { width: 20px; height: 20px; flex: none; color: var(--warn); margin-top: 1px; }

.f-money { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3) var(--s4); margin: 0; }
.f-m { min-width: 0; }
.f-m dt { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.f-m dd { margin: 2px 0 0; font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.f-price { font-size: var(--fs-xl); }
.f-loss { display: inline-flex; align-items: center; gap: 4px; color: var(--crit); font-weight: 800; }
.f-loss svg.ic { width: 18px; height: 18px; }
.f-locked { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s1) var(--s3); margin-top: var(--s3); padding: var(--s3); border-radius: var(--r-md); background: var(--ground); }
.f-locked > svg { color: var(--ink-2); margin-top: 1px; }
.f-locked .btn { margin-top: var(--s2); }

/* Historial */
.hist-chips { margin: 0 0 var(--s2); }
.hist-chips .chip { gap: 6px; padding: 0 var(--s3); }
.mv-list { list-style: none; margin: 0 calc(var(--s4) * -1); padding: 0; }
.mv-list > li + li .mv-row { border-top: 1px solid var(--line); }
.mv-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--s1) var(--s3);
  width: 100%; min-height: 64px; padding: var(--s2) var(--s4);
  border: 0; background: transparent; color: inherit; text-align: left; font: inherit;
}
.mv-row:active { background: var(--surface-2); }
.mv-row:focus-visible { outline-offset: -3px; border-radius: var(--r-md); }
.mv-ic { width: 36px; height: 36px; border-radius: var(--r-pill); display: grid; place-items: center; flex: none; }
.mv-ic svg.ic { width: 20px; height: 20px; }
.mv-in { background: var(--ok-soft); color: var(--ok); }
.mv-out { background: var(--surface-2); color: var(--ink); }
.mv-main { display: grid; gap: 2px; min-width: 0; }
.mv-title { font-size: var(--fs-sm); line-height: 1.3; overflow-wrap: anywhere; }
.mv-title strong { font-size: var(--fs-md); font-weight: 800; }
.mv-meta { font-size: var(--fs-xs); color: var(--ink-2); overflow-wrap: anywhere; }
.mv-flag { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2); }
.mv-flag svg.ic { width: 14px; height: 14px; }
.mv-side { justify-self: end; }
.mv-undated { margin-top: var(--s2); border-top: 1px solid var(--line); padding-top: var(--s1); }
.mv-undated .mv-list { margin-top: var(--s1); }
.f-hist .btn-block { margin-top: var(--s2); }

/* Acciones de la ficha (zona del pulgar) */
.ficha-bar {
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: var(--s3);
  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;
}
.ficha-bar .btn { min-height: var(--tap-lg); border-radius: var(--r-lg); font-size: var(--fs-lg); padding: 0 var(--s3); }

/* ---------- Hoja: ajustar stock ---------- */
.aj-prod { display: grid; gap: 4px; margin: 0 0 var(--s3); }
.aj-prod strong { line-height: 1.3; overflow-wrap: anywhere; }
.aj-prod > span { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: var(--fs-sm); color: var(--ink-2); }
.aj-prod > span strong { color: var(--ink); }
.seg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); border-radius: var(--r-lg); }
.seg-3 .seg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 4px var(--s2); border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.15; }
.seg-3 .seg-btn svg.ic { width: 18px; height: 18px; flex: none; }
.aj-cant { font-size: 1.5rem; font-weight: 800; text-align: right; }
.input[aria-invalid="true"] { border-color: var(--crit); box-shadow: inset 0 0 0 1px var(--crit); }
.aj-preview {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px var(--s2);
  min-height: var(--tap); margin: 0 0 var(--s4); padding: var(--s2) var(--s3);
  border-radius: var(--r-md); background: var(--ground); font-size: var(--fs-sm);
}
.aj-preview svg.ic { width: 18px; height: 18px; }
.aj-neg { flex-basis: 100%; display: flex; gap: 6px; align-items: center; color: var(--warn); font-weight: 700; }
.aj-static { display: flex; align-items: center; gap: var(--s2); margin: 0 0 var(--s3); font-size: var(--fs-sm); color: var(--ink-2); }
.aj-static strong { color: var(--ink); }
.aj-perm { display: flex; gap: var(--s2); align-items: flex-start; margin: var(--s1) 0 var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-md); background: var(--warn-soft); font-size: var(--fs-sm); font-weight: 600; }
.aj-perm svg.ic { width: 20px; height: 20px; flex: none; color: var(--warn); }
.aj-perm.ok { background: var(--ok-soft); }
.aj-perm.aj-info { background: var(--surface-2); font-weight: 400; }
.aj-perm.aj-info svg.ic { color: var(--ink); }
.aj-perm.ok svg.ic { color: var(--ok); }
.aj-actions, .filtros-actions { position: sticky; bottom: calc(var(--s5) * -1); margin: var(--s3) 0 calc(var(--s5) * -1); padding: var(--s3) 0 var(--s5); background: var(--surface); }
.aj-actions .btn-primary, .filtros-actions .btn-primary { flex: 2 1 auto; min-height: var(--tap-lg); border-radius: var(--r-lg); font-size: var(--fs-lg); }
#aj-err { margin-top: var(--s2); }

/* Opciones tipo chip con radio real (accesibles con teclado y lector): el radio cubre el chip */
.chip-radio { position: relative; display: inline-flex; cursor: pointer; }
.chip-radio input { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chip-radio input:checked + .chip { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip-radio input:focus-visible + .chip { outline: 3px solid var(--focus); outline-offset: 2px; }
#sheet-ajuste .fs .chips, #sheet-filtros .fs .chips { margin-top: 0; }

.select { padding-right: var(--s3); font-size: var(--fs-md); }
.check-row { display: flex; align-items: center; gap: var(--s3); min-height: var(--tap); margin: 0 0 var(--s2); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; }
.check-row input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }

/* ---------- Hoja: detalle del movimiento ---------- */
.mv-head { display: flex; align-items: center; gap: var(--s3); margin: 0 0 var(--s3); }
.mv-ic-lg { width: 48px; height: 48px; }
.mv-ic-lg svg.ic { width: 24px; height: 24px; }
.mv-big { margin: 0; font-size: var(--fs-2xl); font-weight: 800; line-height: 1.15; }
.mv-big span { font-size: var(--fs-md); font-weight: 700; color: var(--ink-2); }
.mv-kind { margin: 0; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); }
.mv-id { font-size: var(--fs-xs); overflow-wrap: anywhere; }
.mv-confirm { display: grid; gap: var(--s2); margin-top: var(--s3); padding: var(--s3); border-radius: var(--r-md); background: var(--warn-soft); }
.mv-confirm .state-title:focus { outline: none; }
.mv-confirm .state-title:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Avisos: sobre la barra de navegación, o sobre las acciones de la ficha */
.app-host.in-inv .toasts { bottom: calc(var(--nav-h) + var(--s3)); }
.app-host.in-inv.in-ficha .toasts { bottom: calc(96px + var(--safe-bottom)); }
.app-host.in-inv.has-sheet .toasts { top: calc(64px + var(--safe-top)); bottom: auto; }

/* Teléfonos angostos (360 px y menos) */
@container app (max-width: 380px) {
  .inv-row { padding-left: var(--s3); }
  .ficha-body { padding-inline: var(--s3); }
  .fcard { padding-inline: var(--s3); }
  .mv-list { margin-inline: calc(var(--s3) * -1); }
  .mv-row { padding-inline: var(--s3); gap: var(--s1) var(--s2); }
  .f-big { font-size: 2rem; }
  .ficha-bar { gap: var(--s2); padding-inline: var(--s3); }
}

/* ---------- Ventana ancha: lista y ficha lado a lado ---------- */
@container app (min-width: 840px) {
  .inv { grid-template-columns: minmax(340px, 420px) minmax(0, 1fr); }
  .inv-banner .banner { grid-area: auto; }      /* app.css ubica .banner en el área de la Home */
  .inv-list { border-right: 1px solid var(--line); }
  .ficha-body { padding-inline: var(--s6); }
  .ficha-head { padding-inline: var(--s4); }
  .ficha-bar { display: flex; justify-content: flex-end; border-radius: 0; box-shadow: none; border-top: 1px solid var(--line); padding: var(--s3) var(--s6); }
  .ficha-bar .btn { padding: 0 var(--s6); }
  .app-host.in-inv .toasts { bottom: calc(80px + var(--s4)); }
}

@media (forced-colors: active) {
  .badge, .tag-sug, .mv-ic, .io, .inv-hint { border: 1px solid CanvasText; }
  .fchip[aria-pressed="true"], .chip-radio input:checked + .chip { outline: 2px solid Highlight; }
  .inv-row[aria-current="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
}

/* ---------- Inventario por bodega con la API: operaciones (conteos, ajustes, transferencias) ---------- */
.inv-ops { flex: none; min-width: 48px; justify-content: center; padding: 0 var(--s3); gap: 6px; text-decoration: none; }
.inv-ops svg.ic { width: 18px; height: 18px; }
@container app (max-width: 380px) { .inv-ops > span:not(.fchip-n) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } }
a.mv-row { text-decoration: none; }
.iop-sec { padding-top: var(--s4); font-weight: 700; color: var(--ink); text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--fs-xs); }
.iop-chips { padding: 0 var(--s4) var(--s2); }
.iop-chips .chip svg.ic { width: 16px; height: 16px; }
.iop-l-top { display: flex; align-items: flex-start; gap: var(--s2); }
.iop-l-top .rc-l-head { flex: 1; min-width: 0; }
.iop-l-top .icon-btn { margin: -6px -8px 0 0; color: var(--ink-2); }
.iop-tipo { margin: 0 0 var(--s2); border-radius: var(--r-lg); }
.iop-tipo .seg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: var(--r-md); font-size: var(--fs-sm); }
.iop-tipo .seg-btn svg.ic { width: 18px; height: 18px; flex: none; }
.iop-lines { margin-top: 0; }
.f-kx-head { margin-top: var(--s3); border-top: 1px solid var(--line); padding-top: var(--s2); }
.f-kx-head h3 { margin: 0; }
@media (forced-colors: active) {
  .iop-tipo .seg-btn[aria-pressed="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
}
