/*
 * Popups: an area as a dialog over the page. Loaded only on a page with a
 * popup. A closed <dialog> is hidden by the browser; nothing here shows one.
 * The box's look comes from the dialog's custom properties (Popup::css()).
 */

.sf-popup {
	box-sizing: border-box;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	overflow: visible;
	color: inherit;
	background: transparent;
	border: 0;
}

.sf-popup::backdrop {
	background: transparent;
}

.sf-popup[open] {
	display: flex;
}

/* Over the page: the page behind is darkened and inert. */
.sf-popup--covers[open] {
	position: fixed;
	inset: 0;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	padding: 1rem;
	overflow: auto;
	overscroll-behavior: contain;
	background: rgb(0 0 0 / var(--sf-popup-overlay, 0.6));
}

.sf-popup__box {
	position: relative;
	box-sizing: border-box;
	width: 100%;
	max-width: var(--sf-popup-width, 600px);
	max-height: calc(100vh - 2rem);
	max-height: calc(100dvh - 2rem);
	margin: auto;
	padding: var(--sf-popup-padding, 32px);
	padding-block-start: max(var(--sf-popup-padding, 32px), 3rem);
	overflow: auto;
	color: var(--wp--preset--color--body, inherit);
	background: var(--sf-popup-background, #fff);
	border-radius: var(--sf-popup-radius, 8px);
	box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.25);
}

.sf-popup__content > :first-child {
	margin-block-start: 0;
}

.sf-popup__content > :last-child {
	margin-block-end: 0;
}

/* The whole screen; the content keeps the popup's width in the middle. */
.sf-popup--fullscreen[open] {
	padding: 0;
}

.sf-popup--fullscreen .sf-popup__box {
	display: flex;
	align-items: center;
	justify-content: center;
	max-width: none;
	min-height: 100%;
	max-height: none;
	border-radius: 0;
	box-shadow: none;
}

.sf-popup--fullscreen .sf-popup__content {
	width: 100%;
	max-width: var(--sf-popup-width, 600px);
}

/* Beside the page: it stays usable. */
.sf-popup--floats[open] {
	position: fixed;
	z-index: 100000;
}

.sf-popup--slide-right[open],
.sf-popup--slide-left[open] {
	inset: auto 1rem 1rem auto;
	width: min(var(--sf-popup-width, 600px), calc(100% - 2rem));
}

.sf-popup--slide-left[open] {
	inset: auto auto 1rem 1rem;
}

.sf-popup--bar-top[open],
.sf-popup--bar-bottom[open] {
	inset: var(--wp-admin--admin-bar--height, 0px) 0 auto;
	width: 100%;
}

.sf-popup--bar-bottom[open] {
	inset: auto 0 0;
}

.sf-popup--bar-top .sf-popup__box,
.sf-popup--bar-bottom .sf-popup__box {
	max-width: none;
	padding-block-start: var(--sf-popup-padding, 32px);
	padding-inline-end: max(var(--sf-popup-padding, 32px), 3.5rem);
	border-radius: 0;
}

.sf-popup__close {
	position: absolute;
	inset: 0.375rem 0.375rem auto auto;
	display: grid;
	place-items: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0;
	color: inherit;
	cursor: pointer;
	background: transparent;
	border: 0;
	border-radius: 50%;
}

.sf-popup__close:hover {
	background: rgb(0 0 0 / 0.08);
}

.sf-popup__close:focus-visible {
	outline: 2px solid currentcolor;
	outline-offset: 2px;
}

.sf-popup__close svg {
	width: 1.25rem;
	height: 1.25rem;
}

/*
 * A bar keeps the page out from under it (Popup script: the class and the
 * bar's height on <html>): the page moves by its height, a sticky or fixed
 * header below it, and whatever gets focus is scrolled clear of it.
 */
html.sf-popup-bar-top {
	padding-block-start: var(--sf-popup-bar-height, 0px);
	scroll-padding-block-start: calc(var(--sf-popup-bar-height, 0px) + var(--sf-header-height, 0px));
}

html.sf-popup-bar-bottom {
	padding-block-end: var(--sf-popup-bar-height, 0px);
	scroll-padding-block-end: var(--sf-popup-bar-height, 0px);
}

html.sf-popup-bar-top .sf-sticky-all .sf-site-header {
	top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--sf-popup-bar-height, 0px));
}

@media (min-width: 1025px) {

	html.sf-popup-bar-top .sf-sticky-desktop .sf-site-header {
		top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--sf-popup-bar-height, 0px));
	}
}

@media (max-width: 1024px) {

	html.sf-popup-bar-top .sf-sticky-mobile .sf-site-header {
		top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--sf-popup-bar-height, 0px));
	}
}

@media (max-width: 600px) {

	/* WordPress's admin bar scrolls away there; the header's top is 0. */
	html.sf-popup-bar-top .admin-bar .sf-site-header {
		top: var(--sf-popup-bar-height, 0px);
	}

	.admin-bar .sf-popup--bar-top[open] {
		top: 0;
	}
}

.sf-popup[tabindex="-1"]:focus {
	outline: none;
}

.sf-popup--floats[open]:focus-visible .sf-popup__box {
	outline: 2px solid currentcolor;
	outline-offset: -4px;
}

/* The page behind a popup that covers it does not scroll. */
html.sf-popup-lock {
	overflow: hidden;
}

/* Animation: in only, and none for whoever asked for less motion. */
.sf-popup--fade .sf-popup__box,
.sf-popup--slide-up .sf-popup__box {
	opacity: 0;
	transition: opacity 0.2s ease, transform 0.25s ease;
}

.sf-popup--slide-up .sf-popup__box {
	transform: translateY(1.5rem);
}

.sf-popup.is-open .sf-popup__box {
	opacity: 1;
	transform: none;
}

@media (prefers-reduced-motion: reduce) {

	.sf-popup .sf-popup__box {
		opacity: 1;
		transform: none;
		transition: none;
	}
}
