/* Header behaviors — shared by every header design.
   Design presets style the aesthetics of these states; this file owns the
   positioning/transition mechanics only.

   The element these rules apply to may not be one the suite rendered. Where
   the site has put the integration class on its own header element, the
   binder script MOVES .srd-header and its state classes onto that element,
   leaving the wrapper it rendered carrying nothing but --passthrough. So there
   is exactly one .srd-header in the page, and everything below lands on the
   element that is actually in the layout. Nothing here needs to know which one
   that is; that is the whole point of the arrangement. */

/* The wrapper the suite rendered, once the site element has taken over.

   Keyed on --passthrough ALONE, never .srd-header.srd-header--passthrough: the
   binder has just moved .srd-header off this element, so a rule asking for
   both would not match and the wrapper would keep its box.

   display: contents removes the box while leaving every child exactly where it
   was, so the rules below apply once — to the outer element — instead of to
   two nested boxes fighting over the same position. Descendant selectors are
   unaffected: an element with display: contents is still in the tree, still
   matches, and still passes inheritance down. */
.srd-header--passthrough {
    display: contents;
}

/* Dropdown layering: menu dropdowns must never be painted over by positioned
   page content (e.g. Swiper sliders use z-index: 1). */
.srd-header {
    position: relative;
    z-index: 100;
}

/* Always sticky. */
.srd-header.srd-header--sticky {
    position: sticky;
    top: 0;
}

/* Hide On Scroll Down: pinned exactly like Always sticky, and slid out of view
   while the visitor is scrolling down. header.js owns --hidden and the
   direction tracking; everything here is the mechanics of getting out of the
   way and coming back.

   transform rather than top, because transform is compositor-driven and does
   not lay the page out again on every frame of a 300ms slide that runs on the
   most scroll-sensitive element on the page.

   That choice has one consequence worth stating outright: a transformed element
   becomes the containing block for every position:fixed descendant, and the
   mobile drawer and its overlay are both position:fixed INSIDE .srd-header. A
   transform here silently re-anchors them — the overlay stops covering the
   viewport and the off-canvas drawer slides in at the wrong offset. Hence the
   drawer guard below, which is not a nicety. */
.srd-header.srd-header--sticky-reveal {
    position: sticky;
    top: 0;
}

.srd-header.srd-header--sticky-reveal.srd-header--hidden {
    transform: translateY(-100%);
}

/* The base .srd-header transition at the foot of this file does not mention
   transform, and it cannot be appended to — so the whole list is restated here
   rather than losing the background and shadow fades this mode still wants.
   Reduced motion gets the state change with no slide, which is the honest
   reading of the preference: the header still hides, it just does not travel. */
@media (prefers-reduced-motion: no-preference) {
    .srd-header.srd-header--sticky-reveal {
        transition: transform 0.3s ease, background-color 0.25s ease, box-shadow 0.25s ease;
    }
}

/* While the drawer is open the header is never transformed — not reset with an
   animation, reset outright.

   The script already refuses to hide a header whose drawer is open, and that is
   not enough on its own: the drawer can be opened in the 300ms the slide is
   still running, and for those 300ms a non-zero transform is exactly as
   re-anchoring as a finished one. transition: none is what makes this a
   guarantee rather than a race.

   (0,4,0) so it outranks the --hidden rule above without depending on which
   block a later edit happens to move first. */
body.srd-drawer-open .srd-header.srd-header--sticky-reveal.srd-header--hidden {
    transform: none;
    transition: none;
}

/* Sticky after scrolling past the header: fixed + slid away until the
   scroll watcher adds --stuck. --stuck-leaving is a transitional state the
   watcher applies for the exit animation's duration when scrolling back up
   (it must stay position:fixed for that whole time — transform can't be
   animated once the element has already dropped back into normal flow),
   then removes once the animation completes. Reduced-motion: the watcher
   skips --stuck-leaving entirely and drops --stuck instantly instead, so
   the animations below never need a reduced-motion counterpart. */
