/* ========= PDF VIEWER STYLES ========= */

.pdf-preview-section {
  padding: 5rem 0;
  background: var(--bg);
}

.pdf-preview-header {
  text-align: center;
  margin-bottom: 2rem;
}

.pdf-preview-header h2 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.pdf-preview-header p {
  color: var(--muted);
  font-size: 1rem;
}

.pdf-viewer-container {
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid rgba(27, 58, 87, 0.15);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 800px;
}

.pdf-toolbar,
.pdf-modal-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, rgba(27, 58, 87, 0.03), rgba(27, 58, 87, 0.03));
  border-bottom: 1px solid rgba(27, 58, 87, 0.1);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pdf-control-btn {
  background: transparent;
  border: 1px solid rgba(27, 58, 87, 0.2);
  border-radius: 8px;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--primary);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.pdf-control-btn:hover {
  background: rgba(27, 58, 87, 0.1);
  border-color: var(--primary-soft);
  color: var(--primary-soft);
}

.pdf-control-btn:hover::after {
  content: attr(title);
  position: absolute;
  bottom: -30px;
  background: var(--text);
  color: #ffffff;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
}

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

.page-counter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
}

.page-input {
  width: 50px;
  padding: 0.5rem;
  border: 1px solid rgba(27, 58, 87, 0.2);
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
  color: var(--text);
  font-weight: 600;
}

.page-input:focus {
  outline: none;
  border-color: var(--primary-soft);
  background: rgba(27, 58, 87, 0.05);
}

.zoom-level {
  min-width: 50px;
  text-align: center;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
}

.pdf-canvas-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f9fafb;
  position: relative;
}

#pdf-canvas {
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
  max-width: 100%;
  height: auto;
}

.pdf-loading {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(27, 58, 87, 0.1);
  border-top-color: var(--primary-soft);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Desabilitar seleção de texto no canvas */
#pdf-canvas {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
}

/* Esconder menu de contexto */
.pdf-canvas-wrapper {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

/* ========= PDF MODAL ========= */
.pdf-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 40, 61, 0.96);
  backdrop-filter: blur(8px);
  z-index: 9999;
  animation: fadeIn 0.2s ease;
}

.pdf-modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.pdf-modal-content {
  background: linear-gradient(180deg, #16314a 0%, #10283d 100%);
  border-radius: 16px;
  width: 100%;
  max-width: 90vw;
  height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.pdf-modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, #d0bb6c 50%, transparent);
  z-index: 2;
  pointer-events: none;
}

.pdf-modal-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 0.6rem;
  cursor: pointer;
  color: #ffffff;
  z-index: 100;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}

.pdf-modal-close:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.pdf-modal-close:active {
  transform: scale(0.95);
}

.pdf-modal-toolbar {
  position: relative;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem 1.5rem;
  gap: 3rem;
}

.pdf-modal-toolbar .toolbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pdf-modal-toolbar .toolbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pdf-modal-toolbar .pdf-control-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.85);
}

.pdf-modal-toolbar .pdf-control-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

.pdf-modal-toolbar .pdf-control-btn:hover::after {
  content: attr(title);
  position: absolute;
  bottom: -32px;
  background: #10283d;
  color: #ffffff;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 10;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.pdf-modal-toolbar .page-counter,
.pdf-modal-toolbar .page-info-group,
.pdf-modal-toolbar .current-page,
.pdf-modal-toolbar .total-pages,
.pdf-modal-toolbar .page-separator,
.pdf-modal-toolbar .zoom-level {
  color: rgba(255, 255, 255, 0.92);
  font-weight: 700;
}

.pdf-modal-toolbar .page-input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.pdf-modal-toolbar .page-input:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.pdf-modal-toolbar .pages-badge,
.pdf-modal-toolbar .pages-badge span {
  color: #ffffff;
  font-weight: 700;
}

.pdf-modal-toolbar .pages-badge {
  background: linear-gradient(135deg, rgba(208, 187, 108, 0.22), rgba(230, 214, 168, 0.22));
  border: 1px solid rgba(208, 187, 108, 0.4);
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
}

.pdf-modal-canvas-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 2rem;
  padding-bottom: 2rem;
  background: linear-gradient(135deg, #0a0f1f 0%, #0f1425 100%);
  position: relative;
}

#modal-pdf-canvas {
  box-shadow: 0 8px 32px rgba(27, 58, 87, 0.3);
  max-width: 100%;
  height: auto;
  filter: brightness(0.95);
}

