/* ==========================================================================
   Flip Book PDF Reader – Frontend CSS  v2.1
   ========================================================================== */

/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --fpb-dark:           #111111;
  --fpb-bar-bg:         rgba(20, 20, 20, 0.82);
  --fpb-bar-h:          52px;
  --fpb-bottom-bar-h:   52px;
  --fpb-text:           #ffffff;
  --fpb-accent:         #e94560;
  --fpb-btn-border:     rgba(255, 255, 255, 0.22);
  --fpb-shadow:         0 8px 40px rgba(0, 0, 0, 0.55);
  --fpb-radius:         5px;
  --fpb-transition:     0.22s ease;
  --fpb-columns:        3;
  --fpb-thumb-w:        200px;
  --fpb-thumb-h:        280px;
  /* Largeur réservée de chaque côté pour les flèches de navigation (modal) */
  --fpb-arrow-zone:     72px;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
.fpb-viewer-wrap *,
.fpb-gallery *,
.fpb-modal * {
  box-sizing: border-box;
}

/* ==========================================================================
   1. LECTEUR INLINE
   ========================================================================== */

.fpb-viewer-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #111;
  border-radius: var(--fpb-radius);
  overflow: hidden;
  box-shadow: var(--fpb-shadow);
}

/* ── Toolbar inline ─────────────────────────────────────────────────────── */
.fpb-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: var(--fpb-bar-h);
  background: var(--fpb-bar-bg);
  color: var(--fpb-text);
  flex-shrink: 0;
  z-index: 10;
}

.fpb-page-info {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  flex: 1;
  text-align: center;
  letter-spacing: 0.03em;
}

/* ── Boutons génériques ───────────────────────────────────────────────────── */
.fpb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--fpb-btn-border);
  border-radius: var(--fpb-radius);
  color: var(--fpb-text);
  width: 36px;
  height: 36px;
  cursor: pointer;
  transition: background var(--fpb-transition), border-color var(--fpb-transition),
              transform var(--fpb-transition);
  flex-shrink: 0;
  padding: 0;
}

.fpb-btn:hover,
.fpb-btn:focus {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.5);
  outline: none;
  transform: scale(1.07);
}

.fpb-btn:disabled {
  opacity: 0.25;
  cursor: default;
  transform: none;
}

/* ── Conteneur du livre ───────────────────────────────────────────────────── */
.fpb-book-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;        /* clip le livre lors d'un zoom > 1 ou d'un scale */
  position: relative;
  min-height: 0;
  min-width: 0;
  background-color: #ffffff; /* surchargé en JS via bg_color/bg_image */
}

/* ── Écran de chargement ─────────────────────────────────────────────────── */
.fpb-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(100, 100, 100, 0.8);
  font-size: 14px;
  gap: 14px;
  z-index: 5;
  background: inherit;
  transition: opacity var(--fpb-transition);
}

.fpb-loading.fpb-hidden {
  opacity: 0;
  pointer-events: none;
}

.fpb-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(0, 0, 0, 0.12);
  border-top-color: var(--fpb-accent);
  border-radius: 50%;
  animation: fpb-spin 0.75s linear infinite;
}

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

/* ── Livre StPageFlip ─────────────────────────────────────────────────────── */

/*
 * .fpb-book est transparent (sans ombre ni fond) pour que la couverture
 * (page 1 seule à droite, showCover:true) n'affiche pas de côté blanc factice.
 * StPageFlip gère lui-même les ombres dynamiques via Canvas.
 * Le transform:scale() appliqué pendant le live-resize ne recalcule pas les
 * dimensions — c'est instantané, aucune page n'est vidée.
 */
.fpb-book {
  box-shadow: none;
  background: transparent;
  /* transform-origin est défini en JS */
  will-change: transform;   /* optimise le compositing GPU pendant le scale */
}

/* Wrapper de page individuel (créé par StPageFlip) */
.fpb-book .stf__item {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

/* Wrapper global StPageFlip */
.fpb-book .stf__wrapper {
  background: transparent;
}

.fpb-page {
  background: #ffffff;
  overflow: hidden;
}

.fpb-page canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
}

