*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f5f5f5;
  overscroll-behavior: none; /* Evitar efeitos de puxão nos navegadores */
}

.edicao-single {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.edicao-header {
  text-align: center;
  padding: 0.25rem;
  margin-bottom: 0.5rem;
}

.edicao-title {
  font-size: 1.25rem;
  color: #333;
  margin-bottom: 0.25rem;
}

.edicao-meta {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  color: #666;
  font-size: 0.8rem;
}

.pdf-container {
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0.5rem 0;
  min-height: 70vh;
  position: relative;
}

/* Overlay de proteção */
.pdf-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(240, 240, 240, 0.7);
  z-index: 99;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: not-allowed;
}

#flipbook-container {
  position: relative;
  width: 100%;
  height: 65vh;
  background: #f0f0f0;
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  -webkit-user-select: none;
  touch-action: pan-x pan-y pinch-zoom !important;
  -ms-touch-action: pan-x pan-y pinch-zoom !important;
  -webkit-overflow-scrolling: touch;
  will-change: transform;
}

/* Container para zoom em flipbook otimizado */
.zoom-container {
  transform-origin: center center;
  will-change: transform;
  touch-action: none;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform-style: preserve-3d;
  perspective: 1000px;
  transition: none !important; /* Desativar transições por padrão */
  -webkit-transition: none !important;
  -webkit-transform: translate3d(0,0,0);
  transform: translate3d(0,0,0);
}

/* Quando estiver inativo, permitir transições */
.zoom-container.inactive {
  transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1) !important;
  -webkit-transition: transform 0.2s cubic-bezier(0.215, 0.61, 0.355, 1) !important;
}

/* Classe para indicar quando está deslizando com inércia */
.zoom-container.sliding {
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
  -webkit-transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
}

/* Melhorias para suporte a toque e arrasto após zoom */
.zoom-container.dragging {
  transition: none !important;
  -webkit-transition: none !important;
  will-change: transform !important;
  touch-action: none !important;
  -ms-touch-action: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  cursor: grabbing !important;
}

#flipbook {
  margin: 0 auto;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* Cursores para zoom melhorados */
#flipbook-container.can-grab {
  touch-action: none !important;
  -ms-touch-action: none !important;
  cursor: grab;
}

#flipbook-container.grabbing {
  cursor: grabbing;
}

/* Melhorando a interação de arrastar o conteúdo ampliado */
#flipbook-container.grabbing * {
  cursor: grabbing !important;
  user-select: none !important;
}

/* Prevenir seleção de texto durante o arrasto */
#flipbook-container.can-grab *,
#flipbook-container.grabbing * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  touch-action: none !important;
}

/* Otimizações para canvas em dispositivos móveis */
.pdf-page-canvas {
  background: white;
  margin: 0 auto;
  display: block;
  width: 100%;
  height: 100%;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  image-rendering: -webkit-optimize-contrast; /* Para melhor qualidade em zoom */
}

/* Durante pinça, desativar TODAS as animações e transições */
#flipbook-container.pinching * {
  animation: none !important;
  transition: none !important;
  -webkit-transition: none !important;
}

/* Indicação de zoom */
.zoom-level {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.8);
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 12px;
  color: #333;
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.zoom-level.visible {
  opacity: 1;
}

/* Estilos para o flipbook */
#flipbook .page {
  background-color: white;
  background-size: 100% 100%;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  transform: translateZ(0);
}

#flipbook .hard {
  background: #ccc;
  color: #333;
  text-align: center;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

#flipbook .page-wrapper {
  perspective: 2000px;
}

/* Sombras nos cantos das páginas */
#flipbook .shadow {
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.25);
}

.pdf-toolbar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: white;
  border-top: 1px solid #eee;
  position: relative;
  z-index: 10;
  flex-wrap: wrap;
}

/* Melhorar o visual dos botões */
.pdf-button {
  background: #f5f0f0;
  border: 1px solid #ddd;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  color: #333;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  font-size: 0.9rem;
}

.pdf-button:hover {
  background: #e0e0e0;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.pdf-button:active {
  transform: translateY(0);
  box-shadow: none;
}

