/**
 * Site header: solid forest frame, logo left, primary menu right.
 *
 * The background comes from --bst-header-bg; the transparent variant over
 * a hero only changes that variable (see below and hero.css).
 *
 * Menu: shared type style and states, then desktop (>= 1024px) and
 * mobile (< 1024px). The breakpoint is set for GeneratePress in
 * inc/header.php; keep the media queries here in sync with it.
 */

/* Frame. `.bst-header` beats the GeneratePress `.site-header` inline rule by load order. */

.bst-header {
	--bst-header-bg: var(--color-forest);
	--focus-color: var(--color-white);

	background-color: var(--bst-header-bg);
	color: var(--color-white);
}

/*
 * Transparent variant on pages that start with a hero (body class from
 * bstieunhien_theme_has_hero()). The hero is pulled up underneath
 * (hero.css); the header keeps its GeneratePress `position: relative`
 * and needs no z-index, so dropdowns and the drawer stack as before.
 */
.bst-has-hero .bst-header {
	--bst-header-bg: transparent;
}

/*
 * Row. Two classes to beat `.has-inline-mobile-toggle .inside-header`
 * and the GeneratePress inline padding. Side padding comes from
 * .bst-container.
 */
.bst-header .bst-header__inner {
	position: relative;
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	min-height: var(--header-height);
	padding-top: 0;
	padding-bottom: 0;
	text-align: left;
}

/* Hairline under the row, spanning the content width only. */
.bst-header .bst-header__inner::after {
	position: absolute;
	right: var(--gap);
	bottom: 0;
	left: var(--gap);
	height: 1px;
	background-color: var(--color-line-on-dark);
	content: "";
}

/* Logo (text wordmark) */

.bst-logo,
.bst-logo:hover,
.bst-logo:focus {
	color: inherit;
	text-decoration: none;
}

.bst-logo {
	font-family: var(--font-heading);
	font-size: var(--text-logo);
	font-weight: 400;
	line-height: 1.3;
	letter-spacing: 0.02em;
	text-transform: uppercase;
}

/*
 * Navigation. Selectors start with `.bst-header .main-navigation
 * .main-nav` so they match or beat the GeneratePress rules, and win by
 * load order.
 */

.bst-header .main-navigation {
	background-color: transparent;
}

/* Type style, all levels, both layouts */
.bst-header .main-navigation .main-nav ul li a {
	background-color: transparent;
	color: var(--color-white);
	font-family: var(--font-body);
	font-size: var(--text-menu);
	font-weight: 500;
	letter-spacing: 0.15em;
	text-decoration: none;
	text-transform: uppercase;
}

/* States: hover, keyboard focus / open submenu (sfHover), current page and ancestors */
.bst-header .main-navigation .main-nav ul li:hover > a,
.bst-header .main-navigation .main-nav ul li.sfHover > a,
.bst-header .main-navigation .main-nav ul li > a:focus-visible,
.bst-header .main-navigation .main-nav ul li[class*="current-menu-"] > a,
.bst-header .main-navigation .main-nav ul li.current_page_item > a,
.bst-header .main-navigation .main-nav ul li.current_page_ancestor > a {
	background-color: transparent;
	color: var(--color-accent);
}

/* Chevron on parent items */
.bst-header .main-navigation .main-nav .menu-item-has-children > a > .dropdown-menu-toggle {
	color: var(--color-accent);
	font-size: 0.85em;
	letter-spacing: 0;
}

/* Mobile toggle. Beats `button.menu-toggle:hover/:focus` from GeneratePress. */
.bst-header .menu-toggle,
.bst-header .menu-toggle:hover,
.bst-header .menu-toggle:focus {
	color: var(--color-white);
}

