/*
 * The cookie bar, the preference centre and the re-open control.
 *
 * WRITTEN FOR A THEME WE HAVE NEVER SEEN. This plugin's other surfaces can afford to inherit the
 * host's type and colour — a speakers grid that looks like the site around it is a feature. A
 * consent control cannot: a theme that paints `button:hover` its own brand colour, or sets
 * `button { background: none }`, or hides anything `position: fixed` behind a sticky header, turns
 * a legal obligation into something the visitor cannot see or cannot tell apart. hello-elementor's
 * reset.css was found doing exactly the first of those (it paints both `:hover` and `:focus` #c36
 * and outspecifies a single class of ours), which is why every property such a rule might set is
 * pinned below for EVERY state rather than only for the resting one.
 *
 * The two rules that follow from that:
 *
 *   · colours are stated, never inherited — including on the buttons;
 *   · `:hover`, `:focus`, `:focus-visible` and `:active` are all written out, because a theme rule
 *     on a bare element selector beats a single class of ours and silence is not a default.
 *
 * EQUAL PROMINENCE IS A CSS FACT HERE. `.mep-consent-btn-primary` is Accept all AND Reject all, one
 * rule, no second selector distinguishing them. tests/test-consent-banner.php asserts that neither
 * button has a class the other lacks; this file is the other half of that promise. Making Reject
 * quieter is the single most common way a cookie bar becomes unlawful, and it always arrives as a
 * styling tweak, so it is written down in both places.
 */

.mep-consent {
	position: fixed;
	inset: auto 0 0 0;
	left: 0;
	right: 0;
	bottom: 0;
	/* Above a sticky header and most lightboxes, below nothing the visitor needs more than this. */
	z-index: 2147483000;
	box-sizing: border-box;
	background: #0b1b33;
	color: #ffffff;
	/* Its own stack, so a theme's display font cannot make the copy unreadable at this size. */
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	/* Not flush to the edge: the estate's minimum-padding rule, and a bar whose text touches the
	   screen edge reads as broken on a phone. */
	padding: 16px;
	box-shadow: 0 -2px 12px rgba( 0, 0, 0, 0.35 );
}

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

.mep-consent[hidden],
.mep-consent-reopen[hidden],
#mep-consent-reopen[hidden],
.mep-consent-choices[hidden],
.mep-consent-btn[hidden] {
	/* A theme that sets `display: block` on our elements would otherwise show a bar we hid. The
	   `hidden` attribute is how consent.js reveals and conceals everything here, so it has to win. */
	display: none !important;
}

.mep-consent-inner {
	max-width: 1100px;
	margin: 0 auto;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 16px;
}

.mep-consent-text {
	flex: 1 1 320px;
	min-width: 0;
}

.mep-consent-title {
	margin: 0 0 4px;
	padding: 0;
	font-size: 16px;
	font-weight: 700;
	line-height: 1.3;
	color: #ffffff;
	/* A theme heading rule may add a border, a rule line or a ::after flourish. Not in here. */
	border: 0;
	text-transform: none;
	letter-spacing: normal;
}

.mep-consent-body {
	margin: 0;
	padding: 0;
	color: #ffffff;
}

/* ── the preference centre ──────────────────────────────────────────────────── */

.mep-consent-choices {
	flex: 1 1 100%;
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	margin: 0;
	padding: 12px 0 0;
	border-top: 1px solid rgba( 255, 255, 255, 0.25 );
}

.mep-consent-choice {
	flex: 1 1 260px;
	display: flex;
	align-items: flex-start;
	gap: 8px;
}

.mep-consent-check {
	/* White = input, grey/navy = not. The estate's convention, and here it is also the only way a
	   checkbox stays visible on a dark bar under a theme that recolours form controls. */
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
	margin: 2px 0 0;
	accent-color: #ffffff;
}

.mep-consent-check:disabled {
	/* Always-on, and it should look it rather than look broken. */
	opacity: 0.6;
	cursor: default;
}

.mep-consent-choice-label {
	display: block;
	margin: 0;
	padding: 0;
	color: #ffffff;
	font-weight: 400;
	cursor: pointer;
}

.mep-consent-choice-name {
	display: block;
	font-weight: 700;
}

.mep-consent-choice-note {
	display: block;
	font-size: 13px;
	opacity: 0.85;
}

/* ── the controls ───────────────────────────────────────────────────────────── */

.mep-consent-actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	flex: 0 1 auto;
}

.mep-consent-btn {
	display: inline-block;
	margin: 0;
	padding: 10px 18px;
	border: 2px solid #ffffff;
	border-radius: 2px;
	background: transparent;
	color: #ffffff;
	font: inherit;
	font-weight: 700;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	text-transform: none;
	letter-spacing: normal;
	cursor: pointer;
	box-shadow: none;
	/* A theme's `min-width` or `width: 100%` on buttons would stack these into a column and break
	   the side-by-side equality the two primaries depend on. */
	width: auto;
	min-width: 0;
	max-width: none;
}

