/* ============================================================================
 * GB Viaggi – Custom image gallery (CSS)
 * --------------------------------------------------------------------------
 * Stili per la galleria `.gbv-gallery` e il relativo lightbox `.gbv-lightbox`.
 * La libreria JS (`js/gbv-gallery.js`) è auto-iniziale: si aggancia a ogni
 * `.gbv-gallery` presente nel DOM, legge `data-photos` e genera i tile a
 * runtime. Questo file contiene solo lo styling — non produce markup.
 *
 * --------------------------------------------------------------------------
 * Markup contract
 * --------------------------------------------------------------------------
 *   <div class="gbv-gallery"
 *        data-photos='[{"src":"...","thumb":"...","caption":"..."}, ...]'>
 *   </div>
 *
 *   Schema di ogni elemento di data-photos:
 *     - src     (string, obbligatorio) URL immagine "full" usata nel lightbox
 *     - thumb   (string, opzionale)   URL miniatura mostrata nei tile
 *     - caption (string, opzionale)   alt + didascalia nel lightbox
 *
 *   Quando si fa echo del JSON da PHP, usare i flag
 *   JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
 *   per evitare rotture dell'HTML.
 *
 * --------------------------------------------------------------------------
 * Modalità 1 — Grid (default)
 * --------------------------------------------------------------------------
 * Layout booking.com style: 1 tile grande + 4 tile piccoli in griglia
 * 2fr 1fr 1fr / 1fr 1fr, aspect-ratio 16:9. Con più di 5 foto, sull'ultimo
 * tile compare un overlay `.gbv-tile-more` con "+N foto". Con meno di 5
 * foto la griglia si popola solo con i tile disponibili.
 *
 * Comportamento immagini (impostato dal JS):
 *   - Tile principale (`.gbv-tile-main`): carica `src` (full), eager
 *   - Tile piccoli: caricano `thumb`, lazy
 *   - Su mobile il JS inietta <link rel=preload> per le prime 1-3 foto
 *
 * --------------------------------------------------------------------------
 * Modalità 2 — Inline (senza grid)
 * --------------------------------------------------------------------------
 * Aggiungere la classe `gbv-gallery-inline` per un singolo tile 16:9, niente
 * griglia, niente animazioni di ingresso. Pensata per card di risultati,
 * item di carosello, mini-preview. Click → stesso lightbox della grid.
 *
 * In modalità inline viene usata solo la prima foto di data-photos e non
 * viene mai generato l'overlay "+N foto".
 *
 * --------------------------------------------------------------------------
 * Lightbox
 * --------------------------------------------------------------------------
 * Una sola istanza globale per pagina. Layout responsive:
 *   - desktop (>= 900px): split view, immagine a sinistra + colonna thumb
 *     a destra (max ~8 visibili, scroll per le altre)
 *   - mobile  (<  900px): fullscreen, striscia di thumb orizzontale in basso
 *
 * --------------------------------------------------------------------------
 * No-JS
 * --------------------------------------------------------------------------
 * La galleria è renderizzata interamente lato JS. Senza JS il contenitore
 * resta vuoto. Per un fallback mostrare un <a>/<img> classico in un
 * <noscript> parallelo al `.gbv-gallery`.
 * ============================================================================ */


