/* NGX GDPR - banner, preferences modal, floating button. All colours come from CSS custom properties set on #ngx-gd. */

.ngxgd {
	--ngxgd-bg: #ffffff;
	--ngxgd-fg: #1d2327;
	--ngxgd-btn-bg: #1d2327;
	--ngxgd-btn-fg: #ffffff;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 16px;
	line-height: 1.5;
	color: var(--ngxgd-fg);
}

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

/* Author display rules would otherwise beat the hidden attribute. */
.ngxgd [hidden] {
	display: none !important;
}

/* ---------- Banner ---------- */
.ngxgd-banner {
	position: fixed;
	z-index: 99999;
	inset-inline: 0;
	inset-block-end: 0;
	max-height: 90vh;
	max-height: 90dvh;
	overflow-y: auto;
	padding: 20px 56px 20px 20px;
	background: var(--ngxgd-bg);
	color: var(--ngxgd-fg);
	border-block-start: 1px solid color-mix(in srgb, var(--ngxgd-fg) 25%, transparent);
	box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
}

.ngxgd-banner:focus {
	outline: none;
}

.ngxgd-banner:focus-visible {
	outline: 3px solid var(--ngxgd-fg);
	outline-offset: -3px;
}

.ngxgd--bottom .ngxgd-banner {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	column-gap: 24px;
	align-items: center;
}

.ngxgd--bottom .ngxgd-title,
.ngxgd--bottom .ngxgd-desc {
	grid-column: 1;
}

.ngxgd--bottom .ngxgd-actions {
	grid-column: 2;
	grid-row: 1 / span 2;
	min-width: 480px;
}

