/**
 * TikTok Video Carousel — Frontend CSS
 *
 * Stili principali del widget. Caricati solo se il widget è presente nella pagina.
 * Non impone colori, font o stili globali del tema.
 *
 * @package TikTokVideoCarousel
 * @version 1.0.0
 */

/* ─── Reset base ─────────────────────────────────────────────────────────── */

.ttvc-carousel-wrapper *,
.ttvc-carousel-wrapper *::before,
.ttvc-carousel-wrapper *::after {
	box-sizing: border-box;
}

/* ─── Wrapper principale ─────────────────────────────────────────────────── */

.ttvc-carousel-wrapper {
	position: relative;
	width: 100%;
	overflow: hidden; /* Evita scroll orizzontale della pagina. */
}

/* Overflow visibile ai lati (center mode / slide parziali). */
.ttvc-carousel-wrapper.ttvc-overflow-visible {
	overflow: visible;
}

/* ─── Swiper container ───────────────────────────────────────────────────── */

.ttvc-carousel-wrapper .ttvc-swiper {
	width: 100%;
	overflow: hidden;
}

.ttvc-carousel-wrapper.ttvc-overflow-visible .ttvc-swiper {
	overflow: visible;
}

/* ─── Slide interna ──────────────────────────────────────────────────────── */

.ttvc-slide-inner {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
}

/* ─── Wrapper video ──────────────────────────────────────────────────────── */

.ttvc-video-wrapper {
	width: 100%;
	position: relative;
}

/* ─── Container iframe ───────────────────────────────────────────────────── */

.ttvc-iframe-container {
	position: relative;
	width: 100%;
	background-color: #000;
	overflow: hidden;
}

/* ── Rapporti d'aspetto predefiniti ────────────────────────────────────── */

/* 9:16 — Verticale TikTok (predefinito) */
.ttvc-ratio-9-16 .ttvc-iframe-container {
	aspect-ratio: 9 / 16;
}

/* 16:9 — Orizzontale */
.ttvc-ratio-16-9 .ttvc-iframe-container {
	aspect-ratio: 16 / 9;
}

/* 4:5 — Instagram */
.ttvc-ratio-4-5 .ttvc-iframe-container {
	aspect-ratio: 4 / 5;
}

/* 1:1 — Quadrato */
.ttvc-ratio-1-1 .ttvc-iframe-container {
	aspect-ratio: 1 / 1;
}

