/* ==========================================================================
   Sticky header / responsive scroll fix  (CSS only - no markup changes)

   Problem
   -------
   custom.js toggles the class `.is-fixed` on `.sticky-header` while scrolling,
   and `.is-fixed .main-bar` switches to `position:fixed`. Two side effects made
   the UI judder or appear to "stick":

   1. `.main-bar` leaves the document flow, so its wrapper collapses to zero
      height and the whole page jumps up by the header height.
   2. That jump changes `menu.offset().top`, which is the exact value the
      scroll handler compares against - so right on the threshold the class is
      added and removed on alternate scroll events, flip-flopping the layout.

   Fix
   ---
   Let CSS do the sticking (`position:sticky`) and stop the JS-applied
   `position:fixed` from pulling the bar out of the flow. The class still
   toggles, but now it only drives cosmetics (shadow / logo size), so there is
   nothing left to oscillate.

   `position:sticky` needs a scroll container that is the viewport. The theme
   sets `body{overflow-x:hidden}`, which silently turns the body into its own
   scroll container and breaks sticky - `overflow-x:clip` clips the same way
   without creating one. It is behind @supports so older browsers keep the
   original `hidden` behaviour and simply get a normal, non-sticky header
   instead of a broken one.
   ========================================================================== */

@supports (overflow-x: clip) {
  html { overflow-x: clip; }
  body { overflow-x: clip; }

  .site-header {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
  }
}

/* Keep the bar in the flow even when the script adds .is-fixed, so the page
   never jumps and the scroll handler's offset stays constant. */
.is-fixed .main-bar,
.header-transparent .is-fixed .main-bar {
  position: relative !important;
  top: auto;
  left: auto;
}

/* .sticky-no is the theme's opt-out: leave those pages completely alone. */
.sticky-no .site-header { position: relative; }

/* --------------------------------------------------------------------------
   Smooth transitions
   -------------------------------------------------------------------------- */

/* The shadow is the only cue that the header is now floating over content. */
.main-bar {
  box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  transition: box-shadow .25s ease, background-color .25s ease;
  will-change: box-shadow;
}

.is-fixed .main-bar {
  box-shadow: 0 2px 18px 0 rgba(0, 0, 0, .12);
}

/* The logo resizes when .is-fixed is applied; animate height/width together so
   the bar shrinks smoothly instead of snapping between two heights. */
.logo-header,
.is-fixed .logo-header,
.is-fixed.header-curve .logo-header {
  transition: width .25s ease, max-width .25s ease, height .25s ease;
}

.logo-header a img {
  transition: width .25s ease, max-width .25s ease, height .25s ease;
}

/* --------------------------------------------------------------------------
   Responsive behaviour
   -------------------------------------------------------------------------- */

/* Tablet / mobile: the off-canvas menu is position:fixed and must never be
   clipped or offset by the sticky parent. */
@media only screen and (max-width: 991px) {
  .mo-left .header-nav,
  .mo-left .header-nav.show {
    /* already fixed in the theme - restated so a sticky ancestor can never
       turn it into a sticky/absolute child */
    position: fixed;
    top: 0;
    height: 100vh !important;
  }
}

/* Short viewports (landscape phones, small laptops): a sticky header would eat
   too much of the screen, so release it and let the page scroll normally. */
@media only screen and (max-height: 450px) {
  @supports (overflow-x: clip) {
    .site-header { position: relative; top: auto; }
  }
  .is-fixed .main-bar { box-shadow: none; }
}

/* Respect the OS "reduce motion" setting. */
@media (prefers-reduced-motion: reduce) {
  .main-bar,
  .logo-header,
  .is-fixed .logo-header,
  .is-fixed.header-curve .logo-header,
  .logo-header a img {
    transition: none !important;
  }
}
