/**
 * JHR Gallery for Elementor — frontend styles
 *
 * Asset revision 2.1.0
 *
 * GRID HEIGHT NOTE
 * ----------------
 * The grid layout used to reserve its height with a padding-bottom percentage
 * on a zero-height child:
 *
 *     .jhr-gallery--grid .jhr-gallery__item-image { height: 0; padding-bottom: 66.667%; }
 *
 * A percentage padding resolves against the *inline size of the containing
 * block*. When that inline size is indefinite — which is exactly what happens
 * on mobile, where the widget is a flex item inside Elementor's
 * column-direction container and the browser runs an intrinsic-sizing pass —
 * the percentage contributes ZERO to the grid row height. The images still
 * paint at their final size, but the container reports ~0px to the document
 * flow, so everything below rides up over the gallery.
 *
 * The grid now sizes itself with native `aspect-ratio`, which is a definite
 * size and never depends on percentage resolution. The padding hack survives
 * only inside an `@supports not (aspect-ratio: ...)` block for very old
 * browsers, and jhr-gallery.js carries a measured min-height safety net.
 */

.jhr-gallery {
	width: 100%;
}

/*
 * Mobile-optimisation plugins (and some themes) apply `content-visibility: auto`
 * or `contain: layout size` to below-the-fold blocks. Either one makes the
 * browser reserve a GUESSED height for this subtree while the images still
 * paint at full size — which looks exactly like the gallery overlapping what
 * follows it. Opt this widget out.
 */
.jhr-gallery,
.jhr-gallery__container,
.jhr-gallery__item {
	contain: none !important;
	content-visibility: visible !important;
	contain-intrinsic-size: auto !important;
}

.jhr-gallery__container {
	--jhr-columns: 4;
	--jhr-gap: 10px;
	--jhr-row-height: 200px;
	position: relative;
	width: 100%;
	/* Stops a flex/grid ancestor from forcing a min-content width on us. */
	min-width: 0;
}

/* ---------- Filter bar (Multiple galleries) ---------- */
.jhr-gallery__titles {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	justify-content: center;
	margin-bottom: 20px;
}

.jhr-gallery__title {
	background: none;
	border: none;
	cursor: pointer;
	font: inherit;
	color: inherit;
	line-height: 1;
	padding: 8px 14px;
	transition: color 0.2s, background-color 0.2s;
}

.jhr-gallery__title:focus {
	outline: none;
}

/* ---------- Items ---------- */
.jhr-gallery__item {
	display: block;
	position: relative;
	overflow: hidden;
	text-decoration: none;
	transition-property: transform, filter, border-color, border-width, border-radius;
	transition-timing-function: ease;
	transition-duration: 800ms;
}

.jhr-gallery__item.jhr-hidden {
	display: none !important;
}

.jhr-gallery__item-image {
	position: relative;
	width: 100%;
	height: 100%;
	overflow: hidden;
	border-style: solid;
	border-width: 0;
	border-color: transparent;
	transition-property: filter, border-color, border-width, border-radius;
	transition-timing-function: ease;
	transition-duration: 800ms;
	line-height: 0;
}

.jhr-gallery__item-image img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition-property: filter, transform;
	transition-timing-function: ease;
	transition-duration: 800ms;
}

/* ---------- Layout: Grid ---------- */
/*
 * Grid has two modes, and this is the heart of the overlap fix.
 *
 *   A) :not(.jhr-laid-out)  — a real CSS grid. This is what renders before the
 *      script runs, and what stays if JS never runs at all.
 *
 *   B) .jhr-laid-out        — items positioned absolutely and an EXPLICIT pixel
 *      height on the container, written by jhr-gallery.js. This is byte for
 *      byte the same mechanism the masonry layout uses, and masonry is the one
 *      layout that has never overlapped on this site. A content-derived height
 *      can be got wrong by an ancestor that applies `content-visibility`,
 *      `contain`, or an intrinsic-size estimate; an explicit px height cannot.
 */
.jhr-gallery--grid .jhr-gallery__container:not(.jhr-laid-out) {
	display: grid;
	grid-template-columns: repeat(var(--jhr-columns, 4), minmax(0, 1fr));
	grid-auto-rows: auto;
	gap: var(--jhr-gap, 10px);
	height: auto;
}

.jhr-gallery--grid .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item {
	position: relative;
	top: auto;
	left: auto;
	width: auto;
	height: auto;
	min-height: 1px;
}

/* The ratio box for mode A. */
.jhr-gallery--grid .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item-image {
	position: relative;
	width: 100%;
	height: auto;
	padding-bottom: 0;
	aspect-ratio: var(--jhr-aspect-ratio, var(--jhr-aspect-ratio-fallback, 3 / 2));
}

