/* ─────────────────────────────────────────────────────────────
   3D PAGE FLIP CATALOGUE STYLESHEET (StPageFlip)
   ───────────────────────────────────────────────────────────── */

/* Force all wrapper elements on the template page to be transparent so WebGL/fluid canvas is visible */
body.page-template-template-catalogue,
body.page-template-template-catalogue #page,
body.page-template-template-catalogue #primary,
body.page-template-template-catalogue .site-main,
body.page-template-template-catalogue #smooth-wrapper,
body.page-template-template-catalogue #smooth-content {
  background: transparent !important;
  background-color: transparent !important;
}

.catalogue-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 140px); /* 140px offset gives breathing room at the bottom */
  max-height: calc(100vh - 140px);
  margin-top: 110px; /* Sits perfectly below the fixed site header/topbar */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  background: transparent !important;
  padding: 10px 24px 60px 24px;
  box-sizing: border-box;
  overflow: hidden;
}

/* Fullscreen support overrides to remove header margins */
.catalogue-container:fullscreen,
.catalogue-container:-webkit-full-screen {
  margin-top: 0 !important;
  height: 100vh !important;
  max-height: 100vh !important;
  padding: 40px 40px 100px 40px !important;
}

/* Admin bar offsets to prevent scroll overlap when logged in */
body.admin-bar .catalogue-container {
  margin-top: calc(110px + 32px);
  height: calc(100vh - 140px - 32px);
  max-height: calc(100vh - 140px - 32px);
}
@media screen and (max-width: 782px) {
  body.admin-bar .catalogue-container {
    margin-top: calc(110px + 46px);
    height: calc(100vh - 140px - 46px);
    max-height: calc(100vh - 140px - 46px);
  }
}

/* ── VIEWPORT & CONTAINER ── */
.catalogue-viewport {
  width: 100%;
  height: calc(100% - 60px);
  max-height: calc(100vh - 250px);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 10;
  margin-bottom: 10px;
}

.catalogue-container:fullscreen .catalogue-viewport,
.catalogue-container:-webkit-full-screen .catalogue-viewport {
  height: calc(100% - 100px) !important;
  max-height: calc(100vh - 160px) !important;
}

.book-container {
  position: relative;
  background: transparent;
  transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
  will-change: transform;
}

/* StPageFlip Page Item Elements */
.page-wrapper {
  background-color: #ffffff;
  box-shadow: 
    0 20px 45px rgba(2, 18, 58, 0.12),
    inset 0 0 12px rgba(2, 18, 58, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.page-wrapper canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* Spine Shadow Overlay (drawn natively by library, customized here if needed) */
.book-spine-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 10px;
  background: linear-gradient(90deg, rgba(0,0,0,0.06) 0%, rgba(0,0,0,0.0) 50%, rgba(0,0,0,0.06) 100%);
  transform: translateX(-50%);
  z-index: 20;
  pointer-events: none;
}

/* ── LOADING OVERLAY ── */
.catalogue-loader {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.6s;
}

.catalogue-loader.fade-out {
  opacity: 0;
  visibility: hidden;
}

.loader-content {
  text-align: center;
  max-width: 320px;
  width: 90%;
}

.loader-logo {
  font-size: 24px;
  font-weight: 800;
  color: var(--color-ink-deep);
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.loader-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-slate);
  margin-bottom: 20px;
}

.loader-bar-bg {
  width: 100%;
  height: 4px;
  background: rgba(71, 112, 194, 0.12);
  border-radius: var(--rounded-full);
  overflow: hidden;
  position: relative;
  margin-bottom: 12px;
}

.loader-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary-deep) 100%);
  border-radius: var(--rounded-full);
  transition: width 0.15s ease-out;
}

.loader-percentage {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary-deep);
}

/* ── FLOATING CONTROLS ── */
.catalogue-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow:
    0 16px 40px rgba(18, 20, 24, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  padding: 10px 16px;
  border-radius: var(--rounded-full);
  user-select: none;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-divider {
  width: 1px;
  height: 24px;
  background: rgba(2, 18, 58, 0.08);
  margin: 0 4px;
}

.ctrl-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-ink-deep);
  background: transparent;
  border: none;
  cursor: pointer;
  outline: none;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    transform 0.2s ease;
}

.ctrl-btn:hover {
  background: rgba(71, 112, 194, 0.08);
  color: var(--color-primary);
  transform: scale(1.05);
}

.ctrl-btn:active {
  transform: scale(0.95);
}

.ctrl-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.ctrl-btn svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.75;
}

/* Page indicator styling */
.page-indicator {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-ink-deep);
  padding: 0 10px;
  min-width: 100px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.page-indicator span {
  font-family: inherit;
}

/* Download button primary styling */
.ctrl-btn-primary {
  background: var(--color-primary);
  color: white;
}

.ctrl-btn-primary:hover {
  background: var(--color-primary-deep);
  color: white;
}

/* ── TOOLTIP ── */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translate(-50%, -8px) scale(0.8);
  background: var(--color-ink-deep);
  color: white;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--rounded-md);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  z-index: 1001;
}

[data-tooltip]:hover::before {
  opacity: 1;
  transform: translate(-50%, -8px) scale(1);
}

/* ── BACK BUTTON ── */
.catalogue-back-btn {
  position: absolute;
  top: 24px;
  left: 24px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 8px 24px rgba(18, 20, 24, 0.05);
  padding: 8px 16px;
  border-radius: var(--rounded-full);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-ink-deep);
  transition: transform 0.2s ease, background 0.2s ease;
}

.catalogue-back-btn:hover {
  background: rgba(71, 112, 194, 0.08);
  transform: translateX(-4px);
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .catalogue-controls {
    bottom: 16px;
    padding: 8px 12px;
    gap: 8px;
    width: 92%;
    max-width: 480px;
    justify-content: space-between;
    border-radius: var(--rounded-xl);
  }

  .ctrl-btn {
    width: 34px;
    height: 34px;
  }

  .ctrl-btn svg {
    width: 18px;
    height: 18px;
  }

  .page-indicator {
    min-width: 80px;
    font-size: 12px;
  }

  .ctrl-divider {
    height: 20px;
    margin: 0 2px;
  }

  /* Hide zoom on mobile to keep controls simple */
  .ctrl-zoom-group {
    display: none;
  }

  .catalogue-back-btn {
    top: 16px;
    left: 16px;
    padding: 6px 12px;
    font-size: 12px;
  }
}

/* ── RTL SUPPORT ── */
body.rtl .catalogue-controls {
  direction: ltr; /* Keep buttons layout order standard */
}

body.rtl .page-indicator {
  direction: rtl; /* Support Arabic page numbers */
}

body.rtl .ctrl-btn svg.chevron-prev {
  transform: scaleX(-1); /* Mirror back arrow for RTL navigation */
}

body.rtl .ctrl-btn svg.chevron-next {
  transform: scaleX(-1); /* Mirror forward arrow for RTL navigation */
}

body.rtl .catalogue-back-btn {
  left: auto;
  right: 24px;
}

body.rtl .catalogue-back-btn:hover {
  transform: translateX(4px);
}

body.rtl .catalogue-back-btn svg {
  transform: scaleX(-1);
}

@media (max-width: 768px) {
  body.rtl .catalogue-back-btn {
    right: 16px;
  }
}
