/**
 * Ichthus Cookie Notice styles.
 *
 * Override any of these custom properties from your theme, e.g.
 *   :root { --icn-accent: #7a1f2b; --icn-radius: 0; }
 * Default colours meet WCAG 2.2 AA: text 16.7:1, buttons and links 11.4:1, borders 4.8:1.
 */
:where(.icn-root, .icn-dialog, .icn-embed) {
	--icn-bg: #ffffff;
	--icn-text: #1e1e1e;
	--icn-accent: #1f3b5c;
	--icn-accent-text: #ffffff;
	--icn-muted-bg: #f3f4f6;
	--icn-border: #6b7280;
	--icn-focus: var(--icn-accent);
	--icn-radius: 6px;
	--icn-font: inherit;
	--icn-z: 2147483000;
	--icn-shadow: 0 -2px 16px rgba(0, 0, 0, 0.18);
}

.icn-visually-hidden {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

/* ---------- Shared button ---------- */

.icn-root .icn-btn,
.icn-dialog .icn-btn,
.icn-embed .icn-btn {
	-webkit-appearance: none;
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	min-width: 44px;
	margin: 0;
	padding: 0.6em 1.2em;
	border: 2px solid var(--icn-accent);
	border-radius: var(--icn-radius);
	background: var(--icn-accent);
	color: var(--icn-accent-text);
	font-family: var(--icn-font);
	font-weight: 600;
	font-size: 1rem;
	line-height: 1.2;
	letter-spacing: normal;
	text-transform: none;
	text-decoration: none;
	text-shadow: none;
	box-shadow: none;
	cursor: pointer;
}

.icn-root .icn-btn--secondary,
.icn-dialog .icn-btn--secondary,
.icn-embed .icn-btn--secondary {
	background: var(--icn-bg);
	color: var(--icn-accent);
}

.icn-root .icn-btn:hover,
.icn-dialog .icn-btn:hover,
.icn-embed .icn-btn:hover {
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.icn-root :focus-visible,
.icn-dialog :focus-visible,
.icn-embed :focus-visible,
.icn-settings-link:focus-visible {
	outline: 3px solid var(--icn-focus);
	outline-offset: 2px;
}

/* ---------- Banner (first layer) ---------- */

.icn-root[hidden] {
	display: none !important;
}

.icn-root {
	position: fixed;
	z-index: var(--icn-z);
	left: 0;
	right: 0;
	bottom: 0;
	color: var(--icn-text);
	font-family: var(--icn-font);
}

.icn-root.icn-pos-top {
	top: 0;
	bottom: auto;
}

.icn-root.icn-pos-bottom-left {
	left: 1rem;
	right: auto;
	bottom: 1rem;
	max-width: min(26rem, calc(100vw - 2rem));
}

.icn-banner {
	box-sizing: border-box;
	display: grid;
	grid-template-columns: 1fr auto;
	grid-template-areas: "title actions" "text actions";
	gap: 0.5rem 2rem;
	align-items: center;
	max-height: 70vh;
	overflow-y: auto;
	padding: 1.25rem clamp(1rem, 4vw, 2.5rem);
	background: var(--icn-bg);
	border-top: 1px solid var(--icn-border);
	box-shadow: var(--icn-shadow);
}

.icn-pos-top .icn-banner {
	border-top: 0;
	border-bottom: 1px solid var(--icn-border);
}

.icn-pos-bottom-left .icn-banner {
	grid-template-columns: 1fr;
	grid-template-areas: "title" "text" "actions";
	border: 1px solid var(--icn-border);
	border-radius: var(--icn-radius);
}

.icn-root .icn-banner__title {
	grid-area: title;
	margin: 0;
	color: var(--icn-text);
	font-family: var(--icn-font);
	font-weight: 700;
	font-size: 1.2rem;
	line-height: 1.3;
	letter-spacing: normal;
	text-transform: none;
}

.icn-banner__text {
	grid-area: text;
	font-size: 1rem;
	line-height: 1.5;
}

.icn-banner__text p {
	margin: 0 0 0.4em;
	color: var(--icn-text);
}

.icn-root a,
.icn-dialog a {
	color: var(--icn-accent);
	text-decoration: underline;
}

.icn-banner__actions {
	grid-area: actions;
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
}

.icn-pos-bottom .icn-banner__actions,
.icn-pos-top .icn-banner__actions {
	justify-content: flex-end;
}

@media (max-width: 782px) {
	.icn-banner {
		grid-template-columns: 1fr;
		grid-template-areas: "title" "text" "actions";
	}

	.icn-banner__actions {
		justify-content: stretch;
	}

	.icn-banner {
		padding: 1rem;
	}

	/* Accept and Reject stay side by side and equal; Manage spans the row. */
	.icn-banner__actions .icn-btn {
		flex: 1 1 calc(50% - 0.375rem);
	}

	.icn-banner__actions .icn-btn--secondary {
		flex-basis: 100%;
	}
}

/* Keep page content (and keyboard focus) clear of the banner. */
html.icn-banner-open[data-icn-pos="bottom"] body {
	padding-bottom: var(--icn-banner-h, 0);
}

html.icn-banner-open[data-icn-pos="bottom"],
html.icn-banner-open[data-icn-pos="bottom-left"] {
	scroll-padding-bottom: calc(var(--icn-banner-h, 0px) + 1rem);
}

html.icn-banner-open[data-icn-pos="top"] {
	scroll-padding-top: calc(var(--icn-banner-h, 0px) + 1rem);
}

/* ---------- Preferences dialog ---------- */

.icn-dialog {
	box-sizing: border-box;
	width: min(40rem, calc(100vw - 2rem));
	max-height: calc(100vh - 2rem);
	margin: auto;
	padding: 0;
	overflow: auto;
	border: 1px solid var(--icn-border);
	border-radius: var(--icn-radius);
	background: var(--icn-bg);
	color: var(--icn-text);
	font-family: var(--icn-font);
	font-size: 1rem;
	line-height: 1.5;
	z-index: calc(var(--icn-z) + 1);
}

.icn-dialog:not([open]) {
	display: none;
}

/* Fallback for browsers without showModal(). */
.icn-dialog[open][role="dialog"] {
	position: fixed;
	inset: 0;
	box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55);
}

.icn-dialog::backdrop {
	background: rgba(0, 0, 0, 0.55);
}

.icn-dialog__header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	padding: 1.25rem 1.5rem 0;
}

