/**
 * TMC Sticky Header — base styles.
 *
 * Only the sticky positioning, the transparent-overlap offset, and a safe
 * transition baseline live here. Every "scrolled state" effect (shrink padding,
 * min-height, background, shadow, logo height) is driven by the user's Elementor
 * control SELECTORS keyed on `.tmc-sticky--scrolled`, so nothing visual is baked
 * in — the editor controls own the look.
 */

/* Sticky positioning. Elementor containers/sections are static by default; this
 * pins the opted-in element to the top. z-index keeps it above page content. */
.tmc-sticky {
	/* Elementor flexbox containers resolve their own position from a custom
	   property: `.e-con { position: var(--position) }`. Setting the property is
	   how you change a container's position from the outside — and it is the
	   only approach that survives, because that rule is ALSO a single class
	   (0-1-0) and Elementor's stylesheet loads AFTER ours, so a plain
	   `.tmc-sticky { position: sticky }` loses on source order and silently
	   resolves to `relative`. That is why this feature appeared to work only
	   when Elementor's own Sticky effect was switched on. */
	--position: sticky;

	position: -webkit-sticky;
	position: sticky;
	/* The admin toolbar's height is 0 when it isn't showing; WordPress sets it
	   on <html> (32px, 46px on narrow screens). */
	top: calc( var( --wp-admin--admin-bar--height, 0px ) + var( --tmc-sticky-top, 0px ) );
	z-index: var( --tmc-sticky-z, 999 );
	width: 100%;
}

/* `overflow-x: hidden` on BOTH html and body (the tmcelementor theme's
 * style.css, and a common snippet elsewhere) turns body into its own scroll
 * container, and nothing inside it can stick to the page any more: the header
 * scrolled away with everything else. `clip` hides sideways overflow just the
 * same without that side effect (Hello Elementor's reset already uses it).
 * Only on a page with a pinned header, and 0-1-2+ beats the theme's 0-0-2. */
html:has( .tmc-sticky:not( .tmc-sticky--unpinned ) ),
html:has( .tmc-sticky:not( .tmc-sticky--unpinned ) ) body {
	overflow-x: clip;
}

/* Theme Builder header: the WRAPPER pins (see TMC_Sticky_Header::after_render).
 * The header alone can't, because its parent is exactly as tall as it is. The
 * wrapper's negative offset is the header's position inside it, so a top bar
 * above the header scrolls away and the header lands where it would on its own.
 * Set by the parse-time snippet; the runtime moves it to an outer theme wrapper
 * when one is just as tall (Astra's #masthead, for instance). */
.tmc-sticky-host {
	position: -webkit-sticky;
	position: sticky;
	top: calc( var( --wp-admin--admin-bar--height, 0px ) + var( --tmc-sticky-top, 0px ) - var( --tmc-sticky-host-top, 0px ) );
	z-index: var( --tmc-sticky-z, 999 );
}

/* Elementor Pro's Sticky writes `z-index: 99` inline on the element it fixes,
 * which outranks the stylesheet, so a Stacking order set here was ignored
 * (Sticky Header Effects headers relied on 9999 against cookie banners and
 * chat bubbles). Only while Pro's Sticky is active, and only when one is set:
 * the fallback is Pro's own 99. */
.tmc-sticky.tmc-sticky--pro.elementor-sticky--active {
	z-index: var( --tmc-sticky-z, 99 ) !important;
}

/* Not set to stick on this device: back to Elementor's own positioning.
 * 0-3-0, above the doubled-class sticky rule below. */
.tmc-sticky.tmc-sticky.tmc-sticky--unpinned {
	--position: relative;
	position: relative;
	top: auto;
}

/* Hide on scroll down: slides out with a transform, which moves nothing else
 * on the page. Only while hidden, because any transform makes the header the
 * containing block for fixed-position things inside it (menus, popups). */
.tmc-sticky-host.tmc-sticky--hidden,
.tmc-sticky.tmc-sticky--hidden {
	transform: translateY( calc( -100% - 20px ) );
}
.tmc-sticky-host {
	transition: transform 300ms ease;
}

/* The wrapper holds the header's resting height while the header shrinks
 * inside it (reserveSlot() in the runtime), so the page never moves. The strip
 * a shrunken header leaves must not catch clicks meant for the page under it. */
.tmc-sticky-host {
	pointer-events: none;
}
.tmc-sticky-host > * {
	pointer-events: auto;
}

/* Legacy sections (and anything else that does not read --position) need the
   declaration to outrank `.e-con` directly. Doubling the class costs nothing
   and takes this to 0-2-0 without !important. Elementor's own Sticky effect
   sets position inline when active, so it still wins where it is in use. */
.tmc-sticky.tmc-sticky {
	position: -webkit-sticky;
	position: sticky;
}

/* Transparent header: overlay it on top of the first section. The element is
 * taken out of flow at the top and the following content is pulled up by the
 * measured header height (set as --tmc-sticky-height by the JS), so the first
 * section sits behind the header instead of being pushed down by it. */
