/*
 * Nomon Theme — base stylesheet, loaded on the frontend and inside the editor iframe.
 *
 * Tailwind handles reset and utilities; this file owns only what utilities can't express.
 * Responsibilities and the cascade smoke-test: docs/styling.md.
 */

/* Up front so layer order doesn't depend on when Blockstudio's inline style loads. Holds
 * only while Blockstudio emits layered utilities — smoke-test in docs/styling.md. */
@layer theme, base, components, utilities;

/* Unlayered on purpose: wrapping this ties with preflight's `body { line-height: inherit }`. */
body {
	font-size: var(--wp--preset--font-size--regular);
	line-height: 1.45;
	/* Live prose runs the full content width. */
	--prose-cap: 1060px;
}

/* Registered so `ch` resolves against body's font here, not per heading at the point of use. */
@property --prose-cap { syntax: "<length>"; inherits: true; initial-value: 0px; }

/* WP's `size-full` marker collides with Tailwind's utility of that name; unlayered on
 * purpose so it beats the layered utility. See docs/styling.md. */
.wp-block-image.size-full {
	height: auto;
}

@layer base {
	body p { margin-block: 0 10px; }
	body figure { margin-block: 3rem; }

	body :is(h1, h2, h3, h4, h5, h6) { font-weight: 700; }

	body h1 { font-size: var(--wp--preset--font-size--heading-1); line-height: 1.2; margin-block: 0 40px; text-transform: uppercase; width: fit-content; }
	body h1::after { content: ""; display: block; height: 5px; background: var(--wp--preset--color--green); }
	body h2 { font-size: var(--wp--preset--font-size--heading-2); line-height: 1.4; margin-block: 20px 10px; text-transform: uppercase; }
	body :is(h3, .is-style-lead, h2.is-style-green) {
		font-size: var(--wp--preset--font-size--heading-3);
		font-weight: 300;
		line-height: 1.4;
		text-transform: none;
		color: var(--wp--preset--color--green);
		margin-block: 40px 10px;
	}
	.has-slate-background-color .is-style-lead { color: var(--wp--preset--color--white); }

	body :is(strong, b) { font-weight: 400; }

	body p a { color: var(--wp--preset--color--green-dark); }
	.wp-block-list a { color: var(--wp--preset--color--green); }
	body :is(p, .wp-block-list) a { font-weight: 400; text-decoration: none; }
	body :is(p, .wp-block-list) a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
	/* Live underlines every content link in the darker green, even the lighter list links. */
	body :is(p:not(.is-style-lead), .wp-block-list) a:is(:hover, :focus-visible) { text-decoration: underline; text-decoration-color: var(--wp--preset--color--green-dark); }
	body .is-style-lead a { color: inherit; font-weight: 300; text-decoration: underline; }

	/* Stacked headings: any heading directly following another collapses its top margin. */
	body :is(h1, h2, h3, h4, h5, h6) + :is(h1, h2, h3, h4, h5, h6) { margin-top: 0; }

	/* core/list block: restore bullets/numbers and indent that Tailwind preflight zeroes. */
	.wp-block-list { margin-block: 0 10px; padding-inline-start: 40px; }
	.wp-block-list:where(ul) { list-style: disc; }
	.wp-block-list:where(ol) { list-style: decimal; }
	.wp-block-list :where(li > *) { margin-block: 0.5rem; }
	.wp-block-list :where(li > :first-child) { margin-top: 0; }
	.wp-block-list :where(li > :last-child)  { margin-bottom: 0; }

	/* First/last reset: heading at top of a section, paragraph at end, don't push the container. */
	body :is(h1, h2, h3, h4, h5, h6, .is-style-lead):first-child { margin-top: 0; }
	/* Live keeps h2's 20px top margin after the page header; padding because the margin would collapse. */
	.page-header + .wp-block-group:has(> h2:first-child) { padding-top: 20px; }
	body p:last-child { margin-bottom: 0; }
}

