/**
 * Earnox consent banner and preferences dialog.
 *
 * Self-contained, like tools.css: the custom properties are declared locally
 * so the banner still looks right if the plugin is used with another theme.
 * The values mirror the Earnox palette (midnight surface, cyan accent) so it
 * does not look bolted on when the Earnox theme is active.
 *
 * Two rules drive the layout:
 *
 *   - Accept all, Reject all and Manage choices share one button class with
 *     one set of colours. There is no visually dominant "accept" button here,
 *     because a banner that makes rejecting harder is not really a choice.
 *   - The banner sits at the bottom of the DOM and of the viewport. It does
 *     not cover the page, does not steal focus, and leaves the document
 *     scrollable. Only the dialog is modal.
 */

.earnox-consent {
	--ec-surface: #0b1220;
	--ec-surface-raised: #111b2e;
	--ec-surface-inset: #16223a;
	--ec-line: #24344f;
	--ec-line-strong: #33496b;
	--ec-text: #e8eff9;
	--ec-muted: #9db0cc;
	--ec-accent: #22d3ee;
	--ec-accent-strong: #06b6d4;
	--ec-radius: 14px;
	--ec-focus: 0 0 0 2px #0b1220, 0 0 0 4px #22d3ee;
	--ec-shadow: 0 -2px 10px rgba(0, 0, 0, 0.18), 0 18px 48px -18px rgba(0, 0, 0, 0.75);

	font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
	font-size: 16px;
	line-height: 1.55;
}

.earnox-consent *,
.earnox-consent *::before,
.earnox-consent *::after {
	box-sizing: border-box;
}

.earnox-consent [hidden] {
	display: none !important;
}

/* Screen-reader helper, declared here so the consent markup does not depend
   on tools.css being enqueued on the page. */
.earnox-consent .earnox-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* ---------- Banner ---------- */

.earnox-consent__banner {
	position: fixed;
	z-index: 9990;
	left: 50%;
	bottom: 0;
	transform: translateX(-50%);
	width: min(100%, 1180px);
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 1rem 1.5rem;
	background: var(--ec-surface-raised);
	color: var(--ec-text);
	border: 1px solid var(--ec-line);
	border-bottom: 0;
	border-radius: var(--ec-radius) var(--ec-radius) 0 0;
	box-shadow: var(--ec-shadow);
	padding: 1.05rem clamp(1rem, 3vw, 1.6rem);
	padding-bottom: calc(1.05rem + env(safe-area-inset-bottom, 0px));
	opacity: 0;
	transition: opacity 200ms ease, transform 200ms ease;
	will-change: opacity, transform;
}

/* Starting position for the entrance, only while the banner is animating in. */
.earnox-consent__banner:not(.is-visible) {
	transform: translate(-50%, 12px);
}

.earnox-consent__banner.is-visible {
	opacity: 1;
	transform: translateX(-50%);
}

/* Decorative cyan hairline along the top edge, matching the theme's lit rims. */
.earnox-consent__banner::before {
	content: "";
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 1px;
	pointer-events: none;
	background: linear-gradient(90deg, rgba(34, 211, 238, 0), rgba(34, 211, 238, 0.55) 50%, rgba(34, 211, 238, 0));
}

.earnox-consent__copy {
	flex: 1 1 380px;
	min-width: 0;
}

.earnox-consent__title {
	margin: 0 0 0.3rem;
	font-size: 1.0625rem;
	font-weight: 650;
	letter-spacing: -0.015em;
	color: var(--ec-text);
}

.earnox-consent__text {
	margin: 0;
	font-size: 0.9375rem;
	color: var(--ec-muted);
}

.earnox-consent__link {
	color: var(--ec-accent);
	text-underline-offset: 0.18em;
}

.earnox-consent__link:hover,
.earnox-consent__link:focus-visible {
	color: var(--ec-accent-strong);
}

.earnox-consent__link:focus-visible {
	outline: 2px solid transparent;
	outline-offset: 2px;
	box-shadow: var(--ec-focus);
	border-radius: 4px;
}

/* ---------- Actions ---------- */

.earnox-consent__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.55rem;
	flex: 0 1 auto;
}

