/* ================================================================
   CaraHub PDF Showcase Viewer
   ================================================================ */

/* ── Grid ────────────────────────────────────────────────────────── */
.ch-pdf-showcase { width: 100%; }

.ch-pdf-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(24px, 3.5vw, 48px);
}
.ch-pdf-grid--2col { grid-template-columns: repeat(2, 1fr); }
.ch-pdf-grid--4col { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 860px) {
  .ch-pdf-grid       { grid-template-columns: repeat(2, 1fr); }
  .ch-pdf-grid--4col { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .ch-pdf-grid,
  .ch-pdf-grid--2col,
  .ch-pdf-grid--4col { grid-template-columns: 1fr; }
}

/* ── Card ────────────────────────────────────────────────────────── */
.ch-pdf-card {
  cursor: pointer;
  position: relative;
  border-radius: 4px 12px 12px 4px;
  overflow: visible;
  transition: transform .4s cubic-bezier(.16,1,.3,1);
  transform-origin: left center;
  /* Book shadow: left spine darker, right page lighter */
  filter: drop-shadow(-3px 6px 0px rgba(0,0,0,.18)) drop-shadow(6px 16px 24px rgba(0,0,0,.18));
}
.ch-pdf-card:hover {
  transform: translateY(-6px) rotate(-1deg);
  filter: drop-shadow(-4px 8px 0px rgba(0,0,0,.22)) drop-shadow(10px 28px 36px rgba(0,0,0,.24));
}

/* Cover area — the visible book page */
.ch-pdf-card__cover {
  position: relative;
  overflow: hidden;
  background: #ddd;
  aspect-ratio: 3/4;
  border-radius: 4px 12px 12px 4px;
}

/* Book spine — left dark strip */
.ch-pdf-card__spine {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 14px;
  background: linear-gradient(to right, rgba(0,0,0,.28) 0%, rgba(0,0,0,.06) 60%, transparent 100%);
  z-index: 3;
  border-radius: 4px 0 0 4px;
  pointer-events: none;
}

/* Thumbnail image */
.ch-pdf-card__canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Gradient overlay — always visible at bottom for title legibility */
.ch-pdf-card__info {
  position: absolute;
  inset: auto 0 0 0;
  padding: 48px 16px 18px 20px;
  background: linear-gradient(to top, rgba(0,0,0,.78) 0%, rgba(0,0,0,.4) 55%, transparent 100%);
  z-index: 2;
  transform: translateY(4px);
  transition: transform .35s cubic-bezier(.16,1,.3,1), opacity .35s;
  opacity: .92;
}
.ch-pdf-card:hover .ch-pdf-card__info {
  transform: translateY(0);
  opacity: 1;
}
.ch-pdf-card__name {
  margin: 0 0 2px;
  font-size: .9rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}
.ch-pdf-card__sub {
  margin: 0;
  font-size: .72rem;
  color: rgba(255,255,255,.65);
}

/* CTA button — slides up on hover */
.ch-pdf-card__cta {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .28s, transform .28s cubic-bezier(.16,1,.3,1);
}
.ch-pdf-card:hover .ch-pdf-card__cta {
  opacity: 1;
  transform: translateY(0);
}
.ch-pdf-card__cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  background: rgba(255,255,255,.15);
  border: 1.5px solid rgba(255,255,255,.55);
  border-radius: 999px;
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
}

/* ── Spinner ─────────────────────────────────────────────────────── */
.ch-pdf-card__spin {
  display: inline-block;
  position: absolute;
  width: 22px; height: 22px;
  border: 3px solid rgba(0,0,0,.1);
  border-top-color: var(--wp--preset--color--accent, #e8490f);
  border-radius: 50%;
  animation: pdf-spin .7s linear infinite;
}
@keyframes pdf-spin { to { transform: rotate(360deg); } }

/* ── Modal ───────────────────────────────────────────────────────── */
.ch-pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.ch-pdf-modal[hidden] { display: none; }

/* Backdrop — keep dark for focus */
.ch-pdf-modal__bd {
  position: absolute;
  inset: 0;
  background: rgba(6,6,6,.82);
  backdrop-filter: blur(6px);
}

/* Shell — transparent, full-area, no background */
.ch-pdf-modal__shell {
  position: relative;
  z-index: 1;
  width: min(98vw, 1500px);
  height: 96vh;
  display: flex;
  flex-direction: column;
  background: transparent;
  border-radius: 0;
  overflow: visible;
  box-shadow: none;
}

/* Close button — floats top-right of viewport */
.ch-pdf-modal__close {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: none;
  background: rgba(255,255,255,.15);
  color: rgba(255,255,255,.85);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background .18s, color .18s;
}
.ch-pdf-modal__close:hover {
  background: rgba(220,38,38,.7);
  color: #fff;
}

/* Stage */
.ch-pdf-modal__stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 8px 0;
  overflow: visible;
  background: transparent;
}

