/**
 * Structural layout only (justified grid, pager, modal) — anything with an established
 * design-system role (typography/color/spacing/border/shadow on the module's own fields)
 * is handled by Divi's own advanced-fields system instead, so it stays real-Preset/
 * Variable-able in the Builder (photo box-shadow/border are real fields now, not baked in
 * here — see AutoGallery::get_advanced_fields_config()'s 'box_shadow'/'borders' groups;
 * photo spacing is the real 'photo_spacing' field, passed through as an inline `gap`
 * style per page). The modal backdrop mirrors the "Overlay — Dark Medium (Stone Pine
 * 65%)" preset color (gcid-overlay-dark-65) — the one raw value left, since the modal
 * isn't one of the module's own attribute-controlled elements.
 *
 * No separate hero — every photo gets the same treatment, in a classic justified/flow
 * layout (see computeRows() in scripts/frontend.js): each row's height starts at Row
 * Height, then stretches slightly so its total width exactly fills the row — no row ever
 * leaves a gap on the right. The WHOLE matched pool renders as one flat list here;
 * scripts/frontend.js alone decides row-breaking (needs the real rendered container
 * width) and groups those rows into pager-page-sized "screens" that auto-fill Sizing >
 * Height, rather than this template splitting a fixed photos-per-page count into
 * separate server-rendered pages.
 */

.srom_ag_gallery {
	position: relative;
}

/* Sizing > Height / Aspect Ratio define the PHOTO BOX (.srom_ag_justified, sized by scripts/
   frontend.js), not the whole module. Divi's own Sizing styles would otherwise also pin the module
   wrapper to that height/ratio, which left the pager hanging outside the module's background and
   made Aspect Ratio resize the wrapper independently of the photos. */
.srom_auto_gallery.et_pb_module {
	height: auto !important;
	aspect-ratio: auto !important;
}

.srom_ag_pager[hidden] {
	display: none;
}

.srom_ag_justified {
	position: relative;
}

.srom_ag_gallery img {
	/* A near-universal WordPress/theme default (img { max-width: 100% }) otherwise caps
	   each photo at its containing block's width. Harmless on the desktop grid (photos
	   are position:absolute, so the percentage resolves against .srom_ag_justified's full
	   row width, always >= what any single photo needs) but a real, confirmed-live bug on
	   mobile's single scrollable row (position:static/flex item, so it resolves against
	   the narrow flex container itself) — a wide photo's JS-computed width was silently
	   getting crushed back down, distorting its aspect ratio. The row is deliberately
	   wider than the viewport on mobile (that's what makes it scrollable), so this needs
	   to be fully off, not just raised.
	*/
	max-width: none;
}

/* Each photo sits in a .srom_ag_tile frame. The frame is what gets positioned/sized by scripts/frontend.js and what
   the Photo Border / Photo Box Shadow fields style; the <img> fills it. Hover zoom scales only the <img>, so it
   stays clipped inside the frame's border and rounded corners. */
.srom_ag_justified .srom_ag_tile {
	position: absolute;
	top: 0;
	left: 0;
	display: block;
	overflow: hidden;
	cursor: pointer;
	/* Real width/height/position come from JS per-photo, computed from each photo's own
	   natural aspect ratio and its row's height - not set here. No hardcoded
	   border-radius/box-shadow either - real 'borders'/'box_shadow' fields control those. */
}

.srom_ag_tile img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.srom_ag_zoom .srom_ag_tile img {
	transition: transform var(--srom-ag-zoom-dur, 0.8s) var(--srom-ag-zoom-ease, ease-in-out);
	will-change: transform;
}

@media (hover: hover) {
	.srom_ag_zoom .srom_ag_tile:hover img {
		transform: scale(var(--srom-ag-zoom, 1.1));
	}
}

@media (prefers-reduced-motion: reduce) {
	.srom_ag_zoom .srom_ag_tile img {
		transition: none;
	}
	.srom_ag_zoom .srom_ag_tile:hover img {
		transform: none;
	}
}

.srom_ag_modal_count {
	position: absolute;
	top: 22px;
	left: 20px;
	color: #fff;
	font-size: 14px;
	letter-spacing: 0.04em;
	opacity: 0.85;
}

