/* ERP Comercial Chile v10.25.1 — POS operativo compacto
   Mejora visual sin modificar ventas, stock, impuestos, permisos ni base de datos. */

.pos19-root {
  --pos251-panel-gap: 12px;
  --pos251-radius: 20px;
}

/* Menos espacio muerto y mejor aprovechamiento vertical. */
.pos19-shell {
  padding: 6px 8px 9px !important;
}
.pos19-workspace {
  gap: var(--pos251-panel-gap) !important;
}
.pos19-main {
  gap: 12px !important;
}

/* Paso 1: buscador compacto y siempre prioritario. */
.pos19-search-card > div:first-child {
  min-height: 50px !important;
  padding: 8px 14px !important;
}
.pos19-search-card > div:last-child {
  padding: 10px 14px 11px !important;
}
.pos19-search-card h2 {
  font-size: 15px !important;
}
.pos19-search-card h2::before {
  width: 25px !important;
  height: 25px !important;
  flex-basis: 25px !important;
  border-radius: 8px !important;
}
.pos19-product-search {
  height: 47px !important;
  border-width: 1.5px !important;
  border-radius: 14px !important;
  font-size: 14px !important;
  box-shadow: 0 4px 14px rgba(15, 23, 42, .045) !important;
}
.pos19-search-card > div:last-child > div:nth-child(2) {
  margin-top: 4px !important;
  font-size: 10px !important;
  line-height: 1.25 !important;
}
.pos19-search-card > div:last-child > div:nth-child(2) > span:last-child {
  display: none !important;
}
.pos19-search-empty-hint {
  display: none !important;
}

