/**
 * POS mobile v7 — Sales Cart Mode internal scroll layout
 * Mobile-only (≤767.98px). Desktop / tablet ≥768px untouched.
 *
 * Structure: fixed header | scrollable items | fixed footer (checkout).
 * Reuses the same desktop cart component/handlers — layout only.
 */

@media (max-width: 767.98px) {
  :root {
    --bv-mobile-nav-h: 60px;
  }

  /* ------------------------------------------------------------------ */
  /* Cart shell — flex column; NO whole-panel scroll                      */
  /* ------------------------------------------------------------------ */
  .bv-sales-cart-panel.mobile-cart-slide {
    display: flex !important;
    flex-direction: column !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 50 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    border-radius: 0 !important;
    border: none !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-bottom: calc(var(--bv-mobile-nav-h) + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Stop module page scroll while cart overlay is open */
  body:has(.bv-sales-cart-panel.mobile-cart-slide) #root main.flex-1.overflow-y-auto {
    overflow: hidden !important;
  }

  /* ------------------------------------------------------------------ */
  /* Header — Back to Products, order meta, customer (stable)           */
  /* ------------------------------------------------------------------ */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-header,
  .bv-sales-cart-panel.mobile-cart-slide > .p-4.border-b.border-gray-100 {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    overflow: visible !important;
    z-index: 2;
  }

  /* ------------------------------------------------------------------ */
  /* Cart items — ONLY scroll owner                                     */
  /* ------------------------------------------------------------------ */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-scroll {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    scrollbar-width: thin;
  }

  /* Short carts: no forced min-height / blank scroll area */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-scroll:has(.divide-y) {
    flex-grow: 1;
  }

  /* ------------------------------------------------------------------ */
  /* Checkout footer — stable; internal scroll only on very short screens */
  /* ------------------------------------------------------------------ */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-footer,
  .bv-sales-cart-panel.mobile-cart-slide > .p-4.bg-white.border-t.border-gray-100 {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    max-height: min(46dvh, 100%) !important;
    z-index: 2;
    box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.06);
  }

  /* ------------------------------------------------------------------ */
  /* Cart line — mobile-adapted desktop row (same handlers)             */
  /* ------------------------------------------------------------------ */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line {
    padding: 0.75rem 1rem !important;
  }

  /* Name row: full width, remove always visible */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line > div:first-child {
    align-items: flex-start !important;
    gap: 0.5rem !important;
    margin-bottom: 0.375rem !important;
  }

  /* Hide redundant "2×" prefix — qty stepper shows count */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line > div:first-child > span.w-5.shrink-0 {
    display: none !important;
  }

  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-name {
    white-space: normal !important;
    overflow: visible !important;
    display: block !important;
    -webkit-line-clamp: unset !important;
    line-clamp: unset !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    line-height: 1.25 !important;
    word-break: break-word;
  }

  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-remove {
    opacity: 1 !important;
    min-width: 2rem !important;
    min-height: 2rem !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Controls stack vertically on narrow screens — keep all desktop fields */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-controls {
    margin-left: 0 !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
    row-gap: 0.5rem !important;
  }

  /* Quantity stepper row */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-controls > div:first-child {
    align-self: flex-start;
    padding: 0.125rem 0.25rem !important;
  }

  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-controls > div:first-child button {
    min-width: 2.25rem !important;
    min-height: 2.25rem !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-controls > div:first-child input[type="number"] {
    width: 2.5rem !important;
    min-height: 2rem;
    font-size: 0.875rem !important;
  }

  /* Unit price + item discount row wraps cleanly */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-controls > div:nth-child(2),
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-controls > div:nth-child(3) {
    align-self: flex-start;
  }

  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-controls input[type="number"] {
    min-height: 1.75rem;
  }

  /* Line total — right aligned, always visible */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-line-total {
    align-self: flex-end !important;
    margin-left: 0 !important;
    margin-top: 0.125rem !important;
    text-align: right !important;
  }

  /* Preserve v2 mobile cart remove visibility inside scroll area */
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-scroll .opacity-0 {
    opacity: 1 !important;
  }
}

/* Landscape phones — slightly tighter footer cap */
@media (max-width: 767.98px) and (orientation: landscape) {
  .bv-sales-cart-panel.mobile-cart-slide .bv-sales-cart-footer,
  .bv-sales-cart-panel.mobile-cart-slide > .p-4.bg-white.border-t.border-gray-100 {
    max-height: min(52dvh, 100%) !important;
  }
}

/* Desktop ≥768px: explicitly neutral — no mobile-cart-slide rules apply meaningfully */
@media (min-width: 768px) {
  .bv-sales-cart-panel .bv-sales-cart-scroll {
    /* inherit desktop inline cart behavior unchanged */
  }
}
