/**
 * AMA Popups — front end
 *
 * Conflict-proof by design:
 * - Every selector starts with #amap-root, so it outranks theme / page-builder
 *   rules (Astra, Elementor, Spectra…) that target button, a, img, svg.
 * - Each element first resets with `all: revert` (back to browser defaults,
 *   dropping whatever the theme set), then gets only the styles below.
 * - Only amap-* classes and amap-* keyframes are used, so nothing here can
 *   leak into the theme.
 *
 * The image is shown as large as fits the screen, never above its original
 * pixel size, and the popup itself can't scroll.
 *
 * Tweak per site (e.g. Astra → Customizer → Additional CSS):
 *   :root {
 *     --amap-max-w: 60rem;              optional extra width cap (default: none)
 *     --amap-gap: 1rem;                 min distance from the viewport edge
 *     --amap-radius: .5rem;             image corner radius
 *     --amap-backdrop: rgba(0,0,0,.65); overlay colour
 *     --amap-close-bg: rgba(255,255,255,.9);
 *     --amap-close-color: #111;
 *   }
 */

/* Wrapper: takes no space in the page layout. */
#amap-root {
	display: contents;
}

/* ---------- Dialog ---------- */

/*
 * The dialog covers the whole viewport (transparent, never scrolls) and
 * centres the image frame. Its padding is the gap to the screen edge, and as
 * a size container it lets the image fit exactly the space inside it.
 * Clicks on the empty area land on the dialog itself = backdrop click.
 */
#amap-root .amap-popup {
	all: revert;

	--_gap: var(--amap-gap, 1rem);
	--_radius: var(--amap-radius, .5rem);

	box-sizing: border-box;
	position: fixed;
	inset: 0;
	z-index: 2147483647; /* Only matters if the browser has no top layer. */
	width: 100%;
	height: 100%;
	min-width: 0;
	min-height: 0;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: var(--_gap);
	border: 0;
	border-radius: 0;
	background: transparent;
	box-shadow: none;
	color: inherit;
	font: inherit;
	line-height: 1;
	overflow: hidden;
	container-type: size;
	transform: none;
	opacity: 1;
	visibility: visible;
}

#amap-root .amap-popup:not([open]) {
	display: none !important;
}

#amap-root .amap-popup[open] {
	display: grid;
	place-items: center;
}

#amap-root .amap-popup:focus,
#amap-root .amap-popup:focus-visible {
	outline: none;
}

#amap-root .amap-popup::backdrop {
	background: var(--amap-backdrop, rgba(0, 0, 0, .65));
	backdrop-filter: none;
}

/* Theme decorations via pseudo-elements (underline effects, icons…) */
#amap-root .amap-popup *::before,
#amap-root .amap-popup *::after {
	content: none;
}

/* ---------- Frame: hugs the image, anchors the close button ---------- */

#amap-root .amap-popup__frame {
	all: revert;
	box-sizing: border-box;
	position: relative;
	display: block;
	min-width: 0;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	line-height: 0;
}

/* ---------- Image wrapper (link or plain) ---------- */

#amap-root .amap-popup__link,
#amap-root .amap-popup__media {
	all: revert;
	box-sizing: border-box;
	display: block;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--_radius);
	background: none;
	line-height: 0;
	text-decoration: none;
	color: inherit;
	cursor: default;
}

#amap-root .amap-popup__link {
	cursor: pointer;
}

#amap-root .amap-popup__link:hover,
#amap-root .amap-popup__link:focus {
	background: none;
	color: inherit;
	text-decoration: none;
	outline: none;
	opacity: 1;
}

#amap-root .amap-popup__link:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 4px;
}

/* ---------- Image ---------- */

