/**
 * The header in variations (ISS-0076), as Apparence's header is (EnTete.astro).
 *
 * Three things are chosen, and they travel differently:
 *  - the LAYOUT is a template part (header, header-milieu, header-centre): the DOM order follows the screen order,
 *    so the tab order does (WCAG 2.4.3). Studio copies the chosen part into the child theme as parts/header.html.
 *  - the WIDTH and the FIXED header are tokens this file reads, like the separation already is:
 *      --wp--custom--semantic--header--max-width   `wide-size` (as the page) or `none` (edge to edge)
 *      --wp--custom--semantic--header--position    `static` or `sticky`
 *      --wp--custom--semantic--border--header-scroll   the rule that appears while the page scrolls under a fixed
 *    header with no separation. Equal to `border--header` unless Studio says otherwise, so a header that already
 *    has a rule or a shadow never gets a second one.
 *
 * Only the groups of these parts (`.jetstream-header`) are dressed: a header a webmaster rebuilt in the Site Editor
 * keeps its own markup, and is moved by `position` alone. A header part can be saved with a <div> tag, or wrapped in
 * a group: `:is( header.wp-block-template-part, .wp-site-blocks > div.wp-block-template-part:first-child )` reaches a
 * header part that sits straight in the page, <header> or <div>, without matching a footer.
 *
 * A part WRAPPED in a page-level group (a sticky band saved in the Site Editor, see zones.css) is not reached on
 * purpose: `position: sticky` does not leave its parent, so the group is what must stick, and that is the group's own
 * « Sticky » setting in the editor. A rule on the group would answer `static` (the token's default) over a sticky
 * the webmaster chose. Studio says so when it finds such a header.
 */
:is(header.wp-block-template-part, .wp-site-blocks > div.wp-block-template-part:first-child) {
	position: var(--wp--custom--semantic--header--position, static);
	top: 0;
	z-index: 100;
}

/* A fixed header stops under the admin bar, which is fixed above 600 px and scrolls away with the page below. */
body.admin-bar :is(header.wp-block-template-part, .wp-site-blocks > div.wp-block-template-part:first-child) {
	top: var(--wp-admin--admin-bar--height, 0);
}

@media (max-width: 600px) {
	body.admin-bar :is(header.wp-block-template-part, .wp-site-blocks > div.wp-block-template-part:first-child) {
		top: 0;
	}
}

/* A header part that sits straight in the page, with NO band around it, is painted like the band (ISS-0082).
 * Most of a site's templates wrap the header part in a sticky group saved in the Site Editor — white at 72 %, blurred —
 * and that group is what covers the content scrolling under the header. A template without that group (a page template
 * or a single template the webmaster never wrapped) left a fixed header transparent: the text of the page ran through
 * the menu. This is the same look, from the header surface token, for exactly that case: `.wp-site-blocks >
 * div.wp-block-template-part:first-child` is a part NOT wrapped in a group, so a wrapped one (the band paints it) and a
 * footer are never reached. A header that carries `.jetstream-header` paints itself with the rule below and is not
 * made lighter by this one (its own opaque surface sits on top). A header the webmaster WANTS transparent (over a hero)
 * on such a template sets its own background in the editor, which wins over this rule. Without `backdrop-filter`, the surface stays solid:
 * a legible menu before a pretty one. The 72 % and the 22 px are what the band uses today; a webmaster who changes the
 * band keeps it, the two only meet on a template that has no band.
 * Sized by `position`: a static header scrolls away with the page, and the surface is then just its background. */
.wp-site-blocks > :is(header, div).wp-block-template-part:first-child {
	--jetstream-header-frost-opacity: 72%;
	--jetstream-header-frost-blur: 22px;
	background: var(--wp--custom--zone--header--surface);
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
	.wp-site-blocks > :is(header, div).wp-block-template-part:first-child {
		background: color-mix(in srgb, var(--wp--custom--zone--header--surface) var(--jetstream-header-frost-opacity), transparent);
		-webkit-backdrop-filter: saturate(1.8) blur(var(--jetstream-header-frost-blur));
		backdrop-filter: saturate(1.8) blur(var(--jetstream-header-frost-blur));
	}
}

/* The band: the header's own surface, so content scrolling under a fixed header is covered, with the colours that
 * go with it (a surface always has its `on-*`): the text, then the links, their hover and the current page. The links
 * of a submenu panel are left out: the panel has its own surface and text colour (navigation.css), and a link colour
 * from the bar would break that pair. A colour picked in the editor still wins (preset classes are !important).
 * The class is doubled on purpose: core sets `color: inherit` on a menu link with (0,3,0), which would otherwise leave the
 * zone's link colour to the hover and the current page only.
 * The separation: a hairline, transparent without
 * one so nothing moves from one choice to the next, or a shadow. */
