/**
 * DKM Product Image
 *
 * One image, with the next one behind it: the swap is a CSS opacity change,
 * so there is no script on the page for this widget at all.
 */

.wcgi {
	--wcgi-ratio: auto;
	--wcgi-fit: cover;

	/* Elementor renders this element as the flex child itself, so it has to
	   claim its width - without this it shrink-wraps to the image. */
	display: block;
	width: 100%;
	flex: 1 1 auto;
	align-self: stretch;
	min-width: 0;

	/* No spacing of our own: margin and padding are the Style tab's job. */
	margin: 0;
	padding: 0;
}

/* The Style tab puts its corner radius on the element itself, which is this
   root - but the root paints nothing, so a square-cornered frame drawn inside
   it hides the rounding entirely. Inheriting it down to the frame, which is
   what actually clips the picture, is what makes the setting visible. */
.wcgi__frame {
	position: relative;
	width: 100%;
	aspect-ratio: var(--wcgi-ratio);
	border-radius: inherit;
	overflow: hidden;
}

/* Scoped through .wcgi: Elementor's ".elementor img { height: auto }" beats a
   bare class and would stop the picture filling its box. */
.wcgi .wcgi__img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	border-radius: inherit;
	object-fit: var(--wcgi-fit);
}

/* Original ratio: the base image carries the height and the hover image is
   stretched over it, so a differently shaped second photo cannot resize the
   box on hover. */
.wcgi[data-wcgi-ratio="auto"] .wcgi__frame {
	aspect-ratio: auto;
}

.wcgi[data-wcgi-ratio="auto"] .wcgi__img--base {
	height: auto;
}

.wcgi .wcgi__img--hover {
	position: absolute;
	inset: 0;
	height: 100%;
	/* Straight swap, no fade: the second photo is a different angle of the
	   same thing, and cross-fading two product shots reads as a glitch. */
	opacity: 0;
}

.wcgi:hover .wcgi__img--hover,
.wcgi:focus-within .wcgi__img--hover {
	opacity: 1;
}

/* Coarse pointers have no hover to speak of; showing the second image on tap
   (which is what :hover does there) would just look like a glitch. */
@media (hover: none) {
	.wcgi .wcgi__img--hover {
		display: none;
	}
}

/* --------------------------------------------------------- editor states */

.wcgi--loading .wcgi__frame {
	min-height: 120px;
	background: repeating-linear-gradient(135deg, var(--bg-subtle), var(--bg-subtle) 12px, var(--bg-press) 12px, var(--bg-press) 24px);
}
