/**
 * [jit_flipbook] viewer.
 * --jit-fb-ratio (page width / height) is set inline per book.
 */

.jit-fb {
	--jit-fb-bg: #eef2f6;
	--jit-fb-chrome: 150px; /* head + toolbar + paddings, used to fit the book to the screen height */

	position: relative;
	margin: 0 0 48px;
	padding: 20px 20px 16px;
	border: 1px solid var(--jit-color-border);
	border-radius: var(--jit-radius-lg);
	background: var(--jit-fb-bg);
	font-family: var(--jit-font-sans);
	outline: none;
}

.jit-fb:focus-visible {
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--fs-color-primary) 35%, transparent);
}

/* Header */
.jit-fb__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 16px;
}

.jit-fb__title {
	margin: 0;
	font-size: 18px;
	font-weight: 700;
	color: var(--jit-color-text);
}

.jit-fb__count {
	flex: none;
	font-size: 13px;
	color: var(--jit-color-text-muted);
}

/* Stage: side arrows + book */
.jit-fb__stage {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
}

.jit-fb__viewport {
	position: relative;
	flex: 0 1 auto;
	/* two pages side by side, capped so the whole spread fits the screen height */
	width: min(100%, calc((100vh - var(--jit-fb-chrome)) * var(--jit-fb-ratio) * 2));
	min-width: 0;
}

.jit-fb.is-portrait .jit-fb__viewport {
	width: min(100%, calc((100vh - var(--jit-fb-chrome)) * var(--jit-fb-ratio)));
}

.jit-fb__book {
	margin: 0 auto;
	opacity: 0;
	transition: opacity 0.4s ease;
}

.jit-fb.is-ready .jit-fb__book {
	opacity: 1;
}

.jit-fb__sheet {
	background: #fff;
	overflow: hidden;
	user-select: none;
}

.jit-fb__sheet img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	pointer-events: none;
}

.jit-fb__sheet img:not([src]) {
	visibility: hidden;
}

.stf__parent {
	filter: drop-shadow(0 12px 24px rgba(15, 40, 90, 0.18));
}

/* Loading spinner until the library reports ready */
.jit-fb__loading {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 240px;
	pointer-events: none;
}

.jit-fb__loading span {
	width: 36px;
	height: 36px;
	border: 3px solid var(--jit-color-border);
	border-top-color: var(--fs-color-primary);
	border-radius: 50%;
	animation: jit-fb-spin 0.8s linear infinite;
}

.jit-fb.is-ready .jit-fb__loading {
	display: none;
}

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

/* Side arrows */
.jit-fb__nav {
	flex: none;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	border: 1px solid var(--jit-color-border);
	border-radius: 50%;
	background: #fff;
	box-shadow: var(--jit-shadow-card);
	color: var(--jit-color-text);
	font-size: 28px;
	line-height: 40px;
	cursor: pointer;
	transition: background var(--jit-transition), color var(--jit-transition), opacity var(--jit-transition);
}

.jit-fb__nav:hover {
	background: var(--fs-color-primary);
	border-color: var(--fs-color-primary);
	color: #fff;
}

.jit-fb.is-first .jit-fb__nav--prev,
.jit-fb.is-last .jit-fb__nav--next {
	opacity: 0.3;
	pointer-events: none;
}

/* Toolbar */
.jit-fb__bar {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-wrap: wrap;
	gap: 4px;
	margin-top: 16px;
}

.jit-fb__bar button,
.jit-fb__download {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-width: 36px;
	height: 36px;
	margin: 0;
	padding: 0 10px;
	border: 0;
	border-radius: var(--jit-radius-sm);
	background: transparent;
	color: var(--jit-color-text);
	font-size: 18px;
	font-weight: 600;
	line-height: 1;
	text-transform: none;
	letter-spacing: 0;
	cursor: pointer;
	transition: background var(--jit-transition), color var(--jit-transition);
}

.jit-fb__bar button:hover,
.jit-fb__download:hover {
	background: #fff;
	color: var(--fs-color-primary);
}

.jit-fb__download {
	font-size: 13px;
}

.jit-fb__page {
	min-width: 84px;
	padding: 0 8px;
	font-size: 14px;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	text-align: center;
	color: var(--jit-color-text);
}

.jit-fb__sep {
	width: 1px;
	height: 20px;
	margin: 0 6px;
	background: var(--jit-color-border);
}