/* Prose cap; descendant selector so prose inside a nested group is capped too. */
.wp-block-group :is(p, h1, h2, h3, h4, h5, h6, ul, ol),
.site-content > :is(p, h1, h2, h3, h4, h5, h6, ul, ol) {
	max-width: var(--prose-cap);
	/* Pins prose to the contentSize start edge however wide the parent is;
	 * `!important` beats WP's `.is-layout-constrained > * { margin-inline: auto !important }`. */
	margin-inline-start: max(
		0px,
		calc((100% - var(--wp--style--global--content-size)) / 2)
	) !important;
}

/* `blockGap` is null in theme.json so prose margins apply; columns get live's 40px back here. */
.wp-block-columns {
	gap: 40px;
}

/* Auto-bleed, mirroring native `.alignfull`; `!important` matches WP's own margin rule. */
.has-global-padding > .wp-block-group.has-background {
	max-width: none;
	margin-left: calc(var(--wp--style--root--padding-left) * -1) !important;
	margin-right: calc(var(--wp--style--root--padding-right) * -1) !important;
	padding-left: var(--wp--style--root--padding-left);
	padding-right: var(--wp--style--root--padding-right);
}

/* Spacing controls are disabled in theme.json, so colored sections need a default. */
.wp-block-group.has-background {
	padding-block: 60px;
}

.wp-block-group.has-white-background-color {
	padding-block: 80px;
}

/* Descendants inherit this; add a sibling rule per dark swatch as the palette grows. */
.wp-block-group.has-slate-background-color {
	color: var(--wp--preset--color--white);
}

/* Duplo gap; the owl selector leaves the first section flush with the page top. Scoped to
 * duplo blocks only — add block names when composite blocks join. */
.has-global-padding > .wp-block-group + .wp-block-group,
.has-global-padding > .nomon-image-band + .wp-block-group:not(.has-background) {
	margin-top: 75px;
}

p + .nomon-buttons {
	margin-top: 40px;
}

.site-content:has(> .nomon-service-cards:last-child) {
	padding-bottom: 20px;
}

.wp-block-group.is-style-centered {
	text-align: center;
}

/* SEOPress prints no separator markup, and TailwindPHP drops `content-['/']`. */
.site-breadcrumbs li:not(:last-child)::after {
	content: "/";
	margin-inline: 0.25rem;
	color: var(--wp--preset--color--grey);
}

.site-breadcrumbs {
	font-weight: 400;
}

.site-breadcrumbs a {
	color: var(--wp--preset--color--green-dark);
	text-decoration: none;
}

.site-breadcrumbs a:is(:hover, :focus-visible) {
	text-decoration: underline;
}

