/**
 * IBD Analytics: the consent banner and the privacy settings dialog. Colours
 * and spacing come from the theme's variables where it has them.
 */

/* Banner: a card in the bottom-right corner; full width on phones. Over the
 * header (100), under the page-transition wipe (1000). */
.ibd-consent {
	position: fixed;
	right: var(--space-s, 1rem);
	bottom: var(--space-s, 1rem);
	z-index: 999;
	display: grid;
	grid-template-columns: 1fr auto;
	align-items: start;
	gap: 0.75rem 0.5rem;
	box-sizing: border-box;
	width: min(26rem, calc(100% - 2 * var(--space-s, 1rem)));
	padding: 1.25rem 0.5rem 1.25rem 1.25rem;
	border-radius: var(--radius, 24px);
	background-color: var(--black, #121212);
	color: var(--white, #fff);
	box-shadow: 0 8px 32px rgb(18 18 18 / 0.3);
	font-size: 1rem;
	line-height: 1.5;
	animation: ibd-consent-in 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.ibd-consent[hidden] {
	display: none;
}

.ibd-consent__text {
	grid-column: 1;
	grid-row: 1;
	margin: 0;
}

.ibd-consent__text a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 0.2em;
}

.ibd-consent__text a:is(:hover, :focus) {
	color: var(--orange, #f56905);
}

.ibd-consent__allow {
	grid-column: 1;
	grid-row: 2;
	justify-self: start;
	padding: 0.7em 2em;
	border: 0;
	border-radius: var(--radius-pill, 50px);
	background-color: var(--white, #fff);
	color: var(--black, #121212);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
}

.ibd-consent__allow:is(:hover, :focus) {
	background-color: var(--orange, #f56905);
	color: var(--black, #121212);
}

/* Top right; a full 44px target. */
.ibd-consent__close {
	grid-column: 2;
	grid-row: 1;
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	margin-top: -0.75rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--white, #fff);
	cursor: pointer;
}

.ibd-consent__close:is(:hover, :focus) {
	background-color: rgb(255 255 255 / 0.15);
	color: var(--white, #fff);
}

.ibd-consent :focus-visible {
	outline: 3px solid var(--orange, #f56905);
	outline-offset: 2px;
}

@media (max-width: 767px) {
	.ibd-consent {
		right: 0;
		bottom: 0;
		width: 100%;
		border-radius: var(--radius, 24px) var(--radius, 24px) 0 0;
		padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
	}
}

/* Short screens (e.g. 400% zoom: 320 × 256): never taller than 60% of the
 * screen, scrolling inside, so it can't hide its own close button or the
 * whole page. */
.ibd-consent {
	max-height: 60vh;
	max-height: 60dvh;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* While the banner shows, keyboard focus scrolls into view above it rather
 * than behind it (ibd-analytics.js keeps --ibd-consent-height up to date). */
html:has(.ibd-consent:not([hidden])) {
	scroll-padding-bottom: calc(var(--ibd-consent-height, 0px) + 1rem);
}

@keyframes ibd-consent-in {
	from {
		opacity: 0;
		transform: translateY(1rem);
	}
}

/* Privacy settings dialog. */
.ibd-privacy {
	box-sizing: border-box;
	width: min(30rem, calc(100% - 2rem));
	max-height: calc(100% - 2rem);
	padding: var(--space-m, 2rem);
	border: 0;
	border-radius: var(--radius, 24px);
	background-color: var(--white, #fff);
	color: var(--black, #121212);
	box-shadow: 0 8px 48px rgb(18 18 18 / 0.3);
	font-size: 1rem;
	line-height: 1.5;
}

.ibd-privacy::backdrop {
	background-color: rgb(18 18 18 / 0.6);
}

.ibd-privacy__title {
	margin: 0 0 1.25rem;
	font-size: 1.5rem;
	line-height: 1.25;
}

.ibd-privacy__option {
	display: flex;
	align-items: flex-start;
	gap: 1rem;
	margin-bottom: 1.25rem;
	cursor: pointer;
}

.ibd-privacy__option > span {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}

/* The switches: a track with a knob, orange when on. */
.ibd-privacy__option input {
	flex: 0 0 auto;
	position: relative;
	width: 2.75rem;
	height: 1.5rem;
	margin: 0.1rem 0 0;
	border: 2px solid var(--black, #121212);
	border-radius: 1rem;
	background-color: var(--white, #fff);
	appearance: none;
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.ibd-privacy__option input::before {
	content: "";
	position: absolute;
	top: 2px;
	left: 2px;
	width: calc(1.5rem - 8px);
	height: calc(1.5rem - 8px);
	border-radius: 50%;
	background-color: var(--black, #121212);
	transition: transform 0.2s ease;
}

.ibd-privacy__option input:checked {
	background-color: var(--orange, #f56905);
}

.ibd-privacy__option input:checked::before {
	transform: translateX(1.25rem);
}

.ibd-privacy__policy {
	margin: 0 0 1.5rem;
}

.ibd-privacy__policy a {
	color: inherit;
	text-underline-offset: 0.2em;
}

.ibd-privacy__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
}

.ibd-privacy__actions button {
	padding: 0.7em 2em;
	border: 2px solid var(--black, #121212);
	border-radius: var(--radius-pill, 50px);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
}

.ibd-privacy__save {
	background-color: var(--black, #121212);
	color: var(--white, #fff);
}

.ibd-privacy__cancel {
	background-color: transparent;
	color: var(--black, #121212);
}

.ibd-privacy__save:is(:hover, :focus) {
	background-color: var(--dark, #333);
	color: var(--white, #fff);
}

.ibd-privacy__cancel:is(:hover, :focus) {
	background-color: var(--black, #121212);
	color: var(--white, #fff);
}

.ibd-privacy :focus-visible {
	outline: 3px solid var(--orange, #f56905);
	outline-offset: 2px;
}

/* Windows High Contrast (forced colours) drops backgrounds and shadows:
 * borders keep the banner and dialog edges, and the switches keep their
 * knob and "on" fill in system colours. */
.ibd-consent,
.ibd-privacy {
	border: 1px solid transparent;
}

@media (forced-colors: active) {
	.ibd-privacy__option input {
		forced-color-adjust: none;
		border-color: ButtonText;
		background-color: Canvas;
	}

	.ibd-privacy__option input::before {
		background-color: ButtonText;
	}

	.ibd-privacy__option input:checked {
		background-color: Highlight;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ibd-consent {
		animation: none;
	}

	.ibd-privacy__option input,
	.ibd-privacy__option input::before {
		transition: none;
	}
}
