/*
 * ACF PDF Flipbook — stili frontend
 * Overlay modale, contenitore libro, pulsante di chiusura, spinner e responsive.
 */

/* -------------------------------------------------------------------------
 * PULSANTE (stile base: colori/tipografia arrivano dai controlli Elementor)
 * ------------------------------------------------------------------------- */
.apf-button-wrap {
	display: block;
}

.apf-button {
	display: inline-block;
	cursor: pointer;
	border: none;
	line-height: 1.2;
	text-align: center;
	transition: opacity 0.2s ease;
	-webkit-appearance: none;
	appearance: none;
}

.apf-button:hover {
	opacity: 0.9;
}

/* -------------------------------------------------------------------------
 * OVERLAY (sfondo scuro a tutto schermo)
 * ------------------------------------------------------------------------- */
.apf-overlay {
	position: fixed;
	inset: 0;
	display: none; /* nascosto finché non viene aperto dal JS */
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.85);
	z-index: 99999;
	padding: 20px;
	box-sizing: border-box;
	opacity: 0;
	transition: opacity 0.25s ease;
}

/* Stato aperto (attivato dal JS con la classe .is-open) */
.apf-overlay.is-open {
	display: flex;
	opacity: 1;
}

/* -------------------------------------------------------------------------
 * MODALE (contenitore centrale)
 * ------------------------------------------------------------------------- */
.apf-modal {
	position: relative;
	width: 100%;
	max-width: 1400px;
	height: 92vh;
	max-height: 92vh;
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
}

/* -------------------------------------------------------------------------
 * PULSANTE DI CHIUSURA (X in alto a destra)
 * ------------------------------------------------------------------------- */
.apf-close {
	position: absolute;
	top: -14px;
	right: -14px;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	border: none;
	background: #ffffff;
	color: #111111;
	font-size: 28px;
	line-height: 44px;
	text-align: center;
	cursor: pointer;
	z-index: 10;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
	transition: transform 0.15s ease, background 0.15s ease;
	padding: 0;
}

.apf-close:hover {
	transform: scale(1.08);
	background: #f0f0f0;
}

/* -------------------------------------------------------------------------
 * PALCO (area del libro; gestisce overflow/pan durante lo zoom)
 * ------------------------------------------------------------------------- */
.apf-stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 0; /* fondamentale in flex-column per non traboccare */
	width: 100%;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* Quando è ingrandito, consenti scroll/pan e cambia il cursore. */
.apf-stage.is-zoomed {
	overflow: auto;
	cursor: grab;
}

/* -------------------------------------------------------------------------
 * CONTENITORE STABILE DEL LIBRO
 * (#apf-book resta sempre nel DOM; lo zoom è un transform su di esso)
 * ------------------------------------------------------------------------- */
.apf-book {
	position: relative;
	width: 100%;
	height: 100%;
	transform-origin: center center;
	transition: transform 0.2s ease;
}

/* Elemento "usa e getta" su cui StPageFlip inizializza il libro.
 * Deve avere una larghezza REALE: StPageFlip la usa per decidere
 * spread (due pagine) vs pagina singola. */
.apf-book-block {
	position: relative;
	width: 100%;
	height: 100%;
}

/* Le pagine renderizzate da PDF.js sono immagini: si adattano al contenitore */
.apf-book .apf-page {
	background-color: #ffffff;
	background-size: cover;
	background-position: center;
	box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.15);
}

.apf-book .apf-page img {
	width: 100%;
	height: 100%;
	display: block;
	pointer-events: none;
}

/* -------------------------------------------------------------------------
 * BARRA DEI CONTROLLI (in basso)
 * ------------------------------------------------------------------------- */
.apf-toolbar {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 10px 12px;
	margin-top: 10px;
	background: rgba(20, 20, 20, 0.7);
	border-radius: 999px;
	align-self: center;
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
	max-width: 100%;
	box-sizing: border-box;
	flex-wrap: wrap;
}

.apf-btn {
	min-width: 40px;
	height: 40px;
	padding: 0 10px;
	border: none;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.12);
	color: #ffffff;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s ease, transform 0.15s ease;
}

.apf-btn:hover {
	background: rgba(255, 255, 255, 0.28);
}

.apf-btn:active {
	transform: scale(0.94);
}

.apf-btn-reset {
	font-size: 13px;
	font-weight: 600;
	min-width: 56px;
}

.apf-counter {
	color: #ffffff;
	font-size: 14px;
	min-width: 64px;
	text-align: center;
	font-variant-numeric: tabular-nums;
	user-select: none;
}

.apf-sep {
	width: 1px;
	height: 24px;
	background: rgba(255, 255, 255, 0.2);
	margin: 0 4px;
}

/* -------------------------------------------------------------------------
 * SCHERMO INTERO
 * ------------------------------------------------------------------------- */
.apf-overlay:fullscreen,
.apf-overlay:-webkit-full-screen {
	padding: 12px;
}

.apf-overlay.is-fullscreen .apf-modal {
	max-width: 100%;
	height: 100%;
	max-height: 100%;
}

/* -------------------------------------------------------------------------
 * SPINNER DI CARICAMENTO
 * ------------------------------------------------------------------------- */
.apf-loader {
	position: absolute;
	inset: 0;
	display: none; /* mostrato dal JS durante il caricamento */
	flex-direction: column;
	align-items: center;
	justify-content: center;
	color: #ffffff;
	gap: 16px;
	z-index: 5;
}

.apf-loader.is-visible {
	display: flex;
}

.apf-spinner {
	width: 48px;
	height: 48px;
	border: 4px solid rgba(255, 255, 255, 0.25);
	border-top-color: #ffffff;
	border-radius: 50%;
	animation: apf-spin 0.9s linear infinite;
}

.apf-loader-text {
	margin: 0;
	font-size: 15px;
}

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

/* -------------------------------------------------------------------------
 * MESSAGGIO DI ERRORE
 * ------------------------------------------------------------------------- */
.apf-error {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: #ffffff;
	background: rgba(200, 0, 0, 0.9);
	padding: 16px 24px;
	border-radius: 6px;
	font-size: 15px;
	text-align: center;
	z-index: 6;
}

/* -------------------------------------------------------------------------
 * RESPONSIVE
 * Su schermi stretti la modale occupa tutto lo spazio e il flipbook passa
 * automaticamente a pagina singola (gestito lato JS con usePortrait).
 * ------------------------------------------------------------------------- */
@media (max-width: 768px) {
	.apf-overlay {
		padding: 8px;
	}

	.apf-modal {
		height: 94vh;
		max-height: 94vh;
	}

	.apf-close {
		top: 2px;
		right: 2px;
		width: 40px;
		height: 40px;
		font-size: 24px;
		line-height: 40px;
	}

	.apf-toolbar {
		flex-wrap: nowrap;
		gap: 3px;
		padding: 6px 6px;
		margin-top: 6px;
	}

	.apf-btn {
		min-width: 34px;
		height: 34px;
		font-size: 16px;
		padding: 0 6px;
	}

	.apf-btn-reset {
		min-width: 44px;
		font-size: 12px;
	}

	.apf-counter {
		min-width: 44px;
		font-size: 12px;
	}

	/* Separatori nascosti su mobile per recuperare spazio orizzontale. */
	.apf-sep {
		display: none;
	}
}