@layer base {
	html {
		scroll-padding-top: var(--scroll-offset, 2rem);
	}

	@media (prefers-reduced-motion: no-preference) {
		html { scroll-behavior: smooth; }
	}

	body {
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	/* Gutenberg can't hide these toolbar buttons, so cancel the effect instead. */
	:where(h1, h2, h3, h4, h5, h6) :is(strong, b, em, i) {
		font-weight: inherit;
		font-style: inherit;
	}

	/* Same reason as above; the editor iframe loads this file too, so preview matches. */
	:is(p, h1, h2, h3, h4, h5, h6):is(
		.has-text-align-left,
		.has-text-align-center,
		.has-text-align-right
	) {
		text-align: inherit;
	}

	.screen-reader-text {
		border: 0;
		clip-path: inset(50%);
		height: 1px;
		margin: -1px;
		overflow: hidden;
		padding: 0;
		position: absolute;
		width: 1px;
		word-wrap: normal !important;
	}

	.skip-link:focus {
		clip-path: none;
		height: auto;
		margin: 0;
		overflow: auto;
		padding: 1rem;
		position: absolute;
		inset-block-start: 0;
		inset-inline-start: 0;
		width: auto;
		z-index: 100000;
		background: #000;
		color: #fff;
		text-decoration: underline;
	}

	/* WCAG 2.4.4: per-site CSS may restyle or hide the glyph, never the screen-reader text. */
	a.is-external-link::after,
	a.is-new-window::after {
		content: " ↗";
		display: inline-block;
		font-size: 0.85em;
		vertical-align: super;
		line-height: 1;
	}
	a.is-new-window::after {
		content: " ⧉";
	}
	a.is-external-link.is-new-window::after {
		content: " ⧉";
	}

	/* Hides the glyph in the footer and credit bar only; the screen-reader text stays. */
	:is(.site-footer, .nomon_footer) a.is-external-link::after,
	:is(.site-footer, .nomon_footer) a.is-new-window::after,
	:is(.site-footer, .nomon_footer) a.is-external-link.is-new-window::after {
		content: none;
	}
}

/* Critical Swiper layout before the lazy vendor CSS lands. No pre-init `visibility: hidden`
 * — that hid the hero from FlyingPress's above-the-fold pass, costing the LCP preload. */
.swiper { overflow: hidden; }
.swiper-wrapper { display: flex; }
.swiper-slide { flex-shrink: 0; width: 100%; }
/* Overrides FlyingPress Lazy Render's inline style — see docs/runtimes.md. */
.swiper-slide,
.swiper-slide * { content-visibility: visible !important; }

/* Editor-only: flattens Gutenberg's InnerBlocks wrapper chain, which breaks parent flex/grid.
 * Unlayered to outrank editor styles; descendant combinators because `useBlockProps` shifts a level. */
[data-type^="nomon/"] .block-editor-inner-blocks,
[data-type^="nomon/"] .block-editor-block-list__layout {
	display: contents;
}

/* Editor-only: a drag saves the box's computed `aspectRatio`, which the ratio dropdown
 * cannot display or clear (`docs/integrations.md`). Selector length beats the components
 * stylesheet's own `.has-show-handle` rule at (0,3,0). */
[data-type="core/image"] .components-resizable-box__container.has-show-handle .components-resizable-box__handle {
	display: none;
}

/* Editor-only: makes the post title read as page metadata, not the first H1. No negative
 * inline margin needed — `useRootPaddingAwareAlignments` leaves body itself unpadded. */
/* WP core's editor styles add a top padding to the iframe body; zero it. */
body {
	padding-top: 0;
}

.edit-post-visual-editor__post-title-wrapper {
	background-color: #f0f0f0;
	color: #1e1e1e;
	margin-block-start: 0 !important;
	margin-block-end: 3rem;
	padding-inline: var(--wp--style--root--padding-left, clamp(1rem, 5vw, 5rem));
}

.edit-post-visual-editor__post-title-wrapper .editor-post-title {
	color: inherit;
	margin: 0 auto;
	max-width: var(--wp--style--global--content-size, 1440px);
	padding-block: 3rem;
}

.edit-post-visual-editor__post-title-wrapper .editor-post-title::before {
	content: "Sivun otsikko";
	display: block;
	color: #666;
	font-size: 0.875rem;
	font-weight: 500;
	margin-block-end: 0.75rem;
}

.edit-post-visual-editor__post-title-wrapper .editor-post-title [data-rich-text-placeholder]::after {
	color: #666;
	opacity: 1;
}

:root {
	/* Must stay numeric: JS reads it via getComputedStyle for matchMedia. */
	--breakpoint-nav: 768px;

	/* Forks that switch to a full-overlay drawer should set --hamburger-color-active light. */
	--hamburger-color: var(--wp--preset--color--white);
	--hamburger-color-active: var(--wp--preset--color--white);
	--hamburger-width: 1.75rem;
	--hamburger-layer-height: 3px;

	/* Desktop dropdowns */
	--color-main-level: var(--wp--preset--color--white);
	--color-hover-main-level: var(--wp--preset--color--green);
	--color-current: var(--wp--preset--color--green);
	--typography-size-main-level: 1.25rem;
	--typography-weight-main-level: 400;
	--padding-main-level-vertical: 0.875rem;
	--gap-main-level-horizontal: 0;
	--gap-between-dropdown-toggle: 0;
	--dropdown-toggle-size: 0.875rem;

	--color-sub-menu: var(--wp--preset--color--white);
	--color-hover-sub-menu: var(--wp--preset--color--green);
	--color-background-sub-menu: var(--wp--preset--color--slate);
	--typography-size-sub-menu: 1rem;
	--typography-weight-sub-menu: 400;
	--padding-sub-menu-vertical: 0;
	--padding-sub-menu-link-vertical: 0.875rem;
	--padding-sub-menu-link-horizontal: 0.875rem;
	--width-sub-menu: 13.75rem;
	--gap-dropdown: 0.6875rem;

	/* Mobile drawer */
	--width-navigation: 100vw;
	--color-background-menu-items: var(--wp--preset--color--slate);
	--color-separator-nav-mobile: transparent;
	--color-main-level-menu-item-mobile: var(--wp--preset--color--white);
	--color-main-level-menu-item-hover-focus-mobile: var(--wp--preset--color--green);
	--color-sub-menu-mobile: var(--wp--preset--color--white);
	--color-current-menu-item: var(--wp--preset--color--green);
	--color-dropdown-toggle-mobile: var(--wp--preset--color--white);
	--typography-size-main-level-mobile: 1.25rem;
	--typography-weight-main-level-mobile: 400;
	--padding-main-level-vertical-mobile: 0.875rem;
	--typography-size-sub-menu-mobile: 1rem;
	--typography-weight-sub-menu-mobile: 400;
	--margin-left-sub-menu: 0;
	--padding-sub-menu-vertical-mobile: 0.875rem;
	--padding-sub-menu-horizontal-mobile: var(--wp--style--root--padding-left, clamp(1rem, 5vw, 5rem));
}

.hamburger {
	display: block;
	width: var(--hamburger-width);
	height: var(--hamburger-layer-height);
	background-color: var(--hamburger-color);
	position: relative;
	transition: all 0.2s ease 0s;
	flex-shrink: 0;
}
.hamburger::before,
.hamburger::after {
	content: "";
	display: block;
	width: var(--hamburger-width);
	height: var(--hamburger-layer-height);
	background-color: var(--hamburger-color);
	position: absolute;
	transition: all 0.2s ease 0s;
}
.hamburger::before { top: -0.5625rem; }
.hamburger::after  { bottom: -0.5625rem; }

body:not(.js-nav-active) .nav-toggle .hamburger::after,
body:not(.js-nav-active) .nav-toggle:focus .hamburger::after { width: 80%; }
body:not(.js-nav-active) .nav-toggle:hover .hamburger::after { width: 100%; }

.js-nav-active .hamburger { background-color: transparent; }
.js-nav-active .hamburger::before,
.js-nav-active .hamburger::after {
	background-color: var(--hamburger-color-active);
	left: 0;
	top: 0;
}
.js-nav-active .hamburger::before { transform: rotate(-45deg); }
.js-nav-active .hamburger::after  { transform: rotate(45deg); }

.nav-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 3.125rem;
	height: 3.125rem;
	margin: 0;
	padding: 0;
	background: transparent;
	border: 0;
	border-radius: 0;
	cursor: pointer;
	position: relative;
	z-index: 99999;
}