.tmc-sticky--transparent.tmc-sticky--transparent {
	--position: sticky;
	position: -webkit-sticky;
	position: sticky;
	top: 0;
}

/* Lift the page up under a transparent header so the first section sits BEHIND
 * it rather than below it.
 *
 * Applied as a negative bottom margin on the HEADER, not as a top margin on
 * whatever follows it. Two reasons, and the second is the important one:
 *
 *  - The old `.tmc-sticky--transparent + *` only matched when the header was a
 *    direct sibling of the content. In an Elementor Theme Builder header it
 *    never is — the container is the only child of
 *    `<header class="elementor-location-header">` — so it matched nothing.
 *  - The header EXISTS while the page is still parsing; the content that
 *    follows does not. Putting the offset on the header is what lets the height
 *    be published at parse time, before the browser lays that content out, so
 *    there is no frame where the offset is missing and the header hangs over
 *    the page background. On a white body that frame was a white flash.
 *
 * Falls back to 0 so an unmeasured header simply behaves as a normal one. */
.tmc-sticky--transparent {
	/* Set the CUSTOM PROPERTY, exactly as with --position above, and for the
	   same reason: Elementor resolves a container's bottom margin from
	   `.e-con` resolving margin-block-end from var( --margin-block-end ).
	   That rule is
	   also a single class (0-1-0) and Elementor's stylesheet loads AFTER ours,
	   so a plain `margin-bottom` here loses on source order and silently
	   computes to 0 — which is exactly what shipped in b10 and did nothing.
	   Verified in the browser, not assumed. */
	--margin-block-end: calc( -1 * var( --tmc-sticky-height, 0px ) );
}

/* Legacy sections, and anything else that does not read --margin-block-end,
   need the physical property. Both are repeated here at 0-4-0: an element
   with its own margin set (even to 0) gets Elementor's per-element rule,
   `.elementor-N .elementor-element.elementor-element-ID`, at 0-3-0, which beat
   the old 0-2-0 and left a transparent header that sticks in the page flow
   pushing the hero down by its height (snaphappyphotographer.com, Oct 26
   2026; earlier transparent headers were fixed by Pro Sticky, where the
   margin does nothing). No !important, so the editor rule below still wins. */
.tmc-sticky--transparent.tmc-sticky--transparent.tmc-sticky--transparent.tmc-sticky--transparent {
	--margin-block-end: calc( -1 * var( --tmc-sticky-height, 0px ) );
	margin-bottom: calc( -1 * var( --tmc-sticky-height, 0px ) );
}

/* Elementor Pro's Sticky effect keeps a hidden clone of the header (the
   spacer) in the header's place while it is fixed. A transparent header
   needs no slot: the clone must take up nothing, whatever state it was
   cloned in. Left to the shared rules it was its own height minus the
   measured height, and Safari re-clones the header every time an overscroll
   at the top unsticks it (scroll position below 0), so any difference
   between the two showed as a band of page background above the first
   section (staging.tallack.media, Oct 2026). Chrome never unsticks there.
   !important because Elementor's per-instance rules (0-3-0) set this
   container's min-height and padding, and the clone carries the same
   classes; it is invisible scaffolding no control styles. */
.tmc-sticky--transparent.elementor-sticky__spacer {
	--min-height: 0px;
	--margin-block-start: 0px;
	--margin-block-end: 0px;
	height: 0 !important;
	min-height: 0 !important;
	padding-top: 0 !important;
	padding-bottom: 0 !important;
	border-top-width: 0 !important;
	border-bottom-width: 0 !important;
	margin-top: 0 !important;
	margin-bottom: 0 !important;
	overflow: hidden;
}

/* Editing the header template itself in Elementor: no overlap, so the
   editable header doesn't sit on top of the empty canvas below it. Pages
   being edited still show the overlap, because their header is a separate,
   non-edited document. Elementor adds .elementor-edit-area-active to the
   document being edited (editor.js, Elementor 4.3.5). Same 0-2-0 as the
   rules above and later in the file, so it wins. */
.elementor-edit-area-active .tmc-sticky--transparent.tmc-sticky--transparent.tmc-sticky--transparent.tmc-sticky--transparent {
	--margin-block-end: 0px;
	margin-bottom: 0;
}

/* Boot suppression.
 *
 * The class is server-rendered and removed by the runtime once the first state
 * has been applied and painted. Everything the script does on load would
 * otherwise animate, because the transition baseline below is live from the
 * first paint: reload part-way down a page and the header eases from its
 * resting look into its scrolled look over 300ms, and the logo eases from its
 * natural height to the measured one. Both read as a flash.
 *
 * !important is deliberate: the Transition control writes its own value onto
 * the element, so suppression has to outrank it for the one frame it exists.
 *
 * Scoped to the header and its IMAGES, not every descendant. If the runtime
 * never loads — a partial deploy, a CDN miss, a delay-JS optimizer that drops
 * the file — the class is never removed and whatever it covers loses its
 * transitions for the life of the page. A header whose nav hovers, dropdowns
 * and hamburger have all silently stopped easing is a worse outcome than a
 * residual flash on an already-broken deploy, and the two things that actually
 * flashed (the scrolled state, and the logo height) are both covered here. */