/* Loading progress */
.ch-pdf-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}
.ch-pdf-progress[hidden] { display: none; }
.ch-pdf-progress__label {
  margin: 0;
  font-size: .82rem;
  color: rgba(255,255,255,.65);
  font-weight: 500;
}
.ch-pdf-progress__track {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,.15);
  border-radius: 99px;
  overflow: hidden;
}
.ch-pdf-progress__fill {
  height: 100%;
  background: var(--wp--preset--color--accent, #e8490f);
  border-radius: 99px;
  transition: width .2s linear;
  width: 0%;
}
.ch-pdf-progress__count {
  margin: 0;
  font-size: .72rem;
  color: rgba(255,255,255,.4);
}

/* Book wrap — center the book, but DON'T stretch it (so clicks on gray area fall outside #ch-pdf-book) */
.ch-pdf-book-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}
.ch-pdf-book-wrap[hidden] { display: none; }

/* Book el is explicitly sized to exact book content dimensions by JS */
#ch-pdf-book {
  flex-shrink: 0;
  overflow: visible;
}

/* StPageFlip HTML mode — allow 3D transforms to extend beyond container */
.stf__parent,
.stf__block,
.stf__wrapper {
  overflow: visible !important;
}

/* Individual page divs fed to loadFromHTML */
.ch-flip-page {
  width: 100%;
  height: 100%;
  background: #fff;
  overflow: hidden; /* clip page content, not the 3D flip */
}
.ch-flip-page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain; /* contain: bìa lệ cỡ (A4 dọc) letterbox gọn, không bị cắt */
  pointer-events: none;
  user-select: none;
}

/* Scroll viewer (mobile) */
[data-view="scroll"] .ch-pdf-book-wrap {
  align-items: stretch;
}
#ch-pdf-book[style*="overflow"] {  /* scroll mode */
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.ch-scroll-page {
  display: block;
  width: 100%;
  height: auto;
  margin-bottom: 6px;
  border-radius: 2px;
}
.ch-scroll-page:last-child { margin-bottom: 0; }

/* Single-page viewer */
.ch-spv {
  display: block;
  max-width: 100%;
  max-height: 82vh;
  width: auto;
  height: auto;
  border-radius: 4px;
  box-shadow: 0 12px 60px rgba(0,0,0,.5);
}

/* Footer — floating, transparent */
.ch-pdf-modal__footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 0;
  flex-shrink: 0;
  background: transparent;
}

.ch-pdf-nav {
  width: 36px; height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  color: rgba(255,255,255,.85);
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: background .18s, color .18s, opacity .18s;
}
.ch-pdf-nav:hover:not(:disabled) {
  background: rgba(255,255,255,.25);
  color: #fff;
}
.ch-pdf-nav:disabled { opacity: .2; cursor: default; }

.ch-pdf-counter {
  font-size: .72rem;
  font-weight: 600;
  color: rgba(255,255,255,.6);
  letter-spacing: .08em;
  min-width: 70px;
  text-align: center;
}

/* Mobile */
@media (max-width: 899px) {
  .ch-pdf-modal { padding: 0; }
  .ch-pdf-modal__shell { width: 100%; height: 100vh; }
  .ch-pdf-modal__stage { padding: 0; }
  /* Scroll mode: hide nav arrows, counter stays for page tracking */
  [data-view="scroll"] .ch-pdf-nav { display: none; }
  .ch-spv { max-height: 78vh; }
}
