/**
 * FlipBook Viewer Styles
 * Clean, minimal design with semi-transparent overlays.
 */

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

.flipbook-viewer {
    position: relative;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: #555;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    user-select: none;
    -webkit-user-select: none;
}

/* ── Top Bar ───────────────────────────────────────────────────── */
.flipbook-topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 10px 16px;
    background: transparent;
    color: #fff;
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

.flipbook-viewer.controls-hidden .flipbook-topbar {
    opacity: 0;
    pointer-events: none;
}

.flipbook-topbar-left {
    display: none;
    align-items: center;
    gap: 12px;
}

/* Show back + title only when NOT in iframe */
.flipbook-viewer:not(.is-iframe) .flipbook-topbar-left {
    display: flex;
}

.flipbook-viewer:not(.is-iframe) .flipbook-topbar {
    justify-content: space-between;
    background: linear-gradient(to bottom, rgba(0,0,0,0.35) 0%, transparent 100%);
}

.flipbook-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 6px;
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.flipbook-back-btn:hover {
    background: rgba(255,255,255,0.25);
}

.flipbook-back-btn svg {
    width: 16px;
    height: 16px;
}

.flipbook-title {
    font-size: 15px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.flipbook-topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── Icon Buttons ──────────────────────────────────────────────── */
.flipbook-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: rgba(0,0,0,0.3);
    border: none;
    border-radius: 6px;
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.flipbook-icon-btn:hover {
    background: rgba(0,0,0,0.5);
    color: #fff;
}

.flipbook-icon-btn svg {
    width: 18px;
    height: 18px;
}

.flipbook-icon-btn.active {
    background: rgba(255,255,255,0.35);
}

/* ── Book Container ────────────────────────────────────────────── */
.flipbook-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 80px 80px;
    overflow: hidden;
    cursor: default;
    z-index: 1;
}

.flipbook-book {
    position: relative;
    /* StPageFlip manages the dimensions */
    transform-origin: center center;
    transition: transform 0.15s ease-out;
}

/* Inline zoom state */
.flipbook-viewer.inline-zoomed .flipbook-container {
    cursor: grab;
}

.flipbook-container.is-panning {
    cursor: grabbing !important;
}

.flipbook-viewer.inline-zoomed .flipbook-book {
    transition: none; /* instant pan response */
}

/* Hide nav arrows when zoomed in */
.flipbook-viewer.inline-zoomed .flipbook-nav-prev,
.flipbook-viewer.inline-zoomed .flipbook-nav-next {
    opacity: 0 !important;
    pointer-events: none;
}

/* StPageFlip renders a canvas element — ensure it is displayed properly */
.flipbook-book canvas {
    display: block;
}

/* HTML page elements (used by loadFromHtml) */
.flipbook-page {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: #fff;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flipbook-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.flipbook-page--loading {
    background: #f5f5f3;
}

/* ── Loading Spinner ───────────────────────────────────────────── */
.flipbook-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
}

.flipbook-spinner::after {
    content: '';
    display: block;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: rgba(255,255,255,0.6);
    animation: flipbook-spin 0.8s linear infinite;
}

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

/* Full-page initial loader */
.flipbook-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #555;
    z-index: 200;
    transition: opacity 0.4s ease;
}

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

.flipbook-loading-overlay .flipbook-spinner {
    position: static;
    transform: none;
}

.flipbook-loading-text {
    margin-top: 16px;
    font-size: 14px;
    color: rgba(255,255,255,0.6);
}

/* ── Navigation Arrows ─────────────────────────────────────────── */
.flipbook-nav-prev,
.flipbook-nav-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 110;
    width: 48px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    transition: background 0.2s, opacity 0.3s, color 0.2s;
    opacity: 0;
    padding: 0;
}

.flipbook-viewer:hover .flipbook-nav-prev,
.flipbook-viewer:hover .flipbook-nav-next,
.flipbook-viewer.touch-active .flipbook-nav-prev,
.flipbook-viewer.touch-active .flipbook-nav-next {
    opacity: 1;
}

.flipbook-nav-prev:hover,
.flipbook-nav-next:hover {
    background: rgba(0,0,0,0.2);
    color: rgba(255,255,255,0.85);
}

.flipbook-nav-prev:disabled,
.flipbook-nav-next:disabled {
    opacity: 0.2 !important;
    cursor: default;
}

.flipbook-nav-prev {
    left: 16px;
}

.flipbook-nav-next {
    right: 16px;
}

.flipbook-nav-prev svg,
.flipbook-nav-next svg {
    width: 24px;
    height: 24px;
}

.flipbook-viewer.controls-hidden .flipbook-nav-prev,
.flipbook-viewer.controls-hidden .flipbook-nav-next {
    opacity: 0;
    pointer-events: none;
}

/* ── Bottom Bar ────────────────────────────────────────────────── */
.flipbook-bottombar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    background: linear-gradient(to top, rgba(0,0,0,0.45) 0%, transparent 100%);
    color: #fff;
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

.flipbook-viewer.controls-hidden .flipbook-bottombar {
    opacity: 0;
    pointer-events: none;
}

.flipbook-page-indicator {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 70px;
}

/* Page scrubber / slider */
.flipbook-scrubber {
    flex: 1;
    position: relative;
    height: 6px;
    background: rgba(255,255,255,0.25);
    border-radius: 3px;
    cursor: pointer;
}

.flipbook-scrubber-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #4a90d9;
    border-radius: 3px;
    transition: width 0.2s ease;
    pointer-events: none;
}

.flipbook-scrubber-handle {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    transition: left 0.2s ease;
    pointer-events: none;
}

.flipbook-scrubber:hover .flipbook-scrubber-handle {
    width: 18px;
    height: 18px;
}

