/**
 * JHR Gallery for Elementor — frontend styles
 */

/*
 * A grid made of `1fr` tracks has a min-content height of just its row gaps,
 * so a column flex parent (Elementor containers, nested tabs panels) is
 * allowed to shrink this widget to a few pixels while the gallery inside
 * still paints at full height. Refuse to be shrunk.
 */
.elementor-widget-jhr-gallery {
	flex-shrink: 0;
}

.jhr-gallery {
	width: 100%;
}

.jhr-gallery__container {
	--jhr-columns: 4;
	--jhr-gap: 10px;
	--jhr-aspect: 66.667%;
	--jhr-ratio: 3 / 2;
	--jhr-row-height: 200px;
	position: relative;
	width: 100%;
}

/* ---------- 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 ---------- */
.jhr-gallery--grid .jhr-gallery__container {
	display: grid;
	grid-template-columns: repeat(var(--jhr-columns, 4), minmax(0, 1fr));
	gap: var(--jhr-gap, 10px);
	align-items: stretch;
}

/*
 * The ITEM carries the aspect ratio, so every grid row is sized from a real
 * box that the grid algorithm can measure.
 *
 * The previous approach put `height: 0` + a percentage `padding-bottom` on the
 * child (.jhr-gallery__item-image). Percentage padding is resolved against the
 * containing block's width, and during an intrinsic (max-content) sizing pass
 * that width is not yet known, so the browser resolves it to 0. The row then
 * collapses to zero height while the absolutely positioned <img> still paints
 * at its final size - which is why everything under the gallery slid up
 * underneath the images on narrow viewports.
 */
.jhr-gallery--grid .jhr-gallery__item {
	min-width: 0;
	min-height: 0;
	aspect-ratio: var(--jhr-ratio, 3 / 2);
}

/*
 * Defensive reset. In grid the items MUST stay in flow, otherwise the
 * container reports a height of 0 and the content below the widget slides up
 * underneath the images. !important is deliberate: it also beats the inline
 * styles the masonry/justified engine writes, so a leftover absolute position
 * from a layout switch can never survive here.
 */
.jhr-gallery--grid .jhr-gallery__item {
	position: relative !important;
	top: auto !important;
	left: auto !important;
	width: auto !important;
	height: auto !important;
}

.jhr-gallery--grid .jhr-gallery__item-image {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	padding-bottom: 0;
}

.jhr-gallery--grid .jhr-gallery__item-image img {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}

/* Fallback for engines without aspect-ratio (Safari < 15, Chrome < 88). */
@supports not (aspect-ratio: 3 / 2) {
	.jhr-gallery--grid .jhr-gallery__item {
		height: auto;
	}

	.jhr-gallery--grid .jhr-gallery__item::before {
		content: '';
		display: block;
		width: 100%;
		padding-bottom: var(--jhr-aspect, 66.667%);
	}
}

/* ---------- 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;
}

/* ---------- 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;
}