body.js-nav-active { overflow: hidden; }

@media (max-width: 768px) {
	.nav-primary .menu-items ul { display: none; }
	.nav-primary ul .sub-menu.toggled-on { display: block; }

	.nav-primary { align-self: center; }

	.site-header ul,
	.site-header li,
	.site-header a { position: relative; }

	.nav-primary .menu-items-wrapper {
		position: fixed;
		top: 0;
		right: 0;
		width: var(--width-navigation);
		height: calc(100dvh - 7.2rem); /* JS recalculates from actual header height */
		background-color: var(--color-background-menu-items);
		transform: translate3d(100%, 0, 0);
		transition: transform 220ms cubic-bezier(0.19, 1, 0.22, 1), opacity 180ms ease-in-out;
		opacity: 0;
		visibility: hidden;
		pointer-events: none;
		overflow: auto;
		padding-bottom: 7.5rem;
		backface-visibility: hidden;
		z-index: 5;
	}

	.nav-primary .menu-items { margin: 0; padding: 0; list-style: none; }
	.nav-primary .menu-item  { margin: 0; }

	.nav-primary .menu-item a {
		display: block;
		padding-block: var(--padding-main-level-vertical-mobile);
		padding-inline: var(--padding-sub-menu-horizontal-mobile);
		border-top: 1px solid var(--color-separator-nav-mobile);
		color: var(--color-main-level-menu-item-mobile);
		font-size: var(--typography-size-main-level-mobile);
		font-weight: var(--typography-weight-main-level-mobile);
		text-decoration: none;
		position: relative;
		z-index: 0;
	}
	.nav-primary .menu-item a:hover,
	.nav-primary .menu-item a:focus { color: var(--color-main-level-menu-item-hover-focus-mobile); }
	.nav-primary .menu-item > a[aria-current="page"] {
		color: var(--color-current-menu-item);
		text-decoration: underline;
	}

	.nav-primary .menu-item a { text-align: right; line-height: 1; }
	.nav-primary .menu-item-has-children {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-end;
	}
	.nav-primary .menu-item-has-children > .sub-menu { flex-basis: 100%; }
	.nav-primary .menu-item-has-children > a { padding-right: 0; }

	.nav-primary .sub-menu { margin: 0; padding: 0; list-style: none; }
	.nav-primary .sub-menu a {
		color: var(--color-sub-menu-mobile);
		font-size: var(--typography-size-sub-menu-mobile);
		font-weight: var(--typography-weight-sub-menu-mobile);
		padding-block: var(--padding-sub-menu-vertical-mobile);
		padding-left: calc(var(--padding-sub-menu-horizontal-mobile) + var(--margin-left-sub-menu));
	}
	.nav-primary .sub-menu .sub-menu a {
		padding-left: calc(var(--padding-sub-menu-horizontal-mobile) + var(--margin-left-sub-menu) * 2);
	}

	.nav-primary .dropdown-toggle {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		overflow: hidden;
		padding-block: var(--padding-sub-menu-vertical-mobile);
		padding-left: var(--padding-sub-menu-horizontal-mobile);
		padding-right: calc(var(--padding-sub-menu-horizontal-mobile) - calc(var(--dropdown-toggle-size) / 2));
		background: transparent;
		border: 0;
		color: var(--color-dropdown-toggle-mobile);
		cursor: pointer;
		z-index: 100;
	}
	.nav-primary .dropdown-toggle svg {
		width: var(--dropdown-toggle-size);
		height: var(--dropdown-toggle-size);
		transition: transform 150ms;
		pointer-events: none;
	}
	.nav-primary .dropdown-toggle.toggled-on svg { transform: rotate(180deg); }
	.nav-primary .sub-menu .dropdown-toggle { color: var(--color-sub-menu-mobile); }

	.js-nav-active .nav-primary .menu-items-wrapper {
		opacity: 1;
		visibility: visible;
		pointer-events: auto;
		transform: translate3d(0, 0, 0);
	}
}

