/*
 * 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.7;
	color: var(--wp--preset--color--black);
}

:root {
	--site-gutter: 60px;
	--prose-cap: 67.5rem;
}

@media (max-width: 767.98px) {
	:root { --site-gutter: 40px; }

	/* `html:root` outranks the `:root` preset block WordPress prints. */
	html:root {
		--wp--preset--font-size--heading-1: 2.1875rem;
		--wp--preset--font-size--display: 2.1875rem;
		--wp--preset--font-size--heading-2: 1.875rem;
	}
}

@media (max-width: 478.98px) {
	:root { --site-gutter: 20px; }
}

/* 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 {
	width: auto;
	height: auto;
}

/* Core's unlayered `.wp-block-image { margin: 0 0 1em }` outranks `@layer base`. */
.wp-block-image {
	margin-bottom: 30px;
}

/* Block, not inline-block: the line box under an inline anchor opens a gap above the caption. */
.wp-block-image > a {
	display: block;
	width: fit-content;
}

/* Text-align control is hidden; unlayered at (0,2,1) to beat core's unlayered `:root .has-text-align-*`. */
:root :is(p, h1, h2, h3, h4, h5, h6):is(
	.has-text-align-left,
	.has-text-align-center,
	.has-text-align-right
) {
	text-align: inherit;
}

@layer base {
	body :is(p, h1, h2, h3, h4, h5, h6, figure) { margin-block: 0 30px; }
	body p:last-child { margin-bottom: 0; }

	body :is(h1, h2, h3, h4, h5, h6) { font-weight: 700; line-height: 1.4; overflow-wrap: break-word; }
	body h1 { font-size: var(--wp--preset--font-size--heading-1); }
	body h2 { font-size: var(--wp--preset--font-size--heading-2); }
	body h3 { font-size: var(--wp--preset--font-size--heading-3); }
	body h4 { font-size: var(--wp--preset--font-size--heading-4); }
	body h5 { font-size: var(--wp--preset--font-size--heading-5); }
	body h6 { font-size: var(--wp--preset--font-size--heading-6); }

	/* Markers hang into the gutter so list text lines up with paragraph text, as on the legacy site. */
	.wp-block-list { margin-block: 0 30px; padding-inline-start: 0; list-style-position: outside; }
	.wp-block-list:where(ul) { list-style-type: disc; }
	.wp-block-list:where(ol) { list-style-type: decimal; }
	.wp-block-list li { margin: 0; }
	.wp-block-list .wp-block-list { margin: 0; padding-inline-start: 1.5em; }

	figcaption { font-size: var(--wp--preset--font-size--small); }

	.wp-block-table th { font-weight: 700; text-align: center; }

	.site-content :is(p, li, td) a { color: var(--wp--preset--color--blue-mid); text-decoration: none; }
	.site-content :is(p, li, td) a:is(:hover, :focus-visible) { text-decoration: underline; }

	:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
}

/* Centred, as the legacy content column; `!important` matches WP's constrained-layout margin rule. */
:is(.wp-block-group, .site-content, .site-content > article) > :is(p, h1, h2, h3, h4, h5, h6, ul, ol, figure, .nomon-buttons, .wsf-form, .search-form) {
	max-width: var(--prose-cap);
	margin-inline: auto !important;
}

/* Legacy 0 0 30 prose rhythm; WP's unlayered block-gap rule (24px top, 0 bottom) beats the layered base. */
.wp-block-group > :is(p, h1, h2, h3, h4, h5, h6, ul, ol, figure, .nomon-buttons, .wsf-form) {
	margin-block: 0 30px;
}

.site-content > .wp-block-group {
	margin-block-start: 0;
}

/* 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: clamp(2rem, 6vw, 4rem);
}

.wp-block-group.has-blue-dark-background-color {
	color: var(--wp--preset--color--white);
}

/* Owl selector leaves the first section flush with the page top. */
.has-global-padding > .wp-block-group + .wp-block-group {
	margin-top: var(--wp--preset--spacing--section);
}

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

	/* 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;
	}

	.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:not([data-type]) {
	display: contents;
}

/* Editor-only: the block wrapper, not the link, is the flex child of `nomon/buttons`. */
[data-type="nomon/button"] {
	display: grid;
}
.nomon-buttons--equal.flex-row > [data-type="nomon/button"] {
	flex: 1 1 0%;
	min-width: 0;
}

