/**
 * Nützliches Flipbook – Frontend CSS
 */

.nfb-root {
  --nfb-bg: #f3f4f6;
  --nfb-accent: #C7D245;
  --nfb-radius: 8px;
  --nfb-frame-padding: 16px;
  --nfb-max-height: none;
  --nfb-zoom: 1;
  --nfb-btn-size: 40px;
  --nfb-btn-icon: 20px;
  --nfb-toolbar-gap: 6px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0 auto 1.5em;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.nfb-align-left { margin-left: 0; margin-right: auto; }
.nfb-align-center { margin-left: auto; margin-right: auto; }
.nfb-align-right { margin-left: auto; margin-right: 0; }

.nfb-book-shell {
  background: var(--nfb-bg);
  border-radius: var(--nfb-radius);
  padding: var(--nfb-frame-padding);
  position: relative;
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}

.nfb-book-stage {
  position: relative;
  width: 100%;
  min-height: 240px;
  display: block;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.nfb-book-stage.nfb-is-zoomed {
  cursor: grab;
  touch-action: none;
}

.nfb-book-stage.nfb-is-zoomed.nfb-is-panning {
  cursor: grabbing;
  user-select: none;
}

.nfb-reader-close {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 20;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  align-items: center;
  justify-content: center;
  color: #1f2937;
}

.nfb-reader-close .dashicons {
  font-family: dashicons !important;
  width: 22px !important;
  height: 22px !important;
  font-size: 22px !important;
  line-height: 1 !important;
}

.nfb-reader-close[hidden] {
  display: none !important;
}

/* Full-screen reader overlay (mobile / fullscreen fallback) */
.nfb-root.nfb-reader-open .nfb-book-shell {
  position: fixed;
  inset: 0;
  z-index: 99999;
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  box-sizing: border-box;
  overflow: hidden;
}

.nfb-root.nfb-reader-open .nfb-reader-close {
  display: inline-flex;
}

.nfb-root.nfb-reader-open .nfb-book-stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.nfb-root.nfb-reader-open .nfb-toolbar {
  flex: 0 0 auto;
  margin-top: 8px;
  padding-top: 8px;
}

.nfb-root.nfb-reader-open .nfb-toolbar-secondary {
  display: inline-flex;
}

.nfb-zoom-layer {
  position: relative;
  width: 100%;
  display: block;
}

.nfb-book {
  width: 100%;
  max-width: none !important;
  max-height: var(--nfb-max-height);
  transform-origin: 0 0;
  will-change: transform;
  display: block;
  box-sizing: border-box;
}

.nfb-book.stf__parent,
.nfb-book .stf__wrapper,
.nfb-book .stf__block {
  margin: 0 auto;
  max-width: none !important;
}

.nfb-page-canvas,
.nfb-book canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

.nfb-loading {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.85);
  color: #4b5563;
  font-size: 14px;
}

.nfb-loading.is-hidden {
  display: none;
}

.nfb-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--nfb-accent);
  border-radius: 50%;
  animation: nfb-spin 0.8s linear infinite;
}

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

.nfb-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--nfb-toolbar-gap, 6px);
  flex-wrap: wrap;
  min-width: 0;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.nfb-toolbar[hidden] {
  display: none !important;
}

.nfb-toolbar-spacer {
  flex: 1;
}

