/*
 * Faiha header: floating rounded navigation container.
 *
 * Desktop (1025px+): a centred rounded container (max ~1380px) floating
 * 20px below the top of the viewport, light in light mode and deep navy in
 * dark mode. Logo left, primary navigation centred in the remaining space,
 * red "Contact Us" button and the theme toggle on the right. On scroll it
 * keeps its shape, moves up slightly, gets a little shorter and a stronger
 * shadow. It never becomes a flat full-width strip.
 *
 * Mobile / tablet (up to 1024px): a compact rounded bar with just the logo,
 * theme toggle and menu button; the full navigation stays in Kadence's
 * drawer.
 *
 * Built on Kadence's own header markup and sticky script (no extra
 * JavaScript). Kadence's sticky states on the desktop main row:
 *   .kadence-sticky-header.item-is-fixed.item-at-start   at the top
 *   .kadence-sticky-header.item-is-fixed.item-is-stuck   after scrolling
 * The fixed row itself stays transparent; the rounded container is its
 * inner .site-header-row-container-inner (position: relative, so the
 * Services mega menu anchors to it).
 *
 * Homepage: Kadence's transparent header (functions.php), so the
 * container floats over the dark hero. Other pages: the header area is a
 * navy band that runs into the dark page hero, so the container floats
 * over dark there too.
 *
 * Two logos are printed (functions.php): white lettering for dark mode,
 * dark lettering for the light container.
 */

#masthead {
	/* Faiha palette only (foundation.css tokens): white surface, navy text, Faiha red actions. */
	--hdr-bg: var(--faiha-surface);
	--hdr-text: var(--faiha-navy-900);
	--hdr-text-muted: var(--faiha-text-secondary);
	--hdr-border: color-mix(in srgb, var(--faiha-navy-900) 8%, transparent);
	--hdr-control-border: color-mix(in srgb, var(--faiha-navy-900) 14%, transparent);
	--hdr-control-hover: color-mix(in srgb, var(--faiha-navy-900) 5%, transparent);
	--hdr-accent: var(--faiha-color-brand-strong);
	--hdr-shadow: var(--faiha-shadow-float);
	--hdr-shadow-stuck: var(--faiha-shadow-float-strong);
	--hdr-radius: 1.5rem; /* 24px */
	--hdr-max: 86.25rem; /* 1380px */
	--hdr-top: var(--faiha-header-offset);
	--hdr-top-stuck: 0.75rem;
	--hdr-height: var(--faiha-header-height);
	--hdr-height-stuck: 4.25rem; /* 68px */
}

/* Dark: deep navy container (not black), white text, lighter hairline border, Faiha red lifted for contrast on navy. */
:root[data-theme="dark"] #masthead {
	--hdr-bg: var(--faiha-navy-700);
	--hdr-text: var(--faiha-text-on-dark);
	--hdr-text-muted: var(--faiha-text-on-dark-secondary);
	--hdr-border: color-mix(in srgb, var(--faiha-text-on-dark) 10%, transparent);
	--hdr-control-border: color-mix(in srgb, var(--faiha-text-on-dark) 18%, transparent);
	--hdr-control-hover: color-mix(in srgb, var(--faiha-text-on-dark) 8%, transparent);
	--hdr-accent: color-mix(in srgb, var(--faiha-color-brand) 80%, #fff);
	--hdr-shadow: 0 12px 32px color-mix(in srgb, #000 35%, transparent);
	--hdr-shadow-stuck: 0 16px 40px color-mix(in srgb, #000 45%, transparent);
}

/* The rows around the container are transparent; only the container is painted. */
#masthead .site-header-row-container-inner,
#masthead #main-header .kadence-sticky-header,
#masthead #mobile-header .site-main-header-wrap {
	background-color: transparent;
}

/* Non-homepage pages: navy band behind the floating container, continuous with the dark page hero. */
body.non-transparent-header #masthead {
	background-color: var(--faiha-navy-900);
}

/* ---------------------------------------------------------------- */
/* Logo: one of the two printed logos per theme                     */
/* ---------------------------------------------------------------- */

#masthead .site-branding a.brand img.faiha-logo-on-dark,
:root[data-theme="dark"] #masthead .site-branding a.brand img.faiha-logo-on-light {
	display: none;
}

:root[data-theme="dark"] #masthead .site-branding a.brand img.faiha-logo-on-dark {
	display: block;
}

#masthead .site-branding a.brand img {
	width: 150px;
	max-width: 150px;
	height: auto;
}

/* ---------------------------------------------------------------- */
/* Desktop: floating container                                       */
/* ---------------------------------------------------------------- */