.wp-block-template-part .jetstream-header {
	background: var(--wp--custom--zone--header--surface);
	color: var(--wp--custom--zone--header--on-surface);
	border-bottom: var(--wp--custom--semantic--border--width--hairline) solid var(--wp--custom--semantic--border--header);
	box-shadow: var(--wp--custom--semantic--elevation--header);
}

.wp-block-template-part .jetstream-header.jetstream-header a:where(:not(.wp-element-button, .wp-block-navigation__submenu-container a)) {
	color: var(--wp--custom--zone--header--link);
}

.wp-block-template-part .jetstream-header.jetstream-header a:where(:not(.wp-element-button, .wp-block-navigation__submenu-container a)):hover {
	color: var(--wp--custom--zone--header--link-hover);
}

.wp-block-template-part .jetstream-header.jetstream-header a:where(:not(.wp-element-button, .wp-block-navigation__submenu-container a))[aria-current] {
	color: var(--wp--custom--zone--header--link-active);
}

/* A header is not a card, even when its part was saved with a <div> tag (zones.css only reaches <header>). */
.wp-block-template-part .jetstream-header,
.wp-block-template-part .jetstream-header__row,
.wp-block-template-part .jetstream-header__actions {
	border-radius: 0;
}

/* The row: the width token, centred; the band above runs edge to edge and carries the site gutter (zones.css). */
.wp-block-template-part .jetstream-header__row {
	box-sizing: border-box;
	width: 100%;
	max-width: var(--wp--custom--semantic--header--max-width, var(--wp--style--global--wide-size));
	margin-inline: auto;
	min-height: var(--wp--custom--semantic--size--header);
}

/* Milieu and centre: the menu really in the middle, two side columns of equal width. Their row is set to
 * `left`, not `space-between`, on purpose: navigation-mobile.css sends the menu last on a space-between row, which
 * would pull the centre layout's menu (first in the DOM, so first in the tab order) to the right of the logo. */
.wp-block-template-part .jetstream-header__row--milieu,
.wp-block-template-part .jetstream-header__row--centre {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: center;
}

.wp-block-template-part .jetstream-header__row--milieu .jetstream-header__logo,
.wp-block-template-part .jetstream-header__row--centre .jetstream-header__nav {
	justify-self: start;
}

.wp-block-template-part .jetstream-header__row--milieu .jetstream-header__nav,
.wp-block-template-part .jetstream-header__row--centre .jetstream-header__logo {
	justify-self: center;
}

.wp-block-template-part .jetstream-header__row--milieu .jetstream-header__actions,
.wp-block-template-part .jetstream-header__row--centre .jetstream-header__actions {
	justify-self: end;
}

/* Below 600 px WordPress folds the menu into its button. Milieu has no centre left to keep: the logo, then the
 * button and the search on the right. Centre keeps its three columns: the button, the logo, the search. */
@media (max-width: 599px) {
	.wp-block-template-part .jetstream-header__row--milieu {
		display: flex;
		justify-content: flex-end;
		/* The search is folded away down here: its empty group must not leave a gap after the button. */
		gap: 0;
	}

	.wp-block-template-part .jetstream-header__row--milieu .jetstream-header__logo {
		margin-inline-end: auto;
	}
}

/* A fixed header with no separation: the rule appears as the page scrolls. Browsers without scroll-driven
 * animations keep no rule, which is intended. */
@keyframes jetstream-header-rule {
	from {
		border-bottom-color: var(--wp--custom--semantic--border--header);
	}

	to {
		border-bottom-color: var(--wp--custom--semantic--border--header-scroll);
	}
}

@supports (animation-timeline: scroll()) {
	.wp-block-template-part .jetstream-header {
		animation: jetstream-header-rule linear both;
		animation-timeline: scroll(root block);
		animation-range: 0 48px;
	}
}

/* The bar's menu entries: Apparence pads each one by `space.nav-item` above and below (12 px by default), so the target
 * is a comfortable row, not the height of the text (ISS-0080). Top-level entries of the bar only (a menu of explicit entries, or the automatic page list, whose entries sit one list deeper), above the width where
 * WordPress turns the menu into a button: the overlay and the submenus have their own spacing (navigation-mobile.css,
 * navigation.css). `is-menu-open` sits on the responsive container, not on the navigation: an overlay opened at a desktop
 * width (menu set to « always ») is left out too. */
@media (min-width: 600px) {
	.wp-block-template-part .jetstream-header .wp-block-navigation__responsive-container:not(.is-menu-open) :where(.wp-block-navigation__container, .wp-block-page-list) > .wp-block-navigation-item > .wp-block-navigation-item__content {
		padding-block: var(--wp--custom--semantic--space--nav-item, 0.75rem);
	}
}
