/* A product menu has one viewport budget. Its three desktop columns scroll
   inside that budget, so the last master group cannot sit below a clipped
   ancestor. The percentage subtracts the actual positioned header height. */
.mega:has(> .native-product-menu) {
  height: min(680px, calc(100vh - 100% - 12px));
  height: min(680px, calc(100dvh - 100% - 12px - env(safe-area-inset-bottom, 0px)));
  max-height: none;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: contain;
}
.mega > .native-product-menu {
  height: 100%;
  min-height: 0;
  max-height: none;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  padding-top: 20px;
  padding-bottom: 20px;
}
.native-product-menu > .native-product-rail,
.native-product-menu > .native-product-category-panel,
.native-product-menu > .native-product-detail {
  height: 100%;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #87a6b6 #edf3f6;
  scroll-padding-block: 12px;
  padding-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}
.native-product-menu > .native-product-rail {
  padding-right: 12px;
}
.native-product-menu > .native-product-detail {
  padding-right: 12px;
}
.native-product-menu > .native-product-rail::-webkit-scrollbar,
.native-product-menu > .native-product-category-panel::-webkit-scrollbar,
.native-product-menu > .native-product-detail::-webkit-scrollbar {
  width: 8px;
}
.native-product-menu > .native-product-rail::-webkit-scrollbar-thumb,
.native-product-menu > .native-product-category-panel::-webkit-scrollbar-thumb,
.native-product-menu > .native-product-detail::-webkit-scrollbar-thumb {
  border: 2px solid #edf3f6;
  border-radius: 8px;
  background: #87a6b6;
}
.native-product-menu > .native-product-rail::-webkit-scrollbar-track,
.native-product-menu > .native-product-category-panel::-webkit-scrollbar-track,
.native-product-menu > .native-product-detail::-webkit-scrollbar-track {
  background: #edf3f6;
}

.mega :is(a, button, summary) {
  scroll-margin-block: 12px;
}
.mega :is(a, button, summary):focus-visible {
  /* Keep the complete focus ring inside a scrollport's painted bounds. */
  outline-offset: -2px;
}

/* Mobile navigation already uses disclosure groups. Let the outer menu do
   all vertical scrolling; nested group scrollports hide their final links. */
.mega:has(> .mobile-navigation) {
  max-height: calc(100vh - 100% - 12px);
  max-height: calc(100dvh - 100% - 12px - env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-padding-block: 16px;
  padding-top: 12px;
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}
.mobile-navigation {
  min-height: 0;
  padding-bottom: 12px;
}

@media (max-width: 1300px) {
  /* Also cover resizing an already open desktop menu below the header breakpoint. */
  .mega:has(> .native-product-menu) {
    height: auto;
    max-height: calc(100vh - 100% - 12px);
    max-height: calc(100dvh - 100% - 12px - env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
    overflow-y: auto;
    scroll-padding-block: 16px;
    -webkit-overflow-scrolling: touch;
  }
  .mega > .native-product-menu {
    height: auto;
    grid-template-rows: auto;
    padding-top: 16px;
    padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  }
  .native-product-menu > .native-product-rail,
  .native-product-menu > .native-product-category-panel,
  .native-product-menu > .native-product-detail {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding-right: 0;
    scrollbar-gutter: auto;
  }
}
