/* ============================================================
   style.css — Flipbook PDF Application
   ============================================================ */

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #1a1a2e;
  --color-surface: #16213e;
  --color-header: #0f3460;
  --color-accent: #e94560;
  --color-accent-hover: #c73652;
  --color-text: #eaeaea;
  --color-text-muted: #a0a0b0;
  --color-border: rgba(255, 255, 255, 0.1);
  --header-height: 60px;
  --footer-height: 64px;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
}

html {
  height: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  /* Desktop: kunci viewport, tidak ada scroll */
  height: 100%;
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────── */
.header {
  height: var(--header-height);
  background: var(--color-header);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 100;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.logo-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.book-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), transform var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-icon {
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text);
  font-size: 18px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-nav {
  padding: 10px 20px;
  background: var(--color-accent);
  color: #fff;
  font-size: 14px;
  min-width: 100px;
}

.btn-nav:hover {
  background: var(--color-accent-hover);
}

.btn-nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-zoom {
  width: 34px;
  height: 34px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-text);
  font-size: 16px;
  border-radius: 6px;
  padding: 0;
}

.btn-zoom:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-fullscreen {
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text);
  font-size: 18px;
  border-radius: var(--radius);
  padding: 0;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.btn-fullscreen:hover {
  background: rgba(255, 255, 255, 0.2);
}

.btn-retry {
  padding: 12px 32px;
  background: var(--color-accent);
  color: #fff;
  font-size: 15px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: background var(--transition);
  font-weight: 600;
}

.btn-retry:hover {
  background: var(--color-accent-hover);
}

/* ── Main Viewer Area ──────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  padding: 10px 8px;
}

/* Landscape PDF: kurangi padding agar halaman lebih besar */
body.pdf-landscape .main {
  padding: 6px 4px;
}

.flipbook-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.flipbook-container {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  transform-origin: center top;
}

#flipbook {
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.6);
}

/* StPageFlip canvas pages */
#flipbook .stf__item {
  background: #fff;
}

/* ── Zoom Controls ─────────────────────────────────────────── */
.zoom-controls {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 50;
}

/* ── Footer Navigation ─────────────────────────────────────── */
.footer {
  height: var(--footer-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-shrink: 0;
  padding: 0 16px;
}

.page-info {
  font-size: 14px;
  color: var(--color-text-muted);
  min-width: 160px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── Loading Overlay ───────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 999;
  transition: opacity 0.4s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
}

.loading-percent {
  font-size: 14px;
  color: var(--color-text-muted);
}

.progress-track {
  width: 260px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--color-accent);
  border-radius: 99px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ── Error Overlay ─────────────────────────────────────────── */
.error-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 998;
}

.error-overlay.hidden {
  display: none;
}

.error-icon {
  font-size: 64px;
  line-height: 1;
}

.error-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
}

.error-desc {
  font-size: 14px;
  color: var(--color-text-muted);
  text-align: center;
  max-width: 320px;
}

/* ── Utility ───────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Fullscreen adjustments ────────────────────────────────── */
:fullscreen .header,
:fullscreen .footer {
  flex-shrink: 0;
}

:fullscreen .main {
  background: #000;
  padding: 4px;
}

:fullscreen #flipbook {
  box-shadow: none;
}

/* Landscape fullscreen: maksimalkan area viewer */
:fullscreen body.pdf-landscape .main {
  padding: 2px;
}

/* ── Mobile Scroll View ────────────────────────────────────── */
.scroll-viewer {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0 16px;
}

.scroll-page {
  width: 100%;
  height: auto;
  display: block;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}

/* ── Responsive — Mobile ───────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --header-height: 54px;
    --footer-height: 60px;
  }

  /* Mobile: body bisa scroll vertikal */
  html {
    height: auto;
    min-height: 100%;
  }

  body {
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Header sticky di atas saat scroll */
  .header {
    position: sticky;
    top: 0;
    z-index: 200;
  }

  .book-title {
    font-size: 13px;
  }

  .logo-img {
    height: 30px;
  }

  /* Main: ikut tinggi konten, tidak ada overflow hidden */
  .main {
    flex: none;
    height: auto;
    overflow: visible;
    padding: 0;
  }

  /* Wrapper: ikut tinggi scroll-viewer */
  .flipbook-wrapper {
    height: auto;
    overflow: visible;
    align-items: flex-start;
    padding: 0;
  }

  /* Sembunyikan zoom (tidak relevan di mobile scroll) */
  .zoom-controls {
    display: none;
  }

  /* Footer disembunyikan di mobile — user cukup scroll */
  .footer {
    display: none;
  }

  .btn-nav {
    min-width: 80px;
    padding: 9px 14px;
    font-size: 13px;
  }

  .page-info {
    font-size: 13px;
    min-width: 120px;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 0 12px;
  }

  .book-title {
    font-size: 12px;
  }

  .btn-nav {
    min-width: 70px;
    padding: 8px 12px;
  }

  .footer {
    gap: 8px;
    padding: 0 10px;
  }

  .page-info {
    min-width: 100px;
    font-size: 12px;
  }
}

/* ── StPageFlip Override ───────────────────────────────────── */
.stf__parent {
  display: block !important;
}