/* -------------------------------------------------------------------------- */
/*  Grid layout: 1 large + 4 small (the booking.com hero)                     */
/* -------------------------------------------------------------------------- */
.gbv-gallery {
	position: relative;
	display: grid;
	grid-template-columns: 2fr 1fr 1fr;
	grid-template-rows: 1fr 1fr;
	gap: 4px;
	width: 100%;
	aspect-ratio: 16 / 9;
	background: #e9ecef;
	border-radius: 8px;
	overflow: hidden;
}
.gbv-gallery .gbv-tile {
	position: relative;
	display: block;
	overflow: hidden;
	background: #000;
	text-decoration: none;
	cursor: zoom-in;
	-webkit-tap-highlight-color: transparent;
	opacity: 0;
	transform: scale(1.02);
	animation: gbv-tile-in 0.4s ease forwards;
}
.gbv-gallery .gbv-tile:nth-child(1) { grid-row: 1 / 3; grid-column: 1; animation-delay: 0.00s; }
.gbv-gallery .gbv-tile:nth-child(2) { grid-row: 1; grid-column: 2; animation-delay: 0.05s; }
.gbv-gallery .gbv-tile:nth-child(3) { grid-row: 1; grid-column: 3; animation-delay: 0.10s; }
.gbv-gallery .gbv-tile:nth-child(4) { grid-row: 2; grid-column: 2; animation-delay: 0.15s; }
.gbv-gallery .gbv-tile:nth-child(5) { grid-row: 2; grid-column: 3; animation-delay: 0.20s; }
.gbv-gallery .gbv-tile img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	transition: transform 0.45s ease, opacity 0.3s ease;
}
@media (hover: hover) {
	.gbv-gallery .gbv-tile:hover img {
		transform: scale(1.04);
		opacity: 0.92;
	}
}
@keyframes gbv-tile-in {
	to { opacity: 1; transform: scale(1); }
}
.gbv-tile-more {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	background: rgba(0, 0, 0, 0.55);
	color: #fff;
	font-size: 17px;
	font-weight: 600;
	letter-spacing: 0.3px;
	pointer-events: none;
	transition: background 0.25s ease;
}
@media (hover: hover) {
	.gbv-tile-overlay:hover .gbv-tile-more {
		background: rgba(0, 0, 0, 0.7);
	}
}
.gbv-tile-more::before {
	content: "";
	width: 20px;
	height: 20px;
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'><path d='M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z'/><circle cx='12' cy='12' r='3.2'/></svg>");
	background-size: contain;
	background-repeat: no-repeat;
}

/* -------------------------------------------------------------------------- */
/*  Inline variant: single image (used in result cards, items, recensioni)    */
/* -------------------------------------------------------------------------- */
.gbv-gallery.gbv-gallery-inline {
	display: block;
	aspect-ratio: auto;
	background: transparent;
	border-radius: 6px;
}
.gbv-gallery.gbv-gallery-inline .gbv-tile {
	display: block;
	aspect-ratio: 16 / 9;
	grid-row: auto;
	grid-column: auto;
	animation: none;
	opacity: 1;
	transform: none;
}
.gbv-gallery.gbv-gallery-inline .gbv-tile img {
	transition: transform 0.3s ease;
}
@media (hover: hover) {
	.gbv-gallery.gbv-gallery-inline .gbv-tile:hover img {
		transform: scale(1.03);
		opacity: 0.95;
	}
}

