/*
 * Sticky header: the top bar (logo, account, cart) stays visible while scrolling,
 * the menu bar slides away when scrolling down and comes back when scrolling up.
 *
 * Everything is scoped to html.sticky-header-on, which sticky-header.js sets,
 * so without JavaScript the header behaves exactly as before.
 *
 * #header becomes display:contents so that .header-top and .header-nav are
 * sticky relative to <body> (a sticky element cannot leave its parent box).
 * The layout never changes while scrolling, so there is no content jump.
 */
/* The theme sets body{height:100%}; sticky children cannot leave the body box,
   so it has to grow with the content. */
html.sticky-header-on body {
  height: auto;
  min-height: 100%;
}

html.sticky-header-on #header {
  display: contents;
  border-bottom: 0;
}

/* Normal vertical padding of .header-top (mirrors the theme's breakpoints) */
html.sticky-header-on { --ht-pad: 1.25rem; --ht-pad-compact: 1rem; }
@media (min-width: 640px)  { html.sticky-header-on { --ht-pad: 1.375rem; } }
@media (min-width: 768px)  { html.sticky-header-on { --ht-pad: 1.5rem; } }
@media (min-width: 1024px) { html.sticky-header-on { --ht-pad: 1.625rem; } }
@media (min-width: 1367px) { html.sticky-header-on { --ht-pad: 1.75rem; } }

html.sticky-header-on #header .header-top {
  position: sticky;
  top: 0;
  z-index: 1002;
  background-color: #fff;
  transition: padding .25s ease, margin-bottom .25s ease;
}

/* Compact top bar once the page is scrolled (desktop only): less padding, but the same total
   flow height (margin-bottom makes up the difference), so content never jumps. */
@media (min-width: 768px) {
  html.sticky-header-on.is-compact #header .header-top {
    padding-top: var(--ht-pad-compact);
    padding-bottom: var(--ht-pad-compact);
    margin-bottom: calc(2 * (var(--ht-pad) - var(--ht-pad-compact)));
  }
}

/* Slightly smaller logo in the compact top bar (desktop) */
html.sticky-header-on #header #_desktop_logo a {
  transition: width .25s ease;
}

@media (min-width: 1024px) {
  html.sticky-header-on.is-compact #header #_desktop_logo a {
    width: 14rem;
  }
}

html.sticky-header-on #header .header-nav {
  position: sticky;
  top: var(--header-top-h, 5rem);
  z-index: 1001;
  background-color: #fff;
  border-bottom: 1px solid rgba(37, 40, 45, .2);
  transition: transform .25s ease, visibility 0s linear 0s;
}

/* Menu hidden: slides up behind the top bar */
html.sticky-header-on.is-nav-hidden #header .header-nav {
  transform: translateY(-100%);
  visibility: hidden;
  transition: transform .25s ease, visibility 0s linear .25s;
}

/* The top bar takes over the divider line while the menu is hidden */
html.sticky-header-on.is-nav-hidden #header .header-top {
  box-shadow: 0 1px 0 rgba(37, 40, 45, .2);
}

/* Mobile: the (open) mobile menu lives in .header-nav, keep it scrollable */
@media (max-width: 767px) {
  html.sticky-header-on #header .header-nav {
    max-height: calc(100vh - var(--header-top-h, 4rem));
    max-height: calc(100dvh - var(--header-top-h, 4rem));
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html.sticky-header-on #header .header-top,
  html.sticky-header-on #header #_desktop_logo a,
  html.sticky-header-on #header .header-nav,
  html.sticky-header-on.is-nav-hidden #header .header-nav {
    transition: none;
  }
}
