/* PDF Viewer v4.0 - Acervo O Popular - Clean viewer + HD Zoom */

.av-viewer {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 80vh;
  background: #f5f5f5;
  border-radius: 6px;
  overflow: hidden;
}

.av-stage {
  flex: 1;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  outline: none;
  background: #e8e8e8;
  min-height: 60vh;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* Page layer */
.av-page-layer {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}

/* Page anchor - wraps side pages, sized to match current canvas, explicitly centered */
.av-page-anchor {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Side pages - positioned adjacent to anchor */
.av-side {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  cursor: pointer;
  pointer-events: all;
  z-index: 1;
}
.av-side-left {
  right: 100%;
  margin-right: 6px;
}
.av-side-right {
  left: 100%;
  margin-left: 6px;
}

.av-side-page {
  display: block;
  opacity: 0.35;
  border-radius: 2px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  transition: opacity 0.25s ease;
  max-height: 100%;
}
.av-side:hover .av-side-page {
  opacity: 0.55;
}

/* PDF page canvas */
.av-page {
  display: block;
  background: white;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05);
  border-radius: 3px;
  max-width: none;
  transform-origin: center center;
}

/* Loading */
.av-loading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  z-index: 20;
  color: #555;
  font-size: 14px;
  font-family: 'Poppins', system-ui, sans-serif;
}
.av-loading a { color: #2563eb; }

.av-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(0,0,0,0.08);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: av-spin .7s linear infinite;
}
@keyframes av-spin { to { transform: rotate(360deg); } }

.av-progress-bar {
  width: 220px; height: 4px;
  background: rgba(0,0,0,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.av-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #2563eb, #3b82f6);
  border-radius: 2px;
  transition: width .3s ease;
}

/* HD re-render indicator */
.av-hd-indicator {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(255,255,255,0.92);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 10;
  font-size: 12px;
  color: #555;
  font-family: 'Poppins', system-ui, sans-serif;
}
.av-hd-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(0,0,0,0.08);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: av-spin .6s linear infinite;
}

/* Toolbar */
.av-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  flex-wrap: wrap;
}

.av-btn {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  color: #374151;
  width: 38px; height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all .15s;
}
.av-btn:hover { background: #e5e7eb; }
.av-btn:active { background: #d1d5db; transform: scale(0.95); }
.av-btn:disabled { opacity: .3; cursor: default; }
.av-btn:disabled:hover { background: #f3f4f6; }

.av-page-info {
  color: #374151;
  font-size: 14px;
  min-width: 65px;
  text-align: center;
  font-family: 'Poppins', system-ui, sans-serif;
  font-weight: 500;
}

.av-zoom-label {
  color: #6b7280;
  font-size: 12px;
  min-width: 42px;
  text-align: center;
  font-family: 'Poppins', system-ui, sans-serif;
}

.av-sep {
  width: 1px; height: 22px;
  background: #e5e7eb;
  margin: 0 4px;
}

/* Mobile */
@media (max-width: 768px) {
  .av-viewer { min-height: 85vh; border-radius: 0; }
  .av-stage { min-height: 70vh; }
  .av-toolbar { padding: 8px 10px; gap: 5px; }
  .av-btn { width: 42px; height: 42px; }
}

@media (max-width: 600px) {
  .av-viewer { min-height: 90vh; }
  .av-stage { min-height: 75vh; }
  .av-side { display: none !important; }
  .av-page-anchor { display: none !important; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .av-viewer { min-height: 95vh; }
  .av-stage { min-height: 80vh; }
}

/* Kill old viewer remnants */
#loading, .pdf-loading-overlay, #emergency-loading-button,
.flipbook-nav, .zoom-level, .pdf-toolbar, .zoom-tips,
#flipbook { display: none !important; }
