/*
 * Post gallery + lightbox.
 *
 * Targets WordPress' two gallery flavors that can appear inside
 * `the_content()` on the post types that embed galleries:
 *   - classic shortcode .gallery (figures wrapped in .gallery-icon a)
 *   - block editor .wp-block-gallery (figures wrapped directly in a)
 *
 * Layout: 8 thumbnails in a single row on desktop, stepping down at
 * the usual breakpoints. Thumbnails are forced to a square aspect with
 * object-fit: cover so the row stays even regardless of source aspect.
 *
 * Lightbox markup is created on the fly by gallery.js. We style it
 * here so the JS only has to manage state. Selectors are prefixed
 * .agentplus-lightbox to stay clear of plugin styles.
 *
 * Scope: every selector that targets the inline gallery uses an
 * `:is(.single-post, .single-novosti, .single-foto_video_galerija)`
 * prefix so adding a new gallery-bearing CPT in future means editing
 * one list at the top instead of every block below.
 */

/* --------------------------------------------------------------
 * Classic [gallery] shortcode + block-editor gallery.
 * -------------------------------------------------------------- */
:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery {
	display: grid;
	grid-template-columns: repeat(8, minmax(0, 1fr));
	gap: 8px;
	margin: 28px 0;
	padding: 0;
	list-style: none;
}

/* Reset WP-injected columns class — we control columns from breakpoints. */
:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery[class*="gallery-columns-"],
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery[class*="columns-"] {
	grid-template-columns: repeat(8, minmax(0, 1fr));
}

:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-item,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .wp-block-image,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .blocks-gallery-item {
	margin: 0;
	padding: 0;
	width: auto !important;
	max-width: none !important;
	flex: 0 0 auto !important;
}

/* Wrapper that always exists, whether or not an <a> is inside.
 * Classic gallery: .gallery-icon. Block gallery: .wp-block-image
 * (or the older .blocks-gallery-item). Hover overlay + image zoom
 * are keyed here so they work regardless of per-item link setting. */
:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-icon,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .wp-block-image,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .blocks-gallery-item {
	position: relative;
	overflow: hidden;
	margin: 0;
	border-radius: 6px;
	background: #eaeaea;
}

:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-icon::after,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .wp-block-image::after,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .blocks-gallery-item::after {
	position: absolute;
	inset: 0;
	background: rgba(10, 10, 10, 0);
	transition: background 180ms ease;
	content: "";
	pointer-events: none;
}

:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-icon:hover::after,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-icon:focus-within::after,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .wp-block-image:hover::after,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .wp-block-image:focus-within::after,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .blocks-gallery-item:hover::after {
	background: rgba(10, 10, 10, 0.25);
}

:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery a,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery a {
	display: block;
}

:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery img,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery img {
	display: block;
	width: 100%;
	height: 100%;
	aspect-ratio: 1 / 1;
	object-fit: cover;
	transition: transform 240ms ease;
	cursor: zoom-in;
}

:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-icon:hover img,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-icon:focus-within img,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .wp-block-image:hover img,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .wp-block-image:focus-within img,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery .blocks-gallery-item:hover img {
	transform: scale(1.05);
}

:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery .gallery-caption,
:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery figcaption {
	margin-top: 6px;
	font-family: var(--font-body);
	font-size: 12px;
	line-height: 16px;
	color: #6a6a6a;
	text-align: center;
}