/* -------------------------------------------------------------------------- */
/*  LIGHTBOX                                                                   */
/* -------------------------------------------------------------------------- */
.gbv-lightbox {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: none;
	flex-direction: column;
	background: #000;
	color: #fff;
	touch-action: none;
	overscroll-behavior: contain;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.gbv-lightbox.gbv-lb-open {
	display: flex;
	animation: gbv-lb-fade 0.25s ease;
}
@keyframes gbv-lb-fade {
	from { opacity: 0; }
	to   { opacity: 1; }
}
.gbv-lightbox * { box-sizing: border-box; }
.gbv-lb-backdrop {
	position: absolute;
	inset: 0;
	z-index: 0;
	cursor: pointer;
}

/* SVG icon used inside the close/prev/next buttons. Block display +
   explicit dimensions guarantees the icon is sized and positioned
   independent of font metrics (avoids the off-center look you get
   with Unicode glyphs like ‹ › ×). */
.gbv-lb-icon {
	display: block;
	width: 22px;
	height: 22px;
	flex: 0 0 auto;
	pointer-events: none;
}
.gbv-lb-header {
	position: relative;
	z-index: 3;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 16px;
	flex-shrink: 0;
}
.gbv-lb-counter {
	font-size: 15px;
	font-weight: 500;
	color: #fff;
	letter-spacing: 0.5px;
	opacity: 0.9;
	font-variant-numeric: tabular-nums;
}
.gbv-lb-close {
	background: rgba(255, 255, 255, 0.12);
	border: none;
	color: #fff;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s ease, transform 0.15s ease;
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
}
.gbv-lb-close:hover,
.gbv-lb-close:focus-visible {
	background: rgba(255, 255, 255, 0.22);
	outline: none;
	transform: scale(1.05);
}
.gbv-lb-info {
	background: rgba(255, 255, 255, 0.12);
	border: none;
	color: #fff;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	font-size: 14px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.2s ease;
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
	font-style: italic;
	font-family: Georgia, "Times New Roman", serif;
	padding: 0;
}
.gbv-lb-info:hover,
.gbv-lb-info:focus-visible {
	background: rgba(255, 255, 255, 0.22);
	outline: none;
}
.gbv-lb-info[aria-pressed="true"] {
	background: rgba(255, 255, 255, 0.3);
}

/* Body: stage + thumbs. Mobile: column. Desktop (>= 900px): row. */
.gbv-lb-body {
	position: relative;
	z-index: 1;
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	min-height: 0;
	min-width: 0;
}

/* Stage */
.gbv-lb-stage {
	position: relative;
	flex: 1 1 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	min-height: 0;
	min-width: 0;
	padding: 12px;
}
.gbv-lb-track {
	position: absolute;
	inset: 0;
	overflow: hidden;
}
.gbv-lb-slide {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	/* No transition: photo changes are instant. Swipe drag uses inline
	   transforms which are untransitioned too, so the release snaps
	   cleanly without a slide-in animation. */
}
.gbv-lb-slide[hidden] { display: none !important; }

/* Image + caption stack vertically inside the photo group. The group
   also hosts an absolutely-positioned skeleton placeholder. */
.gbv-lb-photo {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	max-width: 100%;
}

/* Skeleton placeholder shown while the main image is loading. Solid
   base + a moving highlight so the user clearly sees the photo is
   loading. Sits behind the main image. */
.gbv-lb-skel {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 55%;
	height: 65%;
	max-width: 90%;
	max-height: 80%;
	background: rgba(255, 255, 255, 0.06);
	border-radius: 4px;
	overflow: hidden;
	z-index: 0;
	pointer-events: none;
	transition: opacity 0.3s ease;
}
.gbv-lb-skel::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: linear-gradient(
		90deg,
		transparent 0%,
		rgba(255, 255, 255, 0.12) 50%,
		transparent 100%
	);
	animation: gbv-skel-shimmer 1.4s ease-in-out infinite;
}
@keyframes gbv-skel-shimmer {
	0%   { transform: translateX(-100%); }
	100% { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
	.gbv-lb-skel::after { animation: none; opacity: 0.3; }
}
.gbv-lb-photo-loaded .gbv-lb-skel,
.gbv-lb-photo-error  .gbv-lb-skel { opacity: 0; }

/* Main image: starts at opacity 0 and fades in on load. */
.gbv-lb-img {
	display: block;
	position: relative;
	z-index: 1;
	max-width: 55%;
	max-height: 65%;
	width: auto;
	height: auto;
	object-fit: contain;
	user-select: none;
	-webkit-user-drag: none;
	-webkit-tap-highlight-color: transparent;
	border-radius: 4px;
	box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
	opacity: 0;
	transition: opacity 0.35s ease;
}
.gbv-lb-photo-loaded .gbv-lb-img,
.gbv-lb-photo-error  .gbv-lb-img { opacity: 1; }

.gbv-lb-caption {
	margin-top: 10px;
	color: rgba(255, 255, 255, 0.92);
	font-size: 13px;
	font-style: italic;
	line-height: 1.4;
	text-align: left;
	max-width: 55%;
	padding: 0 2px;
}

/* Prev / next arrows. Floating buttons on the left and right edges of
   the stage. The body has padding so they sit just inside the stage. */
.gbv-lb-prev,
.gbv-lb-next {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	z-index: 5;
	width: 48px;
	height: 48px;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.45);
	border: 1px solid rgba(255, 255, 255, 0.2);
	color: #fff;
	font-size: 28px;
	line-height: 1;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: background 0.2s ease, transform 0.15s ease;
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
}
.gbv-lb-prev:hover,
.gbv-lb-prev:focus-visible,
.gbv-lb-next:hover,
.gbv-lb-next:focus-visible {
	background: rgba(0, 0, 0, 0.7);
	outline: none;
}
.gbv-lb-prev:active,
.gbv-lb-next:active { transform: translateY(-50%) scale(0.95); }
.gbv-lb-prev { left: 12px; }
.gbv-lb-next { right: 12px; }