/*
 * One button style for every choice. Accept, Reject and Manage are the same
 * size, the same colour and the same weight on purpose.
 */
.earnox-consent__btn {
	appearance: none;
	font: inherit;
	font-size: 0.9375rem;
	font-weight: 620;
	line-height: 1.2;
	color: var(--ec-text);
	background: var(--ec-surface-inset);
	border: 1px solid var(--ec-line-strong);
	border-radius: 999px;
	padding: 0.65rem 1.2rem;
	cursor: pointer;
	white-space: nowrap;
	flex: 1 1 auto;
	min-width: 8.5rem;
	text-align: center;
	transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.earnox-consent__btn:hover {
	background: #1c2b47;
	border-color: var(--ec-accent);
	color: #ffffff;
}

.earnox-consent__btn:focus-visible {
	outline: 2px solid transparent;
	outline-offset: 2px;
	box-shadow: var(--ec-focus);
}

.earnox-consent__btn:active {
	transform: translateY(1px);
}

/* ---------- Dialog ---------- */

.earnox-consent__backdrop {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 9995;
	background: rgba(4, 8, 16, 0.66);
}

.earnox-consent__dialog {
	position: fixed;
	z-index: 9996;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	width: min(calc(100vw - 2rem), 560px);
	max-height: min(86vh, 720px);
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--ec-surface);
	color: var(--ec-text);
	border: 1px solid var(--ec-line);
	border-radius: var(--ec-radius);
	box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.8);
	padding: clamp(1.1rem, 3vw, 1.6rem);
	opacity: 0;
	transition: opacity 180ms ease;
}

.earnox-consent__dialog.is-visible {
	opacity: 1;
}

.earnox-consent__dialog-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.5rem;
}

.earnox-consent__dialog-head .earnox-consent__title {
	font-size: 1.15rem;
	margin: 0;
}

.earnox-consent__close {
	appearance: none;
	background: transparent;
	border: 1px solid transparent;
	color: var(--ec-muted);
	font-size: 1.5rem;
	line-height: 1;
	padding: 0.2rem 0.5rem;
	border-radius: 8px;
	cursor: pointer;
	flex: 0 0 auto;
}

.earnox-consent__close:hover {
	color: var(--ec-text);
	border-color: var(--ec-line-strong);
}

.earnox-consent__close:focus-visible {
	outline: 2px solid transparent;
	outline-offset: 2px;
	box-shadow: var(--ec-focus);
}

/* ---------- Category list ---------- */

.earnox-consent__groups {
	list-style: none;
	margin: 1.1rem 0;
	padding: 0;
	display: grid;
	gap: 0.7rem;
}

.earnox-consent__group {
	background: var(--ec-surface-raised);
	border: 1px solid var(--ec-line);
	border-radius: 10px;
	padding: 0.85rem 1rem;
}

.earnox-consent__group-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
}

.earnox-consent__group-desc {
	margin: 0.45rem 0 0;
	font-size: 0.875rem;
	color: var(--ec-muted);
}

.earnox-consent__always {
	font-size: 0.7rem;
	font-weight: 680;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--ec-muted);
	background: var(--ec-surface-inset);
	border-radius: 999px;
	padding: 0.2rem 0.6rem;
	white-space: nowrap;
}

/* ---------- Switch ---------- */

.earnox-consent__switch {
	display: inline-flex;
	align-items: center;
	gap: 0.7rem;
	cursor: pointer;
	position: relative;
	min-width: 0;
}

/*
 * The checkbox stays in the layout and stays focusable. It is made visually
 * transparent rather than display:none, because display:none would take it
 * out of the tab order and the dialog would stop being operable by keyboard.
 */
.earnox-consent__checkbox {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	opacity: 0;
	cursor: pointer;
}

.earnox-consent__checkbox:disabled {
	cursor: default;
}

.earnox-consent__switch-track {
	flex: 0 0 auto;
	width: 42px;
	height: 24px;
	border-radius: 999px;
	background: var(--ec-surface-inset);
	border: 1px solid var(--ec-line-strong);
	position: relative;
	transition: background 140ms ease, border-color 140ms ease;
}

.earnox-consent__switch-track::after {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: var(--ec-muted);
	transition: transform 140ms ease, background 140ms ease;
}