.icn-dialog .icn-dialog__title {
	margin: 0;
	color: var(--icn-text);
	font-family: var(--icn-font);
	font-weight: 700;
	font-size: 1.35rem;
	line-height: 1.3;
	letter-spacing: normal;
	text-transform: none;
}

.icn-dialog .icn-dialog__close {
	-webkit-appearance: none;
	appearance: none;
	flex: none;
	width: 44px;
	height: 44px;
	margin: -0.5rem -0.75rem 0 0;
	padding: 0;
	border: 0;
	border-radius: var(--icn-radius);
	background: transparent;
	color: var(--icn-text);
	font-family: var(--icn-font);
	font-weight: 400;
	font-size: 1.75rem;
	line-height: 1;
	cursor: pointer;
}

.icn-dialog__body {
	padding: 0.5rem 1.5rem 0;
}

.icn-dialog__body > p {
	margin: 0 0 1rem;
}

.icn-cats {
	margin: 0;
	padding: 0;
	list-style: none;
}

.icn-cat {
	margin: 0;
	padding: 1rem 0;
	border-top: 1px solid #d1d5db;
}

.icn-cat__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

.icn-dialog .icn-cat__title {
	margin: 0;
	color: var(--icn-text);
	font-family: var(--icn-font);
	font-weight: 700;
	font-size: 1.05rem;
	line-height: 1.3;
	letter-spacing: normal;
	text-transform: none;
}

.icn-cat__title label {
	cursor: pointer;
}

.icn-cat__always {
	flex: none;
	font-weight: 600;
	font-size: 0.95rem;
}

.icn-cat__desc {
	margin: 0.35rem 0 0;
	font-size: 0.95rem;
}

