/* ═══════════════════════════════════════════════════════════
   FLIPBOOK VIEWER - Revista Digital A Trolha
   CSS completo para o visualizador de revista digital
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── Container ─── */
.flipbook-container {
  width: 100%;
  height: 80vh;
  display: flex;
  flex-direction: column;
  background: #1a1a2e;
  border-radius: 12px;
  overflow: hidden;
  font-family: 'Inter', 'Roboto', sans-serif;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.flipbook-container:fullscreen {
  height: 100vh;
  border-radius: 0;
}

/* ─── Toolbar ─── */
.flipbook-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: linear-gradient(135deg, #16213e 0%, #0f3460 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  z-index: 10;
}

.flipbook-toolbar-left,
.flipbook-toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.flipbook-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #e0e0e0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

@media (hover: hover) {
  .flipbook-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }
}

.flipbook-btn:active:not(:disabled) {
  transform: translateY(0);
  background: rgba(255, 255, 255, 0.25);
}

.flipbook-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.flipbook-btn svg {
  width: 18px;
  height: 18px;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* Page Info */
.flipbook-page-info {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #ccc;
  font-size: 13px;
  font-weight: 500;
  margin: 0 4px;
}

.flipbook-page-input {
  width: 48px;
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  font-family: inherit;
  appearance: textfield;
  -moz-appearance: textfield;
}

.flipbook-page-input::-webkit-outer-spin-button,
.flipbook-page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.flipbook-page-input:focus {
  outline: none;
  border-color: #e94560;
  box-shadow: 0 0 0 2px rgba(233, 69, 96, 0.2);
}

/* Zoom Info */
.flipbook-zoom-info {
  color: #ccc;
  font-size: 12px;
  font-weight: 600;
  min-width: 40px;
  text-align: center;
  letter-spacing: 0.5px;
}

/* ─── Viewport ─── */
.flipbook-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: 
    radial-gradient(ellipse at center, #1a1a2e 0%, #0d0d1a 100%);
  /* Subtle pattern */
  background-image:
    radial-gradient(ellipse at center, rgba(255,255,255,0.02) 0%, transparent 70%),
    radial-gradient(ellipse at center, #1a1a2e 0%, #0d0d1a 100%);
}

/* ─── Book Wrapper ─── */
.flipbook-book-wrapper {
  transition: transform 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── Book ─── */
.flipbook-book {
  display: flex;
  gap: 0;
  align-items: flex-start;
  position: relative;
  box-shadow: 
    0 0 40px rgba(0, 0, 0, 0.5),
    0 0 100px rgba(0, 0, 0, 0.3),
    inset 0 0 3px rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  overflow: hidden;
}

/* ─── Pages ─── */
.flipbook-page {
  position: relative;
  background: transparent;
  overflow: hidden;
  box-sizing: border-box;
  flex-shrink: 0;
}

.flipbook-page-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flipbook-page-inner canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.flipbook-page-left {
  /* Spine line using inset shadow — doesn't affect layout width */
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.18), inset -8px 0 15px -8px rgba(0, 0, 0, 0.25);
}

.flipbook-page-right {
  /* Page shadow on right side - spine effect */
  box-shadow: inset 8px 0 15px -8px rgba(0, 0, 0, 0.25);
}

.flipbook-page-single {
  box-shadow: 
    inset 4px 0 10px -4px rgba(0, 0, 0, 0.15),
    inset -4px 0 10px -4px rgba(0, 0, 0, 0.15);
}

/* Page Number */
.flipbook-page-number {
  position: absolute;
  bottom: 8px;
  font-size: 11px;
  color: rgba(0, 0, 0, 0.35);
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

.flipbook-page-left .flipbook-page-number {
  left: 12px;
}

.flipbook-page-right .flipbook-page-number {
  right: 12px;
}

.flipbook-page-single .flipbook-page-number {
  left: 50%;
  transform: translateX(-50%);
}

/* ─── Nav Areas ─── */
.flipbook-nav-area {
  position: absolute;
  top: 0;
  width: 15%;
  height: 100%;
  cursor: pointer;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.flipbook-nav-left {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.08), transparent);
}

.flipbook-nav-right {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.08), transparent);
}

@media (hover: hover) {
  .flipbook-nav-area:hover {
    opacity: 1;
  }
}

/* ─── Flip Animation ─── */
.flipbook-flip-overlay {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  z-index: 20;
  pointer-events: none;
}

.flipbook-flip-next {
  right: 0;
  animation: flipNext 0.6s ease-in-out forwards;
  background: linear-gradient(to left, 
    rgba(0, 0, 0, 0.15) 0%, 
    rgba(0, 0, 0, 0.05) 30%, 
    transparent 100%
  );
  transform-origin: left center;
}

.flipbook-flip-prev {
  left: 0;
  animation: flipPrev 0.6s ease-in-out forwards;
  background: linear-gradient(to right, 
    rgba(0, 0, 0, 0.15) 0%, 
    rgba(0, 0, 0, 0.05) 30%, 
    transparent 100%
  );
  transform-origin: right center;
}

@keyframes flipNext {
  0% { 
    transform: perspective(2000px) rotateY(0deg);
    opacity: 0;
  }
  30% { 
    opacity: 1;
  }
  100% { 
    transform: perspective(2000px) rotateY(-40deg);
    opacity: 0;
  }
}

@keyframes flipPrev {
  0% { 
    transform: perspective(2000px) rotateY(0deg);
    opacity: 0;
  }
  30% { 
    opacity: 1;
  }
  100% { 
    transform: perspective(2000px) rotateY(40deg);
    opacity: 0;
  }
}

