/*
  Ultracell V20.45 — Mobile Scroll Owner Consolidation
  Diagnóstico base: o travamento em Android/Xiaomi vem da disputa entre body rolável,
  páginas internas fixed, bottom nav fixed e camadas antigas com overflow/height.
  Política: telas normais rolam pelo documento/body; apenas modais, zoom e carrinho
  mantêm tratamento especial quando necessário.
*/

@media (max-width: 760px) {
  :root {
    --uc-mobile-max: 430px;
    --uc-bottom-nav-space: calc(112px + env(safe-area-inset-bottom, 0px));
    --uc-bottom-nav-space-large: calc(144px + env(safe-area-inset-bottom, 0px));
  }

  html,
  body {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior-x: none !important;
    overscroll-behavior-y: auto !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
    -webkit-text-size-adjust: 100% !important;
  }

  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open),
  body.uc-backoffice-mobile-app-active:not(.modal-open):not(.uc-image-viewer-open),
  body.official-mobile-active:not(.modal-open):not(.uc-image-viewer-open) {
    position: static !important;
    inset: auto !important;
    display: block !important;
    min-height: 100dvh !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) #app,
  body.uc-backoffice-mobile-app-active:not(.modal-open):not(.uc-image-viewer-open) #app,
  body.official-mobile-active:not(.modal-open):not(.uc-image-viewer-open) #app {
    position: relative !important;
    inset: auto !important;
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 100dvh !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    transform: none !important;
    contain: none !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .v19-app {
    position: relative !important;
    inset: auto !important;
    display: block !important;
    width: min(100vw, var(--uc-mobile-max)) !important;
    min-width: 0 !important;
    min-height: 100dvh !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 auto !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    touch-action: pan-y !important;
    overscroll-behavior-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: var(--uc-bottom-nav-space-large) !important;
    transform: none !important;
    contain: none !important;
    will-change: auto !important;
  }

  body.v19-store-mobile-active .v19-page[hidden] {
    display: none !important;
  }

  /*
    Ponto principal da V20.45:
    páginas normais deixam de ser overlays fixed com scroll próprio. Elas entram no fluxo
    e o documento passa a ser o dono da rolagem, comportamento mais estável em MIUI/WebView.
  */
  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .v19-page:not([hidden]) {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    inset: auto !important;
    transform: none !important;
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: calc(100dvh - var(--uc-bottom-nav-space)) !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    overscroll-behavior-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    contain: none !important;
    will-change: auto !important;
    padding-bottom: var(--uc-bottom-nav-space-large) !important;
    z-index: auto !important;
  }

  /* Quando uma página interna está ativa, o conteúdo da home não deve ficar acima dela no fluxo. */
  body.v19-store-mobile-active.v19-internal-page-active .v19-topbar,
  body.v19-store-mobile-active.v19-internal-page-active .catalog-dev-notice,
  body.v19-store-mobile-active.v19-internal-page-active .catalog-dev-notice-v19,
  body.v19-store-mobile-active.v19-internal-page-active .v19-section-title,
  body.v19-store-mobile-active.v19-internal-page-active .v19-active-filter,
  body.v19-store-mobile-active.v19-internal-page-active .v19-category-strip,
  body.v19-store-mobile-active.v19-internal-page-active #v19-product-grid {
    display: none !important;
  }

  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .v19-grid,
  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) #v19-product-grid,
  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .v19-news-grid,
  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .v19-categories-content,
  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .v19-profile-content {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    touch-action: pan-y !important;
    contain: none !important;
    will-change: auto !important;
  }

  body.v19-store-mobile-active .v19-page-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 8 !important;
    transform: none !important;
    touch-action: pan-y !important;
  }

  body.v19-store-mobile-active .v19-category-strip,
  body.v19-store-mobile-active .v19-filter-strip {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    touch-action: pan-x !important;
    overscroll-behavior-x: contain !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body.v19-store-mobile-active .v19-grid,
  body.v19-store-mobile-active #v19-product-grid,
  body.v19-store-mobile-active .v19-product,
  body.v19-store-mobile-active .v19-product-info,
  body.v19-store-mobile-active .v19-product-title,
  body.v19-store-mobile-active .v19-product-media {
    transform: none !important;
    contain: none !important;
    will-change: auto !important;
  }

  body.v19-store-mobile-active .v19-product,
  body.v19-store-mobile-active .v19-product *:not(button):not(a):not(input):not(select):not(textarea) {
    touch-action: pan-y !important;
  }

  body.v19-store-mobile-active .v19-product-actions,
  body.v19-store-mobile-active .v19-qty,
  body.v19-store-mobile-active .v19-add-cart,
  body.v19-store-mobile-active .v19-bottom-nav,
  body.v19-store-mobile-active .v19-bottom-nav * {
    touch-action: manipulation !important;
  }

  body.v19-store-mobile-active .v19-bottom-nav {
    position: fixed !important;
    left: 50% !important;
    right: auto !important;
    bottom: 0 !important;
    width: min(100vw, var(--uc-mobile-max)) !important;
    transform: translateX(-50%) !important;
    z-index: 90 !important;
    pointer-events: auto !important;
  }

  body.v19-store-mobile-active .v19-bottom-nav::before,
  body.v19-store-mobile-active .v19-bottom-nav::after {
    content: none !important;
    display: none !important;
    pointer-events: none !important;
  }

  /* Carrinho: mantém footer próprio, mas deixa a página no fluxo para evitar overlay fixed no MIUI. */
  body.v19-store-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .v19-page-cart:not([hidden]) {
    display: flex !important;
    flex-direction: column !important;
    min-height: calc(100dvh - var(--uc-bottom-nav-space)) !important;
    overflow: visible !important;
    padding-bottom: var(--uc-bottom-nav-space-large) !important;
  }

  body.v19-store-mobile-active .v19-page-cart:not([hidden]) .v19-cart-content {
    flex: 0 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    padding-bottom: 20px !important;
  }

  body.v19-store-mobile-active .v19-page-cart .v19-cart-footer {
    position: sticky !important;
    left: auto !important;
    right: auto !important;
    bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important;
    width: 100% !important;
    max-width: none !important;
    transform: none !important;
    z-index: 20 !important;
  }

  /* Backoffice / official mobile: política de rolagem única sem alterar visual. */
  body.uc-backoffice-mobile-app-active:not(.modal-open):not(.uc-image-viewer-open) .uc-app,
  body.uc-backoffice-mobile-app-active:not(.modal-open):not(.uc-image-viewer-open) .uc-mobile-app,
  body.uc-backoffice-mobile-app-active:not(.modal-open):not(.uc-image-viewer-open) .uc-app-content,
  body.uc-backoffice-mobile-app-active:not(.modal-open):not(.uc-image-viewer-open) .uc-mobile-app-content,
  body.official-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .official-mobile-shell,
  body.official-mobile-active:not(.modal-open):not(.uc-image-viewer-open) .official-mobile-content {
    min-height: 100dvh !important;
    height: auto !important;
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
  }

  body.modal-open,
  body.uc-image-viewer-open {
    overflow: hidden !important;
    touch-action: none !important;
  }
}