/* Desktop menu */
@media (min-width: 1024px) {

	/*
	 * Top level. The li is as tall as the header, so hover reaches the
	 * dropdown without a gap; the link is a compact box centered in it,
	 * so the focus outline fits around the label.
	 */
	.bst-header .main-navigation .main-nav > ul > li {
		line-height: var(--header-height);
	}

	.bst-header .main-navigation .main-nav > ul > li > a {
		display: inline-block;
		padding: 0.5em calc(var(--gap) / 2);
		line-height: 1.5;
		vertical-align: middle;
	}

	/* Last item: text ends at the container edge (minus trailing tracking). */
	.bst-header .main-navigation .main-nav > ul > li:last-child > a {
		padding-right: 0;
	}

	.bst-header .main-navigation .main-nav > ul > li:last-child:not(.menu-item-has-children) > a {
		margin-right: -0.15em;
	}

	/* Chevron on parent items, all levels: directly after the label. */
	.bst-header .main-navigation .main-nav .menu-item-has-children > a > .dropdown-menu-toggle {
		height: auto;
		padding: 0 0 0 0.6em;
	}

	/*
	 * Nested parents: undo the GeneratePress float and vertical offset so
	 * the chevron sits after the label like the top level, and point it
	 * left, toward the flyout. The svg is rotated (not the span) so the
	 * GeneratePress baseline nudge (`top: .125em`) stays vertical.
	 */
	.bst-header .main-navigation .main-nav ul ul .menu-item-has-children > a > .dropdown-menu-toggle {
		float: none;
		margin-top: 0;
		padding-top: 0;
		padding-bottom: 0;
	}

	.bst-header .main-navigation .main-nav ul ul .menu-item-has-children > a > .dropdown-menu-toggle .gp-icon svg {
		transform: rotate(90deg);
	}

	/* Dropdown panel. Opens under its parent li (GeneratePress positioning). */
	.bst-header .main-navigation .main-nav ul ul {
		width: max-content;
		min-width: 16em;
		max-width: 22em;
		padding: 0.75em 0;
		border: 1px solid var(--color-line-on-dark);
		background-color: var(--color-forest);
		box-shadow: none;
		font-size: var(--text-menu);
		line-height: 1.5;
	}

	/*
	 * Inset by 0.3em (~4px: 2px outline + 2px offset) so the focus outline
	 * stays inside the panel; padding shrinks by the same amount, so the
	 * text still lines up under the parent label.
	 */
	.bst-header .main-navigation .main-nav ul ul li a {
		margin: 0 0.3em;
		padding: 0.6em calc(var(--gap) / 2 - 0.3em);
		line-height: 1.5;
		white-space: normal;
	}

	/* Last top-level item: open the panel leftwards so it stays on screen. */
	.bst-header .main-navigation .main-nav > ul > li:last-child > ul {
		right: 0;
	}

	/* Keyboard fallback without JS: open on focus inside the item. */
	.bst-header .main-navigation:not(.toggled) ul li:focus-within > ul {
		left: auto;
		height: auto;
		overflow: visible;
		opacity: 1;
		pointer-events: auto;
	}

	/*
	 * Third level: the menu sits at the right of the header, so flyouts
	 * open to the left of the panel to stay on screen (the chevron points
	 * left, see above).
	 */
	.bst-header .main-navigation:not(.toggled) ul ul li:hover > ul,
	.bst-header .main-navigation:not(.toggled) ul ul li.sfHover > ul,
	.bst-header .main-navigation:not(.toggled) ul ul li:focus-within > ul {
		top: 0;
		right: 100%;
		left: auto;
	}
}

/*
 * Translucent dropdowns over a hero (desktop, body.bst-has-hero only).
 * The glass sits on a ::before layer, not on the panel itself: a panel
 * with backdrop-filter would become the backdrop root of the level-3
 * flyout inside it, which could then no longer blur the photo. On a
 * layer, both levels blur the page behind them the same way.
 * Without backdrop-filter support: forest at 85%.
 */