@media (min-width: 1025px) {
	#masthead #main-header .kadence-sticky-header {
		box-sizing: border-box;
		padding: var(--hdr-top) var(--faiha-container-padding) 0;
		transition: padding var(--faiha-duration-base) var(--faiha-ease-standard);
	}

	#masthead #main-header .site-header-row-container-inner {
		position: relative;
		box-sizing: border-box;
		max-width: var(--hdr-max);
		margin-inline: auto;
		border: 1px solid var(--hdr-border);
		border-radius: var(--hdr-radius);
		background-color: var(--hdr-bg);
		box-shadow: var(--hdr-shadow);
		transition:
			box-shadow var(--faiha-duration-base) var(--faiha-ease-standard),
			background-color var(--faiha-duration-theme) var(--faiha-ease-standard),
			border-color var(--faiha-duration-theme) var(--faiha-ease-standard);
	}

	#masthead #main-header .site-header-row-container-inner > .site-container {
		max-width: none;
		padding-inline: 1.25rem 1rem;
	}

	#masthead #main-header .site-main-header-inner-wrap {
		min-height: var(--hdr-height);
		transition: min-height var(--faiha-duration-base) var(--faiha-ease-standard);
	}

	/* Scrolled: same floating shape, a little higher, shorter and more elevated. */
	#masthead #main-header .kadence-sticky-header.item-is-fixed:not(.item-at-start) {
		padding-top: var(--hdr-top-stuck);
	}

	#masthead #main-header .kadence-sticky-header.item-is-fixed:not(.item-at-start) .site-header-row-container-inner {
		box-shadow: var(--hdr-shadow-stuck);
	}

	#masthead #main-header .kadence-sticky-header.item-is-fixed:not(.item-at-start) .site-main-header-inner-wrap {
		min-height: var(--hdr-height-stuck);
	}

	/*
	 * Layout: logo | navigation, centred on the container | button + toggle.
	 * A three-column grid; Kadence's right section is flattened
	 * (display: contents) so its items can sit in the centre and right
	 * columns. The button and toggle share the right cell, the button offset
	 * by the toggle's width.
	 */
	#masthead #main-header .site-main-header-inner-wrap {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
		align-items: center;
	}

	#masthead #main-header .site-header-main-section-left {
		grid-column: 1;
		justify-self: start;
	}

	#masthead #main-header .site-header-main-section-right {
		display: contents;
	}

	#masthead #main-header .site-header-item-main-navigation {
		grid-column: 2;
		grid-row: 1;
	}

	#masthead #main-header .site-header-main-section-right > .site-header-item:not(.site-header-item-main-navigation) {
		grid-column: 3;
		grid-row: 1;
		justify-self: end;
		margin: 0;
	}

	#masthead #main-header .site-header-main-section-right > .site-header-item:has(.header-button-wrap) {
		margin-right: calc(2.75rem + 0.625rem); /* toggle width + gap */
	}
}

/* ---------------------------------------------------------------- */
/* Primary navigation                                                */
/* ---------------------------------------------------------------- */

#masthead #primary-menu > li > a {
	padding-inline: 0.875rem;
	color: var(--hdr-text);
	font-family: var(--faiha-font-heading);
	font-size: 0.9375rem;
	font-weight: var(--faiha-weight-nav);
	letter-spacing: 0;
	transition: color var(--faiha-duration-fast) var(--faiha-ease-standard);
}

/*
 * Active page: red text + a small red underline. Only for links to real
 * pages; Kadence also marks the homepage section anchors (/#…) as current
 * on the homepage, which would light up several items at once.
 */
#masthead #primary-menu > li > a:hover,
#masthead #primary-menu > li > a:focus-visible,
#masthead #primary-menu > li.current-menu-item > a:not([href*="#"]),
#masthead #primary-menu > li.current-menu-ancestor > a:not([href*="#"]) {
	color: var(--hdr-accent);
}

#masthead #primary-menu > li.current-menu-item > a:not([href*="#"]),
#masthead #primary-menu > li.current-menu-ancestor > a:not([href*="#"]) {
	text-decoration: underline;
	text-decoration-thickness: 2px;
	text-underline-offset: 0.5rem;
}

#masthead #primary-menu > li > a:focus-visible {
	outline-width: 2px;
	outline-style: solid;
	outline-color: var(--hdr-accent);
	outline-offset: 2px;
	border-radius: 0.5rem;
}

/* ---------------------------------------------------------------- */
/* Header button: the primary button style (Faiha red)               */
/* ---------------------------------------------------------------- */