/* ==========================================================================
   2. MODAL FULLSCREEN
   ========================================================================== */

.fpb-modal {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: var(--fpb-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fpb-modal.fpb-modal-open {
  animation: fpb-fadein 0.2s ease;
}

@keyframes fpb-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Bouton fermeture ─────────────────────────────────────────────────────── */
.fpb-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 30;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.65);
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--fpb-transition), transform var(--fpb-transition),
              border-color var(--fpb-transition);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
}

.fpb-modal-close:hover {
  background: #e94560;
  border-color: #e94560;
  transform: scale(1.12) rotate(90deg);
}

.fpb-modal-close:focus {
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 2px;
}

/* ── Titre haut-centre ────────────────────────────────────────────────────── */
.fpb-modal-title-wrap {
  position: absolute;
  top: 0;
  left: 60px;
  right: 60px;
  height: 52px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.fpb-modal-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  letter-spacing: 0.02em;
}

/* ── Zone du livre (modal) ────────────────────────────────────────────────── */
/*
 * left/right = --fpb-arrow-zone : réserve l'espace pour les flèches latérales
 * → elles ne chevauchent jamais le contenu du flipbook.
 * padding-top/bottom exclu des dimensions utiles via clientHeight-padding en JS.
 */
.fpb-modal .fpb-book-container {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--fpb-arrow-zone);
  right: var(--fpb-arrow-zone);
  padding-top: var(--fpb-bar-h);
  padding-bottom: var(--fpb-bottom-bar-h);
}

/* ── Flèches latérales ────────────────────────────────────────────────────── */
.fpb-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--fpb-btn-border);
  color: var(--fpb-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--fpb-transition), transform var(--fpb-transition),
              opacity var(--fpb-transition);
  opacity: 0.55;
  padding: 0;
}

.fpb-nav-arrow:hover {
  background: rgba(255, 255, 255, 0.15);
  opacity: 1;
  transform: translateY(-50%) scale(1.1);
}

.fpb-nav-arrow:disabled {
  opacity: 0.12;
  cursor: default;
  transform: translateY(-50%);
}

.fpb-nav-left  { left: 12px; }
.fpb-nav-right { right: 12px; }

/* ── Bande de miniatures ──────────────────────────────────────────────────── */
.fpb-page-strip {
  position: absolute;
  bottom: var(--fpb-bottom-bar-h);
  left: 0;
  right: 0;
  height: 116px;
  z-index: 25;
  background: rgba(12, 12, 12, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.25) transparent;
}

.fpb-page-strip::-webkit-scrollbar        { height: 4px; }
.fpb-page-strip::-webkit-scrollbar-track  { background: transparent; }
.fpb-page-strip::-webkit-scrollbar-thumb  { background: rgba(255,255,255,.25); border-radius: 2px; }

.fpb-strip-inner {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px 8px;
  height: 100%;
  width: max-content;
}

.fpb-strip-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 3px;
  padding: 3px 3px 4px;
  transition: transform var(--fpb-transition), background var(--fpb-transition);
  border: 1.5px solid transparent;
}

.fpb-strip-thumb:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.fpb-strip-thumb.fpb-strip-active {
  border-color: var(--fpb-accent);
  background: rgba(233, 69, 96, 0.15);
}

.fpb-strip-thumb canvas {
  display: block;
  max-width: 90px;
  height: auto;
  border-radius: 2px;
  background: #e0e0e0;
}

.fpb-strip-thumb:not(.fpb-strip-loaded) canvas {
  width: 90px;
  height: 64px;
  animation: fpb-pulse 1.4s ease-in-out infinite;
}

@keyframes fpb-pulse {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.8; }
}

.fpb-strip-num {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.55);
  line-height: 1;
  pointer-events: none;
}

.fpb-strip-thumb.fpb-strip-active .fpb-strip-num {
  color: var(--fpb-accent);
  font-weight: 700;
}

