/**
 * Cookie consent: banner/settings card, fallback button, embed placeholders.
 *
 * Reads the theme's tokens with fallbacks, so it looks like the club's site
 * on sportadmin-cards and still holds together on any other theme. The card's
 * colours come from the page itself (copied by the script into
 * --sa-consent-bg / --sa-consent-fg); buttons use the theme's own button
 * classes. See docs/consent.md.
 */

/* --- Card ----------------------------------------------------------------- */

.sa-consent {
	position: fixed;
	right: 1rem;
	bottom: 1rem;
	z-index: 99990;
	box-sizing: border-box;
	width: 24rem;
	max-width: calc(100vw - 2rem);
	max-height: calc(100vh - 2rem);
	overflow-y: auto;
	padding: 1.25rem;
	background: var(--sa-consent-bg, var(--wp--preset--color--ljus, #fff));
	color: var(--sa-consent-fg, var(--wp--preset--color--body-text, #111));
	border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
	border-radius: var(--wp--custom--card-radius, 6px);
	box-shadow: var(--wp--preset--shadow--large, 0 10px 30px rgba(0, 0, 0, 0.2));
	font-size: 0.9375rem;
	line-height: 1.5;
	text-align: left;
}

@media (max-width: 600px) {
	.sa-consent {
		left: 0.5rem;
		right: 0.5rem;
		bottom: 0.5rem;
		width: auto;
		max-width: none;
	}
}

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

.sa-consent__title {
	margin: 0 0 0.375rem;
	padding-right: 2rem;
	font-size: 1.0625rem;
	font-weight: 700;
	line-height: 1.3;
}

.sa-consent__title:focus {
	outline: none;
}

.sa-consent__text {
	margin: 0 0 1rem;
}

.sa-consent a {
	color: inherit;
	font-size: inherit;
	font-family: inherit;
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

.sa-consent__actions {
	display: flex;
	gap: 0.5rem;
	margin-top: 0.25rem;
}

.sa-consent__actions .wp-block-button {
	flex: 1 1 0;
	margin: 0;
}

/* Equal weight for every choice: same theme button, same size. */
.sa-consent .wp-block-button__link,
.sa-consent-embed .wp-block-button__link {
	display: block;
	width: 100%;
	padding: 0.625em 1em;
	font-size: 0.9375rem;
	line-height: 1.3;
	text-align: center;
	white-space: nowrap;
	cursor: pointer;
}

.sa-consent__link {
	display: block;
	margin: 0.75rem auto 0;
	padding: 0.25rem 0.5rem;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 0.15em;
	cursor: pointer;
}

.sa-consent__close {
	position: absolute;
	top: 0.625rem;
	right: 0.625rem;
	width: 2rem;
	height: 2rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	color: inherit;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
}

.sa-consent__close:hover {
	background: color-mix(in srgb, currentColor 8%, transparent);
}

.sa-consent__link:focus-visible,
.sa-consent__close:focus-visible,
.sa-consent__switch:focus-visible,
.sa-consent-fab:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* --- Settings toggles ----------------------------------------------------- */

.sa-consent__options {
	margin: 0.5rem 0 1rem;
}

.sa-consent__option {
	display: flex;
	align-items: flex-start;
	gap: 0.75rem;
	padding: 0.625rem 0;
	border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent);
}

.sa-consent__option:first-child {
	border-top: 0;
}

.sa-consent__option-text {
	flex: 1 1 auto;
	cursor: pointer;
}

.sa-consent__option-label {
	display: block;
	font-weight: 600;
}

.sa-consent__option-desc {
	display: block;
	font-size: 0.8125rem;
	opacity: 0.8;
}

.sa-consent__switch {
	-webkit-appearance: none;
	appearance: none;
	position: relative;
	flex: 0 0 auto;
	width: 2.5rem;
	height: 1.5rem;
	margin: 0.125rem 0 0;
	border: 0;
	border-radius: 999px;
	background: color-mix(in srgb, currentColor 25%, transparent);
	cursor: pointer;
	transition: background-color 0.15s ease;
}

.sa-consent__switch::after {
	content: "";
	position: absolute;
	top: 0.1875rem;
	left: 0.1875rem;
	width: 1.125rem;
	height: 1.125rem;
	border-radius: 50%;
	background: var(--wp--preset--color--vit, #fff);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
	transition: transform 0.15s ease;
}

.sa-consent__switch:checked {
	background: var(--wp--preset--color--accent, #2563eb);
}

.sa-consent__switch:checked::after {
	transform: translateX(1rem);
}

.sa-consent__switch:disabled {
	opacity: 0.55;
	cursor: default;
}

/* --- Fallback button (pages without a footer link) ------------------------ */

.sa-consent-fab {
	position: fixed;
	right: 1rem;
	bottom: 1rem;
	z-index: 99989;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
	border-radius: 50%;
	background: var(--sa-consent-bg, var(--wp--preset--color--ljus, #fff));
	color: var(--sa-consent-fg, var(--wp--preset--color--body-text, #111));
	box-shadow: var(--wp--preset--shadow--medium, 0 4px 12px rgba(0, 0, 0, 0.18));
	cursor: pointer;
}

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

/* --- Embed placeholders --------------------------------------------------- */

.sa-consent-embed {
	position: relative;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	padding: 1.25rem;
	border-radius: var(--wp--custom--card-radius, 6px);
	background: var(--wp--preset--color--mork, #111);
	color: var(--wp--preset--color--vit, #fff);
	text-align: center;
	font-size: 0.9375rem;
	line-height: 1.45;
}

/* The inline aspect-ratio reserves the embed's shape, and with the default
   min-height: auto the box still grows when its text needs more room (a
   16:9 box on a phone is shorter than the text). Never clip: the "Öppna på"
   link is what keeps the content reachable without consent. A box with no
   ratio gets a floor instead. */
.sa-consent-embed:not([style*="aspect-ratio"]) {
	min-height: 12rem;
}

.sa-consent-embed--post:not([style*="aspect-ratio"]),
.sa-consent-embed--content:not([style*="aspect-ratio"]) {
	min-height: 14rem;
}

/* Space below like any block. The element selector lifts it over core's
   `.wp-block-post-content-is-layout-flow > *` margin reset (0,1,0), which
   loads later and would otherwise stack two placeholders edge to edge. */
figure.sa-consent-embed {
	margin: 0 0 var(--wp--preset--spacing--70, 1.5rem);
}

/* Core's responsive embed wrapper reserves a 16:9 box with ::before and
   absolutely positions the iframe in it. A placeholder sits in the flow
   instead, so it can grow on a narrow screen: drop the reservation while the
   wrapper holds one. (0,4,1) beats core's (0,3,1). Without :has() support the
   box sits below an empty reservation, which is untidy but never clipped. */
.wp-embed-responsive .wp-has-aspect-ratio .wp-block-embed__wrapper:has(> .sa-consent-embed)::before {
	display: none;
}

.wp-block-embed__wrapper > figure.sa-consent-embed {
	margin: 0;
}

.sa-consent-embed template {
	display: none;
}

.sa-consent-embed__body {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.625rem;
	max-width: 26rem;
}

.sa-consent-embed__provider {
	font-size: 0.75rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	opacity: 0.75;
}

.sa-consent-embed__text,
.sa-consent-embed__note {
	margin: 0;
}

.sa-consent-embed__note,
.sa-consent-embed__open {
	font-size: 0.8125rem;
	opacity: 0.85;
}

.sa-consent-embed .wp-block-button {
	margin: 0.25rem 0;
}

.sa-consent-embed .wp-block-button__link {
	width: auto;
}

.sa-consent-embed a {
	color: inherit;
	font-size: inherit;
	font-family: inherit;
	text-decoration: underline;
	text-underline-offset: 0.15em;
}

@media (prefers-reduced-motion: reduce) {
	.sa-consent__switch,
	.sa-consent__switch::after {
		transition: none;
	}
}
