/**
 * Native Gallery justified layout (Elementor e-gallery-justified math, real <img>).
 */
figure.wp-block-gallery.has-nested-images.is-justified,
figure.wp-block-gallery.is-justified,
.wp-block-gallery.is-justified {
	display: block !important;
	position: relative;
	flex-wrap: unset;
	align-items: unset;
	gap: 0 !important;
	box-sizing: border-box;
	width: 100%;
	aspect-ratio: 1 / var(--container-aspect-ratio, 0.75);
}

/*
 * alignfull uses negative margins to break out of .has-global-padding, but
 * that does not widen a 100%-wide packer. Stretch the gallery so JS
 * clientWidth matches the breakout (padding × 2 on the right otherwise).
 */
figure.wp-block-gallery.has-nested-images.alignfull.is-justified,
figure.wp-block-gallery.alignfull.is-justified,
.wp-block-gallery.alignfull.is-justified {
	width: calc(100% + var(--wp--style--root--padding-left, 0px) + var(--wp--style--root--padding-right, 0px));
	max-width: none;
}

figure.wp-block-gallery.is-justified:not(.is-justified-ready):not(.aa-justified-ready) > .wp-block-image,
figure.wp-block-gallery.is-justified:not(.is-justified-ready):not(.aa-justified-ready) > figure {
	visibility: hidden;
}

figure.wp-block-gallery.has-nested-images.is-justified > .wp-block-image,
figure.wp-block-gallery.is-justified > .wp-block-image,
figure.wp-block-gallery.is-justified > figure.wp-block-image {
	position: absolute;
	display: block !important;
	flex: none !important;
	float: none !important;
	margin: 0 !important;
	max-width: none !important;
	width: calc(var(--item-width) * (100% - var(--hgap) * var(--gap-count))) !important;
	height: var(--item-height);
	top: calc(var(--item-top) + (var(--row) * var(--vgap)));
	inset-inline-start: calc(
		var(--item-start) * (100% - var(--hgap) * var(--gap-count)) + var(--hgap) * var(--item-row-index)
	);
	inset-inline-end: auto;
	overflow: hidden;
}

figure.wp-block-gallery.is-justified > .wp-block-image a,
figure.wp-block-gallery.is-justified > .wp-block-image .wp-block-image__crop-area {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
}

figure.wp-block-gallery.has-nested-images.is-justified > .wp-block-image img,
figure.wp-block-gallery.has-nested-images.is-justified.is-cropped > .wp-block-image img,
figure.wp-block-gallery.is-justified > .wp-block-image img {
	display: block;
	width: 100% !important;
	height: 100% !important;
	max-width: none !important;
	object-fit: fill;
	aspect-ratio: auto !important;
}

figure.wp-block-gallery.is-justified > .wp-block-image figcaption,
figure.wp-block-gallery.is-justified > .wp-block-image .wp-element-caption {
	position: absolute;
	inset-inline: 0;
	bottom: 0;
	margin: 0;
	padding: 0.35em 0.5em;
	background: rgba(0, 0, 0, 0.45);
	color: #fff;
}