.fpb-btn.fpb-btn-active {
  background: rgba(233, 69, 96, 0.3);
  border-color: var(--fpb-accent);
  color: #fff;
}

/* ── Barre inférieure ─────────────────────────────────────────────────────── */
.fpb-bottom-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--fpb-bottom-bar-h);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fpb-bar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0 16px;
}

.fpb-bottom-bar .fpb-page-info {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
}

.fpb-bottom-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.fpb-bottom-actions .fpb-btn {
  width: 36px;
  height: 36px;
  border-radius: 6px;
}

/* ==========================================================================
   3. GALERIE DE VIGNETTES
   ========================================================================== */

.fpb-gallery {
  display: grid;
  grid-template-columns: repeat(var(--fpb-columns), 1fr);
  gap: 28px;
  padding: 16px 0;
}

.fpb-gallery-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  outline: none;
}

.fpb-gallery-item:focus .fpb-thumb {
  box-shadow: 0 0 0 3px var(--fpb-accent);
}

.fpb-thumb {
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  /*box-shadow: 0 3px 14px rgba(0, 0, 0, 0.22);
  background: #f0f0f0;*/
  transition: transform var(--fpb-transition), box-shadow var(--fpb-transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.fpb-gallery-item:hover .fpb-thumb,
.fpb-gallery-item:focus .fpb-thumb {
  transform: translateY(-5px) scale(1.025);
 /* box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);*/
}

.fpb-thumb img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
}

.fpb-thumb canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto !important;
  height: auto !important;
}

.fpb-thumb-overlay {
  position: absolute;
  inset: 0;
  /* background: rgba(0, 0, 0, 0.28);*/
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--fpb-transition);
}

.fpb-gallery-item:hover .fpb-thumb-overlay,
.fpb-gallery-item:focus .fpb-thumb-overlay {
  opacity: 1;
}

.fpb-thumb-overlay svg {
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
  transition: transform var(--fpb-transition);
}

.fpb-gallery-item:hover .fpb-thumb-overlay svg {
  transform: scale(1.18);
}

.fpb-thumb-title {
  margin: 9px 0 0;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: inherit;
  max-width: var(--fpb-thumb-w);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   4. BOUTON LINK [fpb_link]
   ========================================================================== */

.fpb-link {
  background:      transparent;
  border:          none;
  padding:         0;
  margin:          0;
  cursor:          pointer;
  font:            inherit;
  color:           inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  display:         inline;
  line-height:     inherit;
}

.fpb-link:hover,
.fpb-link:focus {
  opacity: 0.75;
  outline: none;
}

/* ==========================================================================
   5. PLEIN ÉCRAN NATIF
   ========================================================================== */

.fpb-viewer-wrap:fullscreen,
.fpb-viewer-wrap:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  border-radius: 0;
}

/* ==========================================================================
   6. MESSAGES D'ÉTAT
   ========================================================================== */

.fpb-error,
.fpb-empty {
  padding: 12px 16px;
  border-radius: 4px;
  font-size: 14px;
}

.fpb-error {
  background: #fdecea;
  color: #b71c1c;
  border-left: 4px solid #e53935;
}

.fpb-empty {
  color: #888;
  font-style: italic;
}

/* ==========================================================================
   7. RESPONSIVE
   ========================================================================== */

@media (max-width: 900px) {
  .fpb-gallery { --fpb-columns: 2; }
  .fpb-nav-arrow { width: 42px; height: 42px; }
  .fpb-nav-left  { left: 8px; }
  .fpb-nav-right { right: 8px; }
  .fpb-modal .fpb-book-container { left: 58px; right: 58px; }
}

@media (max-width: 580px) {
  .fpb-gallery   { --fpb-columns: 1; justify-items: center; }
  .fpb-nav-arrow { width: 34px; height: 34px; opacity: 0.85; }
  .fpb-nav-left  { left: 4px; }
  .fpb-nav-right { right: 4px; }
  .fpb-modal .fpb-book-container { left: 42px; right: 42px; }
}
