/*
 * GAINVO Storefront v0.10.54 — Scrolling Phase 3
 * Independent overlay-surface scrolling with background freeze.
 *
 * Contract:
 * - ordinary pages keep document-owned vertical scrolling (Phase 1);
 * - when a modal/sheet/dialog opens, the page behind it is frozen in place;
 * - each overlay has exactly one intentional vertical scroll surface;
 * - scroll chaining/bounce cannot reveal or move the page underneath;
 * - iOS momentum scrolling, keyboard reveal and safe areas remain usable;
 * - scrollbar chrome stays hidden on phone, tablet and desktop.
 */

/* Background freeze. JS stores the exact page position in
   --gainvo-overlay-body-top and restores it after the last overlay closes. */
html.gainvo-overlay-open{
  overflow:hidden!important;
  overscroll-behavior:none!important;
}
body.gainvo-overlay-open{
  position:fixed!important;
  top:var(--gainvo-overlay-body-top,0px)!important;
  left:0!important;
  right:0!important;
  width:100%!important;
  max-width:100%!important;
  overflow:hidden!important;
  overscroll-behavior:none!important;
  touch-action:none;
}

/* Re-enable interaction only inside true overlay surfaces while the page is
   frozen. This prevents backdrop and edge gestures from moving the document. */
body.gainvo-overlay-open :where(
  #cartSheet,#checkoutSheet,#productModal,#customerAccountSheet,#accountEditorSheet,
  #iosInstallSheet,#cartConflict,#locationDialog,#shopMapSheet,#advertisementDetailsShell
){
  touch-action:auto;
}

/* Fixed shells do not scroll themselves when they have a dedicated body. */
:where(.cart-sheet,.checkout-sheet,.product-modal,.customer-account-sheet,.account-editor-sheet,.ad-details-panel){
  overflow:hidden!important;
  overscroll-behavior:none!important;
  max-width:100%;
}

/* Basket: fixed handle/header/footer, one middle scroll owner. */
.cart-sheet{
  display:grid!important;
  grid-template-rows:auto auto minmax(0,1fr) auto!important;
}
#cartItems{
  grid-row:3!important;
}
.cart-sheet>.cart-footer{
  grid-row:4!important;
}

/* Checkout: fixed handle/header, one body scroll owner. */
.checkout-sheet{
  display:grid!important;
  grid-template-rows:auto auto minmax(0,1fr)!important;
}
#checkoutBody{grid-row:3!important}

/* Product details: fixed app bar + one scrolling body. */
.product-modal{
  display:flex!important;
  flex-direction:column!important;
}
.product-modal>.pdp-topbar{flex:0 0 auto!important}
.product-modal>#productModalBody{flex:1 1 auto!important;min-height:0!important}

/* Account sheets previously scrolled the complete shell. Convert them to a
   stable handle/header plus one dedicated body scroll surface. Receipt views
   use the same editor body and therefore inherit the same behaviour. */
.customer-account-sheet,
.account-editor-sheet{
  display:grid!important;
  grid-template-rows:auto auto minmax(0,1fr)!important;
  overflow:hidden!important;
}
.customer-account-sheet>.sheet-handle,
.account-editor-sheet>.sheet-handle{grid-row:1!important}
.customer-account-sheet>.sheet-head,
.account-editor-sheet>.sheet-head{
  grid-row:2!important;
  position:relative!important;
  top:auto!important;
  margin-bottom:0!important;
}
#customerAccountBody,
#accountEditorBody{
  grid-row:3!important;
  min-height:0!important;
}

/* Location popup: controls remain stable while a long result list scrolls. */
.location-dialog-card{
  display:grid!important;
  grid-template-rows:auto auto auto auto minmax(0,1fr) auto!important;
  overflow:hidden!important;
}
.location-dialog-card>.location-dialog-head{grid-row:1!important}
.location-dialog-card>#useDeviceLocation{grid-row:2!important}
.location-dialog-card>.location-search-box{grid-row:3!important}
.location-dialog-card>#locationDialogStatus{grid-row:4!important}
.location-dialog-card>#locationResults{grid-row:5!important;min-height:0!important}
.location-dialog-card>#locationCartWarning{grid-row:6!important}