@media (max-width: 782px) {
	.logged-in.admin-bar .nav-primary .menu-items-wrapper { margin-top: 46px; }
}

@media (min-width: 769px) {
	.nav-toggle { display: none; }

	.nav-primary { line-height: 0; padding-block: 0; }

	.nav-primary .menu-items {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: flex-end;
		column-gap: var(--gap-main-level-horizontal);
		row-gap: 0.625rem;
		margin: 0;
		padding: 0;
		list-style: none;
		position: relative;
	}

	.nav-primary .menu-item { margin: 0; position: relative; }

	.nav-primary .menu-item > a {
		display: inline-flex;
		align-items: center;
		color: var(--color-main-level);
		font-size: var(--typography-size-main-level);
		font-weight: var(--typography-weight-main-level);
		padding-block: var(--padding-main-level-vertical);
		white-space: nowrap;
		text-decoration: none;
	}
	.nav-primary .menu-item > a:hover,
	.nav-primary .menu-item > a:focus { color: var(--color-hover-main-level); }
	.nav-primary .menu-item > a[aria-current="page"] {
		color: var(--color-current);
		text-decoration: underline;
	}
	.nav-primary .menu-items > .menu-item > a { padding-inline: 0.875rem; }
	.nav-primary .menu-items > .menu-item-has-children > a { padding-right: 3px; }

	.nav-primary .menu-item.menu-item-has-children {
		display: flex;
		align-items: center;
		justify-content: space-between;
		gap: var(--gap-between-dropdown-toggle);
	}

	/* Bridges the menu-item/submenu gap so hover survives the empty space; only present
	 * while hovered, so it doesn't capture clicks at rest. */
	.nav-primary .menu-item.menu-item-has-children::after {
		content: "";
		display: block;
		position: absolute;
		top: 100%;
		width: 100%;
		max-width: var(--width-sub-menu);
		height: var(--gap-dropdown);
		visibility: hidden;
	}
	.nav-primary .menu-item.menu-item-has-children.hover-intent::after {
		visibility: visible;
		z-index: 100;
	}
	.nav-primary .sub-menu .menu-item-has-children::after { display: none; }

	.nav-primary .sub-menu {
		position: absolute;
		top: 100%;
		left: 0;
		width: var(--width-sub-menu);
		margin: 0;
		margin-top: var(--gap-dropdown);
		padding: 0;
		list-style: none;
		background-color: var(--color-background-sub-menu);
		box-shadow: 0 1px 20px rgba(0, 0, 0, 0.1);
		opacity: 0;
		visibility: hidden;
		z-index: 9;
	}
	.nav-primary .sub-menu .sub-menu {
		top: 0;
		left: 100%;
		margin-top: calc(-1 * var(--padding-sub-menu-vertical));
	}

	.nav-primary .sub-menu.is-out-of-viewport { left: auto; right: 0; }
	.nav-primary .sub-menu.is-out-of-viewport .sub-menu,
	.nav-primary .sub-menu .sub-menu.is-out-of-viewport { left: auto; right: 100%; }

	.nav-primary .menu-item .sub-menu a {
		display: inline-flex;
		align-items: center;
		width: 100%;
		color: var(--color-sub-menu);
		font-size: var(--typography-size-sub-menu);
		font-weight: var(--typography-weight-sub-menu);
		line-height: 1;
		padding-block: var(--padding-sub-menu-link-vertical);
		padding-inline: var(--padding-sub-menu-link-horizontal);
		text-decoration: none;
		white-space: normal;
	}
	.nav-primary .menu-item .sub-menu a:hover,
	.nav-primary .menu-item .sub-menu a:focus {
		color: var(--color-hover-sub-menu);
	}
	.nav-primary .menu-item .sub-menu a[aria-current="page"] {
		color: var(--color-current);
		text-decoration: underline;
	}

	/* :hover for mouse, :focus-within for keyboard, .hover-intent (JS) for the hover bridge;
	 * .is-dismissed (Escape) wins until focus or the pointer leaves the item. */
	.nav-primary .menu-item-has-children:hover > .sub-menu,
	.nav-primary .menu-item-has-children:focus-within > .sub-menu,
	.nav-primary .menu-item-has-children.hover-intent > .sub-menu {
		opacity: 1;
		visibility: visible;
		z-index: 12;
	}
	.nav-primary .menu-item-has-children.is-dismissed > .sub-menu {
		opacity: 0;
		visibility: hidden;
	}

	/* Dropdown toggle on desktop is decorative — pointer-events: none lets
	 * clicks fall through to the parent <a>. The chevron is live's static CSS one. */
	.nav-primary .dropdown-toggle {
		position: relative;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		padding: 0;
		background: transparent;
		border: 0;
		color: var(--color-main-level);
		pointer-events: none;
		/* WCAG 2.5.8 24px target; the link's 3px padding keeps live's chevron position. */
		min-width: 24px;
		min-height: 24px;
	}
	.nav-primary .dropdown-toggle svg { display: none; }
	.nav-primary .dropdown-toggle::before {
		content: "";
		position: absolute;
		top: 50%;
		right: 50%;
		width: 9px;
		height: 9px;
		margin: -5px -5px 0 0;
		border-right: 2px solid;
		border-bottom: 2px solid;
		transform-origin: right bottom;
		transform: translateX(-5px) rotate(45deg);
	}
	.nav-primary .sub-menu .dropdown-toggle::before { transform: translateY(-5px) rotate(-45deg); }
}

.site-header :focus-visible {
	outline: 2px solid var(--wp--preset--color--white);
	outline-offset: 2px;
}

/* Live tucks the top 20px of the home hero under the solid tablet header. */
@media (min-width: 769px) and (max-width: 991px) {
	.home .site-header {
		position: relative;
		z-index: 100;
		margin-bottom: -20px;
	}
}

@media (min-width: 992px) {
	.home .site-header {
		position: absolute;
		inset-inline: 0;
		top: var(--wp-admin--admin-bar--height, 0px);
		z-index: 100;
		background-color: transparent;
	}
}
