/*
 * Header (parts/header.html -> patterns/header.php).
 *
 * The template part's <header> is a direct child of .wp-site-blocks, so it
 * can stick. By default it is in the flow and scrolls away with the page.
 * States (classes from assets/js/header.js):
 *   - at the page top: the full-height bar, solid black;
 *   - over a hero (post content starts with a `.kt-hero` section): at the
 *     top it is a translucent band laid over the hero, which starts at the
 *     page top;
 *   - `.is-pinned` (the reader scrolled up): stuck to the top, solid black
 *     and compact, the logo shorter, so the bar takes less of the viewport;
 *     it slides in;
 *   - `.is-pinned.is-hidden` (scrolling down again): slid up out of view.
 * The bar's current stuck height is published as --kt-header-sticky-height
 * for bars that stick below it (assets/css/anchor-nav-offset.css): 0 unless
 * it is pinned and in view.
 * Below 1024px the Navigation block's overlay (hamburger) menu is used: the
 * block is set to overlayMenu "always" and shown inline from 1024px up here.
 */

:root {
	--kt-header-height: 88px;
	--kt-header-compact-height: 64px;
	--kt-logo-height: 56px;
	--kt-logo-compact-height: 48px;
	--kt-header-sticky-height: 0px;
}

@media (min-width: 1024px) {

	:root {
		--kt-header-height: 136px;
		--kt-header-compact-height: 80px;
		--kt-logo-height: 92px;
		--kt-logo-compact-height: 64px;
	}
}

:root:has(.wp-site-blocks > header.wp-block-template-part.is-pinned:not(.is-hidden)) {
	--kt-header-sticky-height: var(--kt-header-compact-height);
}

.wp-site-blocks > header.wp-block-template-part {
	position: relative;
	z-index: 100;
	background-color: var(--wp--preset--color--black);
	color: var(--wp--preset--color--white);
	transition: background-color 0.2s ease, transform 0.2s ease, margin-block-end 0.2s ease;
}

/* Pinning is instant (the slide-in covers it): the bar and logo snap to
   compact, and the margin with them. Unpinning at the top eases back. */
.wp-site-blocks > header.wp-block-template-part.is-pinned {
	position: sticky;
	top: var(--wp-admin--admin-bar--height, 0px);
	animation: kt-header-in 0.2s ease;
	transition: background-color 0.2s ease, transform 0.2s ease;
}

.wp-site-blocks > header.wp-block-template-part.is-pinned.is-hidden {
	transform: translateY(-100%);
}

@keyframes kt-header-in {

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

/* The compact bar is shorter than its slot in the flow; the bottom margin
   makes up the difference so the page content never jumps. Over a hero the
   slot is collapsed altogether: the bar overlaps the hero, which reserves
   --kt-header-height at its top (hero.css). */
.wp-site-blocks > header.wp-block-template-part.is-pinned {
	margin-block-end: calc(var(--kt-header-height) - var(--kt-header-compact-height));
}

body:has(.wp-site-blocks > main .wp-block-post-content > .kt-hero:first-child) .wp-site-blocks > header.wp-block-template-part {
	margin-block-end: calc(-1 * var(--kt-header-height));
}

body:has(.wp-site-blocks > main .wp-block-post-content > .kt-hero:first-child) .wp-site-blocks > header.wp-block-template-part.is-pinned {
	margin-block-end: calc(-1 * var(--kt-header-compact-height));
}

body:has(.wp-site-blocks > main .wp-block-post-content > .kt-hero:first-child) .wp-site-blocks > header.wp-block-template-part:not(.is-pinned) {
	background-color: rgb(0 0 0 / 55%);
}

.kt-header.wp-block-group {
	box-sizing: border-box;
	min-height: var(--kt-header-height);
	transition: min-height 0.2s ease;

	/* Content-width gutters: 80px at 1440, the 1280px container when wider. */
	padding-inline: max(var(--wp--style--root--padding-left, 16px), calc((100% - var(--wp--style--global--content-size, 1280px)) / 2));
	align-items: center;
	gap: var(--wp--preset--spacing--50);
}

.is-pinned .kt-header.wp-block-group {
	min-height: var(--kt-header-compact-height);
	transition: none;
}

/* Logo: at most the Site Logo block's width (237px, the SVG's 237x92), capped
   to the bar's height: full-size at the page top, shorter once scrolled. */
.kt-header .wp-block-site-logo img {
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: var(--kt-logo-height);
	transition: max-height 0.2s ease;
}

.is-pinned .kt-header .wp-block-site-logo img {
	max-height: var(--kt-logo-compact-height);
	transition: none;
}

/* Navigation: Inter 600 15px uppercase white, 64px gaps at 1440. */
.kt-header__nav.wp-block-navigation {
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--sm);
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	color: var(--wp--preset--color--white);
}