[data-type="nomon/hero"]:not(:has(.wp-block)),
[data-type="nomon/service-cards"]:not(:has(.wp-block)) {
	min-height: 4rem;
	outline: 1px dashed currentColor;
}

/* Editor-only: Blockstudio's marker span takes `:first-child`, so the block after it gets a block gap. */
:is(.is-layout-flow, .is-layout-constrained) > [data-blockstudio-render-marker]:first-child + * {
	margin-block-start: 0;
}

/* Editor-only: the front end swaps the `+` glyph for `plus.svg` (inc/integrations/core-blocks.php). */
[data-type="core/accordion-heading"] .wp-block-accordion-heading__toggle-icon {
	position: relative;
	-webkit-text-fill-color: transparent;
}
[data-type="core/accordion-heading"] .wp-block-accordion-heading__toggle-icon::before {
	content: "";
	position: absolute;
	inset: 0;
	background-color: currentColor;
	mask: url("../icons/plus.svg") center / contain no-repeat;
}

/* 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;
}

.post-type-post .edit-post-visual-editor__post-title-wrapper .editor-post-title::before {
	content: "Artikkelin otsikko";
}

.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: 767px;

	--hamburger-color: var(--wp--preset--color--blue-dark);
	--hamburger-color-active: var(--wp--preset--color--blue-dark);
	--hamburger-width: 2rem;
	--hamburger-layer-height: 3px;

	/* Desktop dropdowns */
	--color-main-level: var(--wp--preset--color--white);
	--color-hover-main-level: var(--wp--preset--color--white);
	--color-current: var(--wp--preset--color--white);
	--typography-size-main-level: 1.25rem;
	--typography-weight-main-level: 400;
	--line-height-main-level: 34px;
	--gap-main-level-horizontal: 35px;
	--gap-between-dropdown-toggle: 10px;
	--dropdown-toggle-size: 20px;

	--color-sub-menu: var(--wp--preset--color--blue-dark);
	--color-hover-sub-menu: var(--wp--preset--color--blue-dark);
	--color-background-sub-menu: var(--wp--preset--color--white);
	--color-background-hover-sub-menu: var(--wp--preset--color--blue);
	--typography-size-sub-menu: 1.125rem;
	--typography-weight-sub-menu: 400;
	--line-height-sub-menu-link: 60px;
	--padding-sub-menu-vertical: 0;
	--padding-sub-menu-link-horizontal: 20px;
	--width-sub-menu: max-content;
	--gap-dropdown: 0;

	/* Mobile drawer */
	--width-navigation: 300px;
	--padding-navigation: 30px;
	--color-background-menu-items: var(--wp--preset--color--blue-dark);
	--color-backdrop-nav-mobile: rgb(0 0 0 / 0.5);
	--color-main-level-menu-item-mobile: var(--wp--preset--color--white);
	--color-sub-menu-mobile: var(--wp--preset--color--white);
	--color-dropdown-toggle-mobile: var(--wp--preset--color--white);
	--typography-size-main-level-mobile: 1.1875rem;
	--typography-weight-main-level-mobile: 400;
	--padding-menu-item-mobile: 10px;
	--margin-left-sub-menu: 20px;
	--transition-nav-mobile: 0.3s cubic-bezier(0.77, 0, 0.175, 1);
}

.hamburger {
	display: block;
	width: var(--hamburger-width);
	height: var(--hamburger-layer-height);
	border-radius: 4px;
	background-color: var(--hamburger-color);
	position: relative;
	transition: all 0.3s;
	flex-shrink: 0;
}
.hamburger::before,
.hamburger::after {
	content: "";
	display: block;
	width: var(--hamburger-width);
	height: var(--hamburger-layer-height);
	border-radius: 4px;
	background-color: var(--hamburger-color);
	position: absolute;
	transition: all 0.3s;
}
.hamburger::before { top: -8px; }
.hamburger::after  { bottom: -8px; }