/* Thumb strip — on mobile: horizontal at the bottom; on desktop:
   vertical scrollable column on the right with 2 columns, filling the
   same height as the stage (scrollable when there are many photos). */
.gbv-lb-thumbs {
	position: relative;
	z-index: 2;
	display: flex;
	flex-direction: row;
	gap: 6px;
	padding: 10px 12px 12px;
	overflow-x: auto;
	overflow-y: hidden;
	flex-shrink: 0;
	background: rgba(0, 0, 0, 0.5);
	-webkit-overflow-scrolling: touch;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-ms-overflow-style: none;
}
.gbv-lb-thumbs::-webkit-scrollbar { display: none; }
.gbv-lb-thumb {
	position: relative;
	flex: 0 0 auto;
	width: 72px;
	height: 54px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 5px;
	overflow: hidden;
	background: #000;
	cursor: pointer;
	padding: 0;
	opacity: 0.5;
	transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
}
.gbv-lb-thumb.gbv-lb-thumb-loaded,
.gbv-lb-thumb.gbv-lb-thumb-error {
	background: transparent;
}
.gbv-lb-thumb:hover { opacity: 0.95; border-color: rgba(255, 255, 255, 0.35); }
.gbv-lb-thumb.gbv-lb-thumb-active {
	border-color: #fff;
	opacity: 1;
	box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4);
}
.gbv-lb-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.25s ease;
}
.gbv-lb-thumb.gbv-lb-thumb-loaded img { opacity: 1; }
.gbv-lb-thumb.gbv-lb-thumb-error img { opacity: 1; } /* show broken-img icon if load fails */

/* Skeleton placeholder shown while the thumb image is loading. Solid
   base + a moving highlight so the user clearly sees the thumb is
   loading (not just an empty black square). Removed on the img load
   event. */
.gbv-lb-thumb-skel {
	position: absolute;
	inset: 0;
	background: rgba(255, 255, 255, 0.10);
	overflow: hidden;
	border-radius: inherit;
}
.gbv-lb-thumb-skel::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 60%;
	height: 100%;
	background: linear-gradient(
		90deg,
		transparent 0%,
		rgba(255, 255, 255, 0.25) 50%,
		transparent 100%
	);
	animation: gbv-skel-shimmer 1.4s ease-in-out infinite;
}
@keyframes gbv-skel-shimmer {
	0%   { transform: translateX(-100%); }
	100% { transform: translateX(200%); }
}
@media (prefers-reduced-motion: reduce) {
	.gbv-lb-thumb-skel::after { animation: none; }
}

body.gbv-lightbox-open {
	overflow: hidden !important;
	touch-action: none;
}

