/* ==============================================================
 * Header UX (inc/header-ux.php, js/header-ux.js)
 * 1. Rotating top-bar messages
 * 2. Sticky, compact header (#hux-sticky = #masthead + #header-bottom)
 * ============================================================== */

/* ---------- 1. Top-bar ticker ---------- */

/* All messages share one grid cell, so the slot is as tall as the longest
   message from the first paint: no layout shift when they change. */
.hux-ticker {
	display: grid;
	overflow: hidden;
}

.hux-ticker__item {
	grid-area: 1 / 1;
	align-self: center;
	opacity: 0;
	visibility: hidden;
	transform: translateY(100%);
	transition:
		transform .5s cubic-bezier(.22, .61, .36, 1),
		opacity .5s ease,
		visibility 0s linear .5s;
}

.hux-ticker__item.is-active {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition-delay: 0s;
}

.hux-ticker__item.is-leaving {
	opacity: 0;
	transform: translateY(-100%);
}

/* Items going back to the start position move while invisible. */
.hux-ticker__item.is-resetting {
	transition: none;
}

.hux-ticker .top-bar-ad a {
	color: inherit;
	text-decoration: underline;
}

@media (max-width: 768px) {
	.hux-ticker .top-bar-ad,
	#top-bar p.top-bar-ad {
		font-size: 14px;
	}
}

/* ---------- 2. Sticky header ---------- */

:root {
	--hux-top: 0px;          /* sticky offset (WP admin bar) */
	--hux-delta: 0px;        /* full height - compact height, set by JS */
	--hux-sticky-h: 90px;    /* compact height, set by JS */
	--hux-ease: cubic-bezier(.4, 0, .2, 1);
	--hux-dur: .25s;
}

/* Anchors land below the pinned header (JS sets the exact value incl. admin bar). */
html {
	scroll-padding-top: var(--hux-scroll-pad, 100px);
}

body.admin-bar {
	--hux-top: 32px;
}

@media screen and (max-width: 782px) {
	body.admin-bar {
		--hux-top: 46px;
	}
}

/* The admin bar is not fixed on small phones, it scrolls away. */
@media screen and (max-width: 600px) {
	body.admin-bar {
		--hux-top: 0px;
	}
}

.hux-sticky {
	position: -webkit-sticky;
	position: sticky;
	top: var(--hux-top);
	z-index: 1000;
	overflow-anchor: none; /* never pick the pinned header as the scroll anchor */
	background: #fff;
	box-shadow: 0 0 0 rgba(27, 39, 91, 0);
	transition:
		box-shadow var(--hux-dur) var(--hux-ease),
		margin-bottom var(--hux-dur) var(--hux-ease);
}

/* The header shrinks by --hux-delta; the same amount is given back as margin so
   the page content below never moves. */
.hux-sticky.is-compact {
	margin-bottom: var(--hux-delta);
	box-shadow: 0 6px 18px rgba(27, 39, 91, .08);
}

.hux-sticky #masthead {
	background: #fff;
	transition:
		padding-top var(--hux-dur) var(--hux-ease),
		padding-bottom var(--hux-dur) var(--hux-ease);
}

.hux-sticky #masthead img.custom-logo {
	transition: max-width var(--hux-dur) var(--hux-ease);
}

.hux-sticky div#header-bottom {
	background: #fff;
	transition:
		padding-top var(--hux-dur) var(--hux-ease),
		padding-bottom var(--hux-dur) var(--hux-ease);
}

/* Compact state (beats the !important .pt-4/.pb-4 utilities). */
.hux-sticky.is-compact #masthead {
	padding-top: 10px !important;
	padding-bottom: 10px !important;
}

.hux-sticky.is-compact #masthead img.custom-logo {
	max-width: 130px;
}

.hux-sticky.is-compact div#header-bottom {
	padding-top: 12px;
	padding-bottom: 12px;
	border-bottom-color: transparent;
}

/* Long category dropdowns must stay reachable while the header is pinned. */
.hux-sticky.is-compact .main-navigation #primary-menu > li > ul.sub-menu {
	max-height: calc(100vh - var(--hux-top) - var(--hux-sticky-h) - 16px);
	overflow-y: auto;
	overscroll-behavior: contain;
}

@media (max-width: 991.98px) {
	.hux-sticky.is-compact #masthead {
		padding-top: 8px !important;
		padding-bottom: 8px !important;
	}
}

@media (max-width: 576px) {
	.hux-sticky.is-compact #masthead img.custom-logo {
		max-width: 110px;
	}
}

/* Used by JS while measuring heights. */
.hux-sticky.hux-no-anim,
.hux-sticky.hux-no-anim * {
	transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
	.hux-ticker__item,
	.hux-sticky,
	.hux-sticky #masthead,
	.hux-sticky #masthead img.custom-logo,
	.hux-sticky div#header-bottom {
		transition: none !important;
	}
	.hux-ticker__item,
	.hux-ticker__item.is-leaving {
		transform: none;
	}
}

/* Top bar links stay white in every state (the theme's global a:focus/a:active turns text blue = invisible on the blue bar). */
#top-bar a,
#top-bar a:visited,
#top-bar a:hover,
#top-bar a:focus,
#top-bar a:active {
	color: #fff;
}

#top-bar a:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}
