/* ==========================================================================
   HEADER / PRIMARY NAV

   Overrides for My Listing's own header (`.c27-main-header`, markup in
   my-listing/sections/header.php). Three things are changed here:

     1. the last menu item's dropdown is anchored to its right edge, so it
        cannot open off the side of the screen;
     2. the header sits *over* the page's hero rather than above it, and is
        transparent for as long as the hero is behind it;
     3. nothing -- the hide-on-scroll-down / show-on-scroll-up behaviour is
        the parent theme's and already works. It is documented at the bottom
        so the next person does not go looking for it in the child theme.

   The parent writes several of its header colours into an inline <style> block
   built in sections/header.php ($GLOBALS['case27_custom_styles']), some of them
   with !important. That block is printed after this stylesheet, so the
   transparency rules below deliberately carry both !important and an extra
   element selector (`header.c27-main-header...`) to outrank it. Dropping either
   one silently restores the opaque bar.
   ========================================================================== */

/* --- Header height -------------------------------------------------------
   Mirrors the parent's own header heights, which are hard-coded per
   breakpoint in my-listing/assets/dist/header.css (and repeated there on
   `.c27-top-content-margin`, the spacer that normally holds content clear of
   the fixed header). We collapse that spacer on hero pages, so we need the
   same numbers to pad the hero by instead. If a My Listing update changes
   them, these three values are what must follow. */
:root { --kbia-header-h: 89px; }

@media (max-width: 1200px) {
	:root { --kbia-header-h: 80px; }
}

@media (max-width: 480px) {
	:root { --kbia-header-h: 60px; }
}

/* --- Dropdowns -----------------------------------------------------------
 *
 * Every submenu is `position: absolute; left: 0; width: 215px` against its
 * own menu item. The menu is right-aligned, so the last item sits roughly one
 * gutter from the viewport edge and 215px of dropdown does not fit next to
 * it -- "Get in Touch" opened 72px off-screen at 1440px wide.
 *
 * Anchoring the last dropdown to its item's right edge instead lines it up
 * with the end of the nav, which is where the eye already is. Only the last
 * item needs it: every earlier dropdown has the width of the items after it
 * to grow into.
 */
@media (min-width: 1201px) {
	.c27-main-header .main-nav > li:last-child > .i-dropdown {
		left: auto;
		right: 0;
	}

	/* The landing-page link inc/nav.php repeats at the top of each submenu is
	   there because assets/js/nav.js turns the mobile row into a toggle, which
	   takes its own link away. Above this breakpoint the row is still a link
	   and the hover dropdown opens on its own, so the copy would just be the
	   same destination listed twice. */
	.c27-main-header .main-nav .kbia-menu-item-self {
		display: none;
	}
}

/* --- The repeated landing-page row ---------------------------------------
 *
 * inc/nav.php repeats a section's own page as the first item of its submenu,
 * because assets/js/nav.js turns the mobile row above into a toggle. The two
 * rows therefore carry the same words a line apart, and in the parent's menu
 * styling they are also the same size, weight and colour -- which reads as the
 * menu having stuttered rather than as an offer to open the section itself.
 *
 * Weight and the brand blue are enough to separate them: the top row is the
 * control, this one is the destination. Nothing is hidden from anyone -- the
 * text is the full page title either way, which is what a screen reader
 * announces and what the browser's find-in-page matches.
 */
@media (max-width: 1200px) {
	.c27-main-header .main-nav .kbia-menu-item-self > a {
		font-weight: 600;
		color: var(--kbia-blue-600);
	}
}

/* --- Transparent over the hero -------------------------------------------
 *
 * `.c27-top-content-margin` is an empty div the parent drops between the
 * header and <main> to push content below the fixed header. On a page that
 * opens with a hero we want the opposite: the hero should run up under the
 * header and show through it.
 *
 * The :has() test keys off the markup rather than off a body class, so any
 * template that opens with a hero gets this without registering itself
 * anywhere. Browsers without :has() keep the spacer and the opaque header --
 * the layout is unchanged for them, just less pretty.
 */
body:has(#content > .kbia-hero:first-child) .c27-top-content-margin {
	display: none;
}

/* The homepage hero is bottom-aligned and tall, so it needs no compensation --
   the header simply overlays its empty upper area. An interior hero is
   top-aligned and its copy would slide under the header, so it gets the
   header's height added to the padding it already had. */
#content > .kbia-hero--interior:first-child {
	padding-block-start: calc(var(--kbia-band-y-lg) + var(--kbia-header-h));
}

/*
 * `.header-skin` is the parent's background layer -- a positioned div behind
 * the header's contents, which is what carries the colour and the bottom
 * border. Fading that rather than the <header> keeps the logo and menu fully
 * opaque while the bar behind them goes away.
 */
.c27-main-header .header-skin {
	transition: background-color var(--kbia-dur) var(--kbia-ease-out),
	            border-bottom-color var(--kbia-dur) var(--kbia-ease-out);
}

header.c27-main-header.kbia-header--over-hero .header-skin {
	background: transparent !important;
	border-bottom-color: transparent !important;
}

/*
 * White menu text over an uncontrolled video frame is a contrast gamble: the
 * hero's own scrim darkens the left of the frame, where the copy sits, but the
 * nav is on the right where the footage can be bright. This gradient is the
 * smallest thing that makes the text dependable -- it is dark only at the very
 * top and gone by the bottom of the bar, so the hero still reads as running
 * behind an open header rather than under a second tinted strip.
 *
 * Only over a hero that actually carries footage. An interior hero is flat
 * --kbia-blue-800 and its contrast with white is already known good, so there
 * the same gradient would just be an unexplained smudge at the top of the page.
 */
body:has(#content > .kbia-hero--video:first-child)
	header.c27-main-header.kbia-header--over-hero::before {
	content: "";
	position: absolute;
	inset: 0 0 auto;
	height: calc(var(--kbia-header-h) * 1.8);
	pointer-events: none;
	background: linear-gradient(180deg, rgb(0 0 0 / 45%) 0%, rgb(0 0 0 / 0%) 100%);
}

@media (prefers-reduced-motion: reduce) {
	.c27-main-header .header-skin { transition: none; }
}

/* --- Hide on scroll down, show on scroll up ------------------------------
 *
 * Not implemented here: My Listing already does it. sections/header.php ships
 * the header with `header-fixed`, and assets/dist/header.js toggles three
 * classes against the scroll position -- `header-scroll` past the header's own
 * height (which also switches it to position: fixed), `header-scroll-hide`
 * 250px later, and `header-scroll-active` whenever the last scroll was
 * upwards. `.header-scroll-hide` translates the bar up by -100%, and
 * `.header-scroll-active` wins over it to bring the bar back.
 *
 * The only thing the child theme adds is the transparency above, which has to
 * survive `.header-scroll` -- the header goes solid the moment it is past the
 * hero, not the moment it is past its own height.
 */