/* -------------------------------------------------------------------------- */
/*  Desktop split-view: image left, scrollable 2-col thumbs on the right      */
/* -------------------------------------------------------------------------- */
@media (min-width: 900px) {
	.gbv-lb-body {
		flex-direction: row;
		padding: 8px 20px 20px;
		gap: 20px;
		align-items: stretch;
	}
	.gbv-lb-stage {
		flex: 1 1 auto;
		padding: 16px 60px;       /* room for prev/next arrows */
		border-radius: 0;
		background: transparent;
		align-self: stretch;
	}
	.gbv-lb-thumbs {
		flex: 0 0 auto;
		flex-direction: row;
		flex-wrap: wrap;
		align-content: flex-start;
		justify-content: flex-start;
		width: 340px;
		max-width: 32vw;
		align-self: stretch;       /* match stage height, top and bottom aligned */
		height: auto;
		overflow-y: auto;
		overflow-x: hidden;
		gap: 8px;
		padding: 16px;
		border-radius: 10px;
		border: 1px solid rgba(255, 255, 255, 0.08);
		background: rgba(255, 255, 255, 0.04);
		box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
		-ms-overflow-style: auto;
		scrollbar-width: thin;
		scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
	}
	.gbv-lb-thumbs::-webkit-scrollbar { display: block; width: 6px; }
	.gbv-lb-thumbs::-webkit-scrollbar-thumb {
		background: rgba(255, 255, 255, 0.25);
		border-radius: 3px;
	}
	.gbv-lb-thumbs::-webkit-scrollbar-track { background: transparent; }
	.gbv-lb-thumb {
		width: calc(50% - 4px);
		height: auto;
		aspect-ratio: 4 / 3;
		flex: 0 0 calc(50% - 4px);
		border-radius: 6px;
	}
	/* Image can be larger on desktop (more horizontal space) */
	.gbv-lb-img {
		max-width: 90%;
		max-height: 80%;
	}
	/* On desktop the prev/next sit just inside the stage padding */
	.gbv-lb-prev { left: 16px; }
	.gbv-lb-next { right: 16px; }
}

/* -------------------------------------------------------------------------- */
/*  Mobile responsive                                                          */
/* -------------------------------------------------------------------------- */
@media (max-width: 768px) {
	.gbv-gallery {
		grid-template-columns: 1fr 1fr;
		grid-template-rows: 2fr 1fr 1fr;
		aspect-ratio: 4 / 5;
	}
	.gbv-gallery .gbv-tile:nth-child(1) { grid-row: 1; grid-column: 1 / 3; }
	.gbv-gallery .gbv-tile:nth-child(2) { grid-row: 2; grid-column: 1; }
	.gbv-gallery .gbv-tile:nth-child(3) { grid-row: 2; grid-column: 2; }
	.gbv-gallery .gbv-tile:nth-child(4) { grid-row: 3; grid-column: 1; }
	.gbv-gallery .gbv-tile:nth-child(5) { grid-row: 3; grid-column: 2; }
	.gbv-tile-more { font-size: 14px; }
}

@media (max-width: 480px) {
	.gbv-lb-header { padding: 6px 12px; }
	.gbv-lb-counter { font-size: 13px; }
	.gbv-lb-close { width: 40px; height: 40px; font-size: 22px; }
	.gbv-lb-prev,
	.gbv-lb-next { width: 40px; height: 40px; font-size: 22px; }
	.gbv-lb-prev { left: 8px; }
	.gbv-lb-next { right: 8px; }
	.gbv-lb-thumb { width: 56px; height: 42px; }
	.gbv-lb-thumbs { padding: 8px 10px 10px; gap: 5px; }
	.gbv-lb-caption { font-size: 12px; margin-top: 8px; }
	/* Mobile: image can fill the available space (user kept mobile UX) */
	.gbv-lb-img { max-width: 100%; max-height: 70%; }
}

@media (max-width: 360px) {
	.gbv-lb-thumb { width: 48px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
	.gbv-gallery .gbv-tile,
	.gbv-gallery .gbv-tile img,
	.gbv-lb-slide,
	.gbv-lb-img,
	.gbv-lb-loader,
	.gbv-lightbox {
		animation: none !important;
		transition: none !important;
	}
}