.srd-header.srd-header--sticky-scrolled.srd-header--stuck,
.srd-header.srd-header--sticky-scrolled.srd-header--stuck-leaving {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

@media (prefers-reduced-motion: no-preference) {
    .srd-header.srd-header--sticky-scrolled.srd-header--stuck {
        animation: srd-header-slide-down 0.3s ease;
    }

    .srd-header.srd-header--sticky-scrolled.srd-header--stuck-leaving {
        animation: srd-header-slide-up 0.3s ease forwards;
    }
}

@keyframes srd-header-slide-down {
    from { transform: translateY(-100%); }
    to   { transform: translateY(0); }
}

@keyframes srd-header-slide-up {
    from { transform: translateY(0); }
    to   { transform: translateY(-100%); }
}

/* WP admin bar offset for the out-of-flow states, at every width.

   A header in normal flow needs nothing here: core sets html { margin-top }
   for the bar and the whole document moves with it. These six states are the
   ones that opt out of that — sticky, fixed and absolute all resolve `top`
   against the viewport or a containing block, not against that margin — so
   each has to be told about the bar itself.

   NOT scoped to a breakpoint, and that is the decision rather than an
   oversight. The overlap it fixes is not width-dependent in this stylesheet:
   the header is at top: 0 at every width, and a site that appears to need this
   only below some number has a THEME rule covering it above that number. On a
   bound header both rules land on the same element and the theme's usually
   carries an ID, so it outranks this one and wins wherever it applies. Writing
   the theme's breakpoint in here would encode somebody else's number that this
   file cannot verify and that its owner is free to change.

   The transparent variants are spelled out rather than left to the plain
   --sticky selector they would otherwise match. That selector is (0,3,0) and so
   is the transparent positioning rule below, which sets top: 0 and comes later
   in the file — an order-decided tie the admin bar loses, putting the header
   under it for every logged-in editor. (0,4,0) settles it without depending on
   which block is written first. */
.admin-bar .srd-header.srd-header--sticky,
.admin-bar .srd-header.srd-header--sticky-reveal,
.admin-bar .srd-header.srd-header--transparent.srd-header--sticky,
.admin-bar .srd-header.srd-header--transparent.srd-header--sticky-reveal,
.admin-bar .srd-header.srd-header--sticky-scrolled.srd-header--stuck,
.admin-bar .srd-header.srd-header--sticky-scrolled.srd-header--stuck-leaving {
    top: 32px;
}

/* Core's taller bar, and it runs all the way down — there is no third tier.

   Below 600px core drops #wpadminbar to position: absolute, so the bar scrolls
   away with the page, and this offset was briefly taken back to 0 there on that
   reasoning: holding 46px for a bar that has scrolled off reserves a strip of
   nothing above a pinned header. That is a real cost and it is the smaller one.
   top: 0 put the header over the bar at scroll position 0, which is the state
   every page load starts in and the one an editor opening their phone sees
   first. The gap it avoids needs a genuinely fixed header AND the visitor to
   have scrolled; a transparent Not-sticky header is position: absolute, so it
   carries this offset down the page with it and never shows a gap at all.

   A visible overlap on every load beats a conditional gap after scrolling.
   Making it scroll-aware would mean reading --scrolled from here, and that
   class means a different scroll position in every sticky mode — it belongs to
   the solid-background treatment, not to the admin bar. */
@media (max-width: 782px) {
    .admin-bar .srd-header.srd-header--sticky,
    .admin-bar .srd-header.srd-header--sticky-reveal,
    .admin-bar .srd-header.srd-header--transparent.srd-header--sticky,
    .admin-bar .srd-header.srd-header--transparent.srd-header--sticky-reveal,
    .admin-bar .srd-header.srd-header--sticky-scrolled.srd-header--stuck,
    .admin-bar .srd-header.srd-header--sticky-scrolled.srd-header--stuck-leaving {
        top: 46px;
    }
}

/* Transparent over hero — POSITIONING.

   Out of flow, so the hero starts at the top of the page rather than below the
   header, and it STAYS out of flow at every scroll position where nothing else
   is positioning it. Dropping back into normal flow part-way down the page
   would push everything below it down by the header's height, which reads as
   the page jumping and not as a header changing state.

   The :not()s are what confine transparency to its own job, and they are the
   whole of the fix for a real bug. This used to be

       .srd-header--transparent.srd-header--sticky,
       .srd-header--transparent.srd-header--scrolled { position: sticky; top: 0 }

   — and the second selector pinned the header to the top of the viewport the
   moment the page moved, in EVERY sticky mode, because --scrolled is set by the
   watcher at 24px whatever Sticky Header says. Transparent silently turned into
   Always sticky: Sticky After Scroll snapped to the top at 24px and went solid
   there, instead of scrolling away and returning at its own threshold, and Not
   sticky was sticky. Nothing could see it from the settings — every value saved
   and read back correctly, and the header that appeared was a working header.

   Positioning belongs to the Sticky Header setting. Transparency owns the
   overlay and the background, and steps aside the moment a sticky mode has
   something to say: --stuck and --stuck-leaving for Sticky After Scroll (both,
   because the exit animation has to stay position:fixed for its duration), and
   --scrolled for Always sticky, whose own rule at the top of this file pins it
   from there.

   Excluded rather than left to source order on purpose. The Sticky After Scroll
   rule above is (0,3,0), and so was this selector before the :not()s — a tie
   decided by which rule came later in the file, which is not a thing a future
   edit should be able to reverse by moving a block. */
.srd-header.srd-header--transparent:not(.srd-header--sticky):not(.srd-header--sticky-reveal):not(.srd-header--stuck):not(.srd-header--stuck-leaving) {
    position: absolute;
    left: 0;
    right: 0;
}

/* Transparent + Always sticky: fixed for the whole scroll. Never absolute, and
   never sticky.

   This used to be absolute until --scrolled and sticky after it, and the switch
   was a visible jolt. Both halves were individually right and the transition
   between them is what was wrong: absolute takes the header out of flow, which
   is what lets the hero start at the top of the page, and sticky puts it BACK
   IN flow. So at 24px of scroll the header reclaimed its own height and shoved
   every pixel of the page down by it — a hero that jumps, on the first flick of
   the wheel, on the one scroll position a visitor is guaranteed to pass through.

   position: fixed is out of flow like absolute and pinned like sticky, so one
   value covers the whole scroll and there is no transition left to be wrong.
   A transparent header now never re-enters normal flow in any sticky mode —
   Not sticky is absolute throughout, After Scroll goes absolute to fixed (both
   out of flow), and this is fixed throughout. That invariant is swept in
   test-render rather than left as a property of three separate rules.

   The cost is the one position: fixed always carries — an ancestor with
   transform, filter, backdrop-filter, perspective or contain becomes its
   containing block and it stops being pinned to the viewport. That was already
   true of Sticky After Scroll, the Placement probe already reports exactly
   those five as `affects: fixed`, and the note there names Always sticky too. */
.srd-header.srd-header--transparent.srd-header--sticky,
.srd-header.srd-header--transparent.srd-header--sticky-reveal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

/* --stuck on a transparent header is fixed, whatever mode put it there.

   Belt and braces. The watcher only sets --stuck in Sticky After Scroll, whose
   own rule above already says fixed, so in a correct build this changes nothing
   — and that is the point. Without it, "a transparent header is never in normal
   flow" is a property of this stylesheet AND a JavaScript gate together, and the
   stylesheet alone sends a --stuck Not-sticky header back to position: relative.
   A one-line change in header.js should not be able to make the page jump. */
.srd-header.srd-header--transparent.srd-header--stuck,
.srd-header.srd-header--transparent.srd-header--stuck-leaving {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

/* Transparent over hero — BACKGROUND. The solid state each design returns to is
   its own business; this only takes the background away while --scrolled is
   off. What --scrolled means per sticky mode is decided in header.js. */
.srd-header.srd-header--transparent:not(.srd-header--scrolled) {
    background: transparent;
    box-shadow: none;
}

/* Smooth background/shadow changes on all scroll-reactive states. */
.srd-header {
    transition: background-color 0.25s ease, box-shadow 0.25s ease;
}