/* Paso 2: la página no crece indefinidamente al agregar productos. */
.pos19-cart-card {
  min-height: 0 !important;
}
.pos19-cart-card > div:first-child {
  min-height: 52px !important;
  padding: 9px 14px !important;
}
.pos19-cart-scroll-desktop {
  max-height: min(46dvh, 430px);
  overflow: auto !important;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
.pos19-cart-scroll-desktop table thead {
  position: sticky;
  top: 0;
  z-index: 8;
  box-shadow: 0 1px 0 #e2e8f0;
}
.pos19-cart-card table th,
.pos19-cart-card table td {
  padding: 10px 12px !important;
}
.pos19-cart-card table td:first-child p:first-child {
  line-height: 1.25 !important;
}
.pos19-cart-scroll-mobile {
  max-height: 52dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

/* Paso 4: panel fijo, compacto y con acciones siempre visibles. */
.pos19-checkout {
  align-self: start !important;
}
.pos19-checkout-card {
  display: flex !important;
  max-height: calc(100dvh - 64px) !important;
  flex-direction: column !important;
  overflow: hidden !important;
  border-radius: var(--pos251-radius) !important;
}
.pos19-checkout-header {
  position: relative !important;
  top: auto !important;
  z-index: 40;
  min-height: 50px !important;
  flex: 0 0 auto;
  padding: 8px 13px !important;
}
.pos19-checkout-header h2 {
  font-size: 15px !important;
}
.pos19-checkout-header h2::before {
  width: 25px !important;
  height: 25px !important;
  flex-basis: 25px !important;
  border-radius: 8px !important;
}
.pos19-checkout-body {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 9px 10px 10px !important;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  scroll-padding-top: 102px;
  scroll-padding-bottom: 108px;
}
.pos19-checkout-body.space-y-3 > :not([hidden]) ~ :not([hidden]) {
  margin-top: 8px !important;
}
.pos19-total-card {
  top: 0 !important;
  z-index: 30 !important;
  border-radius: 17px !important;
  padding: 12px 14px !important;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .22) !important;
}
.pos19-total-card > strong {
  margin-top: 4px !important;
  font-size: clamp(1.85rem, 2.3vw, 2.35rem) !important;
  line-height: 1 !important;
}
.pos19-total-card > div:last-child {
  margin-top: 8px !important;
  padding-top: 8px !important;
}
.pos19-checkout-body > section {
  border-radius: 15px !important;
  padding: 10px !important;
}
.pos19-checkout-body select,
.pos19-checkout-body input[type="number"],
.pos19-checkout-body input[type="date"] {
  min-height: 40px;
}

/* Descuento/IVA/Margen queda disponible, pero no ocupa espacio en cada venta. */
.pos19-adjustments {
  overflow: hidden;
  border-radius: 15px !important;
}
.pos19-adjustments > summary {
  min-height: 40px !important;
  padding: 8px 11px !important;
  user-select: none;
}
.pos19-adjustments > summary::after {
  content: "+";
  display: inline-flex;
  width: 23px;
  height: 23px;
  flex: 0 0 23px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #f1f5f9;
  color: #475569;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  transition: transform .18s ease, background .18s ease;
}
.pos19-adjustments[open] > summary::after {
  content: "−";
  background: #e0e7ff;
  color: #4338ca;
}
.pos19-adjustments[open] > summary {
  border-bottom: 1px solid #f1f5f9;
}
.pos19-adjustments > div:last-child {
  padding: 10px !important;
}

/* Registrar/Cancelar nunca desaparecen al desplazar ajustes del cobro. */
.pos19-checkout-actions {
  position: sticky;
  bottom: -10px;
  z-index: 45;
  margin-right: -2px;
  margin-bottom: -10px;
  margin-left: -2px;
  padding: 9px 2px 10px !important;
  border-top: 1px solid rgba(226, 232, 240, .92);
  background: linear-gradient(180deg, rgba(255,255,255,.88), #fff 24%);
  box-shadow: 0 -12px 24px rgba(15, 23, 42, .07);
  backdrop-filter: blur(8px);
}
.pos19-primary-action {
  min-height: 49px !important;
  border-radius: 14px !important;
}
.pos19-cancel-action {
  min-height: 38px !important;
  padding-top: 8px !important;
  padding-bottom: 8px !important;
  border-radius: 13px !important;
}

@media (min-width: 1024px) {
  .pos19-shell {
    padding: 6px 8px 10px !important;
  }
  .pos19-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(350px, 405px) !important;
  }
  .pos19-checkout-card {
    position: sticky !important;
    top: 6px !important;
  }
}

@media (min-width: 1440px) {
  .pos19-workspace {
    grid-template-columns: minmax(0, 1fr) 405px !important;
  }
}

@media (max-width: 1023px) {
  .pos19-checkout-card {
    max-height: none !important;
    overflow: visible !important;
  }
  .pos19-checkout-body {
    overflow: visible !important;
  }
  .pos19-checkout-actions {
    position: relative;
    bottom: auto;
    margin: 0;
    padding: 8px 0 0 !important;
    border-top: 0;
    box-shadow: none;
    backdrop-filter: none;
  }
}

@media (max-width: 640px) {
  .pos19-shell {
    padding: 4px !important;
  }
  .pos19-search-card > div:last-child > div:nth-child(2) {
    display: none !important;
  }
  .pos19-product-search {
    height: 46px !important;
  }
  .pos19-cart-scroll-mobile {
    max-height: none;
    overflow: visible;
  }
}

/* ========================================================================== 
   ERP Comercial Chile v10.25.2 — POS una sola pantalla (desktop)
   - Buscador en la barra superior junto a Historial / Cerrar caja.
   - Carrito con filas completas y scroll interno después de 7–10 artículos.
   - Cliente y documento siempre visibles en la misma pantalla.
   - Sin cambios en lógica de venta, stock, IVA, permisos ni base de datos.
   ========================================================================== */

@media (min-width: 1024px) {
  .pos19-root {
    --pos252-toolbar-h: 58px;
    --pos252-cart-head-h: 46px;
    --pos252-table-head-h: 38px;
    --pos252-row-h: 58px;
    --pos252-list-h: 444px; /* cabecera 38 + 7 filas de 58 */
    min-height: 0 !important;
  }

  /* La estructura completa queda en una sola cuadrícula. display:contents permite
     ubicar búsqueda, carrito, cliente y cobro sin alterar la lógica React. */
  .pos19-shell {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(350px, 405px) !important;
    grid-template-rows: var(--pos252-toolbar-h) auto auto !important;
    grid-template-areas:
      "search cash"
      "cart checkout"
      "client checkout" !important;
    align-content: start !important;
    align-items: start !important;
    gap: 10px !important;
    min-height: 0 !important;
    padding: 7px 8px 9px !important;
    overflow: hidden !important;
  }

  .pos19-workspace,
  .pos19-main {
    display: contents !important;
  }

  /* Barra de caja: conservar sólo las acciones, compactas y a la derecha. */
  .pos19-cashbar {
    grid-area: cash;
    align-self: stretch !important;
    min-width: 0 !important;
    height: var(--pos252-toolbar-h) !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 18px !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  .pos19-cashbar > div:first-child {
    display: flex !important;
    height: 100% !important;
    align-items: center !important;
    justify-content: flex-end !important;
    padding: 6px 2px !important;
  }

  .pos19-cashbar > div:first-child > div:first-child,
  .pos19-cashbar > div:nth-child(2) {
    display: none !important;
  }

  .pos19-cashbar > div:first-child > div:last-child {
    width: 100% !important;
    justify-content: flex-end !important;
  }

  .pos19-cashbar button {
    height: 44px !important;
    border-radius: 14px !important;
    padding-inline: 14px !important;
    font-size: 12px !important;
  }

  /* PASO 1 convertido en buscador de barra superior. */
  .pos19-search-card {
    grid-area: search;
    align-self: stretch !important;
    z-index: 80 !important;
    height: var(--pos252-toolbar-h) !important;
    min-height: 0 !important;
    overflow: visible !important;
    border-width: 1px !important;
    border-top-width: 2px !important;
    border-radius: 18px !important;
    box-shadow: 0 4px 15px rgba(15, 23, 42, .05) !important;
  }

  .pos19-search-card > div:first-child {
    display: none !important;
  }

  .pos19-search-card > div:last-child {
    position: relative !important;
    height: 100% !important;
    padding: 6px 8px !important;
  }

  .pos19-product-search {
    height: 44px !important;
    border-width: 1.5px !important;
    border-radius: 13px !important;
    padding-left: 43px !important;
    font-size: 14px !important;
    box-shadow: none !important;
  }

  .pos19-search-card > div:last-child > div:first-child > svg {
    left: 14px !important;
    width: 18px !important;
    height: 18px !important;
  }

  .pos19-search-card > div:last-child > div:nth-child(2),
  .pos19-search-empty-hint {
    display: none !important;
  }

  /* Los resultados se abren como panel flotante y no empujan el carrito. */
  .pos19-search-card > div:last-child > :nth-child(3):not(.pos19-search-empty-hint) {
    position: absolute !important;
    top: calc(100% + 7px) !important;
    right: 0 !important;
    left: 0 !important;
    z-index: 120 !important;
    max-height: min(62dvh, 570px) !important;
    margin-top: 0 !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    border: 1px solid #dbe4f0 !important;
    border-radius: 18px !important;
    background: #fff !important;
    padding: 8px !important;
    box-shadow: 0 24px 65px rgba(15, 23, 42, .20) !important;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
  }

  /* PASO 2: altura exacta de filas para que nunca quede un artículo cortado. */
  .pos19-cart-card {
    grid-area: cart;
    align-self: start !important;
    display: flex !important;
    width: 100% !important;
    min-height: 0 !important;
    max-height: calc(var(--pos252-cart-head-h) + var(--pos252-list-h)) !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  .pos19-cart-card > div:first-child {
    min-height: var(--pos252-cart-head-h) !important;
    height: var(--pos252-cart-head-h) !important;
    flex: 0 0 var(--pos252-cart-head-h) !important;
    padding: 6px 12px !important;
  }

  .pos19-cart-card > div:first-child p:first-child {
    font-size: 8px !important;
  }

  .pos19-cart-card > div:first-child h2 {
    font-size: 15px !important;
  }

  .pos19-cart-card h2::before {
    width: 24px !important;
    height: 24px !important;
    flex-basis: 24px !important;
    border-radius: 8px !important;
  }

  .pos19-cart-scroll-desktop {
    min-height: 0 !important;
    max-height: var(--pos252-list-h) !important;
    flex: 0 1 auto !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    scroll-snap-type: y proximity;
  }

  .pos19-cart-scroll-desktop table {
    table-layout: fixed !important;
  }

  .pos19-cart-scroll-desktop table thead,
  .pos19-cart-scroll-desktop table thead tr {
    height: var(--pos252-table-head-h) !important;
  }

  .pos19-cart-scroll-desktop table tbody tr {
    height: var(--pos252-row-h) !important;
    min-height: var(--pos252-row-h) !important;
    scroll-snap-align: start;
  }

  .pos19-cart-card table th {
    height: var(--pos252-table-head-h) !important;
    padding: 7px 10px !important;
    vertical-align: middle !important;
  }

  .pos19-cart-card table td {
    height: var(--pos252-row-h) !important;
    max-height: var(--pos252-row-h) !important;
    padding: 6px 10px !important;
    vertical-align: middle !important;
  }

  .pos19-cart-card table th:first-child,
  .pos19-cart-card table td:first-child {
    width: 40% !important;
  }

  .pos19-cart-card table td:first-child p {
    max-width: 100% !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
  }

  .pos19-cart-card table td:first-child p:first-child {
    font-size: 13px !important;
    line-height: 1.15 !important;
  }

  .pos19-cart-card table td:first-child p:nth-child(2),
  .pos19-cart-card table td:first-child p:nth-child(3) {
    font-size: 10px !important;
    line-height: 1.1 !important;
  }

  .pos19-cart-card table input[type="number"] {
    height: 34px !important;
  }

  .pos19-cart-card table td:nth-child(3) p {
    margin-top: 2px !important;
    line-height: 1.05 !important;
  }

  /* PASO 3 compacto: cliente, documento y configuración en una sola fila. */
  .pos19-client-card {
    grid-area: client;
    z-index: 70 !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  .pos19-client-card > div:first-child {
    min-height: 38px !important;
    height: 38px !important;
    padding: 4px 11px !important;
  }

  .pos19-client-card > div:first-child p:first-child {
    display: none !important;
  }

  .pos19-client-card > div:first-child h2 {
    font-size: 14px !important;
  }

  .pos19-client-card h2::before {
    width: 23px !important;
    height: 23px !important;
    flex-basis: 23px !important;
    border-radius: 7px !important;
  }

  .pos19-client-card > div:last-child {
    display: grid !important;
    grid-template-columns: minmax(270px, 1.25fr) minmax(280px, .95fr) minmax(170px, .55fr) !important;
    align-items: end !important;
    gap: 8px !important;
    padding: 7px 9px 9px !important;
  }

  .pos19-client-card > div:last-child > div:first-child,
  .pos19-client-card > div:last-child > div:nth-child(2),
  .pos19-client-card > div:last-child > details {
    min-width: 0 !important;
    margin: 0 !important;
  }

  .pos19-client-card > div:last-child > div:first-child > div:first-child {
    margin-bottom: 3px !important;
  }

  .pos19-client-card > div:last-child > div:first-child > div:first-child > span:last-child {
    display: none !important;
  }

  .pos19-client-card > div:last-child input,
  .pos19-client-card > div:last-child select {
    height: 39px !important;
    min-height: 39px !important;
    border-radius: 12px !important;
  }

  .pos19-client-card > div:last-child > div:nth-child(2) {
    grid-template-columns: minmax(130px, .72fr) minmax(0, 1fr) !important;
    gap: 7px !important;
  }

  .pos19-client-card > div:last-child > div:nth-child(2) label > span {
    margin-bottom: 3px !important;
  }

  .pos19-client-card > div:last-child > div:nth-child(2) > div:last-child {
    min-height: 39px !important;
    padding: 5px 10px !important;
    border-radius: 12px !important;
  }

  .pos19-client-card > div:last-child > details {
    position: relative !important;
    overflow: visible !important;
    border-radius: 12px !important;
  }

  .pos19-client-card > div:last-child > details > summary {
    min-height: 39px !important;
    height: 39px !important;
    padding: 5px 9px !important;
  }

  .pos19-client-card > div:last-child > details > summary p:first-child {
    font-size: 11px !important;
  }

  .pos19-client-card > div:last-child > details > summary div > div {
    display: none !important;
  }

  /* Configuración se abre hacia arriba como popover y no alarga la página. */
  .pos19-client-card > div:last-child > details[open] > div:last-child {
    position: absolute !important;
    right: 0 !important;
    bottom: calc(100% + 7px) !important;
    z-index: 130 !important;
    width: min(570px, 72vw) !important;
    max-height: 55dvh !important;
    overflow-y: auto !important;
    border: 1px solid #dbe4f0 !important;
    border-radius: 16px !important;
    background: #fff !important;
    box-shadow: 0 22px 60px rgba(15, 23, 42, .20) !important;
  }

  /* El selector de cliente también abre hacia arriba para quedar dentro del viewport. */
  .pos19-client-card > div:last-child > div:first-child > div.absolute.left-0.right-0.top-full {
    top: auto !important;
    bottom: calc(100% + 7px) !important;
    max-height: min(54dvh, 470px) !important;
  }

  /* PASO 4 ocupa el alto combinado de carrito + cliente. */
  .pos19-checkout {
    grid-area: checkout;
    align-self: stretch !important;
    min-height: 0 !important;
    height: 100% !important;
  }

  .pos19-checkout-card {
    position: relative !important;
    top: auto !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
  }

  .pos19-checkout-body {
    min-height: 0 !important;
  }
}

/* 8 filas completas en pantallas habituales; 10 en monitores altos. */
@media (min-width: 1024px) and (min-height: 820px) {
  .pos19-root { --pos252-list-h: 502px; /* cabecera 38 + 8 filas */ }
}

@media (min-width: 1024px) and (min-height: 1010px) {
  .pos19-root { --pos252-list-h: 618px; /* cabecera 38 + 10 filas */ }
}

@media (min-width: 1440px) {
  .pos19-shell {
    grid-template-columns: minmax(0, 1fr) 405px !important;
  }
}