.pdf-button i {
  margin-right: 0.5rem;
  font-size: 1.1rem;
}

/* Dicas de uso */
.zoom-tips {
  width: 100%;
  text-align: center;
  padding: 6px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 4px;
  margin-top: 6px;
  color: #666;
  font-size: 0.75rem;
  display: block;
}

#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.95);
  padding: 1.5rem;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  box-shadow: 0 8px 20px rgba(0,0,0,0.15);
  min-width: 200px;
  text-align: center;
}

#loading span {
  margin-top: 1rem;
  color: #333;
  font-weight: 500;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsividade */
@media (max-width: 768px) {
  .edicao-title {
    font-size: 1.1rem;
  }
  
  .edicao-meta {
    font-size: 0.75rem;
  }
  
  .edicao-header {
    padding: 0.15rem;
    margin-bottom: 0.25rem;
  }
  
  .pdf-container {
    margin: 0.25rem 0;
    min-height: 65vh;
  }
  
  #flipbook-container {
    height: 60vh;
  }
  
  .pdf-toolbar {
    padding: 0.25rem;
  }
  
  .pdf-button {
    flex: 0 0 auto;
    min-width: 40px;
    padding: 6px 10px;
    font-size: 0.75rem;
  }
  
  .zoom-tips {
    font-size: 0.7rem;
    padding: 4px;
    margin-top: 4px;
  }
}

/* Em dispositivos pequenos, mostrar apenas ícones e reduzir ainda mais os espaços */
@media (max-width: 480px) {
  .pdf-container {
    margin: 0;
    border-radius: 0;
  }
  
  .edicao-single {
    padding: 0.25rem;
  }
  
  .edicao-header {
    padding: 0.15rem 0;
    margin-bottom: 0.1rem;
  }
  
  #flipbook-container {
    height: 55vh;
  }
  
  .pdf-button span {
    display: none;
  }
  
  .pdf-button i {
    margin-right: 0;
  }
  
  .pdf-toolbar {
    padding: 0.2rem;
  }
  
  .pdf-button {
    padding: 5px;
    min-width: auto;
  }
}

/* Desativar a seleção de texto no flipbook */
#flipbook {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Esconder o texto no flipbook (para evitar cópia) */
#flipbook canvas::selection {
  background: transparent;
}

/* Botão de navegação personalizado */
.flipbook-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.7);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: none; /* Escondido inicialmente - será mostrado via JS */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  transition: all 0.3s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.flipbook-nav:hover {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.flipbook-nav.prev {
  left: 20px;
}

.flipbook-nav.next {
  right: 20px;
}

/* Otimizações específicas para dispositivos touch */
@media (pointer: coarse) {
  /* Aumentar áreas de toque para dispositivos móveis */
  .flipbook-nav {
    width: 48px;
    height: 48px;
    opacity: 0.7;
    transform: translateY(-50%) scale(1.1); /* Botões menores */
  }
}

/* Compensar o admin bar do WordPress e outros espaços */
body.admin-bar .container {
  margin-top: -32px !important; /* Para compensar o admin bar */
}

@media screen and (max-width: 782px) {
  body.admin-bar .container {
    margin-top: -46px !important; /* Admin bar é maior em dispositivos móveis */
  }
}

/* Reduzir espaços entre elementos no tema padrão do WordPress */
.site-header {
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

.site-content, 
.content-area, 
.site-main {
  padding-top: 0 !important;
  margin-top: 0 !important;
}

/* Garantir que o container principal ocupe todo o espaço disponível */
.container {
  width: 100%;
  max-width: 100%;
  padding: 0 !important;
  margin: 0 !important;
}

/* Suporte específico para touch em iOS */
@supports (-webkit-touch-callout: none) {
  .zoom-container {
    -webkit-transform: translate3d(0,0,0);
    transform: translate3d(0,0,0);
  }
  
  .zoom-container.dragging {
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
  }
  
  #flipbook-container, 
  .zoom-container,
  #flipbook,
  .pdf-page-canvas {
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }
}