/**
 * meta-consent — styling for the Klaro consent UI (no-css build).
 *
 * Skinning model: every visual value is a `--mc-*` custom property (the styling
 * API). Their defaults map to the active theme's theme.json presets
 * (`--wp--preset--color--*`, `--wp--preset--font-size--*`,
 * `--wp--preset--spacing--*`, using the MCDS / Meta Web Platform slugs), with
 * neutral greyscale fallbacks, so the UI takes on the site's design system and
 * stays legible where a preset is missing. No brand colour is hard-coded here.
 *
 * Per-site choices (a theme's button weight, hover treatment, …) override the
 * `--mc-*` vars via the `meta_consent_theme` filter (name => value), or inject
 * extra rules via `meta_consent_custom_css`. See README "Skinning".
 *
 * Equal prominence (EU): Accept and Decline share one button role, in the notice
 * and the modal, so refusing is exactly as prominent as accepting. Only "Save
 * choices" is secondary. Don't style Decline separately.
 *
 * Selectors target Klaro 0.7.x DOM classes (validated against the vendored
 * no-css build): cookie-notice / cookie-modal / cm-* / cn-* / slider.
 */

.klaro {
	/* Palette */
	--mc-bg:               var( --wp--preset--color--background-surface-1, #ffffff );
	--mc-heading:          var( --wp--preset--color--text-primary, #111111 );
	--mc-text:             var( --wp--preset--color--text-primary, #111111 );
	--mc-muted:            var( --wp--preset--color--text-secondary, #555555 );
	--mc-border:           var( --wp--preset--color--border-default, #dddddd );
	--mc-border-strong:    var( --wp--preset--color--border-interactive, #767676 );
	--mc-link:             var( --wp--preset--color--interactive-text, #111111 );
	--mc-link-hover:       var( --wp--preset--color--interactive-hover, #333333 );
	--mc-link-weight:      inherit;
	--mc-focus:            var( --wp--preset--color--interactive-pressed, #111111 );
	--mc-scrim:            color-mix( in srgb, var( --wp--preset--color--background-inverse, #000000 ) 55%, transparent );

	/* Buttons. Primary: Accept and Decline (equal prominence). Secondary: Save. */
	--mc-accent:           var( --wp--preset--color--interactive-primary, #111111 );
	--mc-accent-text:      var( --wp--preset--color--text-always-white, #ffffff );
	--mc-accent-border:    var( --mc-accent );
	--mc-accent-hover:     var( --wp--preset--color--interactive-hover, #333333 );
	--mc-accent-hover-text: var( --mc-accent-text );
	--mc-accent-hover-border: var( --mc-accent-hover );
	--mc-btn-bg:           var( --mc-bg );
	--mc-btn-text:         var( --mc-link );
	--mc-btn-border:       var( --mc-border-strong );
	--mc-btn-hover-text:   var( --mc-link-hover );
	--mc-btn-border-width: 1px;
	--mc-btn-weight:       var( --mc-fw-medium );
	--mc-btn-fs:           var( --mc-fs-body );
	--mc-btn-lh:           var( --mc-lh-body );
	--mc-btn-tracking:     normal;
	--mc-btn-pad:          var( --mc-space-sm ) calc( var( --mc-space-md ) + var( --mc-space-xs ) );

	/* Toggles (WCAG 1.4.11: 3:1 against the modal background). Off is a neutral
	   outlined track, so it never reads as pre-ticked; on is the theme's
	   interactive colour; locked (required) is muted on. */
	--mc-knob:             var( --wp--preset--color--background-surface-1, #ffffff );
	--mc-toggle-on:        var( --mc-accent );
	--mc-toggle-off-line:  var( --wp--preset--color--text-secondary, #555555 );
	--mc-toggle-off-fill:  var( --mc-bg );
	--mc-toggle-locked:    var( --wp--preset--color--interactive-disabled, #cccccc );
	--mc-toggle-focus:     var( --mc-focus );

	/* Shape, depth, type */
	--mc-radius:           16px;
	--mc-btn-radius:       999px;
	--mc-shadow:           var( --wp--preset--shadow--natural, 0 8px 24px rgba( 0, 0, 0, 0.16 ) );
	--mc-font:             inherit;
	--mc-fs-body:          var( --wp--preset--font-size--md, 1rem );
	--mc-fs-sm:            var( --wp--preset--font-size--sm, 0.875rem );
	--mc-fs-title:         var( --wp--preset--font-size--lg, 1.5rem );
	--mc-lh-body:          1.5;
	--mc-lh-title:         1.25;
	--mc-tracking:         normal; /* body text letter-spacing */
	--mc-fw-regular:       400;
	--mc-fw-medium:        500;
	--mc-fw-title:         var( --mc-fw-medium );

	/* Spacing */
	--mc-space-xs:         var( --wp--preset--spacing--xs, 4px );
	--mc-space-sm:         var( --wp--preset--spacing--sm, 8px );
	--mc-space-md:         var( --wp--preset--spacing--md, 16px );
	--mc-space-lg:         var( --wp--preset--spacing--lg, 24px );
	--mc-gap:              calc( var( --mc-space-sm ) + var( --mc-space-xs ) );
	--mc-pad:              var( --mc-space-lg );
	--mc-inset:            var( --mc-space-md ); /* notice distance from the viewport edge */

	font-family: var( --mc-font );
	color: var( --mc-text );
	font-size: var( --mc-fs-body );
	line-height: var( --mc-lh-body );
	letter-spacing: var( --mc-tracking );
}

/* One text style for all consent copy (notice text, modal intro, category
   titles and descriptions): the page's body text. Set on the elements, so a
   theme's own paragraph rules can't make the notice and the modal differ. */
.klaro .cookie-notice .cn-body p,
.klaro .cookie-modal .cm-header p:not( .title ),
.klaro .cm-list-title,
.klaro .cm-list-description {
	font-size: var( --mc-fs-body );
	line-height: var( --mc-lh-body );
	letter-spacing: var( --mc-tracking );
}

/* One heading style for the notice heading and the modal title. */
.klaro .cookie-notice .cn-body h2,
.klaro .cookie-modal .cm-header h1,
.klaro .cookie-modal .cm-header .title {
	color: var( --mc-heading );
	font-size: var( --mc-fs-title );
	font-weight: var( --mc-fw-title );
	line-height: var( --mc-lh-title );
}

/* Links are underlined: the Cookie Policy link sits inside body text, so colour
   alone would not distinguish it (WCAG 1.4.1). */
.klaro a,
.klaro .cm-link,
.klaro .cm-caret,
.klaro .cm-services-toggle {
	color: var( --mc-link );
	font-weight: var( --mc-link-weight );
	text-decoration: underline;
	text-underline-offset: 2px;
}

.klaro a:hover,
.klaro .cm-link:hover,
.klaro .cm-caret:hover,
.klaro .cm-services-toggle:hover {
	color: var( --mc-link-hover );
}

.klaro a:focus-visible {
	outline: 2px solid var( --mc-focus );
	outline-offset: 2px;
	border-radius: 2px;
}

/* ------------------------------------------------------------------ Notice */
.klaro .cookie-notice {
	position: fixed;
	left: var( --mc-inset );
	right: var( --mc-inset );
	bottom: var( --mc-inset );
	z-index: 1000;
	display: flex;
	flex-direction: column;
	max-width: 720px;
	max-height: calc( 100vh - 2 * var( --mc-inset ) );
	max-height: calc( 100dvh - 2 * var( --mc-inset ) );
	margin-inline: auto;
	padding: var( --mc-pad );
	background: var( --mc-bg );
	color: var( --mc-text );
	border: 1px solid var( --mc-border );
	border-radius: var( --mc-radius );
	box-shadow: var( --mc-shadow );
}

/* Klaro focuses the notice/modal on open; suppress the default browser ring on
   these non-interactive containers (controls inside keep their focus styles). */
.klaro .cookie-notice:focus,
.klaro .cookie-notice:focus-visible,
.klaro .cookie-modal .cm-modal:focus,
.klaro .cookie-modal .cm-modal:focus-visible {
	outline: none;
}

.klaro .cookie-notice .cn-body {
	display: flex;
	flex-direction: column;
	min-height: 0;
	margin: 0;
}

/* The copy scrolls inside the notice if the viewport is too short for it (small
   phones, landscape, zoomed text); the heading and buttons stay visible. It holds
   the Cookie Policy link, so the region is reachable by keyboard. */
.klaro .cookie-notice .cn-body p {
	flex: 0 1 auto;
	min-height: 3lh;
	margin: 0 0 var( --mc-gap );
	overflow-y: auto;
}

/* Notice heading (consentNotice.title); type is shared with the modal title. */
.klaro .cookie-notice .cn-body h2 {
	flex: 0 0 auto;
	margin: 0 0 var( --mc-space-sm );
}

.klaro .cookie-notice .cn-ok,
.klaro .cn-buttons {
	display: flex;
	flex: 0 0 auto;
	flex-wrap: wrap;
	gap: var( --mc-gap );
	align-items: center;
}

/* "Configure cookies" stays a link; padded to a 24px touch target. */
.klaro .cookie-notice .cn-learn-more {
	display: inline-block;
	min-height: 24px;
	padding-block: 2px;
}

/* Notice control order (left -> right): Allow all cookies, Decline optional
   cookies, Configure cookies. */
.klaro .cookie-notice .cn-ok .cn-buttons {
	order: 1;
	flex-shrink: 1; /* wrap long (translated) labels instead of overflowing */
}

.klaro .cookie-notice .cn-ok .cn-learn-more {
	order: 2;
}

.klaro .cookie-notice .cn-buttons .cm-btn-success {
	order: 1;
}

.klaro .cookie-notice .cn-buttons .cn-decline {
	order: 2;
}

/* ------------------------------------------------------------------- Modal */
.klaro .cookie-modal {
	position: fixed;
	inset: 0;
	z-index: 1010;
	display: flex;
	align-items: center;
	justify-content: center;
}

.klaro .cookie-modal .cm-bg {
	position: fixed;
	inset: 0;
	background: var( --mc-scrim );
}

.klaro .cookie-modal .cm-modal {
	position: relative;
	z-index: 1;
	width: min( calc( 100vw - 2 * var( --mc-inset ) ), 600px );
	max-height: 85vh;
	max-height: 85dvh;
	overflow: auto;
	background: var( --mc-bg );
	color: var( --mc-text );
	border-radius: var( --mc-radius );
	box-shadow: var( --mc-shadow );
}

.klaro .cookie-modal .cm-header,
.klaro .cookie-modal .cm-body,
.klaro .cookie-modal .cm-footer {
	padding: var( --mc-pad );
}

/* Close button — placed at the top end (top right; top left in RTL). Its SVG ships two unstroked <line>s in the
   no-css build, so give them a visible stroke (don't add a glyph, or it doubles). */
.klaro .cookie-modal .cm-modal .hide,
.klaro .cookie-modal .cm-modal button.hide {
	position: absolute;
	top: var( --mc-space-md );
	inset-inline-end: var( --mc-space-md );
	width: 24px;
	height: 24px;
	padding: 0;
	border: 0;
	background: transparent;
	color: var( --mc-heading );
	cursor: pointer;
	line-height: 0;
}

.klaro .cookie-modal .cm-modal .hide svg {
	width: 14px;
	height: 14px;
}

.klaro .cookie-modal .cm-modal .hide svg line {
	stroke: currentColor;
	stroke-width: 1.5;
}

.klaro .cookie-modal .cm-modal .hide:hover {
	color: var( --mc-link-hover );
}

.klaro .cookie-modal .cm-modal .hide:focus-visible {
	outline: 2px solid var( --mc-focus );
	outline-offset: 2px;
	border-radius: 2px;
}

.klaro .cookie-modal .cm-header {
	position: relative;
	padding-inline-end: 56px; /* room for the close button */
	border-bottom: 1px solid var( --mc-border );
}

/* Logo above the title (shown only when --mc-logo is set by PHP). */
.klaro .cookie-modal .cm-header::before {
	content: "";
	display: var( --mc-logo-display, none );
	width: 92px;
	height: 28px;
	margin-bottom: var( --mc-gap );
	background: var( --mc-logo, none ) left center / contain no-repeat;
}

.klaro .cookie-modal .cm-header h1,
.klaro .cookie-modal .cm-header .title {
	margin: 0;
}

.klaro .cookie-modal .cm-header p {
	margin: var( --mc-space-sm ) 0 0;
}

.klaro .cookie-modal .cm-footer {
	display: flex;
	flex-wrap: wrap;
	gap: var( --mc-gap );
	justify-content: flex-end;
	border-top: 1px solid var( --mc-border );
}

/* Footer buttons usually sit in a wrapper; space them too. */
.klaro .cookie-modal .cm-footer .cm-footer-buttons,
.klaro .cookie-modal .cm-footer .cm-btn-group {
	display: flex;
	flex-wrap: wrap;
	gap: var( --mc-gap );
	justify-content: flex-end;
	width: 100%;
}

/* ----------------------------------------------------- Purpose / service rows */
/* Remove list markers only. NOTE: do not reset li padding here — a
   `.cookie-modal li` rule (0-2-1) would outrank `.cm-purpose` (0-2-0) and
   clobber its row padding. Reset the specific lists' box instead. */
.klaro .cookie-modal ul,
.klaro .cookie-modal li {
	list-style: none;
}

.klaro .cm-purposes {
	margin: 0;
	padding: 0;
}

/* Top-level purposes: symmetric padding so each divider has equal space
   above and below. */
/* Divider as border-TOP so its following space (padding-top) lives on the same
   element — guarantees equal spacing below every divider. */
.klaro .cm-purpose {
	padding: var( --mc-space-md ) 0;
	border-top: 1px solid var( --mc-border );
}

.klaro .cm-purpose:first-child {
	border-top: 0;
	padding-top: 0;
}

/* Nested services: caret stays at the purpose indent; the service list indents. */
.klaro .cm-services {
	margin: var( --mc-gap ) 0 0;
	padding: 0; /* the browser's list indent; rows align with the header */
}

.klaro .cm-content {
	margin: var( --mc-space-sm ) 0 0;
	padding: 0 0 0 var( --mc-space-md );
}

.klaro .cm-service {
	padding: var( --mc-gap ) 0 0;
	border-bottom: 0;
}

/* Title + toggle share one row; toggle pinned right with clear separation. */
.klaro .cm-list-label {
	display: flex;
	align-items: center;
	gap: var( --mc-gap );
	cursor: pointer;
}

.klaro .cm-list-title {
	flex: 1 1 auto;
	color: var( --mc-heading );
	font-weight: var( --mc-fw-medium );
}

.klaro .cm-list-label .cm-switch,
.klaro .cm-list-label .slider {
	order: 9;
	margin-inline-start: auto;
	flex: 0 0 auto;
}

.klaro .cm-list-description {
	margin: var( --mc-space-sm ) 0 0;
	color: var( --mc-muted );
}

/* Hide Klaro's per-service "purpose: Analytics" label. With groupByPurpose off
   each service is its own toggle and the purpose duplicates the service title,
   so it is redundant noise. */
.klaro .cm-service .purposes,
.klaro p.purposes {
	display: none;
}

/* "N services" expander spacing. */
.klaro .cm-purpose .cm-caret,
.klaro .cm-purpose > .cm-link {
	display: inline-block;
	margin-top: var( --mc-space-sm );
}

/* Toggle — visually hide the native checkbox (sr-only) but keep it fully
   operable via its label[for]. The previous `position:absolute; opacity:0`
   left a clickable 0-size box overlapping the row, interfering with toggling. */
.klaro .cm-list-input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	white-space: nowrap;
}

.klaro .cm-list-label .slider {
	position: relative;
	display: inline-block;
	width: 42px;
	height: 24px;
	/* Off: neutral fill, 2px outline (inset, so the size never changes). */
	background: var( --mc-toggle-off-fill );
	box-shadow: inset 0 0 0 2px var( --mc-toggle-off-line );
	border-radius: var( --mc-btn-radius );
	transition: background 0.15s ease;
}

.klaro .cm-list-label .slider::before {
	content: "";
	position: absolute;
	top: 4px;
	inset-inline-start: 4px;
	width: 16px;
	height: 16px;
	background: var( --mc-toggle-off-line );
	border-radius: 50%;
	transition: transform 0.15s ease;
}

/* On-state driven by the checkbox's :checked. IMPORTANT: Klaro hardcodes
   "slider round active" on EVERY slider, so `.active` is NOT a state hook —
   styling it as "on" froze all toggles visually on (looked inert). */
.klaro .cm-list-input:checked + .cm-list-label .slider {
	background: var( --mc-toggle-on );
	box-shadow: none;
}

.klaro .cm-list-input:checked + .cm-list-label .slider::before {
	background: var( --mc-knob );
	transform: translateX( 18px );
}

.klaro .cm-list-input:focus-visible + .cm-list-label .slider {
	outline: 2px solid var( --mc-toggle-focus );
	outline-offset: 2px;
}

/* Locked (a required service such as "Strictly necessary"): on, but clearly not
   interactive. Klaro renders it as a disabled, checked input, which assistive
   technology announces as checked and unavailable. */
.klaro .cm-list-input:disabled + .cm-list-label,
.klaro .cm-list-input:disabled + .cm-list-label .slider {
	cursor: default;
}

.klaro .cm-list-input:disabled + .cm-list-label .slider {
	background: var( --mc-toggle-locked );
	box-shadow: none;
}

.klaro .cm-list-input:disabled + .cm-list-label .slider::before {
	background: var( --mc-knob );
	transform: translateX( 18px );
}

/* Right to left, "on" moves the knob toward the start (left). */
.klaro .cm-list-input:checked + .cm-list-label .slider:dir(rtl)::before,
.klaro .cm-list-input:disabled + .cm-list-label .slider:dir(rtl)::before {
	transform: translateX( -18px );
}

/* --------------------------------------------------------------- Buttons */
/* Every button is primary by default: notice "Allow all cookies" and "Decline
   optional cookies", modal "Decline optional" and "Allow all", and the reopened
   modal's one-click Decline. Same fill, colour, weight, size and border, so
   refusing is exactly as prominent as accepting (EU). */
.klaro .cm-btn {
	appearance: none;
	box-sizing: border-box;
	min-height: 24px;
	margin: 0;
	padding: var( --mc-btn-pad );
	cursor: pointer;
	font-family: var( --mc-font );
	font-size: var( --mc-btn-fs );
	font-weight: var( --mc-btn-weight );
	line-height: var( --mc-btn-lh );
	letter-spacing: var( --mc-btn-tracking );
	text-align: center;
	text-decoration: none;
	background: var( --mc-accent );
	color: var( --mc-accent-text );
	border: var( --mc-btn-border-width ) solid var( --mc-accent-border );
	border-radius: var( --mc-btn-radius );
	transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.klaro .cm-btn:hover {
	background: var( --mc-accent-hover );
	color: var( --mc-accent-hover-text );
	border-color: var( --mc-accent-hover-border );
}

/* Secondary: "Save choices" only (Klaro's cm-btn-accept, which also carries
   cm-btn-success). */
.klaro .cm-btn.cm-btn-accept {
	background: var( --mc-btn-bg );
	color: var( --mc-btn-text );
	border-color: var( --mc-btn-border );
}

.klaro .cm-btn.cm-btn-accept:hover {
	background: var( --mc-btn-bg );
	color: var( --mc-btn-hover-text );
	border-color: var( --mc-btn-hover-text );
}

.klaro .cm-btn:focus-visible {
	outline: 2px solid var( --mc-focus );
	outline-offset: 2px;
}

/* ------------------------------------------------------------------ Mobile */
/* Below the theme's tablet breakpoint: a compact notice (tighter spacing,
   close to the screen edge) with full-width, stacked buttons. Text stays the
   page's body size. */
@media ( max-width: 767px ) {
	.klaro {
		--mc-inset: var( --mc-space-sm );
		--mc-pad: var( --mc-space-md );
		--mc-gap: var( --mc-space-sm );
		--mc-fs-title: calc( var( --mc-fs-body ) * 1.25 );
		--mc-btn-pad: var( --mc-space-sm ) var( --mc-space-md );
	}

	.klaro .cookie-notice {
		padding-block: calc( var( --mc-space-sm ) + var( --mc-space-xs ) );
	}

	.klaro .cookie-notice .cn-body p {
		max-height: 40vh;
		max-height: 40dvh;
	}

	.klaro .cookie-notice .cn-ok,
	.klaro .cn-buttons,
	.klaro .cookie-modal .cm-footer,
	.klaro .cookie-modal .cm-footer .cm-footer-buttons {
		flex-direction: column;
		align-items: stretch;
	}

	.klaro .cm-btn {
		width: 100%;
	}
}

/* Consent controls outside Klaro (e.g. a footer "Configure cookies" link) are
   rendered hidden for every visitor and revealed by the runtime only where
   consent is required. Themes often set `display` on such items (core
   navigation items use flex), which would defeat the plain [hidden] attribute. */
[data-meta-consent-reveal][hidden] {
	display: none !important;
}

