/**
 * Pop-up (<dialog class="bms-popup">): structural styles only.
 *
 * Layout, sizing and states. Colours and type come from theme tokens (with
 * fallbacks); the theme owns the look. Loaded only when a pop-up is selected.
 */

.bms-popup {
	box-sizing: border-box;
	width: calc(100% - 2 * var(--wp--preset--spacing--40, 1rem));
	max-width: 32rem;
	max-height: none;
	margin: auto;
	padding: 0;
	overflow: hidden;
	border: 0;
	border-radius: 0;
	background-color: var(--wp--preset--color--base, #fff);
	color: var(--wp--preset--color--contrast, #171b33);
}

.bms-popup::backdrop {
	background-color: rgba(26, 33, 80, 0.72);
}

/* Fills the dialog box, so a click that targets the dialog itself is on the backdrop. */
.bms-popup__inner {
	max-height: calc(100vh - 2 * var(--wp--preset--spacing--40, 1rem));
	max-height: calc(100dvh - 2 * var(--wp--preset--spacing--40, 1rem));
	overflow-y: auto;
	overscroll-behavior: contain;
}

.bms-popup__close {
	position: absolute;
	inset-block-start: 0;
	inset-inline-end: 0;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: 2.75rem;
	height: 2.75rem;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background-color: var(--wp--preset--color--base, #fff);
	color: var(--wp--preset--color--contrast, #171b33);
	cursor: pointer;
}

.bms-popup__close svg {
	display: block;
	width: 1.5rem;
	height: 1.5rem;
	pointer-events: none;
}

/* Inset ring: the dialog clips overflow, so an outer ring would be cut at the corner. */
.bms-popup__close:focus-visible {
	outline: var(--wp--custom--focus--width, 2px) solid var(--wp--preset--color--accent-1, #26306d);
	outline-offset: calc(-1 * var(--wp--custom--focus--width, 2px) - 2px);
}

.bms-popup__media {
	margin: 0;
}

.bms-popup__media img {
	display: block;
	width: 100%;
	height: auto;
	max-height: 40vh;
	object-fit: cover;
	border-radius: 0;
}

.bms-popup__body {
	padding: var(--wp--preset--spacing--50, 1.5rem);
}

.bms-popup__body > * {
	margin-block: 0;
}

.bms-popup__body > * + * {
	margin-block-start: var(--wp--preset--spacing--40, 1rem);
}

/* Keep the heading clear of the close button when there is no image above it. */
.bms-popup__title {
	padding-inline-end: 2.75rem;
}

.bms-popup__media + .bms-popup__body .bms-popup__title {
	padding-inline-end: 0;
}

.bms-popup__text > :first-child {
	margin-block-start: 0;
}

.bms-popup__text > :last-child {
	margin-block-end: 0;
}

/* Phones: a bottom sheet. */
@media (max-width: 39.99rem) {

	.bms-popup {
		width: 100%;
		max-width: 100%;
		margin-block-start: auto;
		margin-block-end: 0;
		margin-inline: 0;
	}

	.bms-popup__inner {
		max-height: 90vh;
		max-height: 90dvh;
	}

	.bms-popup__body {
		padding-block-end: calc(var(--wp--preset--spacing--50, 1.5rem) + env(safe-area-inset-bottom, 0px));
	}
}

@media (prefers-reduced-motion: no-preference) {

	.bms-popup[open] {
		animation: bms-popup-in calc(var(--wp--custom--transition--duration, 150ms) * 1.5) ease-out;
	}

	.bms-popup[open]::backdrop {
		animation: bms-popup-fade calc(var(--wp--custom--transition--duration, 150ms) * 1.5) ease-out;
	}
}

@keyframes bms-popup-in {

	from {
		opacity: 0;
		transform: translateY(0.5rem);
	}

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

@keyframes bms-popup-fade {

	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}
