/* wpagent/popup — native <dialog> (P11). Prop values arrive from the style
 * engine as declarations on .wpab.wpab-<uid> (padding, background, border…)
 * or custom properties (--wpab-popup-*); the values below are the fallbacks.
 * Gutenberg shows the block as a <div class="wpab-popup"> holding its inner
 * blocks: it gets the panel look so the content is edited in context. */

dialog.wpab-popup {
	box-sizing: border-box;
	width: min(var(--wpab-popup-w, 600px), calc(100vw - 32px));
	max-width: none;
	max-height: calc(100vh - 32px);
	max-height: calc(100dvh - 32px);
	margin: auto;
	padding: 32px 24px;
	overflow: visible;
	border: 0 solid currentColor;
	border-radius: var(--wp--preset--border-radius--md, 12px);
	background: var(--wp--preset--color--surface, #fff);
	color: var(--wp--preset--color--ink, inherit);
	box-shadow: 0 30px 80px -24px rgba(16, 24, 40, 0.45);
}
dialog.wpab-popup[open] {
	display: flex;
	flex-direction: column;
	animation: wpab-popup-in 0.22s ease-out;
}
dialog.wpab-popup::backdrop {
	background: rgba(16, 24, 40, 0.6);
}
dialog.wpab-popup[open]::backdrop {
	animation: wpab-popup-fade 0.22s ease-out;
}
dialog.wpab-popup:focus {
	outline: none;
}

.wpab-popup__body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
}
.wpab-popup__body > * + * {
	margin-top: 16px;
}

/* Layouts ------------------------------------------------------------------ */
dialog.wpab-popup--drawer-left,
dialog.wpab-popup--drawer-right {
	width: min(var(--wpab-popup-w, 400px), 100vw);
	height: 100vh;
	height: 100dvh;
	max-height: none;
	border-radius: 0;
}
dialog.wpab-popup--drawer-left {
	margin: 0 auto 0 0;
}
dialog.wpab-popup--drawer-right {
	margin: 0 0 0 auto;
}
dialog.wpab-popup--bottom-bar {
	width: min(var(--wpab-popup-w, 100vw), 100vw);
	max-height: 80vh;
	max-height: 80dvh;
	margin: auto auto 0;
	border-radius: var(--wp--preset--border-radius--md, 12px) var(--wp--preset--border-radius--md, 12px) 0 0;
}
dialog.wpab-popup--drawer-left[open] {
	animation-name: wpab-popup-from-left;
}
dialog.wpab-popup--drawer-right[open] {
	animation-name: wpab-popup-from-right;
}
dialog.wpab-popup--bottom-bar[open] {
	animation-name: wpab-popup-from-bottom;
}

/* Close button ------------------------------------------------------------- */
.wpab-popup__close-form {
	display: contents;
}
.wpab-popup__close {
	position: absolute;
	top: 8px;
	right: 8px;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-width: 40px;
	min-height: 40px;
	margin: 0;
	padding: 0 8px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--wpab-popup-close, currentColor);
	font: inherit;
	font-size: 14px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
}
.wpab-popup__close .wpab-popup__close-icon {
	width: var(--wpab-popup-close-size, 20px);
	height: var(--wpab-popup-close-size, 20px);
	flex: none;
}
.wpab-popup__close--circle {
	padding: 0;
	background: var(--wpab-popup-close-bg, var(--wp--preset--color--ink, #101828));
	color: var(--wpab-popup-close, var(--wp--preset--color--surface, #fff));
}
.wpab-popup__close--text {
	padding: 0 12px;
}
.wpab-popup__close:hover {
	opacity: 0.8;
}
.wpab-popup__close:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}
/* Outside: above a modal / bottom bar, beside a drawer (on the dimmed page). */
.has-close-outside .wpab-popup__close {
	top: auto;
	bottom: calc(100% + 8px);
	right: 0;
	color: var(--wpab-popup-close, #fff);
}
.has-close-outside.wpab-popup--drawer-left .wpab-popup__close,
.has-close-outside.wpab-popup--drawer-right .wpab-popup__close {
	top: 8px;
	bottom: auto;
}
.has-close-outside.wpab-popup--drawer-left .wpab-popup__close {
	right: auto;
	left: calc(100% + 8px);
}
.has-close-outside.wpab-popup--drawer-right .wpab-popup__close {
	right: calc(100% + 8px);
}
.has-close-outside .wpab-popup__close--circle {
	color: var(--wpab-popup-close, var(--wp--preset--color--ink, #101828));
	background: var(--wpab-popup-close-bg, var(--wp--preset--color--surface, #fff));
}

/* Without JavaScript a #<id> link shows the content in place (no overlay). */
dialog.wpab-popup:target:not([open]):not([data-wpab-ready]) {
	position: static;
	display: block;
	height: auto;
	max-height: none;
	margin: 24px auto;
}
dialog.wpab-popup:target:not([open]) .wpab-popup__close-form {
	display: none;
}

/* Builder canvas preview (rendered open, in the flow) and Gutenberg. */
dialog.wpab-popup.is-preview {
	position: relative;
	inset: auto;
	height: auto;
	max-height: none;
	margin: 24px auto;
	animation: none;
	outline: 1px dashed rgba(16, 24, 40, 0.35);
	outline-offset: 4px;
}
div.wpab-popup {
	box-sizing: border-box;
	max-width: var(--wpab-popup-w, 600px);
	margin-inline: auto;
	padding: 32px 24px;
	border-radius: var(--wp--preset--border-radius--md, 12px);
	background: var(--wp--preset--color--surface, #fff);
	outline: 1px dashed rgba(16, 24, 40, 0.35);
	outline-offset: 4px;
}

/* Page scroll lock while a popup is open (set by view.js). */
html.wpab-popup-open {
	overflow: hidden;
}

@keyframes wpab-popup-in {
	from {
		opacity: 0;
		transform: translateY(12px) scale(0.98);
	}
}
@keyframes wpab-popup-fade {
	from {
		opacity: 0;
	}
}
@keyframes wpab-popup-from-left {
	from {
		transform: translateX(-100%);
	}
}
@keyframes wpab-popup-from-right {
	from {
		transform: translateX(100%);
	}
}
@keyframes wpab-popup-from-bottom {
	from {
		transform: translateY(100%);
	}
}

@media (prefers-reduced-motion: reduce) {
	dialog.wpab-popup[open],
	dialog.wpab-popup[open]::backdrop {
		animation: none;
	}
}