/* --- Responsive thumbnail grid --------------------------------- */
@media (max-width: 1199px) {
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery,
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery,
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery[class*="gallery-columns-"],
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery[class*="columns-"] {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

@media (max-width: 599px) {
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery,
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery,
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .gallery[class*="gallery-columns-"],
	:is(.single-post, .single-novosti, .single-foto_video_galerija) .wp-block-gallery[class*="columns-"] {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 6px;
	}
}

/* --------------------------------------------------------------
 * Lightbox — created on demand by gallery.js.
 * -------------------------------------------------------------- */
.agentplus-lightbox {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(8, 8, 8, 0.92);
	opacity: 0;
	visibility: hidden;
	transition: opacity 200ms ease, visibility 0s linear 200ms;
}

.agentplus-lightbox.is-open {
	opacity: 1;
	visibility: visible;
	transition: opacity 200ms ease, visibility 0s;
}

.agentplus-lightbox__stage {
	position: relative;
	width: min(92vw, 1280px);
	height: min(86vh, 900px);
	display: flex;
	align-items: center;
	justify-content: center;
}

.agentplus-lightbox__img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	display: block;
	user-select: none;
	-webkit-user-drag: none;
	border-radius: 6px;
	box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
	transition: opacity 160ms ease;
}

.agentplus-lightbox.is-loading .agentplus-lightbox__img {
	opacity: 0.45;
}

.agentplus-lightbox__caption {
	position: absolute;
	bottom: -38px;
	left: 50%;
	transform: translateX(-50%);
	max-width: 90%;
	padding: 6px 12px;
	background: rgba(0, 0, 0, 0.55);
	border-radius: 4px;
	color: #fff;
	font-family: var(--font-body);
	font-size: 13px;
	line-height: 18px;
	text-align: center;
}

.agentplus-lightbox__caption:empty {
	display: none;
}

/* Optional "Pročitaj originalni članak" link — sits centrally below the
 * image (below the caption pill if one is present). Surfaces only when
 * the parent .gallery has a data-source-url, so all other lightboxes
 * stay unaffected. */
.agentplus-lightbox__source {
	position: absolute;
	bottom: -78px;
	left: 50%;
	transform: translateX(-50%);
	display: inline-block;
	padding: 10px 22px;
	background: #bb2548;
	border-radius: 4px;
	color: #fff;
	font-family: var(--font-heading);
	font-weight: 700;
	font-size: 13px;
	line-height: 18px;
	letter-spacing: 1px;
	text-transform: uppercase;
	text-decoration: none;
	white-space: nowrap;
	transition: background-color 0.2s ease;
}

.agentplus-lightbox__source:visited {
	color: #fff;
}

.agentplus-lightbox__source:hover,
.agentplus-lightbox__source:focus {
	background: #8e1c39;
	color: #fff;
	text-decoration: none;
}

.agentplus-lightbox__source[hidden] {
	display: none;
}

/* --- Buttons --------------------------------------------------- */
.agentplus-lightbox__btn {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(255, 255, 255, 0.25);
	border-radius: 50%;
	color: #fff;
	cursor: pointer;
	transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
	-webkit-appearance: none;
	appearance: none;
	padding: 0;
}

.agentplus-lightbox__btn:hover,
.agentplus-lightbox__btn:focus {
	background: var(--color-brand-red, #bb2548);
	border-color: var(--color-brand-red, #bb2548);
	outline: none;
}

.agentplus-lightbox__btn[disabled] {
	opacity: 0.35;
	cursor: default;
}

.agentplus-lightbox__btn[disabled]:hover {
	background: rgba(255, 255, 255, 0.08);
	border-color: rgba(255, 255, 255, 0.25);
}

.agentplus-lightbox__btn--prev {
	top: 50%;
	left: 16px;
	transform: translateY(-50%);
}

.agentplus-lightbox__btn--next {
	top: 50%;
	right: 16px;
	transform: translateY(-50%);
}

.agentplus-lightbox__btn--close {
	top: 16px;
	right: 16px;
}

.agentplus-lightbox__arrow {
	position: relative;
	display: block;
	width: 16px;
	height: 16px;
}

.agentplus-lightbox__arrow::before {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 10px;
	height: 10px;
	border-top: 2px solid currentColor;
	border-right: 2px solid currentColor;
	content: "";
	transform: translate(-50%, -50%) rotate(45deg);
}

.agentplus-lightbox__btn--prev .agentplus-lightbox__arrow::before {
	transform: translate(-50%, -50%) rotate(-135deg);
}

.agentplus-lightbox__close {
	position: relative;
	display: block;
	width: 16px;
	height: 16px;
}

.agentplus-lightbox__close::before,
.agentplus-lightbox__close::after {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 18px;
	height: 2px;
	background: currentColor;
	content: "";
}

.agentplus-lightbox__close::before {
	transform: translate(-50%, -50%) rotate(45deg);
}

.agentplus-lightbox__close::after {
	transform: translate(-50%, -50%) rotate(-45deg);
}

.agentplus-lightbox__counter {
	position: absolute;
	top: 24px;
	left: 24px;
	padding: 6px 12px;
	background: rgba(0, 0, 0, 0.4);
	border-radius: 999px;
	color: #fff;
	font-family: var(--font-heading);
	font-weight: 700;
	font-size: 12px;
	letter-spacing: 1px;
}

/* --- Mobile lightbox tweaks ----------------------------------- */
@media (max-width: 599px) {
	.agentplus-lightbox__btn {
		width: 44px;
		height: 44px;
	}

	.agentplus-lightbox__btn--prev {
		left: 8px;
	}

	.agentplus-lightbox__btn--next {
		right: 8px;
	}

	.agentplus-lightbox__btn--close {
		top: 12px;
		right: 12px;
	}

	.agentplus-lightbox__counter {
		top: 16px;
		left: 16px;
	}

	.agentplus-lightbox__caption {
		bottom: -34px;
		font-size: 12px;
	}
}

/* Prevent background scrolling while open. */
body.has-lightbox-open {
	overflow: hidden;
}
