/**
 * Site header.
 *
 * One grid, three zones: brand / navigation / actions. The middle column is
 * auto-sized and the outer two each take an equal share of what is left, so the
 * navigation stays optically centred however wide the logo or the action
 * cluster happen to be.
 *
 * Every offset is a logical property, so RTL and LTR are the same stylesheet.
 * The only direction-aware rule is the CTA arrow, which is a directional glyph
 * and has to mirror.
 *
 * Two modes:
 *   .site-header--overlay  hero templates; transparent, sits on the photo
 *   .site-header--solid    everything else; a bar in normal flow
 * Both pick up .is-stuck once the page scrolls, which paints the solid bar.
 *
 * @package legacy
 */

:root {
	--lg-header-height: 76px;
	--lg-header-radius: 10px;
	--lg-header-control: 42px;
	--lg-header-menu-font-size: 14px;
	--lg-mobile-menu-font-size: 17px;
}

@media (max-width: 1023px) {

	:root {
		--lg-header-height: 64px;
		--lg-header-control: 40px;
	}
}

/* -------------------------------------------------------------------------
 * 1. Shell
 * ---------------------------------------------------------------------- */

.site-header {
	--lg-header-ink: var(--lg-text);
	--lg-header-ink-muted: var(--lg-muted);
	--lg-header-hairline: var(--lg-border-soft);
	--lg-logo-on-light: block;
	--lg-logo-on-dark: none;

	position: sticky;
	top: 0;
	z-index: 1000;
	inset-inline: 0;
	background-color: var(--lg-surface);
	border-bottom: 1px solid var(--lg-header-hairline);
	box-sizing: border-box;
	transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* The outer columns never go below their content, so when the action cluster
 * outgrows its half (a signed-out visitor in Arabic on a narrow desktop) the
 * navigation gives way to one side instead of disappearing under the buttons.
 * Whenever both halves fit, they are equal and the navigation stays centred. */
.site-header__inner {
	display: grid;
	grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
	align-items: center;
	gap: clamp(0.75rem, 2.5vw, 2.5rem);
	width: 100%;
	max-width: 1560px;
	margin-inline: auto;
	min-height: var(--lg-header-height);
	padding-inline: clamp(1rem, 4vw, 3.5rem);
	box-sizing: border-box;
}

.site-header__brand {
	justify-self: start;
	min-width: 0;
}

.site-header__nav {
	justify-self: center;
	display: flex;
	align-items: center;
	gap: clamp(0.75rem, 1.6vw, 1.5rem);
	min-width: 0;
}

.site-header__actions {
	justify-self: end;
	display: flex;
	align-items: center;
	gap: 0.625rem;
	min-width: 0;
}

/* Overlay mode: the hero runs under the header until the page scrolls. */
.site-header--overlay {
	position: absolute;
	top: 0;
	background-color: transparent;
	border-bottom-color: transparent;
}

.site-header--overlay:not(.is-stuck) {
	--lg-header-ink: #ffffff;
	--lg-header-ink-muted: rgba(255, 255, 255, 0.78);
	--lg-header-hairline: transparent;
	--lg-logo-on-light: none;
	--lg-logo-on-dark: block;
}

/* A short scrim keeps white nav text legible over a bright photograph. */
.site-header--overlay:not(.is-stuck)::before {
	content: "";
	position: absolute;
	inset-block-start: 0;
	inset-inline: 0;
	block-size: calc(var(--lg-header-height) * 1.9);
	background: linear-gradient(to bottom, rgba(10, 14, 13, 0.55), rgba(10, 14, 13, 0));
	pointer-events: none;
	z-index: -1;
}

.site-header.is-stuck {
	background-color: var(--lg-surface);
	box-shadow: 0 6px 24px var(--lg-shadow-sm);
}

:root[data-theme="dark"] .site-header {
	--lg-logo-on-light: none;
	--lg-logo-on-dark: block;
}

/* Only the overlay header changes positioning when it sticks: it starts out of
 * flow over the hero and becomes a fixed bar. The solid header is already
 * `sticky`, so switching it to `fixed` would pull the page up underneath it. */
.site-header--overlay.is-stuck {
	position: fixed;
	top: 0;
	border-bottom-color: var(--lg-border-soft);
	animation: lg-header-drop 0.28s ease;
}

@keyframes lg-header-drop {

	from {
		transform: translateY(-100%);
	}

	to {
		transform: translateY(0);
	}
}

.site-header__skip:focus {
	position: fixed;
	top: 0.75rem;
	inset-inline-start: 0.75rem;
	z-index: 1100;
	width: auto;
	height: auto;
	clip: auto;
	clip-path: none;
	padding: 0.7rem 1.1rem;
	border-radius: 8px;
	background-color: var(--lg-accent);
	color: var(--lg-on-accent);
	font-size: 15px;
	font-weight: 700;
	text-decoration: none;
}

/* -------------------------------------------------------------------------
 * 2. Brand
 * ---------------------------------------------------------------------- */

.site-logo {
	display: inline-flex;
	align-items: center;
	max-width: clamp(130px, 15vw, 190px);
	text-decoration: none;
}

.site-logo__img {
	display: none;
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: calc(var(--lg-header-height) - 28px);
	object-fit: contain;
}

.site-logo__img--light {
	display: var(--lg-logo-on-light);
}

.site-logo__img--dark {
	display: var(--lg-logo-on-dark);
}

/* No dark-ink artwork available: render the light one as a silhouette rather
 * than let a white logo disappear against a white bar. */
.site-header--mono-logo .site-logo__img--light {
	filter: brightness(0) saturate(100%);
}

.site-logo__text {
	color: var(--lg-header-ink);
	font-size: 22px;
	font-weight: 800;
	line-height: 1;
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
 * 3. Navigation
 * ---------------------------------------------------------------------- */

.site-nav {
	display: flex;
	align-items: center;
	gap: clamp(0.6rem, 1.5vw, 1.5rem);
	margin: 0;
	padding: 0;
	list-style: none;
}

.site-nav > li {
	position: relative;
}

.site-nav > li > a {
	position: relative;
	display: inline-flex;
	align-items: center;
	padding-block: 0.4rem;
	color: var(--lg-header-ink-muted);
	font-family: inherit;
	font-size: var(--lg-header-menu-font-size);
	font-weight: 600;
	line-height: 1.4;
	white-space: nowrap;
	text-decoration: none;
	transition: color 0.25s ease;
}

/* Underline grows from the inline start, so it runs the right way in both
 * directions without a mirrored rule. */
.site-nav > li > a::after {
	content: "";
	position: absolute;
	inset-block-end: 0;
	inset-inline-start: 0;
	inline-size: 0;
	block-size: 2px;
	border-radius: 2px;
	background-color: var(--lg-accent);
	transition: inline-size 0.25s ease;
}

.site-nav > li > a:hover,
.site-nav > li > a:focus-visible {
	color: var(--lg-header-ink);
}

.site-nav > li > a:hover::after,
.site-nav > li > a:focus-visible::after,
.site-nav > li.current-menu-item > a::after,
.site-nav > li.current_page_item > a::after {
	inline-size: 100%;
}

.site-nav > li.current-menu-item > a,
.site-nav > li.current_page_item > a {
	color: var(--lg-header-ink);
}

.site-nav > li > a:focus-visible {
	outline: 2px solid var(--lg-accent);
	outline-offset: 4px;
	border-radius: 4px;
}

/* Language links read as a utility rather than a destination, whether they come
 * from Polylang's own menu item or from the theme's fallback switcher. */
.site-nav > li.lang-item > a {
	font-size: 15px;
	font-weight: 700;
	letter-spacing: 0.01em;
}

/* A hairline separates the language links from the page links. It hangs off the
 * first language item in the list, or off the fallback list as a whole. */
.site-nav--lang,
.site-nav > li:not(.lang-item) + li.lang-item {
	position: relative;
	padding-inline-start: clamp(0.6rem, 1.5vw, 1.5rem);
}

.site-nav--lang::before,
.site-nav > li:not(.lang-item) + li.lang-item::before {
	content: "";
	position: absolute;
	inset-inline-start: 0;
	inset-block-start: 50%;
	transform: translateY(-50%);
	inline-size: 1px;
	block-size: 18px;
	background-color: var(--lg-header-ink-muted);
	opacity: 0.35;
}

/* Submenus */
.site-nav .sub-menu {
	position: absolute;
	inset-block-start: calc(100% + 0.6rem);
	inset-inline-start: 0;
	z-index: 10;
	min-inline-size: 208px;
	margin: 0;
	padding: 0.4rem;
	list-style: none;
	border: 1px solid var(--lg-border-soft);
	border-radius: 12px;
	background-color: var(--lg-surface);
	box-shadow: 0 14px 34px var(--lg-shadow-md);
	opacity: 0;
	visibility: hidden;
	transform: translateY(-6px);
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease;
}

.site-nav > li:hover > .sub-menu,
.site-nav > li:focus-within > .sub-menu {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

.site-nav .sub-menu a {
	display: block;
	padding: 0.55rem 0.75rem;
	border-radius: 8px;
	color: var(--lg-text);
	font-size: 15px;
	font-weight: 600;
	text-decoration: none;
	transition: background-color 0.2s ease, color 0.2s ease;
}

.site-nav .sub-menu a:hover,
.site-nav .sub-menu a:focus-visible {
	background-color: var(--lg-gold-surface);
	color: var(--lg-brand);
}

/* -------------------------------------------------------------------------
 * 4. Actions
 * ---------------------------------------------------------------------- */

/* The toggle ships as a stand-alone pill; inside the header it becomes a quiet
 * square that matches the CTA height and borrows the header's ink colour. The
 * profile link shares the same square so the two read as a pair. */
.site-header .legacy-theme-toggle,
.header-profile {
	width: var(--lg-header-control);
	height: var(--lg-header-control);
	border: 1px solid var(--lg-header-hairline);
	border-radius: var(--lg-header-radius);
	background-color: transparent;
	color: var(--lg-header-ink);
	-webkit-backdrop-filter: none;
	backdrop-filter: none;
	transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

.site-header--overlay:not(.is-stuck) .legacy-theme-toggle,
.site-header--overlay:not(.is-stuck) .header-profile,
.site-header--overlay:not(.is-stuck) .header-auth__link {
	border-color: rgba(255, 255, 255, 0.34);
	background-color: rgba(255, 255, 255, 0.12);
}

.site-header .legacy-theme-toggle:hover,
.site-header .legacy-theme-toggle:focus-visible,
.header-profile:hover,
.header-profile:focus-visible,
.header-auth__link:hover,
.header-auth__link:focus-visible {
	border-color: var(--lg-accent);
	background-color: var(--lg-accent);
	color: var(--lg-on-accent);
	transform: none;
}

.site-header .legacy-theme-toggle .legacy-theme-toggle-icon {
	width: 19px;
	height: 19px;
}

/* A button is border-box by default and a link is not, so the profile square
 * says so explicitly to come out the same size as the toggle. */
.header-profile {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	box-sizing: border-box;
	font-size: 20px;
	line-height: 1;
	text-decoration: none;
}

.header-profile:focus-visible,
.header-auth__link:focus-visible {
	outline: 2px solid var(--lg-accent);
	outline-offset: 3px;
}

/* Signed-out visitors: sign in and sign up are a matching pair of outlined
 * buttons, which leaves the filled guide CTA as the one primary action. */
.header-auth {
	display: flex;
	align-items: center;
	gap: 0.625rem;
}

.header-auth__link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: var(--lg-header-control);
	padding-inline: 1.15rem;
	border: 1px solid var(--lg-header-hairline);
	border-radius: var(--lg-header-radius);
	box-sizing: border-box;
	color: var(--lg-header-ink);
	font-family: inherit;
	font-size: var(--lg-header-menu-font-size);
	font-weight: 700;
	line-height: 1;
	white-space: nowrap;
	text-decoration: none;
	transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

.header-cta {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	height: var(--lg-header-control);
	padding-inline: 1.15rem;
	border: 1px solid transparent;
	border-radius: var(--lg-header-radius);
	background-color: var(--lg-accent);
	color: var(--lg-on-accent);
	font-family: inherit;
	font-size: var(--lg-header-menu-font-size);
	font-weight: 700;
	line-height: 1;
	white-space: nowrap;
	text-decoration: none;
	transition: background-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.header-cta:hover,
.header-cta:focus-visible {
	background-color: var(--lg-accent-hover);
	color: var(--lg-on-accent);
	transform: translateY(-1px);
	box-shadow: 0 8px 18px var(--lg-accent-a22);
}

.header-cta:focus-visible {
	outline: 2px solid var(--lg-accent);
	outline-offset: 3px;
}

.header-cta__icon {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
	transition: transform 0.25s ease;
}

/* The arrow is a directional glyph, so it mirrors with the document. */
[dir="rtl"] .header-cta__icon {
	transform: scaleX(-1);
}

.header-cta:hover .header-cta__icon {
	transform: translateX(3px);
}

[dir="rtl"] .header-cta:hover .header-cta__icon {
	transform: scaleX(-1) translateX(3px);
}

/* -------------------------------------------------------------------------
 * 5. Mobile menu
 * ---------------------------------------------------------------------- */

.nav-toggle {
	display: none;
	align-items: center;
	justify-content: center;
	width: var(--lg-header-control);
	height: var(--lg-header-control);
	padding: 0;
	border: 1px solid var(--lg-header-hairline);
	border-radius: var(--lg-header-radius);
	background-color: transparent;
	color: var(--lg-header-ink);
	cursor: pointer;
	transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

.site-header--overlay:not(.is-stuck) .nav-toggle {
	border-color: rgba(255, 255, 255, 0.34);
	background-color: rgba(255, 255, 255, 0.12);
}

.nav-toggle__bars,
.nav-toggle__bars::before,
.nav-toggle__bars::after {
	display: block;
	inline-size: 18px;
	block-size: 2px;
	border-radius: 2px;
	background-color: currentColor;
	transition: transform 0.25s ease, opacity 0.2s ease;
}

.nav-toggle__bars {
	position: relative;
}

.nav-toggle__bars::before,
.nav-toggle__bars::after {
	content: "";
	position: absolute;
	inset-inline-start: 0;
}

.nav-toggle__bars::before {
	inset-block-start: -6px;
}

.nav-toggle__bars::after {
	inset-block-start: 6px;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bars {
	background-color: transparent;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bars::before {
	transform: translateY(6px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bars::after {
	transform: translateY(-6px) rotate(-45deg);
}

.mobile-nav {
	position: fixed;
	inset: 0;
	z-index: 999;
	background-color: var(--lg-scrim);
	opacity: 0;
	transition: opacity 0.25s ease;
}

.mobile-nav.is-open {
	opacity: 1;
}

.mobile-nav__panel {
	position: absolute;
	inset-block-start: 0;
	inset-inline: 0;
	max-block-size: 100dvh;
	overflow-y: auto;
	padding: calc(var(--lg-header-height) + 1.25rem) clamp(1rem, 5vw, 2rem) 1.75rem;
	background-color: var(--lg-surface);
	border-bottom: 1px solid var(--lg-border-soft);
	box-shadow: 0 18px 40px var(--lg-shadow-md);
	transform: translateY(-14px);
	opacity: 0;
	transition: transform 0.28s ease, opacity 0.28s ease;
}

.mobile-nav.is-open .mobile-nav__panel {
	transform: translateY(0);
	opacity: 1;
}

.mobile-nav__menu,
.mobile-nav__menu .sub-menu {
	margin: 0;
	padding: 0;
	list-style: none;
}

.mobile-nav__menu > li + li {
	border-top: 1px solid var(--lg-border-soft);
}

.mobile-nav__menu a {
	display: block;
	padding-block: 0.9rem;
	color: var(--lg-text);
	font-size: var(--lg-mobile-menu-font-size);
	font-weight: 600;
	text-decoration: none;
	transition: color 0.2s ease;
}

.mobile-nav__menu a:hover,
.mobile-nav__menu a:focus-visible {
	color: var(--lg-brand);
}

.mobile-nav__menu .sub-menu a {
	padding-inline-start: 1rem;
	font-size: 15px;
	font-weight: 500;
	color: var(--lg-muted);
}

.mobile-nav__languages {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-block: 1.25rem 0.25rem;
}

.mobile-nav__language {
	padding: 0.45rem 0.9rem;
	border: 1px solid var(--lg-border);
	border-radius: 999px;
	color: var(--lg-muted);
	font-size: 14px;
	font-weight: 700;
	text-decoration: none;
}

.mobile-nav__language.is-current {
	border-color: var(--lg-accent);
	background-color: var(--lg-gold-surface);
	color: var(--lg-brand);
}

.mobile-nav__auth {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 0.625rem;
	margin-block-start: 1.25rem;
}

.mobile-nav__auth--logged-in {
	grid-template-columns: minmax(0, 1fr);
}

.mobile-nav__auth-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 48px;
	padding-inline: 0.5rem;
	border: 1px solid var(--lg-border);
	border-radius: var(--lg-header-radius);
	box-sizing: border-box;
	color: var(--lg-text);
	font-size: var(--lg-mobile-menu-font-size);
	font-weight: 700;
	white-space: nowrap;
	text-decoration: none;
	transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.mobile-nav__auth-link:hover,
.mobile-nav__auth-link:focus-visible {
	border-color: var(--lg-accent);
	background-color: var(--lg-gold-surface);
	color: var(--lg-brand);
}

.header-cta--block {
	width: 100%;
	height: 48px;
	margin-block-start: 1.25rem;
	font-size: var(--lg-mobile-menu-font-size);
}

.mobile-nav__auth + .header-cta--block {
	margin-block-start: 0.625rem;
}

body.lg-menu-open {
	overflow: hidden;
}

/* -------------------------------------------------------------------------
 * 6. Breakpoints
 * ---------------------------------------------------------------------- */

@media (max-width: 1023px) {

	.site-header__inner {
		grid-template-columns: 1fr auto;
	}

	.site-header__nav {
		display: none;
	}

	.nav-toggle {
		display: inline-flex;
	}

	.header-cta {
		display: none;
	}

	.header-cta--block {
		display: inline-flex;
	}

	/* Sign in and sign up move into the menu panel with the CTA; the profile
	 * square is small enough to stay in the bar. */
	.header-auth {
		display: none;
	}

	.header-logout {
		display: none;
	}
}

/* Just above the menu breakpoint the bar is at its most crowded, so the account
 * links tighten up to leave the navigation room. */
@media (min-width: 1024px) and (max-width: 1199px) {

	.header-auth {
		gap: 0.4rem;
	}

	.header-auth__link {
		padding-inline: 0.75rem;
	}
}

/* Without the script the toggle cannot open anything, so hide it and let the
 * links wrap onto a second row instead of stranding the menu. */
html:not(.lg-header-ready) .nav-toggle {
	display: none;
}

@media (max-width: 1023px) {

	html:not(.lg-header-ready) .site-header__nav {
		display: flex;
		grid-column: 1 / -1;
		justify-self: stretch;
		justify-content: center;
		flex-wrap: wrap;
		gap: 0.5rem 1rem;
		padding-block-end: 0.85rem;
	}

	html:not(.lg-header-ready) .site-nav {
		flex-wrap: wrap;
		justify-content: center;
	}
}

@media (min-width: 1024px) {

	.mobile-nav {
		display: none !important;
	}
}

@media (max-width: 400px) {

	.site-logo {
		max-width: 118px;
	}

	.site-header__actions {
		gap: 0.45rem;
	}
}

@media (prefers-reduced-motion: reduce) {

	.site-header,
	.site-header__inner *,
	.mobile-nav,
	.mobile-nav__panel {
		transition: none !important;
		animation: none !important;
	}
}