@media (min-width: 1024px) {

	.bst-has-hero .bst-header .main-navigation .main-nav ul ul {
		background-color: transparent;
	}

	.bst-has-hero .bst-header .main-navigation .main-nav ul ul::before {
		position: absolute;
		z-index: -1;
		inset: -1px; /* under the 1px border too */
		background-color: var(--color-forest);
		background-color: color-mix(in srgb, var(--color-forest) 85%, transparent);
		content: "";
	}

	@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {

		.bst-has-hero .bst-header .main-navigation .main-nav ul ul::before {
			background-color: var(--color-glass);
			-webkit-backdrop-filter: blur(var(--blur-glass));
			backdrop-filter: blur(var(--blur-glass));
		}
	}
}

/* Drawer parts: hidden unless the mobile menu is active. */
.bst-drawer-close,
.bst-drawer-backdrop {
	display: none;
}

/* Mobile menu: drawer */
@media (max-width: 1023px) {

	/*
	 * Toggle: 44x44 target. The icon is 1em, so the negative margin puts
	 * the glyph's right edge on the container edge.
	 */
	.bst-header .mobile-menu-control-wrapper .menu-toggle,
	.bst-header .mobile-menu-control-wrapper .menu-toggle:hover,
	.bst-header .mobile-menu-control-wrapper .menu-toggle:focus {
		background-color: transparent;
	}

	.bst-header .mobile-menu-control-wrapper .menu-toggle {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		margin-right: calc((44px - 1em) / -2);
		padding: 0;
		font-size: var(--text-logo);
		line-height: 1;
	}

	.bst-header .mobile-menu-control-wrapper .menu-toggle .gp-icon svg {
		top: 0;
	}

	/*
	 * Drawer. The open state is `html.bst-drawer-open`, set by
	 * assets/js/menu-drawer.js, so the closing animation does not depend on
	 * GeneratePress class timing. The `.toggled` selector matches the
	 * GeneratePress `.has-inline-mobile-toggle #site-navigation.toggled`
	 * rules (margin, background) and wins by load order.
	 */
	.bst-header #site-navigation,
	.bst-header #site-navigation.toggled {
		--focus-color: var(--color-forest);

		position: fixed;
		z-index: 100001; /* above the backdrop and the WP admin bar (99999) */
		top: 0;
		right: auto;
		bottom: 0;
		left: 0;
		width: min(440px, 80vw);
		margin: 0;
		padding: var(--header-height) var(--gap) var(--gap);
		overflow-y: auto;
		overscroll-behavior: contain;
		background-color: var(--color-ivory);
		visibility: hidden;
		transform: translateX(-100%);
		transition: transform 250ms ease, visibility 0s linear 250ms;
	}

	html.bst-drawer-open .bst-header #site-navigation {
		visibility: visible;
		transform: none;
		transition: transform 250ms ease 250ms, visibility 0s;
	}

	/* Page scroll lock while the drawer is open. */
	html.bst-drawer-open,
	html.bst-drawer-open body {
		overflow: hidden;
	}

	/* Backdrop: sweeps in left to right, out right to left after the drawer. */
	.bst-drawer-backdrop {
		position: fixed;
		z-index: 100000; /* above the WP admin bar (99999) */
		inset: 0;
		display: block;
		visibility: hidden;
		background-color: var(--color-backdrop);
		clip-path: inset(0 100% 0 0);
		transition: clip-path 250ms ease 250ms, visibility 0s linear 500ms;
	}

	html.bst-drawer-open .bst-drawer-backdrop {
		visibility: visible;
		clip-path: inset(0);
		transition: clip-path 250ms ease, visibility 0s;
	}

	/*
	 * Keep the menu laid out while the drawer slides out (GP hides it
	 * without .toggled). Static, so the close button is positioned against
	 * the drawer, not this box (GP makes it relative).
	 */
	#site-navigation .inside-navigation {
		position: static;
		display: block;
	}

	#site-navigation .main-nav > ul {
		display: block;
	}

	/*
	 * Close button: thin-line X icon (SVG), top right, 44x44. Four classes
	 * and the ID tie the GeneratePress rule that hides everything in
	 * .inside-navigation except the menu on mobile; load order wins.
	 */
	.bst-header .bst-header__inner #site-navigation .inside-navigation > .bst-drawer-close {
		position: absolute;
		z-index: 1;
		top: calc((var(--header-height) - 44px) / 2);
		right: calc(var(--gap) - 14px); /* 16px icon centered in 44px: its right edge on the content edge */
		display: flex;
		align-items: center;
		justify-content: center;
		width: 44px;
		height: 44px;
		padding: 0;
		border: 0;
		background-color: transparent;
		color: var(--color-forest);
	}

	#site-navigation .bst-drawer-close__icon {
		display: block;
		width: 16px;
		height: 16px;
	}

	#site-navigation .bst-drawer-close:hover,
	#site-navigation .bst-drawer-close:focus {
		background-color: transparent;
		color: var(--color-forest);
	}

	/* Rows: no lines, generous spacing, at least 44px tall. */
	#site-navigation .main-nav li {
		width: 100%;
	}

	#site-navigation .main-nav ul li a {
		display: flex;
		align-items: center;
		min-height: 44px;
		padding: 0.9em 0;
		color: var(--color-text);
		line-height: 1.5;
	}

	/* Current item and its ancestors (current-menu-item/-parent/-ancestor). */
	#site-navigation .main-nav ul li[class*="current-menu-"] > a,
	#site-navigation .main-nav ul li.current_page_item > a,
	#site-navigation .main-nav ul li.current_page_ancestor > a {
		color: var(--color-accent);
	}

	/*
	 * Hover and focus, after the current rule so they win. On the link,
	 * not the li, so hovering a child does not recolor its parent.
	 */
	#site-navigation .main-nav ul li > a:hover,
	#site-navigation .main-nav ul li > a:focus-visible {
		color: var(--color-forest);
	}

	/*
	 * Children: shown only when GeneratePress marks them `.toggled-on`,
	 * independent of `.toggled` so they stay put while the drawer closes.
	 */
	#site-navigation .main-nav ul ul {
		position: static;
		display: none;
		visibility: visible;
		float: none;
		width: auto;
		height: auto;
		padding: 0 0 0.5em var(--gap);
		overflow: visible;
		border: 0;
		background-color: transparent;
		box-shadow: none;
		opacity: 1;
		pointer-events: auto;
	}

	#site-navigation .main-nav ul ul.toggled-on {
		display: block;
	}

	#site-navigation .main-nav ul ul li a {
		padding: 0.4em 0;
		font-family: var(--font-heading);
		font-size: var(--text-link);
		font-style: italic;
		font-weight: 400;
		letter-spacing: 0;
		text-transform: none;
	}

	/* Parent chevron: square 1px outline on the right, forest when open. */
	#site-navigation .main-nav .menu-item-has-children > a {
		padding-top: 0;
		padding-bottom: 0;
	}

	#site-navigation .main-nav .menu-item-has-children > a > .dropdown-menu-toggle {
		display: flex;
		flex: 0 0 auto;
		align-items: center;
		justify-content: center;
		width: 44px;
		min-width: 44px;
		height: 44px;
		margin: 0 0 0 auto;
		padding: 0;
		float: none;
		border: 1px solid var(--color-border);
		border-radius: var(--radius);
		color: var(--color-accent);
		font-size: var(--text-menu);
	}

	#site-navigation .main-nav .dropdown-menu-toggle .gp-icon svg {
		top: 0;
	}

	#site-navigation .main-nav .menu-item-has-children > a > .dropdown-menu-toggle[aria-expanded="true"] {
		border-color: var(--color-forest);
	}
}

@media (max-width: 1023px) and (prefers-reduced-motion: reduce) {

	/* The global rule shortens durations; the sequence delays must go too. */
	.bst-drawer-backdrop,
	.bst-header #site-navigation,
	html.bst-drawer-open .bst-drawer-backdrop,
	html.bst-drawer-open .bst-header #site-navigation {
		transition-delay: 0s !important;
	}
}