/* Scoped to flipbook UI only – must not affect admin .nfb-btn labels */
.nfb-root .nfb-btn,
.nfb-toolbar .nfb-btn,
.nfb-lightbox .nfb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--nfb-btn-size, 40px);
  height: var(--nfb-btn-size, 40px);
  border: none;
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  text-decoration: none;
  transition: background 0.15s ease, transform 0.15s ease;
  /* Rapid taps must page, not trigger the browser's double-tap zoom. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.nfb-root .nfb-btn:hover,
.nfb-toolbar .nfb-btn:hover,
.nfb-lightbox .nfb-btn:hover {
  background: var(--nfb-accent);
  color: #1f2937;
  text-decoration: none;
}

.nfb-root .nfb-btn:focus-visible,
.nfb-toolbar .nfb-btn:focus-visible,
.nfb-lightbox .nfb-btn:focus-visible {
  outline: 2px solid var(--nfb-accent);
  outline-offset: 2px;
}

.nfb-root .nfb-btn .dashicons,
.nfb-root .nfb-btn .dashicons:before,
.nfb-toolbar .nfb-btn .dashicons,
.nfb-toolbar .nfb-btn .dashicons:before,
.nfb-lightbox .nfb-btn .dashicons,
.nfb-lightbox .nfb-btn .dashicons:before {
  font-family: dashicons !important;
  width: var(--nfb-btn-icon, 20px) !important;
  height: var(--nfb-btn-icon, 20px) !important;
  font-size: var(--nfb-btn-icon, 20px) !important;
  line-height: 1 !important;
}

.nfb-page-indicator {
  flex: 0 0 auto;
  min-width: 72px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  font-variant-numeric: tabular-nums;
}

.nfb-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 4px;
}

.nfb-thumbs[hidden] {
  display: none !important;
}

.nfb-thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 72px;
  border: 2px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  padding: 0;
  background: #fff;
  cursor: pointer;
}

.nfb-thumb.is-active,
.nfb-thumb:hover {
  border-color: var(--nfb-accent);
}

.nfb-thumb canvas,
.nfb-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Cover / lightbox */
.nfb-cover-trigger {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  border-radius: var(--nfb-radius);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  text-align: left;
}

.nfb-cover-image {
  display: block;
  width: 100%;
  height: auto;
}

.nfb-cover-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 320px;
  background: #fafbe8;
  color: #374151;
  padding: 24px;
}

.nfb-cover-fallback .dashicons {
  font-family: dashicons !important;
  font-size: 48px;
  width: 48px;
  height: 48px;
  color: var(--nfb-accent);
}

.nfb-cover-play {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--nfb-accent);
  color: #1f2937;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
}

.nfb-cover-play .dashicons {
  font-family: dashicons !important;
  width: 18px !important;
  height: 18px !important;
  font-size: 18px !important;
}

.nfb-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.nfb-lightbox[hidden] {
  display: none !important;
}

.nfb-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.72);
}

.nfb-lightbox-dialog {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  max-height: 95vh;
  overflow: auto;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.nfb-lightbox-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.nfb-lightbox-close .dashicons {
  font-family: dashicons !important;
}

.nfb-root.is-fullscreen .nfb-book-shell {
  min-height: 100vh;
  border-radius: 0;
}

.nfb-root.is-fullscreen .nfb-book-stage {
  min-height: calc(100vh - 80px);
}

/* Narrow screens: compact toolbar, secondary controls only inside the reader. */
@media (max-width: 600px) {
  .nfb-root {
    --nfb-btn-size: 36px;
    --nfb-btn-icon: 18px;
    --nfb-toolbar-gap: 3px;
  }

  .nfb-book-shell {
    --nfb-frame-padding: 8px;
    padding: 8px;
  }

  .nfb-toolbar {
    margin-top: 8px;
    padding-top: 8px;
  }

  .nfb-toolbar-spacer {
    display: none;
  }

  /* Needs the same weight as the .nfb-root .nfb-btn display rule to win. */
  .nfb-root .nfb-toolbar-secondary {
    display: none;
  }

  .nfb-root.nfb-reader-open .nfb-toolbar-secondary {
    display: inline-flex;
  }

  .nfb-page-indicator {
    min-width: 40px;
    font-size: 12px;
  }

  .nfb-book-stage {
    min-height: 200px;
  }
}

/* Small phones: shrink further so a fully equipped toolbar stays on one row. */
@media (max-width: 380px) {
  .nfb-root {
    --nfb-btn-size: 32px;
    --nfb-btn-icon: 16px;
    --nfb-toolbar-gap: 2px;
  }

  .nfb-page-indicator {
    min-width: 34px;
    font-size: 11px;
  }
}

@media (max-width: 340px) {
  .nfb-root {
    --nfb-btn-size: 30px;
    --nfb-btn-icon: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nfb-spinner {
    animation: none;
  }

  .nfb-book {
    transition: none;
  }
}