/*
 * Every state a host rule might claim, claimed first. `.mep-consent .mep-consent-btn` is two
 * classes and beats the bare `button:hover` that themes reach for; the states are written out
 * rather than left to inherit because silence in a cascade is not a value.
 */
.mep-consent .mep-consent-btn:hover,
.mep-consent .mep-consent-btn:focus,
.mep-consent .mep-consent-btn:active {
	background: #ffffff;
	color: #0b1b33;
	border-color: #ffffff;
	box-shadow: none;
	text-decoration: none;
	opacity: 1;
}

/* The keyboard ring, and only for the keyboard — a mouse click must not leave one behind. Same
   judgement as mep-agenda.css: scoped to :focus-visible rather than removed, which would strip the
   ring from keyboard users too. */
.mep-consent .mep-consent-btn:focus-visible {
	outline: 3px solid #ffd166;
	outline-offset: 2px;
}

.mep-consent .mep-consent-btn:focus:not( :focus-visible ) {
	outline: none;
}

/*
 * Accept all and Reject all. ONE rule for both — there is no selector anywhere in this file that
 * distinguishes them, and adding one is the change that makes this bar unlawful.
 */
.mep-consent .mep-consent-btn-primary {
	background: #ffffff;
	color: #0b1b33;
	border-color: #ffffff;
}

.mep-consent .mep-consent-btn-primary:hover,
.mep-consent .mep-consent-btn-primary:focus,
.mep-consent .mep-consent-btn-primary:active {
	background: transparent;
	color: #ffffff;
	border-color: #ffffff;
}

/* The two secondary controls — the way into the centre and the way to save from it. Quieter than
   the primaries, and quieter than BOTH of them equally. */
.mep-consent .mep-consent-btn-quiet {
	background: transparent;
	color: #ffffff;
	border-color: rgba( 255, 255, 255, 0.5 );
	font-weight: 400;
}

/* ── the withdrawal control ─────────────────────────────────────────────────── */

/*
 * Withdrawing has to be as easy as giving, which in practice means: on every page, without
 * hunting. A small round cookie in the corner, permanently there and reachable by keyboard.
 *
 * KEYED ON THE ID, NOT THE CLASS. This control sits outside `.mep-consent`, so it cannot borrow the
 * banner's two-class selectors, and hello-elementor's `[type=button], button { background:
 * transparent; border: 1px solid #c36; color: #c36 }` has the same weight as one class and loads
 * after us. That rule won, and the control rendered as a see-through pink pill with page text
 * showing through it. An id outweighs any element/attribute/class rule a theme writes for buttons.
 *
 * A solid surface, a hairline border and a soft shadow, so it reads as a control above the page on
 * any background. Light by default, dark when the visitor's system is dark or the site says so on
 * <html data-theme>, the same switch the speaker skins use.
 */
#mep-consent-reopen {
	--mep-reopen-bg: #ffffff;
	--mep-reopen-bg-hover: #f1f3f7;
	--mep-reopen-fg: #0b1b33;
	--mep-reopen-border: rgba( 11, 27, 51, 0.14 );
	--mep-reopen-shadow: 0 1px 2px rgba( 0, 0, 0, 0.12 ), 0 4px 14px rgba( 0, 0, 0, 0.16 );
	--mep-reopen-ring: #2563eb;
	--mep-reopen-halo: #ffffff;

	position: fixed;
	left: calc( 16px + env( safe-area-inset-left, 0px ) );
	right: auto;
	top: auto;
	bottom: calc( 16px + env( safe-area-inset-bottom, 0px ) );
	/* Above page content and sticky bars, below a site's own modals and popups (Elementor's sit at
	   9999; <dialog> is in the top layer anyway). The banner itself stays at the top of the stack. */
	z-index: 9000;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	min-width: 44px;
	max-width: 44px;
	margin: 0;
	padding: 0;
	border: 1px solid var( --mep-reopen-border );
	border-radius: 50%;
	background: var( --mep-reopen-bg );
	color: var( --mep-reopen-fg );
	box-shadow: var( --mep-reopen-shadow );
	font-size: 0;
	line-height: 0;
	text-decoration: none;
	cursor: pointer;
	opacity: 1;
	transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

#mep-consent-reopen:hover,
#mep-consent-reopen:focus,
#mep-consent-reopen:active {
	background: var( --mep-reopen-bg-hover );
	color: var( --mep-reopen-fg );
	border-color: var( --mep-reopen-border );
	box-shadow: var( --mep-reopen-shadow );
	text-decoration: none;
	opacity: 1;
}

/* Keyboard ring: blue outline with a halo between it and the button, so it shows on dark and light. */
#mep-consent-reopen:focus-visible {
	outline: 3px solid var( --mep-reopen-ring );
	outline-offset: 3px;
	box-shadow: 0 0 0 3px var( --mep-reopen-halo ), var( --mep-reopen-shadow );
}

#mep-consent-reopen:focus:not( :focus-visible ) {
	outline: none;
}

