/**
 * JezPress Elements — Gallery Grid widget.
 *
 * realcommercial-style photo mosaic + Swiper lightbox.
 *
 * @package JezPress\Elements
 * @since   1.2.5
 */

.jpe-gallery-grid {
	position: relative;
	width: 100%;
}

/* ---- Mosaic ---- */
.jpe-gallery-grid__mosaic {
	display: grid;
	grid-template-columns: 2fr 2fr 1.35fr;
	grid-template-rows: 1fr 1fr;
	gap: 8px;
	height: 420px;
	width: 100%;
}

.jpe-gg__tile {
	position: relative;
	display: block;
	overflow: hidden;
	border-radius: 6px;
	background: #eceff1;
	min-width: 0;
	min-height: 0;
	cursor: pointer;
	text-decoration: none;
}

.jpe-gg__img,
.jpe-gg__tile img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform 0.4s ease;
}

.jpe-gallery-grid--lightbox .jpe-gg__tile:hover .jpe-gg__img {
	transform: scale(1.04);
}

/* Default (4 tiles): two large columns + two stacked on the right. */
.jpe-gallery-grid--count-4 .jpe-gg__tile:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; }
.jpe-gallery-grid--count-4 .jpe-gg__tile:nth-child(2) { grid-column: 2; grid-row: 1 / span 2; }
.jpe-gallery-grid--count-4 .jpe-gg__tile:nth-child(3) { grid-column: 3; grid-row: 1; }
.jpe-gallery-grid--count-4 .jpe-gg__tile:nth-child(4) { grid-column: 3; grid-row: 2; }

/* 3 tiles: one large + two stacked. */
.jpe-gallery-grid--count-3 .jpe-gallery-grid__mosaic { grid-template-columns: 2.4fr 1.4fr; }
.jpe-gallery-grid--count-3 .jpe-gg__tile:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; }
.jpe-gallery-grid--count-3 .jpe-gg__tile:nth-child(2) { grid-column: 2; grid-row: 1; }
.jpe-gallery-grid--count-3 .jpe-gg__tile:nth-child(3) { grid-column: 2; grid-row: 2; }

/* 2 tiles: side by side. */
.jpe-gallery-grid--count-2 .jpe-gallery-grid__mosaic { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.jpe-gallery-grid--count-2 .jpe-gg__tile { grid-row: 1; }

/* 1 tile: single hero. */
.jpe-gallery-grid--count-1 .jpe-gallery-grid__mosaic { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.jpe-gallery-grid--count-1 .jpe-gg__tile { grid-column: 1; grid-row: 1; }

/* ---- "+N more" corner button (realcommercial-style pill) ---- */
.jpe-gg__more {
	position: absolute;
	right: 12px;
	bottom: 12px;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 14px;
	border-radius: 999px;
	background-color: rgba(0, 0, 0, 0.65);
	color: #fff;
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1;
	white-space: nowrap;
	pointer-events: none; /* clicks pass through to the tile's <a> (opens the lightbox) */
	transition: background-color 0.2s ease;
}

.jpe-gg__more-icon {
	width: 18px;
	height: 18px;
	flex: 0 0 auto;
}

/* Default hover: subtly darken whatever the button colour is, so a custom Normal
   background still gets a sensible hover. The Style tab's Hover controls override
   this with explicit colours when set. */
.jpe-gg__tile:hover .jpe-gg__more {
	filter: brightness(0.88);
}

/* ---- Placeholder (editor only) ---- */
.jpe-gallery-grid--placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 160px;
	padding: 24px;
	border: 1px dashed #b0bec5;
	border-radius: 6px;
	background: #f5f7f8;
	color: #607d8b;
	text-align: center;
}

/* ---- Lightbox ---- */
.jpe-gg__lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: none;
	background: rgba(0, 0, 0, 0.92);
}

.jpe-gg__lightbox.is-open {
	display: block;
}

