/* RXD Image Gallery Widget */

.rxd-gallery {
	display: block;
	width: 100%;
	--rxd-gallery-columns: 3;
	--rxd-gallery-gap: 12px;
	--rxd-gallery-caption-bg: rgba( 0, 0, 0, 0.55 );
	--rxd-gallery-popup-bg: #ffffff;
	--rxd-gallery-popup-max-width: 260px;
}

/* Grid layout: fixed column count, rows auto-flow to fit every image.
   align-items: start keeps each item at its own natural height instead of
   stretching to match the tallest item in its row (relevant when images
   keep their original, non-uniform aspect ratio). */
.rxd-gallery--grid {
	display: grid;
	grid-template-columns: repeat( var( --rxd-gallery-columns ), 1fr );
	align-items: start;
	gap: var( --rxd-gallery-gap );
}

/* Masonry layout: CSS multi-column — images flow top-to-bottom, then
   continue in the next column, packing to fit without gaps. */
.rxd-gallery--masonry {
	columns: var( --rxd-gallery-columns );
	column-gap: var( --rxd-gallery-gap );
}

.rxd-gallery--masonry .rxd-gallery-item {
	break-inside: avoid;
	/* CSS multi-column has no native row-gap — vertical spacing between
	   stacked items in a column relies on this margin. !important guards
	   against theme/reset stylesheets that zero out <figure> margins
	   (a common WordPress default), same reasoning as the Tabs widget's
	   colour rules. */
	margin-bottom: var( --rxd-gallery-gap ) !important;
}

.rxd-gallery-item {
	position: relative;
	/* Last-resort safety net, not the primary fix: rxd-gallery.js measures
	   each popup and shifts it (via transform) to stay fully inside the
	   image, which is what actually keeps popups uncropped in normal use.
	   This clip only matters if JS fails to run at all. */
	overflow: hidden;
	margin: 0;
	min-width: 0;
}

.rxd-gallery-item a {
	display: block;
}

.rxd-gallery-item img {
	display: block;
	width: 100%;
	height: auto;
}

/* ── Label (one caption + its own popup) ─────────────────────────────────
   The wrapper is positioned via an inline style from the caption's
   anchor + offset controls (see Gallery_Widget::anchor_style()) — this
   also defines the hover hit-area, so only THIS label's popup reveals on
   hover, not every popup on the image. The popup is positioned relative
   to this (small) wrapper via its own anchor + offset, not the whole
   image, so it floats near the caption that triggers it. */
.rxd-gallery-label {
	position: absolute;
	z-index: 2;
	max-width: calc( 100% - 20px );
}

/* position:absolute + z-index makes each label its own stacking context,
   so a popup's z-index only wins against elements INSIDE its own label —
   it can't outrank a sibling label's caption that way. Raising the
   hovered label's own z-index instead lifts its whole subtree (popup
   included) above every other label on the same photo. */
.rxd-gallery-label:hover {
	z-index: 10;
}

.rxd-gallery-label--has-popup {
	cursor: pointer;
}

.rxd-gallery-caption {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 8px 14px;
	border-radius: 4px;
	background-color: var( --rxd-gallery-caption-bg );
	opacity: 1;
	visibility: visible;
	transition: opacity 0.3s ease, visibility 0s linear 0s;
}

/* Scoped to --has-popup: a caption with no popup has nothing to reveal,
   so it should stay put on hover instead of fading to nothing. */
.rxd-gallery-label--has-popup:hover .rxd-gallery-caption {
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.rxd-gallery-caption-heading {
	font-size: 16px;
	font-weight: 700;
	line-height: 1.3;
	color: #ffffff;
}

.rxd-gallery-caption-subheading {
	font-size: 13px;
	font-style: italic;
	line-height: 1.3;
	color: #eeeeee;
}

/* ── Hover popup ──────────────────────────────────────────────────────────
   Hidden and non-interactive at rest so it never blocks clicks/the
   lightbox link elsewhere on the image. */
.rxd-gallery-popup {
	position: absolute;
	z-index: 5;
	width: max-content;
	max-width: var( --rxd-gallery-popup-max-width );
	padding: 14px 16px;
	border-radius: 6px;
	background-color: var( --rxd-gallery-popup-bg );
	box-shadow: 0 4px 20px rgba( 0, 0, 0, 0.18 );
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.3s ease, visibility 0s linear 0.3s;
}

.rxd-gallery-label:hover .rxd-gallery-popup {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition: opacity 0.3s ease, visibility 0s linear 0s;
}

.rxd-gallery-popup-heading {
	font-size: 16px;
	font-weight: 700;
	margin-bottom: 6px;
	color: #1a1a1a;
}

.rxd-gallery-popup-content {
	font-size: 14px;
	color: #333333;
}

/* Mobile: captions and popup text 2px smaller than desktop. !important
   guards against Elementor's Typography controls, which generate an
   unconditional (non-media-queried) font-size rule the moment an admin
   sets ANY value there — without it, that rule would outrank this one on
   mobile too and the reduction would never actually show. Matches
   Elementor's own default Mobile breakpoint (max-width: 767px). */
@media ( max-width: 767px ) {
	.rxd-gallery-caption-heading {
		font-size: 14px !important;
	}

	.rxd-gallery-caption-subheading {
		font-size: 11px !important;
	}

	.rxd-gallery-popup-heading {
		font-size: 14px !important;
	}

	.rxd-gallery-popup-content {
		font-size: 12px !important;
	}
}