.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: 60px;
	height: 44px;
	margin: 0;
	padding: 10px;
	background: var(--wp--preset--color--white);
	border: 0;
	border-radius: 0;
	cursor: pointer;
	position: relative;
	z-index: 1002;
}

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

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

	body::before {
		content: "";
		position: fixed;
		inset: 0;
		background-color: var(--color-backdrop-nav-mobile);
		opacity: 0;
		visibility: hidden;
		transition: opacity var(--transition-nav-mobile), visibility 0s linear 0.3s;
		z-index: 1000;
	}
	body.js-nav-active::before {
		opacity: 1;
		visibility: visible;
		transition-delay: 0s;
	}

	.nav-primary .menu-items-wrapper {
		position: fixed;
		top: 0;
		left: 0;
		width: var(--width-navigation);
		height: 100dvh;
		padding: var(--padding-navigation);
		background-color: var(--color-background-menu-items);
		transform: translate3d(-100%, 0, 0);
		transition: transform var(--transition-nav-mobile), visibility 0s linear 0.3s;
		visibility: hidden;
		overflow: auto;
		z-index: 1001;
	}
	.js-nav-active .nav-primary .menu-items-wrapper {
		visibility: visible;
		transform: translate3d(0, 0, 0);
		transition-delay: 0s;
	}

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

	.nav-primary .menu-item > :is(a, span) {
		display: block;
		padding: var(--padding-menu-item-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);
		line-height: 1.7;
		text-decoration: none;
	}
	.nav-primary .sub-menu a {
		color: var(--color-sub-menu-mobile);
		padding-left: calc(var(--padding-menu-item-mobile) + var(--margin-left-sub-menu));
	}

	.nav-primary .menu-item-has-children {
		display: flex;
		flex-wrap: wrap;
		align-items: flex-start;
	}
	.nav-primary .menu-item-has-children > :is(a, span) { flex: 1; }
	.nav-primary .menu-item-has-children > .sub-menu { flex-basis: 100%; }

	.nav-primary .dropdown-toggle {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		width: 38px;
		height: 32px;
		margin: 10px 10px 0 0;
		padding: 0;
		background: transparent;
		border: 0;
		color: var(--color-dropdown-toggle-mobile);
		cursor: pointer;
	}
	.nav-primary .dropdown-toggle svg {
		width: 0.75rem;
		height: 0.75rem;
		transition: transform var(--transition-nav-mobile);
		pointer-events: none;
	}
	.nav-primary .dropdown-toggle.toggled-on svg { transform: rotate(180deg); }
}

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

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

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

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

	.nav-primary .menu-item > .nav-link {
		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);
		line-height: var(--line-height-main-level);
		white-space: nowrap;
		text-decoration: none;
	}
	.nav-primary .menu-items > .menu-item:is(:hover, :focus-within) > .nav-link {
		color: var(--color-hover-main-level);
		text-decoration: underline;
	}

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

	.nav-primary .sub-menu {
		position: absolute;
		top: 100%;
		left: 0;
		width: var(--width-sub-menu);
		margin: var(--gap-dropdown) 0 0;
		padding-block: var(--padding-sub-menu-vertical);
		padding-inline: 0;
		list-style: none;
		background-color: var(--color-background-sub-menu);
		opacity: 0;
		visibility: hidden;
		transition: opacity 0.1s, visibility 0.1s;
		z-index: 9;
	}
	.nav-primary .sub-menu.is-out-of-viewport { left: auto; right: 0; }

	.nav-primary .menu-item .sub-menu a {
		display: block;
		color: var(--color-sub-menu);
		font-size: var(--typography-size-sub-menu);
		font-weight: var(--typography-weight-sub-menu);
		line-height: var(--line-height-sub-menu-link);
		padding-inline: var(--padding-sub-menu-link-horizontal);
		text-decoration: none;
		white-space: nowrap;
	}
	.nav-primary .menu-item .sub-menu a:is(:hover, :focus-visible) {
		color: var(--color-hover-sub-menu);
		background-color: var(--color-background-hover-sub-menu);
	}

	/* :hover for mouse, :focus-within for keyboard, .hover-intent (JS) to keep the menu
	 * open briefly after the cursor leaves and absorb stray movement. */
	.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;
	}

	/* Decorative for the mouse; keyboard focus on it opens the panel via :focus-within. */
	.nav-primary .dropdown-toggle {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		padding: 0;
		background: transparent;
		border: 0;
		color: var(--color-main-level);
		pointer-events: none;
	}
	.nav-primary .dropdown-toggle svg {
		width: var(--dropdown-toggle-size);
		height: var(--dropdown-toggle-size);
	}
}