/* ── Thumbnails Panel ──────────────────────────────────────────── */
.flipbook-thumbnails {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 150;
    background: rgba(20, 20, 20, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 12px 12px 12px;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    border-top: 1px solid rgba(255,255,255,0.1);
}

.flipbook-thumbnails.open {
    transform: translateY(0);
}

/* Handle / Tab at top of thumbnails panel */
.flipbook-thumbs-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    margin: -12px -12px 8px -12px;
    cursor: pointer;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

.flipbook-thumbs-handle::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    transition: background 0.2s;
}

.flipbook-thumbs-handle:hover::before {
    background: rgba(255,255,255,0.5);
}

.flipbook-thumbs-handle-dots {
    position: absolute;
    bottom: 2px;
    display: flex;
    gap: 6px;
    opacity: 0.4;
    transition: opacity 0.3s;
}

.flipbook-thumbnails.open .flipbook-thumbs-handle-dots {
    opacity: 0;
}

.flipbook-thumbs-handle-dots span {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: rgba(255,255,255,0.35);
}

.flipbook-thumbs-chevron {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    color: rgba(255,255,255,0.4);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s;
}

.flipbook-thumbnails.open .flipbook-thumbs-chevron {
    transform: translateY(-50%) rotate(180deg);
}

.flipbook-thumbs-handle:hover .flipbook-thumbs-chevron {
    color: rgba(255,255,255,0.6);
}

.flipbook-thumbs-chevron svg {
    width: 14px;
    height: 14px;
}

.flipbook-thumbnails-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.flipbook-thumbnails-scroll::-webkit-scrollbar {
    height: 4px;
}

.flipbook-thumbnails-scroll::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
    border-radius: 2px;
}

.flipbook-thumbnails-scroll::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

.flipbook-thumb {
    flex: 0 0 auto;
    width: 72px;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.2s;
    position: relative;
    background: rgba(255,255,255,0.05);
}

.flipbook-thumb:hover {
    border-color: rgba(255,255,255,0.4);
    transform: scale(1.05);
}

.flipbook-thumb.active {
    border-color: #fff;
}

.flipbook-thumb img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1600 / 2071;
    object-fit: cover;
    background: #2a2a2a;
}

.flipbook-thumb-number {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 2px 0;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 10px;
    text-align: center;
    font-weight: 500;
}

/* ── Zoom / Pan Overlay ────────────────────────────────────────── */
.flipbook-zoom-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.95);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    overflow: hidden;
    touch-action: none;
}

.flipbook-zoom-overlay.open {
    opacity: 1;
    visibility: visible;
}

.flipbook-zoom-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    cursor: grab;
}

.flipbook-zoom-viewport.is-dragging {
    cursor: grabbing;
}

.flipbook-zoom-viewport img {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}

.flipbook-zoom-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1010;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    font-size: 20px;
    transition: background 0.2s;
}

.flipbook-zoom-close:hover {
    background: rgba(255,255,255,0.3);
}

.flipbook-zoom-close svg {
    width: 20px;
    height: 20px;
}

.flipbook-zoom-level {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1010;
    padding: 6px 14px;
    background: rgba(0,0,0,0.65);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 20px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.3px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.flipbook-zoom-level.visible {
    opacity: 1;
}

.flipbook-zoom-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1010;
    padding: 10px 20px;
    background: rgba(0,0,0,0.6);
    border-radius: 8px;
    color: rgba(255,255,255,0.7);
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    text-align: center;
    line-height: 1.5;
}

.flipbook-zoom-hint.visible {
    opacity: 1;
}

/* ── Fullscreen adjustments ────────────────────────────────────── */
.flipbook-viewer:fullscreen,
.flipbook-viewer:-webkit-full-screen {
    background: #444;
}

.flipbook-viewer:fullscreen .flipbook-container,
.flipbook-viewer:-webkit-full-screen .flipbook-container {
    background: #444;
}

/* ── Error state ───────────────────────────────────────────────── */
.flipbook-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #555;
    z-index: 200;
    color: rgba(255,255,255,0.6);
    padding: 24px;
    text-align: center;
}

.flipbook-error-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.flipbook-error-message {
    font-size: 16px;
    margin-bottom: 8px;
    color: #444;
}

.flipbook-error-detail {
    font-size: 13px;
    color: #999;
}

/* ── Responsive ────────────────────────────────────────────────── */

/* Tablet and below */
@media (max-width: 1024px) {
    .flipbook-container {
        padding: 60px 40px;
    }

    .flipbook-title {
        max-width: 200px;
        font-size: 14px;
    }

    .flipbook-nav-prev,
    .flipbook-nav-next {
        width: 40px;
        height: 60px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .flipbook-container {
        padding: 36px 12px;
    }

    .flipbook-topbar {
        padding: 8px 10px;
    }

    .flipbook-title {
        max-width: 140px;
        font-size: 13px;
    }

    .flipbook-back-btn {
        padding: 5px 8px;
        font-size: 12px;
    }

    .flipbook-icon-btn {
        width: 32px;
        height: 32px;
    }

    .flipbook-icon-btn svg {
        width: 16px;
        height: 16px;
    }

    .flipbook-nav-prev,
    .flipbook-nav-next {
        width: 36px;
        height: 50px;
    }

    .flipbook-nav-prev svg,
    .flipbook-nav-next svg {
        width: 20px;
        height: 20px;
    }

    .flipbook-thumb {
        width: 56px;
    }

    .flipbook-bottombar {
        padding: 8px 10px;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .flipbook-title {
        display: none;
    }

    .flipbook-topbar-right {
        gap: 4px;
    }
}

/* Iframe-specific — hide the back button when embedded */
.flipbook-viewer.is-iframe .flipbook-back-btn {
    display: none;
}
