/*
 * Best Before Consent · banner + settings dialog.
 * Tokens only (--bb-*) from the theme's main.css - no new hex values.
 * The theme's existing global `:focus-visible` rule and `prefers-reduced-motion`
 * rule (main.css) already cover every plain button/link here; nothing of our
 * own is added for either.
 *
 * Compact by design (coordinator brief, 16 Nov 2026): one line of text, one
 * row of controls (Essential only / Accept all / a plain "Settings" text
 * link), total height well under ~140px on a phone - a bottom SHEET, not a
 * wall, sitting above the mobile tab bar. On tablet/desktop it becomes a
 * small bottom-LEFT corner card (the chat launcher owns bottom-right), so
 * it never covers page content the way a full-width bar would.
 */

.bb-consent-banner {
	position: fixed;
	top: auto;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 70; /* highest of the bottom-fixed UI stack (tabs 60, stickybasket 59, chat 58, activity 57) — this is a legal notice. */
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 12px 16px;
	background: var(--bb-surface);
	border-top: 1px solid var(--bb-border);
	box-shadow: var(--bb-shadow);
	animation: bbConsentIn .25s var(--bb-ease);
}
.bb-consent-banner[hidden] { display: none !important; }

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

@keyframes bbConsentIn {
	from { transform: translateY(100%); }
	to { transform: translateY(0); }
}

.bb-consent-banner__text {
	margin: 0;
	font-size: .8125rem;
	line-height: 1.35;
	color: var(--bb-body);
}
.bb-consent-banner__text a { color: var(--bb-ink); font-weight: 600; text-decoration: underline; white-space: nowrap; }

.bb-consent-banner__actions {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 10px;
}
.bb-consent-banner__actions .bb-btn { flex: none; }
.bb-consent-banner__settings {
	margin-left: auto;
	flex: none;
	display: inline-flex;
	align-items: center;
	min-height: 40px;
	padding: 0 2px;
	border: 0;
	background: none;
	color: var(--bb-ink);
	font: inherit;
	font-size: .8125rem;
	font-weight: 600;
	text-decoration: underline;
	white-space: nowrap;
	cursor: pointer;
}

.bb-consent-banner .bb-consent-banner__settings { text-decoration: underline; text-underline-offset: 3px; }

/* Mobile (<768): compact floating bar (≤140px incl. padding) that sits ABOVE
   the mobile tab bar (offset, not padding, so the tab bar stays visible and
   tappable). One line of text, then one row: two equal buttons + a "Settings"
   text link. Same body:has(.bb-tabs) offset pattern as chat.css. */