/* WS Form. The Styler prints its variables on `:where([data-wsf-style-id])`, so these win
 * without `!important`; element rules only where WS Form has no variable. */
.wsf-form {
	--wsf-form-color-primary: var(--wp--preset--color--blue-mid);
	--wsf-form-color-accent: var(--wp--preset--color--blue-mid);
	--wsf-form-font-size: 1rem;
	--wsf-form-font-size-small: 0.875rem;
	--wsf-section-legend-font-size: var(--wp--preset--font-size--heading-3);
	--wsf-section-legend-font-weight: 700;
	--wsf-section-legend-gap: 25px;
	--wsf-field-label-font-size: var(--wp--preset--font-size--heading-6);
	--wsf-field-label-gap: 10px;
	--wsf-field-border-radius: 0;
	--wsf-field-box-shadow-color-focus: rgb(10 99 172 / 25%);
	--wsf-field-color-placeholder: var(--wp--preset--color--grey);
	--wsf-field-button-font-size: var(--wp--preset--font-size--heading-6);
	--wsf-field-button-font-weight: 700;
	--wsf-field-button-color: var(--wp--preset--color--white);
	--wsf-field-button-color-hover: var(--wp--preset--color--white);
	--wsf-field-button-color-focus: var(--wp--preset--color--white);
	--wsf-field-button-color-background: var(--wp--preset--color--blue-mid);
	--wsf-field-button-color-background-hover: var(--wp--preset--color--blue-mid);
	--wsf-field-button-color-background-focus: var(--wp--preset--color--blue-mid);
	--wsf-field-button-border-color: var(--wp--preset--color--blue-mid);
	--wsf-field-button-border-color-hover: var(--wp--preset--color--blue-mid);
	--wsf-field-button-border-color-focus: var(--wp--preset--color--blue-mid);
	--wsf-field-button-danger-color-background: var(--wp--preset--color--blue-mid);
	--wsf-field-button-danger-color-background-hover: var(--wp--preset--color--blue-mid);
	--wsf-field-button-danger-color-background-focus: var(--wp--preset--color--blue-mid);
	--wsf-field-button-danger-border-color: var(--wp--preset--color--blue-mid);
	--wsf-field-button-danger-border-color-hover: var(--wp--preset--color--blue-mid);
	--wsf-field-button-danger-border-color-focus: var(--wp--preset--color--blue-mid);
}

/* Legacy look; WS Form only dims the enabled colours. Disabled controls are exempt from contrast. */
.wsf-form .wsf-button-danger:disabled {
	--wsf-field-button-danger-color-background: var(--wp--preset--color--white);
	--wsf-field-button-danger-border-color: var(--wp--preset--color--black);
	--wsf-field-button-danger-color: var(--wp--preset--color--black);
}

.wsf-form [data-row-checkbox] .wsf-label {
	font-size: var(--wp--preset--font-size--small);
}

.wsf-form .wsf-label {
	overflow-wrap: break-word;
}

.wsf-form .wsf-button:is(:hover, :focus-visible) {
	text-decoration: underline;
}

/* Doubled class outranks WS Form's `.wsf-form button.wsf-button:focus { outline: 0 }`. */
.wsf-form .wsf-button.wsf-button:focus-visible {
	outline: 2px solid var(--wp--preset--color--blue-mid);
	outline-offset: 2px;
}