html.srom_ag_lightbox_open {
	overflow: hidden;
}

.srom_ag_pager {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 16px;
	margin-top: 16px;
}

.srom_ag_prev,
.srom_ag_next {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	padding: 4px 10px;
	font-size: 28px;
	line-height: 1;
	color: inherit;
	cursor: pointer;
	/* Arrow Background Color/Corner Radius/Padding (Navigation Icons fields) set
	   background-color/border-radius/padding inline per instance, overriding the
	   padding default above - see build_gallery_html()'s $pager_icon_style. */
}

/* Renders the optional pager icon fields (pager_icon_prev/next). Same technique real
   Divi core uses for its own icon fields (e.g. button icon, class-et-builder-element.php
   ~L16906): the chosen glyph is passed through as the `data-icon` attribute on an element
   carrying the `et-pb-font-icon` class, and a `:before` pulls it in via `content:
   attr(data-icon)` on Divi's own already-enqueued ETmodules icon font — not a hardcoded
   Unicode literal, so it responds to whatever icon is actually selected. Font-size/color
   are set inline per instance (real 'pager_icon_size'/'pager_icon_color' fields), so only
   the rendering mechanics live here. */
.srom_ag_pager .et-pb-font-icon[data-icon]::before {
	content: attr(data-icon);
	font-family: "ETmodules" !important;
	font-weight: 400 !important;
	font-style: normal;
	speak: none;
	display: inline-block;
}

.srom_ag_modal {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(23, 29, 26, 0.65);
}

.srom_ag_modal[hidden] {
	display: none;
}

.srom_ag_modal_image {
	max-width: 90vw;
	max-height: 85vh;
	border-radius: 8px;
	box-shadow: 0 18px 40px rgba(23, 29, 26, 0.32);
}

.srom_ag_modal_close,
.srom_ag_modal_prev,
.srom_ag_modal_next {
	position: absolute;
	background: none;
	border: none;
	color: #fff;
	font-size: 32px;
	line-height: 1;
	cursor: pointer;
	padding: 8px 12px;
}

.srom_ag_modal_close {
	top: 20px;
	right: 20px;
}

.srom_ag_modal_prev {
	left: 12px;
	top: 50%;
	transform: translateY(-50%);
}

.srom_ag_modal_next {
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
}

.srom_ag_empty {
	padding: 24px;
	text-align: center;
	opacity: 0.6;
}

.srom_ag_progress {
	display: none;
}

/* Mobile: no pager pages and no stacked rows - every matched photo flows into one
   horizontally scrollable row (layoutMobileRow() in scripts/frontend.js), all at the same
   height, width from each photo's own real aspect ratio (capped at 85% of the row so the
   next photo always peeks in from the right). .srom_ag_justified is the scroller itself
   (not the whole gallery), so the progress bar that follows it stays put instead of
   scrolling away with the photos. Scroll-snap lands each swipe on a photo edge; the native
   scrollbar is hidden in favour of the thin progress bar. */