/* Fallback per browser che non supportano aspect-ratio (Chrome < 88, Safari < 15) */
@supports not (aspect-ratio: 1) {
	.ttvc-ratio-9-16 .ttvc-iframe-container::before {
		content: '';
		display: block;
		padding-top: 177.78%; /* 16/9 × 100 */
	}
	.ttvc-ratio-16-9 .ttvc-iframe-container::before {
		content: '';
		display: block;
		padding-top: 56.25%; /* 9/16 × 100 */
	}
	.ttvc-ratio-4-5 .ttvc-iframe-container::before {
		content: '';
		display: block;
		padding-top: 125%;
	}
	.ttvc-ratio-1-1 .ttvc-iframe-container::before {
		content: '';
		display: block;
		padding-top: 100%;
	}
	.ttvc-iframe-container > * {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
}

/* ─── Iframe ─────────────────────────────────────────────────────────────── */

.ttvc-iframe {
	display: block;
	width: 100%;
	height: 100%;
	border: none;
	background-color: transparent;
}

/* ─── Loader / Spinner ───────────────────────────────────────────────────── */

.ttvc-loader {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #111;
	z-index: 1;
}

.ttvc-loader-spinner {
	width: 32px;
	height: 32px;
	border: 3px solid rgba(255, 255, 255, 0.2);
	border-top-color: #fff;
	border-radius: 50%;
	animation: ttvc-spin 0.8s linear infinite;
}

@keyframes ttvc-spin {
	to { transform: rotate(360deg); }
}

/* Rispetta prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
	.ttvc-loader-spinner {
		animation: none;
		border-color: rgba(255, 255, 255, 0.5);
	}
}

/* ─── Stato: Caricato ────────────────────────────────────────────────────── */

.ttvc-iframe-container.ttvc-loaded .ttvc-loader {
	display: none;
}

/* ─── Stato: Errore ──────────────────────────────────────────────────────── */

.ttvc-iframe-container.ttvc-load-error,
.ttvc-error-message {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background-color: #1a1a1a;
	color: #ccc;
	font-size: 0.85em;
	text-align: center;
	padding: 1em;
	gap: 0.5em;
}

.ttvc-error-icon {
	font-size: 1.6em;
	color: #e06060;
}

/* ─── Didascalia ─────────────────────────────────────────────────────────── */

.ttvc-slide-caption {
	flex: 0 0 auto;
}

/* ─── Titolo ─────────────────────────────────────────────────────────────── */

.ttvc-title {
	margin: 12px 0 6px;
	padding: 0;
	font-size: 1em;
	font-weight: 600;
	line-height: 1.4;
	/* Colore ereditato dal tema / Elementor. */
}

/* ─── Descrizione ────────────────────────────────────────────────────────── */

.ttvc-description {
	margin: 0;
	padding: 0;
	font-size: 0.875em;
	line-height: 1.5;
	/* Colore ereditato dal tema / Elementor. */
}

/* ─── Frecce di navigazione ──────────────────────────────────────────────── */

.ttvc-nav {
	position: absolute;
	top: 40%;
	transform: translateY(-50%);
	z-index: 20;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	border: none;
	border-radius: 50%;
	background-color: rgba(255, 255, 255, 0.9);
	color: #333;
	cursor: pointer;
	padding: 0;
	transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
	/* Visibilità anche sul bordo del wrapper. */
}

.ttvc-prev {
	left: -22px;
}

.ttvc-next {
	right: -22px;
}

.ttvc-nav svg {
	width: 20px;
	height: 20px;
	display: block;
	stroke: currentColor;
	fill: none;
}

.ttvc-nav:hover,
.ttvc-nav:focus {
	background-color: #fff;
	color: #000;
	outline: 2px solid #000;
	outline-offset: 2px;
}

.ttvc-nav:focus:not(:focus-visible) {
	outline: none;
}

.ttvc-nav:focus-visible {
	outline: 2px solid #005fcc;
	outline-offset: 2px;
}

/* Frecce disabilitate (loop OFF e alla prima/ultima slide). */
.ttvc-nav-disabled {
	opacity: 0.35;
	cursor: default;
	pointer-events: none;
}

/* ─── Dots / Paginazione ─────────────────────────────────────────────────── */

.ttvc-pagination {
	display: flex;
	justify-content: center;
	align-items: center;
	flex-wrap: wrap;
	gap: 4px;
	margin-top: 16px;
	width: 100%;
}

.ttvc-pagination .swiper-pagination-bullet {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background-color: rgba(0, 0, 0, 0.3);
	cursor: pointer;
	transition: width 0.25s ease, height 0.25s ease, background-color 0.25s ease;
}

.ttvc-pagination .swiper-pagination-bullet-active {
	background-color: currentColor;
	width: 12px;
	height: 12px;
}

/* Rispetta prefers-reduced-motion per i dots. */
@media (prefers-reduced-motion: reduce) {
	.ttvc-pagination .swiper-pagination-bullet {
		transition: none;
	}
}

/* ─── Focus visibile per i dots (accessibilità tastiera) ─────────────────── */

.ttvc-pagination .swiper-pagination-bullet:focus-visible {
	outline: 2px solid #005fcc;
	outline-offset: 2px;
}

/* ─── Responsive: nasconde frecce su mobile se troppo strette ───────────── */

@media (max-width: 480px) {
	.ttvc-prev,
	.ttvc-next {
		width: 36px;
		height: 36px;
	}
	.ttvc-prev { left: -8px; }
	.ttvc-next { right: -8px; }
}

/* ─── Fix: evita che l'iframe blocchi il drag Swiper ─────────────────────── */

.swiper-slide:not(.swiper-slide-active) .ttvc-iframe,
.swiper-slide-prev .ttvc-iframe,
.swiper-slide-next .ttvc-iframe {
	pointer-events: none;
}

.swiper-slide-active .ttvc-iframe {
	pointer-events: auto;
}

/* ─── Placeholder vuoto (nessun video configurato) ────────────────────────── */

.ttvc-editor-placeholder {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: 200px;
	padding: 2em;
	background: repeating-linear-gradient(
		45deg,
		#f9f9f9,
		#f9f9f9 10px,
		#f0f0f0 10px,
		#f0f0f0 20px
	);
	border: 2px dashed #ccc;
	border-radius: 8px;
	color: #777;
	font-size: 0.9em;
	text-align: center;
	gap: 0.5em;
}

.ttvc-editor-placeholder-icon {
	font-size: 2em;
	opacity: 0.5;
}