#mep-consent-reopen .mep-consent-reopen-icon {
	display: block;
	width: 22px;
	height: 22px;
	margin: 0;
	flex: 0 0 auto;
	color: inherit;
	pointer-events: none;
}

/* Which cookie: whole once something optional is accepted, bitten otherwise (and before the
   runtime has said, which is also when the control is hidden). consent.js sets the state. */
#mep-consent-reopen .mep-consent-reopen-icon--whole,
#mep-consent-reopen[data-mep-consent-state='accepted'] .mep-consent-reopen-icon--bitten {
	display: none;
}

#mep-consent-reopen[data-mep-consent-state='accepted'] .mep-consent-reopen-icon--whole {
	display: block;
}

[dir='rtl'] #mep-consent-reopen {
	left: auto;
	right: calc( 16px + env( safe-area-inset-right, 0px ) );
}

@media ( prefers-color-scheme: dark ) {
	html:not( [data-theme='light'] ) #mep-consent-reopen {
		--mep-reopen-bg: #1c2538;
		--mep-reopen-bg-hover: #26314a;
		--mep-reopen-fg: #f3f5f9;
		--mep-reopen-border: rgba( 255, 255, 255, 0.18 );
		--mep-reopen-shadow: 0 1px 2px rgba( 0, 0, 0, 0.4 ), 0 4px 14px rgba( 0, 0, 0, 0.45 );
		--mep-reopen-ring: #7aa7ff;
		--mep-reopen-halo: #0b1b33;
	}
}

html[data-theme='dark'] #mep-consent-reopen {
	--mep-reopen-bg: #1c2538;
	--mep-reopen-bg-hover: #26314a;
	--mep-reopen-fg: #f3f5f9;
	--mep-reopen-border: rgba( 255, 255, 255, 0.18 );
	--mep-reopen-shadow: 0 1px 2px rgba( 0, 0, 0, 0.4 ), 0 4px 14px rgba( 0, 0, 0, 0.45 );
	--mep-reopen-ring: #7aa7ff;
	--mep-reopen-halo: #0b1b33;
}

/* ── blocked embeds ─────────────────────────────────────────────────────────── */

/*
 * Where a video or a map would have been. It keeps the embed's own box — MEP_Consent_Embeds carries
 * the width and height across — so allowing one does not jump the page, and it says which company
 * would be loaded rather than "third-party content", because a visitor cannot consent to a category
 * name they have to guess at.
 */
.mep-embed-placeholder {
	box-sizing: border-box;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: 100%;
	max-width: 100%;
	min-height: 180px;
	padding: 20px;
	border: 1px dashed #8a94a6;
	background: #f3f4f6;
	color: #1f2937;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
	font-size: 14px;
	line-height: 1.5;
	text-align: center;
}

.mep-embed-placeholder p {
	margin: 0;
	padding: 0;
	color: #1f2937;
	max-width: 46em;
}

.mep-embed-placeholder-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	justify-content: center;
}

.mep-embed-btn {
	display: inline-block;
	margin: 0;
	padding: 8px 14px;
	border: 2px solid #0b1b33;
	border-radius: 2px;
	background: #0b1b33;
	color: #ffffff;
	font: inherit;
	font-weight: 700;
	line-height: 1.2;
	text-transform: none;
	letter-spacing: normal;
	cursor: pointer;
	box-shadow: none;
	width: auto;
	min-width: 0;
}

.mep-embed-placeholder .mep-embed-btn:hover,
.mep-embed-placeholder .mep-embed-btn:focus,
.mep-embed-placeholder .mep-embed-btn:active {
	background: #ffffff;
	color: #0b1b33;
	border-color: #0b1b33;
	box-shadow: none;
	opacity: 1;
}

.mep-embed-placeholder .mep-embed-btn:focus-visible {
	outline: 3px solid #0b1b33;
	outline-offset: 2px;
}

.mep-embed-placeholder .mep-embed-btn:focus:not( :focus-visible ) {
	outline: none;
}

/* The second control is the way to the full choice, not a second accept. Quieter, and it is a
   button rather than a link because it opens the centre rather than navigating anywhere. */
.mep-embed-placeholder .mep-embed-btn-quiet {
	background: transparent;
	color: #0b1b33;
	font-weight: 400;
}

/* ── narrow screens ─────────────────────────────────────────────────────────── */

@media ( max-width: 640px ) {
	.mep-consent-inner {
		align-items: stretch;
	}

	.mep-consent-actions {
		width: 100%;
	}

	/* Full width and stacked, but still the same width as each other — the equality survives the
	   breakpoint, which is where it is most often lost. */
	.mep-consent .mep-consent-btn {
		flex: 1 1 100%;
	}

	/* The bar can be tall on a phone once the centre is open; let it scroll rather than push its
	   own buttons off the bottom of the screen where they cannot be reached. */
	.mep-consent {
		max-height: 85vh;
		overflow-y: auto;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.mep-consent,
	.mep-consent-reopen,
	.mep-embed-placeholder {
		transition: none !important;
		animation: none !important;
	}
}