/* ─── Loading ─── */
.flipbook-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 46, 0.95);
  z-index: 50;
  gap: 16px;
}

.flipbook-loading p {
  color: #ccc;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

.flipbook-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top: 3px solid #e94560;
  border-radius: 50%;
  animation: fbSpin 0.8s linear infinite;
}

@keyframes fbSpin {
  to { transform: rotate(360deg); }
}

/* ─── Error ─── */
.flipbook-error {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 40px;
}

.flipbook-error p {
  color: #e94560;
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  background: rgba(233, 69, 96, 0.1);
  padding: 20px 30px;
  border-radius: 12px;
  border: 1px solid rgba(233, 69, 96, 0.2);
}

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */

/* Tablet */
@media (max-width: 1024px) {
  .flipbook-container {
    height: 70vh;
  }
  
  .flipbook-toolbar {
    padding: 8px 12px;
  }
  
  .flipbook-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
  }
  
  .flipbook-btn svg {
    width: 16px;
    height: 16px;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .flipbook-container {
    height: 75vh;
    border-radius: 8px;
  }
  
  .flipbook-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }
  
  .flipbook-toolbar-left,
  .flipbook-toolbar-right {
    gap: 4px;
  }
  
  .flipbook-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
  }
  
  .flipbook-btn svg {
    width: 14px;
    height: 14px;
  }
  
  .flipbook-page-info {
    font-size: 11px;
  }
  
  .flipbook-page-input {
    width: 38px;
    font-size: 11px;
    padding: 3px 4px;
  }
  
  .flipbook-zoom-info {
    font-size: 10px;
    min-width: 32px;
  }
  
  .flipbook-nav-area {
    width: 25%;
  }
}

/* Small phones */
@media (max-width: 480px) {
  .flipbook-container {
    height: 65vh;
    border-radius: 6px;
  }
  
  .flipbook-toolbar {
    padding: 6px 8px;
  }
  
  #fb-first,
  #fb-last,
  #fb-zoom-reset {
    display: none;
  }
}

/* ─── Modal Integration ─── */
.modal-overlay .flipbook-container {
  height: 78vh;
  max-height: 78vh;
}

@media (max-width: 768px) {
  .modal-overlay .flipbook-container {
    height: 70vh;
    max-height: 70vh;
  }
}

/* ─── Fullscreen overrides ─── */
.flipbook-container:-webkit-full-screen {
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
}

.flipbook-container:fullscreen {
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
}

/* ─── Print ─── */
@media print {
  .flipbook-toolbar,
  .flipbook-nav-area,
  .flipbook-loading {
    display: none !important;
  }
}

/* ─── Fake Fullscreen Fallback for iOS ─── */
.fb-fake-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  z-index: 999999 !important;
  border-radius: 0 !important;
  margin: 0 !important;
}

/* ══════════════════════════════════════════════════
   MOBILE SCROLL MODE (≤768px)
   Visualização estilo Adobe PDF — rolagem vertical
   ocupa tela cheia
   ══════════════════════════════════════════════════ */
@media (max-width: 768px) {

  .flipbook-container.fb-scroll-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    border-radius: 0 !important;
    z-index: 99999 !important;
    background: #111 !important;
    display: flex;
    flex-direction: column;
    max-height: none !important;
  }

  .flipbook-container.fb-scroll-mode .flipbook-toolbar {
    position: relative;
    z-index: 10;
    background: rgba(15, 15, 30, 0.95) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding: 8px 12px;
    flex-wrap: nowrap;
    gap: 6px;
    flex-shrink: 0;
  }

  .flipbook-container.fb-scroll-mode #fb-first,
  .flipbook-container.fb-scroll-mode #fb-last,
  .flipbook-container.fb-scroll-mode #fb-zoom-in,
  .flipbook-container.fb-scroll-mode #fb-zoom-out,
  .flipbook-container.fb-scroll-mode #fb-zoom-reset,
  .flipbook-container.fb-scroll-mode #fb-zoom-level,
  .flipbook-container.fb-scroll-mode #fb-fullscreen,
  .flipbook-container.fb-scroll-mode #fb-prev,
  .flipbook-container.fb-scroll-mode #fb-next,
  .flipbook-container.fb-scroll-mode .flipbook-nav-area {
    display: none !important;
  }

  .flipbook-container.fb-scroll-mode .flipbook-viewport {
    flex: 1;
    overflow-y: scroll !important;
    overflow-x: hidden !important;
    display: block !important;
    background: #111 !important;
    -webkit-overflow-scrolling: touch;
  }

  .flipbook-container.fb-scroll-mode .flipbook-book-wrapper {
    transform: none !important;
    width: 100% !important;
    display: block !important;
  }

  .flipbook-container.fb-scroll-mode .flipbook-book {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    width: 100% !important;
    height: auto !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    gap: 0 !important;
    background: #111 !important;
  }

  .flipbook-container.fb-scroll-mode .flipbook-page {
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 0 !important;
    box-shadow: none !important;
    background: #111 !important;
  }

  .flipbook-container.fb-scroll-mode .flipbook-page-inner {
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
  }

  .flipbook-container.fb-scroll-mode .flipbook-page-inner canvas {
    width: 100% !important;
    height: auto !important;
    max-width: 100% !important;
    display: block !important;
  }

  .fb-scroll-page-badge {
    position: fixed;
    bottom: 20px;
    right: 16px;
    background: rgba(15, 15, 30, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.15);
    z-index: 100000;
    pointer-events: none;
    font-family: 'Inter', sans-serif;
    letter-spacing: 0.3px;
  }
}