/* Switch: state shown by knob position as well as colour. */
.icn-dialog .icn-switch {
	-webkit-appearance: none;
	appearance: none;
	position: relative;
	flex: none;
	width: 52px;
	height: 30px;
	margin: 0;
	border: 2px solid var(--icn-accent);
	border-radius: 999px;
	background: var(--icn-bg);
	cursor: pointer;
}

.icn-dialog .icn-switch::before {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: var(--icn-accent);
}

.icn-dialog .icn-switch:checked {
	background: var(--icn-accent);
}

.icn-dialog .icn-switch:checked::before {
	left: 25px;
	background: var(--icn-accent-text);
}

.icn-dialog__actions {
	position: sticky;
	bottom: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	padding: 1rem 1.5rem 1.25rem;
	border-top: 1px solid #d1d5db;
	background: var(--icn-bg);
}

@media (max-width: 600px) {
	.icn-dialog__actions .icn-btn {
		flex: 1 1 100%;
	}
}

/* ---------- Click-to-load embed placeholder ---------- */

.icn-embed {
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	/* No explicit min-height: an aspect-ratio box then grows to fit its text. */
	aspect-ratio: var(--icn-ratio, 16 / 9);
	margin: 0 0 1em;
	padding: 1.25rem;
	border: 1px solid var(--icn-border);
	border-radius: var(--icn-radius);
	background: var(--icn-muted-bg);
	color: var(--icn-text);
	font-family: var(--icn-font);
	text-align: center;
}

/*
 * Wrappers that reserve space with padding (fitVids, core responsive embeds):
 * where :has() is supported, drop the reserved space and let the placeholder
 * size itself, so its text never clips on small screens.
 */
.fluid-width-video-wrapper:has(> .icn-embed) {
	padding-top: 0 !important;
	height: auto !important;
}

.wp-block-embed__wrapper:has(> .icn-embed)::before {
	display: none !important;
}

.fluid-width-video-wrapper:has(> .icn-embed) > .icn-embed,
.wp-embed-responsive .wp-has-aspect-ratio .wp-block-embed__wrapper:has(> .icn-embed) > .icn-embed {
	position: static;
	aspect-ratio: var(--icn-ratio, 16 / 9);
	min-height: auto;
	overflow: visible;
}

/*
 * Fallback without :has(): fill wrappers that size the iframe absolutely: core embed blocks (only
 * when the theme supports responsive embeds) and fitVids wrappers (Avada).
 */
.wp-embed-responsive .wp-has-aspect-ratio .wp-block-embed__wrapper > .icn-embed,
.fluid-width-video-wrapper > .icn-embed {
	position: absolute;
	inset: 0;
	aspect-ratio: auto;
	min-height: 0;
	margin: 0;
	overflow: auto;
}

.icn-embed__placeholder {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.75rem;
	max-width: 36rem;
}

.icn-embed__text {
	display: block;
	font-size: 1rem;
	line-height: 1.5;
}

.icn-embed__actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.75rem;
}

.icn-embed .icn-embed__policy {
	color: var(--icn-accent);
	font-size: 0.9rem;
	text-decoration: underline;
}

/* ---------- Persistent "Cookie settings" control ---------- */

.icn-settings-link {
	-webkit-appearance: none;
	appearance: none;
	display: inline;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	text-decoration: underline;
	cursor: pointer;
}

/* ---------- Motion (only when the visitor has not asked for less) ---------- */

@media (prefers-reduced-motion: no-preference) {
	.icn-dialog .icn-switch::before {
		transition: left 0.15s ease;
	}

	.icn-root:not([hidden]) .icn-banner {
		animation: icn-in 0.2s ease-out;
	}

	@keyframes icn-in {
		from {
			opacity: 0;
			transform: translateY(8px);
		}
	}
}

/* ---------- Forced colours / high contrast ---------- */

@media (forced-colors: active) {
	.icn-dialog .icn-switch::before {
		background: CanvasText;
	}

	.icn-dialog .icn-switch:checked {
		background: Highlight;
	}
}
