/* ── Wrapper ─────────────────────────────────────────────────────────────── */
#flipbook-wrapper {
    display: flex;
    flex-direction: column;
    height: 76vh;
    min-height: 520px;
    background: #2a2a2a;
    border-radius: 0px;
    overflow: hidden;
    position: relative;
    font-family: Arial, sans-serif;
}

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.fb-spinner-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: #2a2a2a;
    z-index: 20;
}

.fb-spinner {
    width: 38px;
    height: 38px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: fb-spin 0.75s linear infinite;
}

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

.fb-spinner-text {
    color: rgba(255,255,255,0.6);
    font-size: 13px;
}

/* ── Content layout ──────────────────────────────────────────────────────── */
#flipbook-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ── Flipbook area (main stage) ──────────────────────────────────────────── */
#flipbook-area {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    background: #2a2a2a;
}

/* ── Navigation arrows ───────────────────────────────────────────────────── */
.flip-arrow {
     position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255);
    color: #333;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 1px  3px 1px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

.flip-arrow:hover { background: rgba(255,255,255,0.28); }
.flip-arrow-prev  { left: 10px; }
.flip-arrow-next  { right: 10px; }

/* ── Zoom wrap — padding reserves arrow space; overflow enables scroll ───── */
#flipbook-zoom-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 70px;
    box-sizing: border-box;
    display: flex;
    /* flex-start (not center): centering an overflowing flex item makes its
       top/left overflow unreachable by scrolling in most browsers. Content is
       centered instead via explicit scrollTop/scrollLeft in applyZoom(). */
    align-items: flex-start;
}

#flipbook-zoom-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
#flipbook-zoom-wrap::-webkit-scrollbar-track { background: #1a1a1a; }
#flipbook-zoom-wrap::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

/* Suppress the split-second x/y scrollbar flash turn.js causes while it
   resizes page elements mid page-turn animation. */
#flipbook-zoom-wrap.fb-flipping { overflow: hidden; }

/* ── Zoom inner — always fills the padded content area; centers the book ─── */
#flipbook-zoom-inner {
    min-width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    /* width is set inline by applyZoom() in flipbook-viewer.tpl to fit zoomed content */
}

/* ── Scale wrap (receives CSS transform for zoom) ────────────────────────── */
#flipbook-scale-wrap {
    flex-shrink: 0;
}

/* Prevent turn.js page divs from squishing their canvas ─────────────────── */
#flipbook .page {
    overflow: hidden;
}

#flipbook .page canvas {
    display: block;
}

/* turn.js container */
#flipbook {
    /* width/height set by turn.js */
}

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
#flipbook-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    height: 40px;
    background: #1a1a1a;
    border-top: 1px solid #444;
}

.fb-tool-btn {
    padding: 4px 10px;
    height: 28px;
    border: 1px solid #555;
    border-radius: 3px;
    background: rgba(255,255,255,0.1);
    color: #ddd;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.fb-tool-btn:hover { background: #000033; color: #fff; border-color: #000033; }

.fb-zoom-label {
    font-size: 12px;
    color: #aaa;
    min-width: 38px;
    text-align: center;
}

.fb-page-info {
    font-size: 12px;
    color: #aaa;
    white-space: nowrap;
    padding: 0 4px;
}

.fb-sep {
    width: 1px;
    height: 18px;
    background: #555;
    margin: 0 2px;
    flex-shrink: 0;
}

.fb-sep-right { margin-left: auto; }

/* ── Thumbnail bar ───────────────────────────────────────────────────────── */
#flipbook-thumb-bar {
    flex-shrink: 0;
    height: 98px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #1e1e1e;
    border-top: 1px solid #444;
    overflow-x: auto;
    overflow-y: hidden;
    box-sizing: border-box;
}

#flipbook-thumb-bar::-webkit-scrollbar { height: 4px; }
#flipbook-thumb-bar::-webkit-scrollbar-track { background: #111; }
#flipbook-thumb-bar::-webkit-scrollbar-thumb { background: #555; border-radius: 2px; }

.fb-thumb {
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 2px;
    overflow: hidden;
    background: #333;
    transition: border-color 0.15s;
    height: 80px;
    display: flex;
    flex-direction: column;
}

.fb-thumb:hover  { border-color: #888; }
.fb-thumb.active { border-color: #fff; }

.fb-thumb canvas {
    display: block;
    width: auto;
    height: 62px;
    object-fit: contain;
}

.fb-thumb-label {
    text-align: center;
    font-size: 10px;
    color: #888;
    padding: 2px 0;
    background: #222;
    line-height: 1;
}

/* ── Fullscreen ──────────────────────────────────────────────────────────── */
#flipbook-wrapper.fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border-radius: 0;
}

body.flipbook-fullscreen-active { overflow: hidden; }

/* Thumb bar hide/show toggle */
#flipbook-wrapper.thumbs-hidden #flipbook-thumb-bar { display: none; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #flipbook-wrapper {
        height: 68vh;
        min-height: 380px;
        border-radius: 0;
    }

    .flip-arrow {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    .flip-arrow-prev { left: 2px; }
    .flip-arrow-next { right: 2px; }

    #flipbook-zoom-wrap {
        padding: 0 36px;
    }

    #flipbook-toolbar {
        height: 36px;
        padding: 0 6px;
        gap: 4px;
    }

    .fb-tool-btn {
        padding: 3px 7px;
        height: 26px;
        font-size: 12px;
    }

    .fb-page-info { font-size: 11px; }

    #flipbook-thumb-bar {
        height: 74px;
        gap: 4px;
        padding: 4px 6px;
    }

    .fb-thumb { height: 58px; }
    .fb-thumb canvas { height: 42px; }
    .fb-thumb-label { font-size: 9px; }
}

@media (max-width: 480px) {
    #flipbook-zoom-wrap {
        padding: 0 26px;
    }
    .flip-arrow {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
}