.ngxgd--bottom-left .ngxgd-banner,
.ngxgd--bottom-right .ngxgd-banner {
	inset-inline: auto;
	inline-size: min(440px, calc(100vw - 32px));
	margin: 16px;
	border: 1px solid color-mix(in srgb, var(--ngxgd-fg) 25%, transparent);
	border-radius: 12px;
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.ngxgd--bottom-left .ngxgd-banner {
	inset-inline-start: 0;
}

.ngxgd--bottom-right .ngxgd-banner {
	inset-inline-end: 0;
}

.ngxgd-title {
	margin: 0 0 6px;
	font-size: 1.125rem;
	font-weight: 700;
	line-height: 1.3;
	color: inherit;
}

.ngxgd-desc {
	margin: 0 0 14px;
	font-size: 0.9375rem;
	color: inherit;
}

.ngxgd--bottom .ngxgd-desc {
	margin-block-end: 0;
}

.ngxgd-policy,
.ngxgd-link {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.ngxgd-link {
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	cursor: pointer;
}

.ngxgd-policy:focus-visible,
.ngxgd-link:focus-visible,
.ngxgd-btn:focus-visible,
.ngxgd-x:focus-visible,
.ngxgd-fab:focus-visible,
.ngxgd-switch:focus-visible {
	outline: 3px solid var(--ngxgd-fg);
	outline-offset: 2px;
}

/* ---------- Buttons: accept / reject share EXACTLY the same box, weight and look ---------- */
.ngxgd-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
}

.ngxgd-btn {
	flex: 1 1 0;
	min-inline-size: 0;
	min-block-size: 44px;
	padding: 10px 16px;
	border: 2px solid var(--ngxgd-btn-bg);
	border-radius: 8px;
	font: inherit;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1.25;
	text-align: center;
	cursor: pointer;
}

.ngxgd-btn--solid {
	background: var(--ngxgd-btn-bg);
	color: var(--ngxgd-btn-fg);
}

.ngxgd-btn--outline {
	background: transparent;
	color: var(--ngxgd-fg);
}

.ngxgd-btn:hover {
	filter: brightness(0.92);
}

.ngxgd-x {
	position: absolute;
	inset-block-start: 10px;
	inset-inline-end: 10px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 44px;
	block-size: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.ngxgd-x:hover {
	background: color-mix(in srgb, var(--ngxgd-fg) 10%, transparent);
}

/* ---------- Preferences modal (native <dialog>, focus handling by the browser) ---------- */
.ngxgd-modal {
	inline-size: min(560px, calc(100vw - 24px));
	max-block-size: calc(100vh - 24px);
	max-block-size: calc(100dvh - 24px);
	padding: 0;
	border: 0;
	border-radius: 14px;
	background: var(--ngxgd-bg);
	color: var(--ngxgd-fg);
	box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.ngxgd-modal:modal {
	overscroll-behavior: contain;
}

.ngxgd-modal::backdrop {
	overflow: hidden;
	overscroll-behavior: contain;
	background: rgba(0, 0, 0, 0.55);
}

.ngxgd-form {
	position: relative;
	max-block-size: calc(100vh - 24px);
	max-block-size: calc(100dvh - 24px);
	overflow-y: auto;
	padding: 20px;
}

.ngxgd-modal-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	padding-inline-end: 44px;
}

.ngxgd-cats {
	margin: 16px 0;
	padding: 0;
	list-style: none;
}

.ngxgd-cat {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	padding: 14px 0;
	border-block-start: 1px solid color-mix(in srgb, var(--ngxgd-fg) 20%, transparent);
}

.ngxgd .ngxgd-cat-name {
	display: block;
	font-weight: 700;
	line-height: 30px; /* same height as the switch: title and switch share one centre line */
}

.ngxgd-cat-desc {
	margin: 2px 0 0;
	font-size: 0.875rem;
}

/* ---------- Switch (own look so it works in every browser; also carries the native `switch` attribute) ----------
 * Selectors are deliberately scoped (.ngxgd .ngxgd-cat .ngxgd-switch): themes style `input[type="checkbox"]`
 * (20x20 box, a "✔" ::before, their own radius) and would otherwise beat a single-class rule. The shape properties
 * (size, radius) are !important because some themes force `input { border-radius: … !important }` and the switch is a
 * component this plugin fully owns. */
.ngxgd .ngxgd-cat .ngxgd-switch {
	-webkit-appearance: none;
	appearance: none;
	box-sizing: border-box;
	position: relative;
	flex: none;
	inline-size: 52px;
	block-size: 30px;
	width: 52px !important;
	height: 30px !important;
	min-width: 52px !important;
	margin: 0;
	padding: 0;
	border: 2px solid var(--ngxgd-fg);
	border-radius: 15px !important;
	background: transparent;
	box-shadow: none;
	cursor: pointer;
}

.ngxgd .ngxgd-cat .ngxgd-switch::before {
	content: "";
	box-sizing: border-box;
	position: absolute;
	inset-block-start: 3px;
	inset-inline-start: 3px;
	inline-size: 20px;
	block-size: 20px;
	width: 20px;
	height: 20px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--ngxgd-fg);
	box-shadow: none;
	transform: none;
}

.ngxgd .ngxgd-cat .ngxgd-switch::after {
	content: none;
}

.ngxgd .ngxgd-cat .ngxgd-switch:checked {
	border-color: var(--ngxgd-btn-bg);
	background: var(--ngxgd-btn-bg);
}

.ngxgd .ngxgd-cat .ngxgd-switch:checked::before {
	transform: translateX(22px);
	background: var(--ngxgd-btn-fg);
}

html[dir="rtl"] .ngxgd .ngxgd-cat .ngxgd-switch:checked::before {
	transform: translateX(-22px);
}

.ngxgd .ngxgd-cat .ngxgd-switch:disabled {
	opacity: 0.65;
	cursor: not-allowed;
}

/* While the preferences modal is open the banner behind it would only be noise (and a second set of buttons). */
.ngxgd:has(.ngxgd-modal[open]) .ngxgd-banner {
	visibility: hidden;
}

/* ---------- Floating re-open button (always available: withdrawal must be as easy as consent) ---------- */
.ngxgd-fab {
	position: fixed;
	z-index: 99998;
	inset-block-end: 16px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	inline-size: 48px;
	block-size: 48px;
	padding: 0;
	border: 2px solid var(--ngxgd-btn-fg);
	border-radius: 50%;
	background: var(--ngxgd-btn-bg);
	color: var(--ngxgd-btn-fg);
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
	cursor: pointer;
}

.ngxgd--fab-left .ngxgd-fab {
	inset-inline-start: 16px;
}

.ngxgd--fab-right .ngxgd-fab {
	inset-inline-end: 16px;
}

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
	.ngxgd--bottom .ngxgd-banner {
		display: block;
	}

	.ngxgd--bottom .ngxgd-desc {
		margin-block-end: 14px;
	}

	.ngxgd--bottom .ngxgd-actions {
		min-width: 0;
	}

	.ngxgd-actions {
		flex-direction: column;
	}

	.ngxgd-btn {
		flex: none;
		inline-size: 100%;
	}
}

/* ---------- Motion only for people who did not opt out ---------- */
@media (prefers-reduced-motion: no-preference) {
	.ngxgd-banner:not([hidden]) {
		animation: ngxgd-in 0.2s ease-out;
	}

	.ngxgd .ngxgd-cat .ngxgd-switch::before {
		transition: transform 0.15s ease;
	}
}

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

	to {
		opacity: 1;
		transform: none;
	}
}

@media print {
	.ngxgd {
		display: none;
	}
}