#modal-pdf-loading {
  color: rgba(255, 255, 255, 0.7);
}

#modal-pdf-loading .spinner {
  border-color: rgba(255, 255, 255, 0.1);
  border-top-color: rgba(27, 58, 87, 0.6);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Impressão desabilitada */
@media print {
  .pdf-preview-section,
  .pdf-modal {
    display: none;
  }
}

/* Responsivo */
@media (max-width: 768px) {
  .pdf-viewer-container {
    max-height: 500px;
  }

  .pdf-toolbar {
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
  }

  .toolbar-left,
  .toolbar-right {
    flex: 1;
    justify-content: center;
  }

  .pdf-preview-header h2 {
    font-size: 1.5rem;
  }
  
  .pdf-modal {
    padding: 0;
    background: #10283d;
  }
  
  .pdf-modal-content {
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    width: 100vw;
    position: fixed;
    top: 0;
    left: 0;
    background: #0a0f1f;
    display: flex;
    flex-direction: column;
  }
  
  .pdf-modal-toolbar {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    padding: 0.75rem 1rem;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 50;
    background: linear-gradient(180deg, rgba(27, 58, 87, 0.9), rgba(27, 58, 87, 0.4));
    flex-shrink: 0;
    min-height: 56px;
    border-bottom: 1px solid rgba(27, 58, 87, 0.3);
  }
  
  .pdf-modal-toolbar .toolbar-left,
  .pdf-modal-toolbar .toolbar-center,
  .pdf-modal-toolbar .toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }
  
  .pdf-modal-toolbar .toolbar-left {
    flex: 0 0 auto;
  }
  
  .pdf-modal-toolbar .toolbar-center {
    flex: 1;
    justify-content: center;
  }
  
  .pdf-modal-toolbar .toolbar-right {
    flex: 0 0 auto;
  }
  
  .page-info-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.15rem;
    color: rgba(255, 255, 255, 0.92);
    font-weight: 700;
    background: rgba(255, 255, 255, 0.06);
    padding: 0.7rem 1.4rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    min-width: fit-content;
    letter-spacing: 0.5px;
  }

  .page-info-group .current-page,
  .page-info-group .page-separator,
  .page-info-group .total-pages {
    color: rgba(255, 255, 255, 0.92);
    font-weight: 700;
    font-size: 1.15rem;
  }

  .page-separator {
    color: rgba(255, 255, 255, 0.5);
    font-weight: 700;
  }

  .current-page,
  .total-pages {
    min-width: 28px;
    text-align: center;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.92);
  }

  .pages-badge {
    background: linear-gradient(135deg, rgba(208, 187, 108, 0.22), rgba(230, 214, 168, 0.22));
    border: 1px solid rgba(208, 187, 108, 0.4);
    padding: 0.7rem 1.5rem;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 700;
    white-space: nowrap;
    color: #ffffff;
    letter-spacing: 0.3px;
  }

  .pages-badge span {
    color: #ffffff;
    font-weight: 700;
  }

  #modal-pdf-zoom-in-btn,
  #modal-pdf-zoom-out-btn,
  #modal-pdf-fullscreen-exit-btn {
    display: none !important;
  }

  .pdf-modal-toolbar .pdf-control-btn {
    padding: 0.5rem;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .pdf-modal-toolbar .pdf-control-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.28);
  }

  .pdf-modal-toolbar .pdf-control-btn:active {
    transform: scale(0.95);
  }

  .pdf-modal-toolbar .pdf-control-btn svg {
    width: 18px;
    height: 18px;
    color: rgba(255, 255, 255, 0.9);
  }

  .zoom-level {
    min-width: 50px;
    text-align: center;
    color: rgba(255, 255, 255, 0.92);
    font-weight: 700;
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.06);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.14);
  }
  
  .pdf-modal-toolbar .page-counter {
    font-size: 0.85rem;
    gap: 0.4rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
  }
  
  .pdf-modal-toolbar .page-input {
    width: 40px;
    font-size: 0.75rem;
    padding: 0.35rem;
    background: rgba(27, 58, 87, 0.15);
    border: 1px solid rgba(27, 58, 87, 0.35);
    color: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    text-align: center;
  }
  
  #modal-pdf-prev-btn,
  #modal-pdf-next-btn,
  .page-counter {
    display: none;
  }
  
  .pdf-modal-canvas-wrapper {
    padding: 0;
    margin: 0;
    height: calc(100% - 56px);
    overflow-y: scroll;
    overflow-x: hidden;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex: 1;
    background: #0a0f1f;
    scroll-behavior: smooth;
    scroll-snap-type: y mandatory;
  }
  
  .pdf-pages-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: center;
    width: 100%;
    max-width: 100%;
    scroll-snap-type: y mandatory;
  }
  
  .pdf-page {
    display: block;
    width: 100%;
    height: auto;
    margin: 0;
    padding: 0;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }
  
  #modal-pdf-loading {
    background: transparent;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
  }
  
  @supports (height: 100dvh) {
    .pdf-modal-content {
      height: 100dvh;
    }
  }
}

