/**
 * Altis Consent banner as a bottom-left card.
 *
 * The HubSpot chat owns the bottom-right corner, so the banner keeps clear of
 * it instead of spanning the full width underneath it. The card is up to 400px
 * wide and stops short of the chat. consent-banner.js measures the chat, which
 * HubSpot sizes by device rather than by window width, and moves the card
 * above it when there is no room beside it.
 *
 * Every rule is scoped to #cookie-consent-banner so it outranks the plugin
 * styles. The few !important flags answer the "Cookie banner updates" rules
 * in the Site Editor's custom CSS, which use !important themselves; they can
 * go once those rules are removed.
 */

#cookie-consent-banner {
	--hm-consent-gap: 12px;

	/* Width kept free for the chat; the script replaces it with a measurement. */
	--hm-consent-chat-reserve: 84px;
	--hm-consent-ink: var( --wp--preset--color--main, #131313 );
	--hm-consent-muted: var( --wp--preset--color--secondary, #565656 );
	--hm-consent-action: var( --wp--preset--color--custom-button, #1f63c8 );
	--hm-consent-action-hover: var( --wp--preset--color--custom-button-hover, #5b92e3 );

	left: max( var( --hm-consent-gap ), env( safe-area-inset-left ) );
	right: auto;
	bottom: max( var( --hm-consent-gap ), env( safe-area-inset-bottom ) );

	/* Above page content, below the HubSpot chat (9990) so an open chat covers it. */
	z-index: 9000;
	box-sizing: border-box;
	width: min( 400px, calc( 100% - var( --hm-consent-gap ) - var( --hm-consent-chat-reserve ) ) );
	max-width: none;
	padding: 0;
	border: 1px solid var( --wp--preset--color--border-light, #e1e1e1 );
	border-radius: 16px;
	background: var( --wp--preset--color--base, #fff );
	box-shadow: 0 12px 32px -12px rgba( 19, 19, 19, 0.35 );
	color: var( --hm-consent-ink );
	font-family: inherit;
	font-size: 0.95rem;
	line-height: 1.45;
	animation: hm-consent-in 240ms ease-out both;
}

@media ( min-width: 768px ) {
	#cookie-consent-banner {
		--hm-consent-gap: 24px;
	}
}

/* No room beside the chat, such as a narrow desktop window: sit above it. */
#cookie-consent-banner.is-above-chat {
	bottom: calc( var( --hm-consent-chat-height ) + var( --hm-consent-gap ) );
	width: calc( 100% - 2 * var( --hm-consent-gap ) );
}

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

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

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

/* Choice state. */

#cookie-consent-banner .consent-banner {
	display: block;
	box-sizing: border-box;
	/* stylelint-disable-next-line declaration-no-important */
	padding: 16px !important;
	font-size: inherit;
}

#cookie-consent-banner .consent-banner.hide {
	display: none;
}

#cookie-consent-banner .button-row {
	display: flex;
	flex-direction: column;
	gap: 8px;
	text-align: left;
}

#cookie-consent-banner .cookie-consent-message {
	margin: 0 0 6px;
	color: var( --hm-consent-ink );
	font-size: inherit;
	line-height: inherit;
}

#cookie-consent-banner .cookie-consent-message a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

#cookie-consent-banner .give-consent,
#cookie-consent-banner .revoke-consent,
#cookie-consent-banner .view-preferences,
#cookie-consent-banner .apply-cookie-preferences {
	appearance: none;
	display: block;
	width: 100%;
	min-height: 44px;
	margin: 0;
	padding: 10px 16px;
	border: 2px solid var( --hm-consent-action );
	/* stylelint-disable-next-line declaration-no-important */
	border-style: solid !important;
	border-radius: 100px;
	font: inherit;
	font-weight: 500;
	line-height: 1.2;
	text-align: center;
	cursor: pointer;
	transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

/* Same size and outline for both choices, so neither is harder to find. */
#cookie-consent-banner .give-consent,
#cookie-consent-banner .apply-cookie-preferences {
	background: var( --hm-consent-action );
	/* stylelint-disable-next-line declaration-no-important */
	color: #fff !important;
}

#cookie-consent-banner .revoke-consent,
#cookie-consent-banner .view-preferences {
	background: transparent;
	/* stylelint-disable-next-line declaration-no-important */
	color: var( --hm-consent-action ) !important;
}

#cookie-consent-banner .give-consent:hover,
#cookie-consent-banner .apply-cookie-preferences:hover {
	border-color: var( --hm-consent-action-hover );
	background: var( --hm-consent-action-hover );
}

#cookie-consent-banner .revoke-consent:hover,
#cookie-consent-banner .view-preferences:hover {
	background: rgba( 31, 99, 200, 0.08 );
}

#cookie-consent-banner button:focus-visible {
	outline: 2px solid var( --hm-consent-ink );
	outline-offset: 2px;
}

/*
 * "All categories" mode. Altis keeps a four-column grid for the preferences,
 * which overflows the card, so stack them in one column with the Apply button
 * below. Altis hides the choice buttons while the preferences are open by
 * fading them; take them out of the flow so they leave no gap.
 */

#cookie-consent-banner .cookie-preferences {
	display: none;
}

#cookie-consent-banner .cookie-preferences.show {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 8px;
	height: auto;
	margin: 0 0 12px;
}

#cookie-consent-banner .cookie-preferences label {
	display: flex;
	align-items: center;
	justify-content: flex-start;
	gap: 10px;
	min-height: 32px;
	text-align: left;
	font-size: inherit;
}

#cookie-consent-banner .cookie-preferences input {
	flex: none;
	margin: 0;
}

#cookie-consent-banner .button-row button.hide {
	display: none;
}