.kt-header__nav .wp-block-navigation__container {
	gap: clamp(24px, 4.44vw, 64px);
	align-items: center;
}

.kt-header__nav .wp-block-navigation-item__content {
	text-decoration: none;
}

.kt-header__nav .wp-block-navigation-item__content:hover {
	text-decoration: underline;
	text-underline-offset: 0.3em;
}

/* Current page: red (the AA-safe red for small text on dark). */
.kt-header__nav .current-menu-item > .wp-block-navigation-item__content {
	color: var(--wp--preset--color--red-bright);
}

/* Yhteystiedot: the red header button, inverted on its own page. */
.kt-header__nav.wp-block-navigation .kt-nav-button > .wp-block-navigation-item__content.wp-block-navigation-item__content {
	display: inline-flex;
	align-items: center;
	min-height: 48px;
	box-sizing: border-box;
	padding: 0 var(--wp--preset--spacing--30);
	border-radius: 4px;
	background-color: var(--wp--preset--color--red);
	color: var(--wp--preset--color--white);
	text-decoration: none;
}

.kt-header__nav.wp-block-navigation .kt-nav-button.current-menu-item > .wp-block-navigation-item__content.wp-block-navigation-item__content {
	background-color: var(--wp--preset--color--white);
	color: var(--wp--preset--color--red);
}

.kt-header__nav .kt-nav-button > .wp-block-navigation-item__content:focus-visible {
	outline: 2px solid var(--wp--preset--color--white);
	outline-offset: 3px;
}

/* Hamburger and overlay. */
.kt-header__nav .wp-block-navigation__responsive-container-open,
.kt-header__nav .wp-block-navigation__responsive-container-close {
	color: var(--wp--preset--color--white);
}

.kt-header__nav .wp-block-navigation__responsive-container-open svg,
.kt-header__nav .wp-block-navigation__responsive-container-close svg {
	width: 32px;
	height: 32px;
}

.kt-header__nav .wp-block-navigation__responsive-container.is-menu-open {
	--navigation-layout-justification-setting: flex-start;
	padding-block: var(--wp--preset--spacing--40);
	padding-inline: var(--wp--style--root--padding-left, 16px) var(--wp--style--root--padding-right, 16px);
}

.kt-header__nav .wp-block-navigation__responsive-container.is-menu-open .wp-block-navigation__responsive-container-content .wp-block-navigation__container {

	/* The menu is right-justified in the bar; the overlay lists from the left. */
	--navigation-layout-justification-setting: flex-start;
	gap: var(--wp--preset--spacing--40);
	font-size: var(--wp--preset--font-size--lg);
}

/* From 1024px the menu is inline (mirrors core's 600px "mobile" rules) and
   spreads across the right of the bar (mockup: x 436 to 1346 at 1440). */
@media (min-width: 1024px) {

	.kt-header__nav.wp-block-navigation {
		flex: 0 1 910px;
	}

	.kt-header__nav .wp-block-navigation__responsive-close,
	.kt-header__nav .wp-block-navigation__responsive-dialog,
	.kt-header__nav .wp-block-navigation__responsive-container-content,
	.kt-header__nav .wp-block-navigation__container {
		width: 100%;
	}

	.kt-header__nav .wp-block-navigation__responsive-container:not(.is-menu-open) .wp-block-navigation__container {
		justify-content: space-between;
	}

	.kt-header__nav .wp-block-navigation__responsive-container.hidden-by-default:not(.is-menu-open) {
		display: block;
		width: 100%;
		position: relative;
		z-index: auto;
		background-color: inherit;
	}

	.kt-header__nav .wp-block-navigation__responsive-container.hidden-by-default:not(.is-menu-open) .wp-block-navigation__responsive-container-close,
	.kt-header__nav .wp-block-navigation__responsive-container-open.always-shown {
		display: none;
	}
}

/* Reduced motion: no transitions. Last, so it wins over every transition
   above; the bar's height and its margin must change together, or scroll
   anchoring nudges the page and that reads as a scroll. */
@media (prefers-reduced-motion: reduce) {

	.wp-site-blocks > header.wp-block-template-part,
	.kt-header.wp-block-group,
	.kt-header .wp-block-site-logo img {
		transition: none;
		animation: none;
	}
}