/* Fullscreen */
.jit-fb.is-fullscreen {
	--jit-fb-chrome: 110px;

	display: flex;
	flex-direction: column;
	justify-content: center;
	margin: 0;
	padding: 24px;
	border: 0;
	border-radius: 0;
	background: #1d2a3a;
}

.jit-fb.is-fullscreen .jit-fb__head {
	display: none;
}

.jit-fb.is-fullscreen .jit-fb__nav {
	border-color: rgba(255, 255, 255, 0.2);
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
}

.jit-fb.is-fullscreen .jit-fb__bar button,
.jit-fb.is-fullscreen .jit-fb__download,
.jit-fb.is-fullscreen .jit-fb__page {
	color: #fff;
}

.jit-fb.is-fullscreen .jit-fb__bar button:hover,
.jit-fb.is-fullscreen .jit-fb__download:hover {
	background: rgba(255, 255, 255, 0.12);
}

.jit-fb.is-fullscreen .jit-fb__sep {
	background: rgba(255, 255, 255, 0.2);
}

/* Mobile: drop the side arrows, the toolbar has them */
@media (max-width: 549px) {
	.jit-fb {
		padding: 14px 10px 10px;
	}

	.jit-fb__nav {
		display: none;
	}

	.jit-fb__head {
		flex-direction: column;
		gap: 2px;
	}

	.jit-fb__title {
		font-size: 16px;
	}

	.jit-fb__bar {
		gap: 0;
	}

	.jit-fb__bar button,
	.jit-fb__download {
		min-width: 32px;
		padding: 0 6px;
	}

	.jit-fb__page {
		min-width: 64px;
		padding: 0 4px;
		font-size: 13px;
	}

	.jit-fb__sep {
		margin: 0 2px;
	}
}

/* ---------- [jit_flipbook_card]: cover card on the catalogue index ---------- */
.jit-fb-card {
	display: flex;
	flex-direction: column;
	height: 100%;
	border: 1px solid var(--jit-color-border);
	border-radius: var(--jit-radius-lg);
	background: var(--jit-color-surface);
	box-shadow: var(--jit-shadow-card);
	color: inherit;
	font-family: var(--jit-font-sans);
	overflow: hidden;
	transition: border-color var(--jit-transition), box-shadow var(--jit-transition), transform var(--jit-transition);
}

.jit-fb-card:hover {
	border-color: color-mix(in srgb, var(--fs-color-primary) 40%, transparent);
	box-shadow: var(--jit-shadow-card-hover);
	transform: translateY(-4px);
	color: inherit;
}

.jit-fb-card__cover {
	display: flex;
	justify-content: center;
	padding: 32px 32px 0;
	background: #eef2f6;
}

.jit-fb-card__cover img {
	display: block;
	width: 62%;
	height: auto;
	border-radius: 2px 2px 0 0;
	box-shadow: 0 -2px 18px rgba(15, 40, 90, 0.18);
	transition: transform var(--jit-transition);
	transform-origin: bottom center;
}

.jit-fb-card:hover .jit-fb-card__cover img {
	transform: perspective(900px) rotateY(-8deg) scale(1.02);
}

.jit-fb-card__body {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 6px;
	padding: 20px 24px 22px;
	border-top: 1px solid var(--jit-color-border);
}

.jit-fb-card__title {
	font-size: 18px;
	font-weight: 700;
	line-height: 1.35;
	color: var(--jit-color-text);
}

.jit-fb-card__meta {
	font-size: 13px;
	color: var(--jit-color-text-muted);
}

.jit-fb-card__cta {
	margin-top: auto;
	padding-top: 10px;
	font-size: 14px;
	font-weight: 600;
	color: var(--fs-color-primary);
}

.jit-fb-card__cta span {
	display: inline-block;
	transition: transform var(--jit-transition);
}

.jit-fb-card:hover .jit-fb-card__cta span {
	transform: translateX(4px);
}

/* Back link on single catalogue pages */
.jit-fb-back {
	display: inline-block;
	margin-bottom: 16px;
	font-family: var(--jit-font-sans);
	font-size: 14px;
	font-weight: 600;
	color: var(--fs-color-primary);
}

@media (max-width: 549px) {
	.jit-fb-card__cover {
		padding: 24px 24px 0;
	}

	.jit-fb-card__body {
		padding: 16px 18px 18px;
	}
}