#amap-root .amap-popup__img {
	all: revert;
	box-sizing: border-box;
	display: block;
	width: auto;
	height: auto;
	min-width: 0;
	min-height: 0;
	/*
	 * width/height auto + both max limits = the largest size that fits,
	 * aspect ratio kept. The rendered size itself comes from the `sizes`
	 * attribute (fit to viewport, capped at the original pixel width).
	 * First pair: fallback for browsers without container units.
	 */
	max-width: calc(100vw - var(--_gap) * 2);
	max-height: calc(100vh - var(--_gap) * 2);
	max-height: calc(100dvh - var(--_gap) * 2);
	max-width: min(var(--amap-max-w, 100cqw), 100cqw);
	max-height: 100cqh;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var(--_radius);
	background: none;
	box-shadow: 0 1.25rem 3.75rem rgba(0, 0, 0, .35);
	object-fit: contain;
	opacity: 1;
	filter: none;
	transform: none;
	transition: none;
	vertical-align: top;
}

/* ---------- Close button ---------- */

#amap-root .amap-popup__close {
	all: revert;
	box-sizing: border-box;
	position: absolute;
	top: .5rem;
	right: .5rem;
	left: auto;
	bottom: auto;
	z-index: 1;
	display: grid;
	place-items: center;
	width: 2.5rem;
	height: 2.5rem;
	min-width: 0;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--amap-close-bg, rgba(255, 255, 255, .9));
	color: var(--amap-close-color, #111);
	font: inherit;
	font-size: 1rem;
	line-height: 1;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	box-shadow: 0 .125rem .5rem rgba(0, 0, 0, .25);
	cursor: pointer;
	opacity: 1;
	-webkit-appearance: none;
	appearance: none;
	transform: none;
	transition: background-color .2s linear, transform .2s linear;
}

#amap-root .amap-popup__close:hover {
	background: #fff;
	color: var(--amap-close-color, #111);
	border: 0;
	box-shadow: 0 .125rem .5rem rgba(0, 0, 0, .25);
	transform: scale(1.08);
}

#amap-root .amap-popup__close:focus,
#amap-root .amap-popup__close:active {
	background: var(--amap-close-bg, rgba(255, 255, 255, .9));
	color: var(--amap-close-color, #111);
	border: 0;
	outline: none;
}

#amap-root .amap-popup__close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

/* No `all: revert` on SVG: it would also drop presentation attributes like the path's `d`. */
#amap-root .amap-popup__icon {
	display: block;
	position: static;
	width: 1rem;
	height: 1rem;
	min-width: 0;
	max-width: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	fill: none;
	stroke: none;
	color: inherit;
	opacity: 1;
	transform: none;
	overflow: visible;
	pointer-events: none;
}

#amap-root .amap-popup__icon path {
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
	opacity: 1;
}

/* ---------- Scroll lock while open (no layout shift) ---------- */

html:has(#amap-root .amap-popup[open]) {
	overflow: hidden;
	scrollbar-gutter: stable;
}

/* ---------- Animation ---------- */

#amap-root .amap-popup[open] {
	animation: amap-popup-in .3s cubic-bezier(.2, .8, .2, 1) both;
}

#amap-root .amap-popup[open]::backdrop {
	animation: amap-popup-fade-in .3s linear both;
}

#amap-root .amap-popup.amap-is-closing {
	animation: amap-popup-out .2s linear both;
}

#amap-root .amap-popup.amap-is-closing::backdrop {
	animation: amap-popup-fade-out .2s linear both;
}

@keyframes amap-popup-in {
	from {
		opacity: 0;
		transform: translateY(1rem) scale(.96);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

@keyframes amap-popup-out {
	to {
		opacity: 0;
		transform: scale(.97);
	}
}

@keyframes amap-popup-fade-in {
	from {
		opacity: 0;
	}
}

@keyframes amap-popup-fade-out {
	to {
		opacity: 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	#amap-root .amap-popup[open],
	#amap-root .amap-popup[open]::backdrop,
	#amap-root .amap-popup.amap-is-closing,
	#amap-root .amap-popup.amap-is-closing::backdrop {
		animation: none;
	}

	#amap-root .amap-popup__close {
		transition: none;
	}
}
