/*
 * Site header (core/group, the root of the header parts header, header-over-hero, -light and -accent; its one child is
 * the header-bar template part, whose row has the Header bar style): what the header does as a whole. Colours, padding
 * and the overlay margin are the look part's block settings (text colour, background, a negative bottom margin of
 * --rt-header-height over the hero); a template picks the look by its header part (Replace).
 * - drawn over the section after it (overlay);
 * - the height script (render.php) writes --rt-header-height for the overlay margin and Header offset;
 * - sticky (Position > Sticky, the patterns' default): the header stays at the window top and, once the page scrolls
 *   (view.js), gets the page colour, the contrast text and a shadow; a header with a background colour keeps it;
 * - on the accent background: menu hover in the page colour, a round cart badge.
 * Loaded only on pages where a group uses the style (inc/rt-block-styles.php).
 */
.is-style-site-header {
	/* Menu hover and current page on dark text: the stone grey (accent was too faint on the page colour) */
	--rt-header-hover: var(--wp--preset--color--stone);
	/* Dropdown panels stay inside the header, at its side padding (Dropdown style) */
	--rt-dropdown-edge: var(--wp--preset--spacing--50);
	anchor-name: --rt-dropdown-frame;
	z-index: 20;
}

.is-style-site-header:not(.is-position-sticky) {
	position: relative;
}

/* Sticky: core prints position and top (admin bar included) with z-index 10 on the block's container class */
.is-style-site-header.is-position-sticky {
	z-index: 20;
	transition: color 0.2s ease;
}

/* The header part's wrapper is only as tall as the header, so it lets the header stick to the whole page */
.wp-site-blocks > .wp-block-template-part:has(> .is-style-site-header.is-position-sticky) {
	display: contents;
}

/* Anchors (comments, reviews, accordions) scroll into view below the sticky header; sticky blocks of the page (catalog
   columns) stay below it with --rt-sticky-header (the header's height, render.php) */
html:has(.is-style-site-header.is-position-sticky) {
	--rt-sticky-header: var(--rt-header-height, 0px);
	/* rtthemes-blocks' popovers (image hotspot cards) keep clear of the header */
	--rtthemes-sticky-offset: var(--rt-header-height, 0px);
	scroll-padding-top: calc(var(--wp-admin--admin-bar--height, 0px) + 6rem);
}

/* Scrolled: the backdrop is drawn behind the row, so the header's height and its overlay margin stay as they are; it
   reaches as far below the row as the top padding above it (for a header whose bottom padding is smaller) */
.is-style-site-header.is-scrolled::before {
	content: "";
	position: absolute;
	inset: 0 0 calc(-1 * var(--rt-header-backdrop-extend, 0px));
	z-index: -1;
	background-color: inherit;
	box-shadow: 0 0.125rem 0.75rem rgb(0 0 0 / 8%);
	animation: rt-header-backdrop 0.2s ease;
}

@keyframes rt-header-backdrop {
	from {
		opacity: 0;
	}
}

/* While the header's colour changes (view.js), its descendants follow it frame by frame instead of transitioning on
   their own (they would lag); !important beats the menu's own transitions of any specificity for those 0.25s */
.is-style-site-header.is-recolouring * {
	transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
	.is-style-site-header.is-position-sticky,
	.is-style-site-header.is-scrolled::before {
		transition: none;
		animation: none;
	}
}

.is-style-site-header.is-scrolled:not(.has-background)::before {
	background-color: var(--wp--preset--color--base);
}

.is-style-site-header.is-scrolled:not(.has-background) {
	color: var(--wp--preset--color--contrast) !important;
}

.is-style-site-header.has-accent-background-color {
	--rt-header-hover: var(--wp--preset--color--base);
}

/* White text over a photo keeps the accent hover until the page scrolls (then the text is dark again) */
.is-style-site-header.has-base-color:not(.is-scrolled) {
	--rt-header-hover: var(--wp--preset--color--accent);
}

/* On the accent background the badge turns round: dark fill, accent figure. WooCommerce keeps one badge colour for
   every mini cart on the page (shared Interactivity state), so the block's Count colour cannot differ per header */
.is-style-site-header.has-accent-background-color .wc-block-mini-cart .wc-block-mini-cart__badge {
	background: var(--wp--preset--color--on-accent) !important;
	color: var(--wp--preset--color--accent) !important;
}