/* Legacy fallback only — browsers without aspect-ratio support (pre-2021). */
@supports not (aspect-ratio: 1 / 1) {
	.jhr-gallery--grid .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item-image {
		height: 0;
		padding-bottom: var(--jhr-aspect, var(--jhr-aspect-fallback, 66.667%));
	}
}

/* Mode B — JS positioned, explicit height. */
.jhr-gallery--grid .jhr-gallery__container.jhr-laid-out {
	display: block;
}

.jhr-gallery--grid .jhr-gallery__container.jhr-laid-out .jhr-gallery__item {
	position: absolute;
	top: 0;
	left: 0;
}

/* The item itself is sized in px by JS, so the image simply fills it. */
.jhr-gallery--grid .jhr-gallery__container.jhr-laid-out .jhr-gallery__item-image {
	position: relative;
	width: 100%;
	height: 100%;
	padding-bottom: 0;
	aspect-ratio: auto;
}

.jhr-gallery--grid .jhr-gallery__item-image img {
	position: absolute;
	top: 0;
	left: 0;
	width: 100% !important;
	height: 100% !important;
	max-width: none;
	object-fit: cover;
}

/* ---------- Layout: Justified & Masonry (JS positioned) ---------- */
.jhr-gallery--justified .jhr-gallery__container,
.jhr-gallery--masonry .jhr-gallery__container {
	position: relative;
}

.jhr-gallery--justified .jhr-gallery__item,
.jhr-gallery--masonry .jhr-gallery__item {
	position: absolute;
	top: 0;
	left: 0;
}

/* Pre-JS fallback so images are never invisible */
.jhr-gallery--justified .jhr-gallery__container:not(.jhr-laid-out),
.jhr-gallery--masonry .jhr-gallery__container:not(.jhr-laid-out) {
	display: grid;
	grid-template-columns: repeat(var(--jhr-columns, 4), minmax(0, 1fr));
	gap: var(--jhr-gap, 10px);
}

.jhr-gallery--justified .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item,
.jhr-gallery--masonry .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item {
	position: relative;
}

.jhr-gallery--justified .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item-image,
.jhr-gallery--masonry .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item-image,
.jhr-gallery--justified .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item-image img,
.jhr-gallery--masonry .jhr-gallery__container:not(.jhr-laid-out) .jhr-gallery__item-image img {
	height: auto;
	aspect-ratio: auto;
}

/* ---------- Overlay ---------- */
.jhr-gallery__item-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background-color: rgba(0, 0, 0, 0);
	transition-property: background-color, opacity;
	transition-timing-function: ease;
	transition-duration: 300ms;
	pointer-events: none;
	overflow: hidden;
}

.jhr-gallery__item-overlay--no-bg {
	background-color: transparent !important;
}

.jhr-gallery__item-content {
	max-width: 100%;
	padding: 15px;
	text-align: center;
	transition-property: opacity, transform;
	transition-timing-function: ease;
	transition-duration: 300ms;
}

.jhr-gallery__item-title {
	color: #fff;
	margin-bottom: 5px;
}

.jhr-gallery__item-description {
	color: #fff;
}

/* ---------- Content animations ---------- */
.jhr-anim--fade-in {
	opacity: 0;
}

.jhr-gallery__item:hover .jhr-anim--fade-in {
	opacity: 1;
}

.jhr-anim--grow {
	opacity: 0;
	transform: scale(0.5);
}

.jhr-gallery__item:hover .jhr-anim--grow {
	opacity: 1;
	transform: scale(1);
}

.jhr-anim--shrink {
	opacity: 0;
	transform: scale(1.5);
}

.jhr-gallery__item:hover .jhr-anim--shrink {
	opacity: 1;
	transform: scale(1);
}

.jhr-anim--slide-up {
	opacity: 0;
	transform: translateY(60px);
}

.jhr-gallery__item:hover .jhr-anim--slide-up {
	opacity: 1;
	transform: translateY(0);
}

.jhr-anim--slide-down {
	opacity: 0;
	transform: translateY(-60px);
}

.jhr-gallery__item:hover .jhr-anim--slide-down {
	opacity: 1;
	transform: translateY(0);
}

.jhr-anim--slide-right {
	opacity: 0;
	transform: translateX(-60px);
}

.jhr-gallery__item:hover .jhr-anim--slide-right {
	opacity: 1;
	transform: translateX(0);
}

.jhr-anim--slide-left {
	opacity: 0;
	transform: translateX(60px);
}

.jhr-gallery__item:hover .jhr-anim--slide-left {
	opacity: 1;
	transform: translateX(0);
}

/* ---------- Editor placeholder ---------- */
.jhr-gallery__empty {
	padding: 30px;
	text-align: center;
	border: 1px dashed #c4c8cc;
	color: #6d7882;
	font-size: 13px;
}