/* Intentional vertical scroll owners. */
:where(
  #cartItems,
  #checkoutBody,
  #productModalBody,
  #customerAccountBody,
  #accountEditorBody,
  #locationResults,
  .ios-install-sheet,
  .cart-conflict-card,
  .shop-map-card,
  .ad-details-body,
  .gainvo-overlay-scroll
){
  overflow-y:auto!important;
  overflow-x:hidden!important;
  min-height:0!important;
  max-width:100%!important;
  -webkit-overflow-scrolling:touch;
  overscroll-behavior-y:contain!important;
  overscroll-behavior-x:none!important;
  touch-action:pan-y pinch-zoom!important;
  scrollbar-width:none!important;
  scrollbar-gutter:auto!important;
  -ms-overflow-style:none!important;
  scroll-behavior:auto!important;
  overflow-anchor:auto;
}
:where(
  #cartItems,
  #checkoutBody,
  #productModalBody,
  #customerAccountBody,
  #accountEditorBody,
  #locationResults,
  .ios-install-sheet,
  .cart-conflict-card,
  .shop-map-card,
  .ad-details-body,
  .gainvo-overlay-scroll
)::-webkit-scrollbar{
  display:none!important;
  width:0!important;
  height:0!important;
}

/* Preserve horizontal Phase 2 behaviour inside Product Details and ads. */
.product-modal :where(.pdp-thumbnails,.pdp-related-grid,.pdp-trust-pills,.pdp-buy-summary-v9),
.ad-details-media{
  touch-action:pan-x pan-y pinch-zoom!important;
}

/* Backdrops never become scroll surfaces. */
#overlay:not([hidden]),
.ad-details-backdrop,
.location-dialog,
.shop-map-sheet{
  overscroll-behavior:none!important;
}
#overlay:not([hidden]),.ad-details-backdrop{
  touch-action:none!important;
}

/* Bound every overlay to the usable viewport. The runtime variable stays
   stable during normal Safari toolbar movement and follows visualViewport only
   when a software keyboard genuinely reduces the visible area. */
:where(
  .cart-sheet,.checkout-sheet,.product-modal,.customer-account-sheet,.account-editor-sheet,
  .ios-install-sheet,.cart-conflict-card,.location-dialog-card,.shop-map-card,.ad-details-panel
){
  max-height:calc(var(--gv-overlay-vh,100dvh) - max(8px,env(safe-area-inset-top)) - max(8px,env(safe-area-inset-bottom)))!important;
}

/* Mobile bottom sheets consume the safe area but never create a second page
   behind the keyboard. Checkout keeps its existing full visual-viewport mode. */
@media (max-width:759px){
  :where(.cart-sheet,.customer-account-sheet,.account-editor-sheet,.ios-install-sheet){
    max-height:calc(var(--gv-overlay-vh,100dvh) - max(6px,var(--gv-overlay-top,0px)))!important;
    padding-bottom:max(12px,env(safe-area-inset-bottom))!important;
  }
  .product-modal{
    max-height:calc(var(--gv-overlay-vh,100dvh) - max(6px,var(--gv-overlay-top,0px)))!important;
  }
  .location-dialog-card,.shop-map-card{
    max-height:calc(var(--gv-overlay-vh,100dvh) - max(12px,env(safe-area-inset-top)) - max(12px,env(safe-area-inset-bottom)))!important;
  }
}

/* Focused fields need room above software keyboards and fixed action areas. */
:where(
  #checkoutBody,#customerAccountBody,#accountEditorBody,.location-dialog-card,
  .ios-install-sheet,.cart-conflict-card,.shop-map-card,.ad-details-body
){
  scroll-padding-top:16px!important;
  scroll-padding-bottom:calc(40px + env(safe-area-inset-bottom))!important;
}
:where(
  #checkoutBody,#customerAccountBody,#accountEditorBody,.location-dialog-card
) :where(input,textarea,select,button,[contenteditable="true"]){
  scroll-margin-block:16px 56px!important;
}

/* Desktop overlays remain bounded, centred and independently scrollable. */
@media (min-width:760px){
  :where(.cart-sheet,.checkout-sheet,.product-modal,.customer-account-sheet,.account-editor-sheet,.ios-install-sheet){
    max-height:min(88vh,860px)!important;
  }
  .ad-details-panel{max-height:min(92vh,900px)!important}
}

@media (prefers-reduced-motion:reduce){
  :where(#cartItems,#checkoutBody,#productModalBody,#customerAccountBody,#accountEditorBody,#locationResults,.ios-install-sheet,.cart-conflict-card,.shop-map-card,.ad-details-body){
    scroll-behavior:auto!important;
  }
}