.earnox-consent__checkbox:checked + .earnox-consent__switch-track {
	background: rgba(34, 211, 238, 0.22);
	border-color: var(--ec-accent);
}

.earnox-consent__checkbox:checked + .earnox-consent__switch-track::after {
	transform: translateX(18px);
	background: var(--ec-accent);
}

/* The checkbox itself is invisible, so its track carries focus. The :focus
   pair serves engines without :focus-visible (they drop the :not() rule and
   keep a ring on any focus); the transparent outline shows in forced colours. */
.earnox-consent__checkbox:focus + .earnox-consent__switch-track {
	outline: 2px solid transparent;
	outline-offset: 2px;
	box-shadow: var(--ec-focus);
}

.earnox-consent__checkbox:focus:not(:focus-visible) + .earnox-consent__switch-track {
	outline: none;
	box-shadow: none;
}

.earnox-consent__checkbox:focus-visible + .earnox-consent__switch-track {
	outline: 2px solid transparent;
	outline-offset: 2px;
	box-shadow: var(--ec-focus);
}

.earnox-consent__checkbox:disabled + .earnox-consent__switch-track {
	opacity: 0.65;
}

.earnox-consent__switch-label {
	font-size: 0.95rem;
	font-weight: 620;
	color: var(--ec-text);
}

.earnox-consent__actions--dialog {
	margin-top: 1rem;
}

/* ---------- Scroll lock while the dialog is open ---------- */

html.earnox-consent-open,
html.earnox-consent-open body {
	overflow: hidden;
}

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
	.earnox-consent__banner {
		flex-direction: column;
		align-items: stretch;
		border-left: 0;
		border-right: 0;
		border-radius: var(--ec-radius) var(--ec-radius) 0 0;
		max-height: 80vh;
		overflow-y: auto;
	}

	/*
	 * .earnox-consent__copy's base rule sets `flex: 1 1 380px` so it takes a
	 * sensible share of the row in the default side-by-side layout. Once the
	 * banner switches to flex-direction: column above, the same flex-basis
	 * is read along the vertical axis instead of the horizontal one, forcing
	 * this block to a fixed 380px *height* regardless of its actual content
	 * (on a short phone, that alone can eat most of the viewport). Resetting
	 * the basis to auto here makes it size to its content again.
	 */
	.earnox-consent__copy {
		flex-basis: auto;
	}

	.earnox-consent__actions {
		width: 100%;
	}

	.earnox-consent__btn {
		flex: 1 1 100%;
	}
}

/* ---------- Motion ---------- */

@media (prefers-reduced-motion: reduce) {
	.earnox-consent__banner,
	.earnox-consent__banner:not(.is-visible),
	.earnox-consent__banner.is-visible {
		transition: none;
		transform: translateX(-50%);
		opacity: 1;
	}

	.earnox-consent *,
	.earnox-consent *::before,
	.earnox-consent *::after {
		transition-duration: 0.001ms !important;
		animation-duration: 0.001ms !important;
	}

	.earnox-consent__dialog {
		opacity: 1;
	}
}

/* ---------- Forced colours ---------- */

@media (forced-colors: active) {
	.earnox-consent__banner,
	.earnox-consent__dialog,
	.earnox-consent__group,
	.earnox-consent__btn {
		border: 1px solid CanvasText;
	}

	.earnox-consent__switch-track {
		border: 1px solid CanvasText;
	}

	.earnox-consent__checkbox:checked + .earnox-consent__switch-track::after {
		background: Highlight;
	}
}

/* ---------- Print ---------- */

@media print {
	.earnox-consent {
		display: none !important;
	}
}

/* ---------- No flex gap (Chrome < 84, Safari < 14.1) ----------
   `inset` shipped alongside flex gap, so it is the feature test. Keeps the
   three equal choices from stacking edge to edge on old phones. */

@supports not (inset: 0) {
	.earnox-consent__copy { margin: 0 1.5rem 1rem 0; }
	.earnox-consent__btn { margin: 0 0.55rem 0.55rem 0; }
	.earnox-consent__switch-track { margin-right: 0.7rem; }
	@media (max-width: 720px) {
		.earnox-consent__copy,
		.earnox-consent__btn { margin-right: 0; }
	}
}