@media (max-width: 767px) {
	.srom_ag_gallery {
		display: block;
	}

	.srom_ag_justified {
		display: flex;
		overflow-x: auto;
		overflow-y: hidden;
		scroll-snap-type: x mandatory;
		-webkit-overflow-scrolling: touch;
		overscroll-behavior-x: contain;
		scrollbar-width: none;
	}

	.srom_ag_justified::-webkit-scrollbar {
		display: none;
	}

	.srom_ag_justified:focus-visible {
		outline: 2px solid currentColor;
		outline-offset: 4px;
	}

	.srom_ag_gallery .srom_ag_tile {
		flex: 0 0 auto;
		margin-bottom: 0;
		scroll-snap-align: start;
	}

	/* Progress bar. Size/colors come from Design > Mobile via custom properties on the gallery
	   (--srom-ag-bar-h / --srom-ag-bar-frac / --srom-ag-track / --srom-ag-thumb). With the module
	   extended to the screen edge (--srom-ag-bleed) the bar is sized and centered against the
	   ORIGINAL content width, not the extended one. */
	.srom_ag_progress {
		display: block;
		position: relative;
		height: var(--srom-ag-bar-h, 4px);
		width: calc((100% - var(--srom-ag-bleed, 0px)) * var(--srom-ag-bar-frac, 1));
		margin: 12px 0 0 calc(((100% - var(--srom-ag-bleed, 0px)) * (1 - var(--srom-ag-bar-frac, 1))) / 2);
		border-radius: 999px;
	}

	/* Track = the text color at low opacity unless a Progress Bar Background Color is set. */
	.srom_ag_progress::before {
		content: "";
		position: absolute;
		inset: 0;
		border-radius: inherit;
		background: currentColor;
		opacity: 0.15;
	}

	.srom_ag_has_track .srom_ag_progress::before {
		background: var(--srom-ag-track);
		opacity: 1;
	}

	.srom_ag_progress_thumb {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		border-radius: inherit;
		background: currentColor;
		opacity: 0.6;
	}

	.srom_ag_has_thumb .srom_ag_progress_thumb {
		background: var(--srom-ag-thumb);
		opacity: 1;
	}

	/* Right-edge fade while more photos are off-screen (class set by scripts/frontend.js; only present
	   when "Show Right-Edge Fade" is on). No Fade Color => mask the photos themselves to transparent
	   (works on any background); Fade Color set => overlay that color instead. */
	.srom_ag_more_right:not(.srom_ag_fade_color) .srom_ag_justified {
		-webkit-mask-image: linear-gradient(to right, #000 calc(100% - var(--srom-ag-fade-w, 44px)), transparent);
		mask-image: linear-gradient(to right, #000 calc(100% - var(--srom-ag-fade-w, 44px)), transparent);
	}

	.srom_ag_gallery.srom_ag_fade_color::after {
		content: "";
		position: absolute;
		top: 0;
		right: 0;
		width: var(--srom-ag-fade-w, 44px);
		height: var(--srom-ag-row-h, 0px);
		background: linear-gradient(to right, transparent, var(--srom-ag-fade-color));
		pointer-events: none;
		opacity: 0;
	}

	.srom_ag_gallery.srom_ag_fade_color.srom_ag_more_right::after {
		opacity: 1;
	}

	/* Fullscreen lightbox on phones. Fit Width: the whole photo at screen width (pinch to zoom, swipe
	   left/right for the next photo). Fill Height: the photo scales to the full screen height and the
	   modal scrolls sideways to pan it. */
	.srom_ag_modal {
		background: rgba(10, 12, 11, 0.97);
		align-items: center;
		justify-content: center;
		overflow: auto;
		-webkit-overflow-scrolling: touch;
		overscroll-behavior: contain;
	}

	.srom_ag_modal_image {
		width: 100vw;
		height: 100vh;
		height: 100dvh;
		max-width: 100vw;
		max-height: 100dvh;
		object-fit: contain;
		border-radius: 0;
		box-shadow: none;
		touch-action: pan-x pan-y pinch-zoom;
	}

	.srom_ag_modal[data-fit="fill"] {
		justify-content: flex-start;
	}

	.srom_ag_modal[data-fit="fill"] .srom_ag_modal_image {
		width: auto;
		min-width: 100vw;
		height: 100vh;
		height: 100dvh;
		max-width: none;
		max-height: none;
		flex: 0 0 auto;
	}

	.srom_ag_modal_close,
	.srom_ag_modal_prev,
	.srom_ag_modal_next {
		position: fixed;
		z-index: 2;
		min-width: 48px;
		min-height: 48px;
		font-size: 36px;
		background: rgba(0, 0, 0, 0.45);
		border-radius: 999px;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		padding: 0;
	}

	.srom_ag_modal_close {
		top: max(12px, env(safe-area-inset-top));
		right: 12px;
	}

	.srom_ag_modal_prev {
		top: auto;
		bottom: max(16px, env(safe-area-inset-bottom));
		left: 16px;
		transform: none;
	}

	.srom_ag_modal_next {
		top: auto;
		bottom: max(16px, env(safe-area-inset-bottom));
		right: 16px;
		transform: none;
	}

	.srom_ag_modal_count {
		position: fixed;
		top: max(24px, calc(env(safe-area-inset-top) + 12px));
		left: 16px;
		z-index: 2;
	}

	/* No pager on mobile - swiping replaces it. */
	.srom_ag_pager {
		display: none;
	}
}
