/* =========================================================
   FLIPBOOK MODAL – PDF Viewer with 3D Page Flip
   Each PDF page = 1 flap rotating on left edge
   ========================================================= */

/* ---- Modal Overlay ---- */
.flipbook-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: 'Poppins', 'Inter', sans-serif;
}

.flipbook-modal.is-open {
  display: flex;
}

.flipbook-modal__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: flipbookFadeIn 0.25s ease;
}

/* ---- Modal Content ---- */
.flipbook-modal__content {
  position: relative;
  width: 95vw;
  height: 92vh;
  max-width: 1200px;
  max-height: 900px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: flipbookSlideIn 0.3s ease;
}

/* ---- Header ---- */
.flipbook-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  flex-shrink: 0;
  z-index: 10;
}

.flipbook-modal__title {
  font-size: 1rem;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flipbook-modal__controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.flipbook-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: #f5f5f5;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
}

.flipbook-btn:hover {
  background: #e0e0e0;
  color: #D4001A;
}

.flipbook-btn--close:hover {
  background: #fee;
  color: #D4001A;
}

/* ---- Body (viewport) ---- */
.flipbook-modal__body {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #e8e8e8;
  background-image:
    radial-gradient(circle at 50% 50%, #ddd 0%, #ccc 100%);
}

.flipbook-viewport {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.flipbook-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
}

/* ---- Stage (the book area) ---- */
.flipbook-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* ---- Wrapper (stack of flaps with 3D perspective) ---- */
.flipbook-wrapper {
  display: block;
  perspective: 2500px;
  -webkit-perspective: 2500px;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  box-shadow:
    0 2px 12px rgba(0,0,0,0.15),
    0 8px 32px rgba(0,0,0,0.1);
  border-radius: 2px;
  background: #fff;
}

/* ---- Each flap (page) ---- */
.flipbook-flap {
  transform-origin: left center;
  -webkit-transform-origin: left center;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 0.6s cubic-bezier(0.645, 0.045, 0.355, 1);
  -webkit-transition: -webkit-transform 0.6s cubic-bezier(0.645, 0.045, 0.355, 1);
  border-radius: 0 3px 3px 0;
  box-shadow: inset 1px 0 0 rgba(0,0,0,0.02);
}

/* Canvas inside flap */
.flipbook-flap canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---- Book shadow overlay ---- */
.flipbook-bookshadow {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9998;
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.12) 0%,
    rgba(0, 0, 0, 0.04) 40%,
    transparent 60%
  );
  opacity: 0.8;
}

/* ---- Footer (navigation) ---- */
.flipbook-modal__footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 20px;
  background: #fff;
  border-top: 1px solid #e8e8e8;
  flex-shrink: 0;
  z-index: 10;
}

.flipbook-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  color: #333;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.flipbook-nav:hover:not(:disabled) {
  background: #D4001A;
  color: #fff;
  border-color: #D4001A;
}

.flipbook-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.flipbook-nav svg {
  flex-shrink: 0;
}

.flipbook-page-info {
  font-size: 0.85rem;
  font-weight: 500;
  color: #666;
  min-width: 80px;
  text-align: center;
  user-select: none;
}

/* ---- Loading Indicator ---- */
.flipbook-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(245, 245, 245, 0.95);
  z-index: 100;
}

.flipbook-loading__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e0e0e0;
  border-top-color: #D4001A;
  border-radius: 50%;
  animation: flipbookSpin 0.8s linear infinite;
}

.flipbook-loading span {
  font-size: 0.9rem;
  color: #666;
  font-weight: 500;
}

/* ---- Animations ---- */
@keyframes flipbookFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes flipbookSlideIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes flipbookSpin {
  to { transform: rotate(360deg); }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .flipbook-modal__content {
    width: 100vw;
    height: 100vh;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .flipbook-modal__header {
    padding: 10px 14px;
  }

  .flipbook-modal__title {
    font-size: 0.85rem;
  }

  .flipbook-modal__footer {
    padding: 10px 14px;
    gap: 10px;
  }

  .flipbook-nav {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .flipbook-nav span {
    display: none;
  }

  .flipbook-page-info {
    font-size: 0.75rem;
    min-width: 60px;
  }
}

@media (max-width: 480px) {
  .flipbook-modal__content {
    border-radius: 0;
  }

  .flipbook-nav span {
    display: none;
  }
}