@media (max-width: 767px) {
	.bb-consent-banner {
		left: 8px;
		right: 8px;
		bottom: calc(8px + env(safe-area-inset-bottom));
		gap: 6px;
		padding: 10px 12px;
		border: 1px solid var(--bb-border);
		border-radius: var(--bb-r-tile);
	}
	body:has(.bb-tabs) .bb-consent-banner { bottom: calc(var(--bb-tabs-h, 64px) + 8px + env(safe-area-inset-bottom)); }
	.bb-consent-banner__text { font-size: .75rem; }
	.bb-consent-banner__actions { flex-wrap: nowrap; gap: 8px; }
	.bb-consent-banner__actions .bb-btn { flex: 1 1 0; min-width: 0; padding: 0 10px; white-space: nowrap; }
	.bb-consent-banner__settings { margin-left: 2px; min-height: 40px; }
	/* While the notice is open, the chat launcher and sticky basket would sit
	   under/over it in the same strip - hide them until a choice is made. */
	body:has(#bb-consent-banner:not([hidden])) .bb-chat,
	body:has(#bb-consent-banner:not([hidden])) .bb-stickybasket { visibility: hidden; }
}

/* Activity toasts share the bottom-left corner with the desktop card (and the
   bottom strip on phones) - keep them out of the way until a choice is made. */
body:has(#bb-consent-banner:not([hidden])) .bb-activity { visibility: hidden; }

/* Tablet/desktop (≥768): small bottom-LEFT corner card, not a full-width bar -
   the chat launcher (.bb-chat) sits bottom-right, so the two never collide. */
@media (min-width: 768px) {
	.bb-consent-banner {
		right: auto;
		bottom: 16px;
		left: 16px;
		width: 380px;
		max-width: calc(100vw - 32px);
		border: 1px solid var(--bb-border);
		border-radius: var(--bb-r-panel);
		padding: 16px;
		animation-name: bbConsentInCard;
	}
	@keyframes bbConsentInCard {
		from { transform: translateY(16px); opacity: 0; }
		to { transform: translateY(0); opacity: 1; }
	}
	.bb-consent-banner__actions { gap: 8px; }
}

/*
 * Bug found in QA: the ≥768px block above sets `animation-name:
 * bbConsentInCard` with equal specificity to, and later in source order
 * than, the `prefers-reduced-motion` rule near the top of this file (which
 * only set the shorthand `animation: none` on the base selector) - the
 * cascade let the later, more specific-by-source-order animation-name
 * longhand win at any width ≥768px, re-enabling motion. Repeating the
 * override after the desktop block fixes it at every breakpoint.
 */
@media (prefers-reduced-motion: reduce) {
	.bb-consent-banner { animation: none; }
}

/* ---------- Settings dialog ----------
   Uses the theme's .bb-dialog (main.css): centred modal on desktop, bottom
   sheet on phones; Esc/backdrop/focus-trap come from the theme's global.js.
   Only the contents are styled here. */
.bb-consent-dialog { width: min(480px, calc(100vw - 32px)); }
.bb-consent-dialog .bb-dialog__head { padding: 12px 12px 12px 22px; }
.bb-consent-dialog .bb-dialog__body { padding-top: 8px; padding-bottom: 8px; }
.bb-consent-dialog__intro { margin: 8px 0 4px; color: var(--bb-body); font-size: .875rem; }
.bb-consent-dialog__intro a { color: var(--bb-ink); font-weight: 600; text-decoration: underline; }

.bb-consent-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 14px 0;
	border-bottom: 1px solid var(--bb-border);
}
.bb-consent-row:last-child { border-bottom: 0; }
.bb-consent-row__text { display: flex; flex-direction: column; gap: 2px; }
.bb-consent-row__text strong { color: var(--bb-ink); font-size: .9375rem; }
.bb-consent-row__text span { color: var(--bb-muted); font-size: .8125rem; }

.bb-consent-switch {
	position: relative;
	flex: none;
	width: 48px;
	height: var(--bb-touch);
	padding: 0;
	border: 0;
	background: transparent;
	cursor: pointer;
}
.bb-consent-switch::before {
	content: '';
	position: absolute;
	inset: 50% 0 auto 0;
	transform: translateY(-50%);
	width: 44px;
	height: 26px;
	border-radius: var(--bb-r-pill);
	background: var(--bb-border-2);
	transition: background-color .15s var(--bb-ease);
}
.bb-consent-switch__thumb {
	position: absolute;
	top: 50%;
	left: 2px;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: #fff;
	box-shadow: 0 1px 2px rgba(17, 17, 17, .3);
	transform: translateY(-50%);
	transition: left .15s var(--bb-ease);
}
.bb-consent-switch[aria-checked="true"]::before { background: var(--bb-ink); }
.bb-consent-switch[aria-checked="true"] .bb-consent-switch__thumb { left: 24px; }

@media (prefers-reduced-motion: reduce) {
	.bb-consent-switch::before,
	.bb-consent-switch__thumb { transition: none; }
}

/* Necessary: locked on (shown checked, not interactive). */
.bb-consent-switch.is-locked { cursor: not-allowed; }
.bb-consent-switch.is-locked::before { background: var(--bb-muted); }
.bb-consent-switch.is-locked .bb-consent-switch__thumb { left: 24px; }
.bb-consent-switch:disabled { opacity: 1; }

.bb-consent-dialog__foot {
	display: flex;
	gap: 10px;
}
.bb-consent-dialog__foot .bb-btn { flex: 1 1 0; min-width: 0; }