#masthead .header-button-wrap .button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	min-height: 2.75rem;
	padding: 0.625rem 1.25rem;
	border: 0;
	border-radius: var(--faiha-radius-button);
	background-color: var(--faiha-color-brand-strong);
	color: var(--faiha-text-on-dark);
	font-family: var(--faiha-font-heading);
	font-size: 0.9375rem;
	font-weight: var(--faiha-weight-button);
	line-height: 1.2;
	box-shadow: 0 6px 16px color-mix(in srgb, var(--faiha-color-brand-strong) 24%, transparent);
	transition:
		background-color var(--faiha-duration-fast) var(--faiha-ease-standard),
		box-shadow var(--faiha-duration-fast) var(--faiha-ease-standard);
}

#masthead .header-button-wrap .button:hover,
#masthead .header-button-wrap .button:focus-visible {
	background-color: color-mix(in srgb, var(--faiha-color-brand-strong) 86%, #000);
	color: var(--faiha-text-on-dark);
	box-shadow: 0 8px 20px color-mix(in srgb, var(--faiha-color-brand-strong) 30%, transparent);
}

#masthead .header-button-wrap .button:focus-visible {
	outline-width: 2px;
	outline-style: solid;
	outline-color: var(--hdr-text);
	outline-offset: 3px;
}

/* ---------------------------------------------------------------- */
/* Theme toggle                                                      */
/* ---------------------------------------------------------------- */

.faiha-theme-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.75rem; /* 44px comfortable target */
	height: 2.75rem;
	padding: 0;
	border: 1px solid var(--hdr-control-border, rgba(255, 255, 255, 0.16));
	border-radius: var(--faiha-radius-button);
	background-color: transparent;
	color: var(--hdr-text, var(--faiha-text-on-dark));
	cursor: pointer;
	transition:
		background-color var(--faiha-duration-fast) var(--faiha-ease-standard),
		border-color var(--faiha-duration-fast) var(--faiha-ease-standard);
}

.faiha-theme-toggle:hover,
.faiha-theme-toggle:focus-visible {
	background-color: var(--hdr-control-hover, rgba(255, 255, 255, 0.08));
	border-color: var(--hdr-accent, rgba(255, 255, 255, 0.32));
}

.faiha-theme-toggle-icon {
	display: none;
	line-height: 0;
}

.faiha-theme-toggle-icon--to-dark {
	display: inline-flex;
}

:root[data-theme="dark"] .faiha-theme-toggle-icon--to-dark {
	display: none;
}

:root[data-theme="dark"] .faiha-theme-toggle-icon--to-light {
	display: inline-flex;
}

/* ---------------------------------------------------------------- */
/* Mobile / tablet: compact rounded bar (logo, theme toggle, menu)   */
/* ---------------------------------------------------------------- */

@media (max-width: 1024px) {
	#masthead #mobile-header .site-main-header-wrap {
		box-sizing: border-box;
		padding: 0.75rem var(--faiha-container-padding) 0;
	}

	#masthead #mobile-header .site-header-row-container-inner {
		box-sizing: border-box;
		border: 1px solid var(--hdr-border);
		border-radius: 1.125rem; /* 18px */
		background-color: var(--hdr-bg);
		box-shadow: var(--hdr-shadow);
		transition:
			background-color var(--faiha-duration-theme) var(--faiha-ease-standard),
			border-color var(--faiha-duration-theme) var(--faiha-ease-standard);
	}

	#masthead #mobile-header .site-header-row-container-inner > .site-container {
		padding-inline: 1rem 0.5rem;
	}

	#masthead #mobile-header .site-main-header-inner-wrap {
		min-height: 4rem; /* 64px */
	}

	#masthead #mobile-header .site-header-main-section-right {
		gap: 0.25rem;
	}

	/* Order on mobile: logo … theme toggle, menu button. */
	#masthead #mobile-header .site-header-main-section-right > .faiha-theme-toggle-item {
		order: -1;
	}

	#masthead .site-branding a.brand img {
		width: 128px;
		max-width: 128px;
	}
}

/* Kadence's menu button: comfortable 44px target in the header text colour. */

#mobile-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.75rem;
	height: 2.75rem;
	color: var(--hdr-text);
}

@media (prefers-reduced-motion: reduce) {
	#masthead #main-header .kadence-sticky-header,
	#masthead #main-header .site-header-row-container-inner,
	#masthead #main-header .site-main-header-inner-wrap,
	#masthead #mobile-header .site-header-row-container-inner,
	#masthead #primary-menu > li > a,
	#masthead .header-button-wrap .button,
	.faiha-theme-toggle {
		transition: none;
	}
}