/* Landscape mobile */
@media (max-width: 1024px) and (orientation: landscape) {
  .pdf-modal-content {
    height: 100vh;
  }
  
  .pdf-modal-close {
    top: 0.5rem;
    right: 0.5rem;
    transform: none;
    width: 32px;
    height: 32px;
    padding: 0.5rem;
  }
  
  .pdf-modal-canvas-wrapper {
    height: calc(100vh - 48px);
  }
  
  .pdf-modal-toolbar {
    padding: 0.5rem;
    gap: 0.5rem;
  }
  
  .pdf-modal-toolbar .toolbar-left {
    gap: 0.4rem;
  }
  
  .pdf-modal-toolbar .pdf-control-btn {
    padding: 0.35rem;
    width: 28px;
    height: 28px;
  }
  
  .pdf-modal-toolbar .pdf-control-btn svg {
    width: 16px;
    height: 16px;
  }
  
  .pdf-modal-toolbar .page-counter {
    font-size: 0.75rem;
  }
  
  .pdf-modal-toolbar .page-input {
    width: 35px;
    font-size: 0.7rem;
    padding: 0.3rem;
  }
  
  /* Remover botões de zoom no mobile */
  #modal-pdf-zoom-in-btn,
  #modal-pdf-zoom-out-btn {
    display: none !important;
  }
  
  .pdf-modal-toolbar .zoom-level,
  .zoom-level,
  #modal-pdf-zoom-level {
    display: none !important;
  }
  
  /* Remover badge de páginas no mobile */
  .pdf-modal-toolbar .pages-badge,
  .toolbar-center .pages-badge,
  .pages-badge {
    display: none !important;
  }
  
  /* Mostrar botão de fechar no mobile */
  .pdf-modal-toolbar #modal-pdf-fullscreen-exit-btn,
  #modal-pdf-fullscreen-exit-btn {
    display: flex !important;
  }
  
  /* Botões de navegação lateral no mobile */
  
}

/* Media query mobile - remover 100% */
@media (max-width: 768px) {
  .pdf-modal-toolbar .zoom-level,
  #modal-pdf-zoom-level {
    display: none !important;
  }
  
  /* Garantir que 15 páginas seja removido */
  .pdf-modal-toolbar .toolbar-center,
  .toolbar-center {
    display: none !important;
  }
  
  /* Garantir que o botão de fechar fique visível */
  .pdf-modal-toolbar #modal-pdf-fullscreen-exit-btn,
  #modal-pdf-fullscreen-exit-btn {
    display: flex !important;
  }
}

/* ========= PROTEÇÕES CONTRA DOWNLOAD E CÓPIA ========= */

/* Desabilitar seleção de texto no PDF */
.pdf-modal,
.pdf-modal-canvas-wrapper,
.pdf-pages-container,
.pdf-page {
  user-select: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  -webkit-touch-callout: none !important;
}

/* Desabilitar drag and drop */
.pdf-modal,
.pdf-modal-canvas-wrapper,
.pdf-pages-container,
.pdf-page {
  -webkit-user-drag: none !important;
  pointer-events: auto !important;
}

/* Canvas do PDF com proteção extra */
.pdf-page {
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  pointer-events: auto !important;
  /* Sem image-rendering: pixelated — ele desliga a suavização e deixava o
     texto da prévia serrilhado/borrado ao ser redimensionado na tela. */
  image-rendering: auto;
}