/* ── Brochure Manager – Flipbook v2 ── */

/* ── Container ── */
.bm-flipbook-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 0;
    font-family: inherit;
}

.bm-book-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    background: var(--bm-c-secondary, #f0ebe3);
    border-radius: 8px;
    padding: 30px 20px 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
}

/* ── Book & pages ── */
.bm-book {
    position: relative;
    width: 100%;
    max-width: 1340px;
}

.bm-book-inner {
    display: flex;
    align-items: stretch; /* Both pages always fill the same height — no white strip */
    box-shadow: 0 4px 40px rgba(0,0,0,.35);
    border-radius: 2px;
}

.bm-page {
    position: relative;
    flex: 1;
    background: #fff;
    overflow: hidden;
    cursor: pointer;
    min-width: 0;   /* prevent flex overflow */
    min-height: 0;  /* allow stretch to work without fighting a min-height */
    /* Images inside set the height; the div fills the same height as its sibling */
    display: flex;
    flex-direction: column;
}

/* Blank placeholder page (cover left / last page right with odd count)
   Stays in the flex layout at the correct height — never display:none */
.bm-page-blank {
    background: #f5f3ef;
    cursor: default;
}
.bm-page-blank::after {
    /* subtle lined-paper texture to indicate "empty page" */
    content: '';
    display: block;
    position: absolute;
    inset: 0;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 27px,
        rgba(0,0,0,.04) 27px,
        rgba(0,0,0,.04) 28px
    );
    pointer-events: none;
}
.bm-page-blank .bm-page-img { display: none; }

/* Page image — width fills the page; height stays auto (natural ratio)
   flex: none prevents the image from stretching inside the flex-column page div */
.bm-page-img {
    display: block;
    width: 100%;
    height: auto;   /* preserves aspect ratio — never distort */
    max-width: 100%;
    flex: none;     /* do not stretch inside .bm-page flex column */
}

.bm-page:hover .bm-page-img {
    filter: brightness(.97);
}

/* ── Spine ── */
.bm-spine {
    width: 8px;
    flex-shrink: 0;
    align-self: stretch;    /* spine fills full page height */
    background: linear-gradient(to right, #bbb, #e8e8e8, #bbb);
    box-shadow: inset 0 0 6px rgba(0,0,0,.2);
    z-index: 2;
}

/* ── Inner shadows on page edges ── */
.bm-page-shadow-left {
    position: absolute;
    top: 0; right: 0;
    width: 40px; height: 100%;
    background: linear-gradient(to left, rgba(0,0,0,.08), transparent);
    pointer-events: none;
}
.bm-page-shadow-right {
    position: absolute;
    top: 0; left: 0;
    width: 40px; height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,.08), transparent);
    pointer-events: none;
}

/* ── Flip overlay ── */
/* Covers exactly one half of the book; repositioned by JS per direction */
.bm-flip-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%;
    display: none;        /* shown only during animation */
    perspective: 2000px;
    z-index: 20;
    pointer-events: none;
    overflow: visible;    /* card may arc slightly outside its half */
}

.bm-flip-card {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    /* transform-origin is set DYNAMICALLY by JS per direction */
}

.bm-flip-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
    background: #fff;
}

.bm-flip-back {
    transform: rotateY(180deg);
}

/* Flip face images — same proportional sizing as page images */
.bm-flip-img {
    display: block;
    width: 100%;
    height: auto;
}

/* ── Flip keyframes ──
   NEXT: right page flips LEFT  (rotates around left edge = spine)
         starts face-up (0°), ends face-down (-180°)
   PREV: left page flips RIGHT (rotates around right edge = spine)
         starts face-up (0°), ends face-down (+180°)
── */
@keyframes bmFlipNext {
    0%   { transform: perspective(2000px) rotateY(0deg);    }
    100% { transform: perspective(2000px) rotateY(-180deg); }
}

@keyframes bmFlipPrev {
    0%   { transform: perspective(2000px) rotateY(0deg);    }
    100% { transform: perspective(2000px) rotateY(180deg);  }
}

.bm-flip-animate-next { animation: bmFlipNext .55s ease-in-out forwards; }
.bm-flip-animate-prev { animation: bmFlipPrev .55s ease-in-out forwards; }

/* ── Controls ── */
.bm-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: rgba(255,255,255,.7);
    border-radius: 30px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10;
}