.tmc-sticky--booting,
.tmc-sticky--booting img {
	transition: none !important;
	animation: none !important;
}

/* A graceful transition baseline so the scrolled state eases even before the
 * user sets the Transition control (which overrides this with its own value).
 * The transition is removed entirely for reduced-motion visitors. */
.tmc-sticky {
	transition: padding 300ms ease, min-height 300ms ease,
		background-color 300ms ease, box-shadow 300ms ease, transform 300ms ease;
}

/* transform stays in the list: this outranks Elementor's hover-animation
   class (.elementor-animation-float and friends, 0-1-0), which only declares
   a transform transition, so without it a Float logo jumped 8px on hover
   instead of easing (snaphappyphotographer.com, Oct 26 2026). */
.tmc-sticky img {
	transition: height 300ms ease, max-height 300ms ease, transform 300ms ease;
}

@media ( prefers-reduced-motion: reduce ) {
	.tmc-sticky,
	.tmc-sticky-host,
	.tmc-sticky img {
		transition: none !important;
	}
}

/* Logo shrink.
 *
 * The "Logo height when scrolled" control publishes --tmc-sticky-logo-h on the
 * header rather than writing a rule through the selector field. That field can
 * only be interpolated from a SAVED value, so on the common path — where nobody
 * typed a selector — Elementor emitted an empty rule and the logo silently
 * never shrank. Applying it here covers the two widgets that are actually used
 * for a logo; the selector field remains for anything unusual. */
/* Resting height, measured by the runtime and only present when a shrink is
   configured. Without it the logo sits at `auto`, and `auto` cannot be
   interpolated — which is why the shrink used to snap instead of easing. */
/* :where() keeps this at 0-2-1, so the logo widget's own width still wins.
   --logo-free: pinning would have changed the layout (see measure() in
   tmc-sticky-header.js), so the logo is left exactly as Elementor sizes it. */
.tmc-sticky:where( :not( .tmc-sticky--logo-free ) ) .elementor-widget-image img,
.tmc-sticky:where( :not( .tmc-sticky--logo-free ) ) .elementor-widget-theme-site-logo img {
	height: var( --tmc-sticky-logo-h-rest, auto );
	/* max-height carries a length at REST too. Leaving it `none` here meant it
	   jumped straight to the scrolled value, and a max-height clamps the box
	   immediately — so the logo snapped even while `height` was easing
	   perfectly well. Both ends of BOTH properties have to be lengths. */
	max-height: var( --tmc-sticky-logo-h-rest, none );
	width: auto;
}

/* A pinned logo keeps width:auto at rest too, so its width follows the height
   both ways. The logo widget's own width (0-3-1, e.g. 200px) otherwise snapped
   back the instant the header unscrolled while the height was still easing:
   the logo flashed full width and squashed, then grew (empringhamdisposal.com,
   Oct 26 2026). measure() only sets --logo-pin after checking that this leaves
   the resting layout exactly as it was. The widget's width rule is
   `.elementor-N .elementor-element.elementor-element-ID img`, 0-3-1, printed
   after this file, so a tie loses: the repeated class lifts this to 0-5-1. */
.tmc-sticky.tmc-sticky--logo-pin.tmc-sticky--logo-pin.tmc-sticky--logo-pin .elementor-widget-image img,
.tmc-sticky.tmc-sticky--logo-pin.tmc-sticky--logo-pin.tmc-sticky--logo-pin .elementor-widget-theme-site-logo img {
	width: auto;
}

/* Scrolled: a set height wins; otherwise the share of the resting height
   from "Logo size when scrolled (%)" (1 when unset, so nothing changes). */
.tmc-sticky--scrolled .elementor-widget-image img,
.tmc-sticky--scrolled .elementor-widget-theme-site-logo img {
	height: var( --tmc-sticky-logo-h, calc( var( --tmc-sticky-logo-h-rest, auto ) * var( --tmc-sticky-logo-scale, 1 ) ) );
	max-height: var( --tmc-sticky-logo-h, calc( var( --tmc-sticky-logo-h-rest, none ) * var( --tmc-sticky-logo-scale, 1 ) ) );
	width: auto;
}

/* A shrunk logo stays centred in its column. A logo that is the only thing in
   its container sat at the top of it once the header shrank: the column is a
   flex column with no vertical alignment set, and at rest it is exactly as tall
   as the logo, so nobody had ever set one (bowlsforbellies.org, Oct 26 2026).
   Auto block margins centre it in a flex column and do nothing in a row; the
   inline axis, so left/centre/right alignment, is untouched. 0-4-0 beats the
   widget's own Elementor margin (0-3-0 at most), deliberately and only while
   scrolled. */
.tmc-sticky--scrolled :is( .e-con, .e-con-inner, .elementor-widget-wrap ) > .elementor-widget-image:only-child,
.tmc-sticky--scrolled :is( .e-con, .e-con-inner, .elementor-widget-wrap ) > .elementor-widget-theme-site-logo:only-child {
	margin-block: auto;
}