.jpe-gg__swiper {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

.jpe-gg__slide {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 4vh 6vw;
	box-sizing: border-box;
}

.jpe-gg__slide img {
	max-width: 100%;
	max-height: 92vh;
	width: auto;
	height: auto;
	object-fit: contain;
	display: block;
}

.jpe-gg__close,
.jpe-gg__nav {
	position: absolute;
	z-index: 5;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 0;
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	cursor: pointer;
	border-radius: 50%;
	transition: background-color 0.2s ease;
	padding: 0px !important;
}

.jpe-gg__close:hover,
.jpe-gg__nav:hover {
	background: rgba(255, 255, 255, 0.28);
}

.jpe-gg__close {
	top: 16px;
	right: 16px;
	width: 44px;
	height: 44px;
	padding: 0px !important;
}

.jpe-gg__nav {
	top: 50%;
	transform: translateY(-50%);
	width: 52px;
	height: 52px;
}

.jpe-gg__nav--prev { left: 16px; }
.jpe-gg__nav--next { right: 16px; }
.jpe-gg__nav.swiper-button-disabled { opacity: 0.35; cursor: default; }

.jpe-gg__counter {
	position: absolute;
	bottom: 18px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 5;
	padding: 6px 14px;
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.5);
	color: #fff;
	font-size: 0.9rem;
	font-variant-numeric: tabular-nums;
}

/* ---- Mobile: 1 hero image on top + the rest in a single row underneath ---- */
/* !important is required: the desktop tile-placement rules use
   `.jpe-gallery-grid--count-N .jpe-gg__tile:nth-child(n)` (specificity 0,3,0),
   which outranks the mobile reset below, and the responsive `mosaic_height`
   control's desktop value cascades down to mobile as inline CSS. */
@media (max-width: 767px) {
	.jpe-gallery-grid__mosaic {
		grid-template-rows: none;
		grid-auto-rows: auto;
		height: auto !important;
	}

	/* Reset every tile to normal flow (beats the higher-specificity desktop spans). */
	.jpe-gallery-grid .jpe-gg__tile {
		grid-column: auto !important;
		grid-row: auto !important;
	}

	/* 4 images: hero on top, the other 3 in a single row underneath. */
	.jpe-gallery-grid--count-4 .jpe-gallery-grid__mosaic { grid-template-columns: 1fr 1fr 1fr; }
	.jpe-gallery-grid--count-4 .jpe-gg__tile:nth-child(1)   { grid-column: 1 / -1 !important; aspect-ratio: 16 / 9; }
	.jpe-gallery-grid--count-4 .jpe-gg__tile:nth-child(n+2) { aspect-ratio: 1 / 1; }

	/* 3 images: hero on top, 2 in a row underneath. */
	.jpe-gallery-grid--count-3 .jpe-gallery-grid__mosaic { grid-template-columns: 1fr 1fr; }
	.jpe-gallery-grid--count-3 .jpe-gg__tile:nth-child(1)   { grid-column: 1 / -1 !important; aspect-ratio: 16 / 9; }
	.jpe-gallery-grid--count-3 .jpe-gg__tile:nth-child(n+2) { aspect-ratio: 4 / 3; }

	/* 2 images: side by side. */
	.jpe-gallery-grid--count-2 .jpe-gallery-grid__mosaic { grid-template-columns: 1fr 1fr; }
	.jpe-gallery-grid--count-2 .jpe-gg__tile { aspect-ratio: 3 / 4; }

	/* 1 image: single hero. */
	.jpe-gallery-grid--count-1 .jpe-gallery-grid__mosaic { grid-template-columns: 1fr; }
	.jpe-gallery-grid--count-1 .jpe-gg__tile { aspect-ratio: 16 / 10; }

	/* Corner button scaled down for the smaller tiles. */
	.jpe-gg__more {
		right: 6px;
		bottom: 6px;
		gap: 4px;
		padding: 5px 10px;
		font-size: 0.8rem;
	}
	.jpe-gg__more-icon { width: 14px; height: 14px; }

	.jpe-gg__nav { width: 42px; height: 42px; }
	.jpe-gg__close { top: 10px; right: 10px; width: 40px; height: 40px; }
	.jpe-gg__slide { padding: 2vh 4vw; }
}