.bm-btn {
    background: var(--bm-c-primary, #2c3e50);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background .2s, transform .1s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bm-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--bm-c-primary, #2c3e50) 65%, #000 35%); transform: scale(1.08); }
.bm-btn:disabled { opacity: .35; cursor: default; }

.bm-fullscreen { font-size: 16px; background: var(--bm-c-primary, #7f8c8d); opacity: .8; }

.bm-page-info {
    font-size: 13px;
    color: #555;
    min-width: 130px;
    text-align: center;
}

/* ── Loading overlay ── */
.bm-loading {
    position: absolute;
    inset: 0;
    background: rgba(240,235,227,.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 14px;
    color: #666;
    border-radius: 8px;
    z-index: 30;
}

.bm-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #ddd;
    border-top-color: var(--bm-c-primary, #2c3e50);
    border-radius: 50%;
    animation: bmSpin .8s linear infinite;
}

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

/* ── Inactive message ── */
.bm-inactive {
    text-align: center;
    padding: 40px 20px;
    color: #888;
    font-style: italic;
}

/* ── Close button (fullscreen only) ── */
.bm-btn-close {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 100;
    background: rgba(255,255,255,.15);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background .2s;
}
.bm-btn-close:hover { background: rgba(255,255,255,.35); }

/* ── Custom fullscreen overlay ── */
body.bm-body-noscroll { overflow: hidden !important; }

.bm-fullscreen-active {
    position: fixed !important;
    inset: 0 !important;
    z-index: 99999 !important;
    width: 100vw !important;
    height: 100vh !important;
    border-radius: 0 !important;
    overflow-y: auto !important;
    /* Extra bottom padding keeps the book clear of the fixed controls bar */
    padding: 60px 20px 90px !important;
    background: var(--bm-c-primary, #1a1a2e) !important;
    box-shadow: none !important;
    justify-content: flex-start;
    align-items: center;
}

.bm-fullscreen-active .bm-btn-close {
    display: flex;
}

.bm-fullscreen-active .bm-book {
    max-width: 100%;
    /* margin: auto in a flex column absorbs available space equally above and
       below → centers when content fits; collapses to 0 when taller than viewport
       (scroll kicks in). Do NOT make .bm-book a flex container itself —
       .bm-flip-overlay (position:absolute; top:0; bottom:0) must resolve its
       height against .bm-book-inner, not a stretched flex child. */
    margin-top: auto;
    margin-bottom: auto;
}

/* Controls pinned to the bottom of the viewport, never scrolled away */
.bm-fullscreen-active .bm-controls {
    position: fixed !important;
    bottom: 20px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    background: rgba(255,255,255,.15) !important;
    z-index: 100000 !important;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.bm-fullscreen-active .bm-page-info { color: #e0e0e0; }

.bm-fullscreen-active .bm-btn {
    background: rgba(255,255,255,.25);
    color: #fff;
}
.bm-fullscreen-active .bm-btn:hover:not(:disabled) {
    background: rgba(255,255,255,.45);
    transform: scale(1.08);
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .bm-book-wrapper { padding: 20px 10px 16px; }
}

/* ── Loupe button & zoom picker ─────────────────────────────────────────── */

.bm-loupe-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Active state: button uses brand primary color to signal loupe is ON */
.bm-loupe-btn--active {
    background: var(--bm-c-primary, #2c3e50) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--bm-c-primary, #2c3e50) 40%, transparent 60%);
}

.bm-zoom-picker {
    display: none;           /* hidden until loupe is active */
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,.85);
    border-radius: 20px;
    padding: 4px 10px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.bm-zoom-picker--visible {
    display: flex;
    animation: bmFadeIn .15s ease;
}

@keyframes bmFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.bm-zoom-label {
    font-size: 11px;
    color: #666;
    margin-right: 2px;
    white-space: nowrap;
}

.bm-zoom-opt {
    background: transparent;
    border: 1px solid rgba(0,0,0,.18);
    border-radius: 12px;
    padding: 2px 9px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: #444;
    transition: background .15s, color .15s, border-color .15s;
    line-height: 1.6;
}

.bm-zoom-opt:hover {
    background: var(--bm-c-primary, #2c3e50);
    color: var(--bm-c-primary-text, #fff);
    border-color: var(--bm-c-primary, #2c3e50);
}

.bm-zoom-opt--active {
    background: var(--bm-c-primary, #2c3e50);
    color: var(--bm-c-primary-text, #fff);
    border-color: var(--bm-c-primary, #2c3e50);
}

/* ── Magnifier lens ─────────────────────────────────────────────────────── */

.bm-loupe-lens {
    position: absolute;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid rgba(255,255,255,.9);
    box-shadow:
        0 0 0 1px rgba(0,0,0,.25),
        0 6px 28px rgba(0,0,0,.45),
        inset 0 0 8px rgba(0,0,0,.12);
    pointer-events: none;   /* never blocks mouse events on the page */
    display: none;
    z-index: 50;
    background: #fff;
    /* crosshair reticle in the center */
    background-image:
        linear-gradient(rgba(0,0,0,.25) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,.25) 1px, transparent 1px);
    background-position: center center;
    background-size: 100% 50%, 50% 100%;
}

.bm-loupe-img {
    position: absolute;
    max-width: none !important;  /* must NOT be constrained */
    width: auto;
    height: auto;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

/* Cursor hint: when loupe is active on a page show a + magnifier shape */
.bm-page-left[style*="zoom-in"],
.bm-page-right[style*="zoom-in"] {
    cursor: zoom-in !important;
}
