/* ═══════════════════════════════════════════════
   COMPONENTE: FLIPBOOK
   Usado em: Acervo, Galeria, Produções
   ═══════════════════════════════════════════════ */

/* ===== GLOBAL ===== */
.flipbook-app * {
  box-sizing: border-box;
}

/* Modal do flipbook */
.flipbook-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  z-index: 2147483647 !important;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

body.flipbook-aberto header {
  display: none;
}

.flipbook-modal.ativo,
#flipbookModal.ativo {
  z-index: 2147483647 !important;
}

body.cr-flipbook-aberto #cr-layout-header {
  display: none !important;
}

/* Wrapper */
.flipbook-wrapper {
  width: 95vw;
  max-width: 1200px;
  aspect-ratio: 2 / 1.4;
  position: relative;
}

/* Livro */
.flipbook-book {
  width: 100%;
  height: 100%;
  position: relative;
  perspective: 3000px;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

/* Lombada */
.flipbook-lombada {
  position: absolute;
  top: 0;
  left: 50%;
  width: 8px;
  height: 100%;
  transform: translateX(-50%);
  z-index: 20;
  pointer-events: none;
  background: linear-gradient(to right,
      rgba(0, 0, 0, 0.8),
      rgba(0, 0, 0, 0.4),
      rgba(255, 255, 255, 0.2));
}

.flipbook-lombada::before {
  content: "";
  position: absolute;
  left: -10px;
  width: 20px;
  height: 100%;
  background: radial-gradient(ellipse at center,
      rgba(0, 0, 0, 0.35),
      transparent 70%);
}

/* Folhas */
.flipbook-sheet {
  width: 50%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 50%;
  transform-origin: left;
  transform-style: preserve-3d;
  transition: transform 0.7s ease;
  transform: translateX(-0.5px);
}

.flipbook-page {
  width: 100%;
  height: 100%;
  position: absolute;
  backface-visibility: hidden;
}

.flipbook-page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #ddd;
}

.flipbook-front {
  transform: rotateY(0deg);
}

.flipbook-back {
  transform: rotateY(180deg);
}

.flipbook-sheet.virada {
  transform: translateX(-0.5px) rotateY(-180deg);
}

.flipbook-sheet.virando {
  z-index: 9999 !important;
}

.flipbook-sheet::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.5s;
}

.flipbook-sheet.virada::after {
  opacity: 1;
}

/* Controles */
.flipbook-controles {
  margin-top: 15px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.flipbook-controles button {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  padding: 8px 12px !important;
  cursor: pointer !important;
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  border-radius: 8px !important;
  line-height: normal !important;
  width: auto !important;
  height: auto !important;
  opacity: 1 !important;
  visibility: visible !important;
  text-indent: 0 !important;
  overflow: visible !important;
  transition: 0.2s;
  font-size: 14px !important;
  color: #fff !important;
  text-indent: 0 !important;
  letter-spacing: normal !important;
  white-space: nowrap !important;
  font-family: inherit !important;
}

.flipbook-controles button:hover {
  background: rgba(255, 255, 255, 0.2) !important;
}

.flipbook-controles button:active {
  transform: scale(0.95);
}

.flipbook-controles button:disabled {
  opacity: 0.3;
}

.flipbook-controles button span {
  display: inline !important;
  font-size: 14px !important;
}

.flipbook-ajuda {
  color: #fff;
  font-size: 14px;
  text-align: center;
  margin: 12px 16px 0;
}

.flipbook-page-vazia {
  background: #eee;
}

/* Paginação */
.flipbook-paginacao {
  text-align: center;
  margin-top: 15px;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, .9);
}

/* ===== VARIANTE PRODUÇÃO ===== */
#flipbookModal.cr-flipbook-producao .flipbook-modal {
  background: rgba(0, 0, 0, 0.72);
}

#flipbookModal.cr-flipbook-producao .flipbook-wrapper {
  width: min(92vw, 980px);
  max-width: 980px;
}

#flipbookModal.cr-flipbook-producao .flipbook-book,
#flipbookModal.cr-flipbook-producao .flipbook-sheet,
#flipbookModal.cr-flipbook-producao .flipbook-page {
  background: transparent !important;
}

#flipbookModal.cr-flipbook-producao .flipbook-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

#flipbookModal.cr-flipbook-producao .flipbook-page img {
  width: auto !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  background: transparent !important;
  display: block;
  margin: 0 auto;
}

#flipbookModal.cr-flipbook-producao .flipbook-page-vazia {
  background: transparent !important;
}

/* ===== VARIANTE FOLHETO ===== */
#flipbookModal.cr-flipbook-folheto .flipbook-page {
  background: transparent !important;
  display: flex;
  align-items: center;
}

#flipbookModal.cr-flipbook-folheto .flipbook-front {
  justify-content: flex-start;
}

#flipbookModal.cr-flipbook-folheto .flipbook-back {
  justify-content: flex-end;
}

#flipbookModal.cr-flipbook-folheto .flipbook-page img {
  width: auto !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  background: transparent !important;
  margin: 0 !important;
}

#flipbookModal.cr-flipbook-folheto .flipbook-page-vazia {
  background: transparent !important;
}

/* ===== VARIANTE PADRÃO (LIVROS, EDIÇÕES, CORDÉIS COMUNS) ===== */
#flipbookModal.cr-flipbook-padrao .flipbook-book {
  background: transparent !important;
}

#flipbookModal.cr-flipbook-padrao .flipbook-sheet,
#flipbookModal.cr-flipbook-padrao .flipbook-page {
  background: #fff !important;
}

#flipbookModal.cr-flipbook-padrao .flipbook-page {
  display: block !important;
  overflow: hidden !important;
}

#flipbookModal.cr-flipbook-padrao .flipbook-page img {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  object-fit: cover !important;
  object-position: center center !important;
  background: #fff !important;
  display: block !important;
  margin: 0 !important;
}

/* ===== FLIPBOOK ACERVO - FUNDO OPACO ===== */
#flipbookModal:not(.cr-flipbook-producao):not(.cr-flipbook-folheto) .flipbook-sheet {
  background: #f4f1ea;
}

#flipbookModal:not(.cr-flipbook-producao):not(.cr-flipbook-folheto) .flipbook-page {
  background: #f4f1ea;
  overflow: hidden;
}

/* ===== FLIPBOOK ACERVO - PADRONIZA TAMANHO ===== */
#flipbookModal:not(.cr-flipbook-producao):not(.cr-flipbook-folheto) .flipbook-page {
  background: #fff !important;
  overflow: hidden !important;
}

/* Mantém folhetos estreitos com comportamento especial */
#flipbookModal.cr-flipbook-folheto .flipbook-page {
  background: transparent !important;
  display: flex !important;
  align-items: center !important;
}

#flipbookModal.cr-flipbook-folheto .flipbook-front {
  justify-content: flex-start !important;
}

#flipbookModal.cr-flipbook-folheto .flipbook-back {
  justify-content: flex-end !important;
}

#flipbookModal.cr-flipbook-folheto .flipbook-page img {
  width: auto !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  background: transparent !important;
  margin: 0 !important;
}