/* =====================================================
   Pagemix Flipbook — Frontend Styles
   ===================================================== */

:root {
    --rmpfb-theme:   #1a1a2e;
    --rmpfb-accent:  #e94560;
    --rmpfb-panel:   #16213e;
    --rmpfb-toolbar: rgba(10,10,26,0.95);
    --rmpfb-text:    #f0f0f0;
    --rmpfb-muted:   #888;
    --rmpfb-radius:  12px;
    --rmpfb-shadow:  0 24px 80px rgba(0,0,0,0.6);
}

/* ── Card ─────────────────────────────────────────── */
.rmpfb-card {
    display: inline-flex;
    flex-direction: column;
    background: #fff;
    border-radius: var(--rmpfb-radius);
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
    max-width: 280px;
    width: 100%;
    user-select: none;
    vertical-align: top;
}
.rmpfb-card:hover { transform: translateY(-4px); box-shadow: 0 12px 40px rgba(0,0,0,0.18); }

.rmpfb-card__cover {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    background: var(--rmpfb-theme);
    overflow: hidden;
}
.rmpfb-card__cover-img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .3s ease;
}
.rmpfb-card:hover .rmpfb-card__cover-img { transform: scale(1.04); }

.rmpfb-card__overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0);
    transition: background .2s;
}
.rmpfb-card:hover .rmpfb-card__overlay { background: rgba(0,0,0,0.35); }
.rmpfb-card__play-icon {
    width: 52px; height: 52px;
    color: #fff;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity .2s, transform .2s;
}
.rmpfb-card:hover .rmpfb-card__play-icon { opacity: 1; transform: scale(1); }

.rmpfb-card__lock {
    position: absolute; top: 10px; right: 10px;
    background: var(--rmpfb-accent);
    color: #fff;
    border-radius: 50%;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
}

.rmpfb-card__info { padding: 16px; }
.rmpfb-card__title { margin: 0 0 6px; font-size: 15px; font-weight: 700; color: #1a1a2e; line-height: 1.3; }
.rmpfb-card__desc  { margin: 0 0 12px; font-size: 13px; color: #666; line-height: 1.5; }
.rmpfb-card__btn {
    display: inline-flex; align-items: center;
    background: var(--rmpfb-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s;
    text-decoration: none;
}
.rmpfb-card__btn:hover { background: #c73650; transform: scale(1.02); }

/* ── Password Modal ───────────────────────────────── */
.rmpfb-pw-modal {
    position: fixed; inset: 0; z-index: 999990;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10,10,26,0.8);
    backdrop-filter: blur(8px);
    opacity: 0; pointer-events: none;
    transition: opacity .25s;
}
.rmpfb-pw-modal.active { opacity: 1; pointer-events: all; }

.rmpfb-pw-modal__box {
    background: var(--rmpfb-panel);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 16px;
    padding: 36px 40px;
    max-width: 380px; width: 90%;
    box-shadow: var(--rmpfb-shadow);
    color: var(--rmpfb-text);
    transform: scale(0.92) translateY(20px);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1);
    text-align: center;
}
.rmpfb-pw-modal.active .rmpfb-pw-modal__box { transform: scale(1) translateY(0); }

.rmpfb-pw-modal__icon {
    width: 56px; height: 56px;
    background: var(--rmpfb-accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 18px;
}
.rmpfb-pw-modal__title { font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.rmpfb-pw-modal__subtitle { font-size: 13px; color: var(--rmpfb-muted); margin: 0 0 24px; }
.rmpfb-pw-modal__input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255,255,255,0.07);
    border: 1.5px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: #fff;
    font-size: 16px;
    letter-spacing: .1em;
    outline: none;
    box-sizing: border-box;
    transition: border-color .2s;
    text-align: center;
}
.rmpfb-pw-modal__input:focus { border-color: var(--rmpfb-accent); }
.rmpfb-pw-modal__error {
    font-size: 12px;
    color: #ff6b6b;
    min-height: 18px;
    margin: 8px 0 0;
}
.rmpfb-pw-modal__btn {
    width: 100%;
    margin-top: 16px;
    padding: 13px;
    background: var(--rmpfb-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s;
}
.rmpfb-pw-modal__btn:hover { background: #c73650; }
.rmpfb-pw-modal__btn:disabled { opacity: .6; cursor: default; }
.rmpfb-pw-modal__cancel {
    display: block; margin-top: 12px;
    font-size: 12px; color: var(--rmpfb-muted);
    cursor: pointer; text-decoration: underline; background: none; border: none;
}
.rmpfb-pw-modal__cancel:hover { color: #fff; }

/* ── Fullscreen Viewer ────────────────────────────── */
.rmpfb-viewer {
    position: fixed; inset: 0; z-index: 999999;
    background: var(--rmpfb-theme);
    display: flex; flex-direction: column;
    opacity: 0; pointer-events: none;
    transition: opacity .35s;
}
.rmpfb-viewer.active { opacity: 1; pointer-events: all; }

/* Sidebar */
.rmpfb-sidebar {
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 300px;
    background: var(--rmpfb-panel);
    border-right: 1px solid rgba(255,255,255,0.06);
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    z-index: 10;
    display: flex; flex-direction: column;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
}
.rmpfb-sidebar.open { transform: translateX(0); }
.rmpfb-sidebar__header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center; gap: 10px;
}
.rmpfb-sidebar__title { font-size: 14px; font-weight: 700; color: var(--rmpfb-text); flex: 1; }
.rmpfb-sidebar__close {
    background: none; border: none; cursor: pointer;
    color: var(--rmpfb-muted); padding: 4px;
    border-radius: 4px; transition: color .15s;
}
.rmpfb-sidebar__close:hover { color: #fff; }
.rmpfb-sidebar__tabs {
    display: flex;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.rmpfb-sidebar__tab {
    flex: 1; padding: 10px;
    background: none; border: none; cursor: pointer;
    font-size: 12px; color: var(--rmpfb-muted);
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s;
}
.rmpfb-sidebar__tab.active { color: var(--rmpfb-accent); border-bottom-color: var(--rmpfb-accent); }
.rmpfb-sidebar__content { flex: 1; overflow-y: auto; padding: 12px; }
.rmpfb-sidebar__content::-webkit-scrollbar { width: 4px; }
.rmpfb-sidebar__content::-webkit-scrollbar-track { background: transparent; }
.rmpfb-sidebar__content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* TOC items */
.rmpfb-toc__panel { display: none; }
.rmpfb-toc__panel.active { display: block; }
.rmpfb-toc-item {
    display: block; width: 100%;
    background: none; border: none; cursor: pointer;
    text-align: left; padding: 8px 10px;
    border-radius: 6px;
    color: var(--rmpfb-text); font-size: 13px;
    transition: background .15s;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rmpfb-toc-item:hover { background: rgba(255,255,255,0.07); }
.rmpfb-toc-item.active { background: rgba(233,69,96,0.18); color: var(--rmpfb-accent); }
.rmpfb-toc-item--level-1 { padding-left: 10px; }
.rmpfb-toc-item--level-2 { padding-left: 22px; font-size: 12px; }
.rmpfb-toc-item--level-3 { padding-left: 34px; font-size: 11px; color: var(--rmpfb-muted); }
.rmpfb-toc-item--page {
    display: flex; align-items: center; gap: 8px;
    color: var(--rmpfb-muted); font-size: 12px;
}
.rmpfb-toc-item--page span { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.rmpfb-toc-item--page .rmpfb-toc-thumb {
    width: 36px; height: 48px;
    background: rgba(255,255,255,0.05);
    border-radius: 2px;
    flex-shrink: 0;
    overflow: hidden;
}
.rmpfb-toc-item--page .rmpfb-toc-thumb canvas { width:100%; height:100%; }
.rmpfb-toc-empty { color: var(--rmpfb-muted); font-size: 12px; text-align: center; padding: 20px; }

/* Canvas scroll area */
.rmpfb-canvas-area {
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    box-sizing: border-box;
    scroll-behavior: smooth;
}
.rmpfb-canvas-area::-webkit-scrollbar { width: 6px; height: 6px; }
.rmpfb-canvas-area::-webkit-scrollbar-track { background: rgba(255,255,255,0.03); }
.rmpfb-canvas-area::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

.rmpfb-pages-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    min-width: 100%;
    padding-bottom: 40px;
}

.rmpfb-page-container {
    position: relative;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    background: #fff;
    cursor: grab;
    transition: transform .18s ease;
    /* Prevent background flash during canvas swap */
    contain: layout style;
}
/* Keep the existing canvas visible and in-place while re-rendering */
.rmpfb-page-container canvas {
    display: block;
    /* GPU-composited layer — swap happens in a single paint */
    will-change: contents;
}
.rmpfb-page-container:active { cursor: grabbing; }
.rmpfb-page-container.rmpfb-anim-flip  { animation: rmpfbFlip  .4s cubic-bezier(.4,0,.2,1); }
.rmpfb-page-container.rmpfb-anim-slide { animation: rmpfbSlide .35s ease; }
.rmpfb-page-container.rmpfb-anim-fade  { animation: rmpfbFade  .3s ease; }

@keyframes rmpfbFlip  { from { transform: perspective(1200px) rotateY(-18deg) scale(0.97); opacity:.8; } to { transform: none; opacity:1; } }
@keyframes rmpfbSlide { from { transform: translateX(-40px); opacity:0; } to { transform: none; opacity:1; } }
@keyframes rmpfbFade  { from { opacity:0; } to { opacity:1; } }

.rmpfb-page-container canvas  { display: block; }
.rmpfb-page-container .rmpfb-watermark-overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
.rmpfb-page-container .rmpfb-watermark-overlay span {
    font-size: clamp(24px, 6vw, 64px);
    font-weight: 900;
    letter-spacing: .2em;
    color: #000;
    transform: rotate(-35deg);
    white-space: nowrap;
    user-select: none;
}

/* Toolbar */
.rmpfb-toolbar {
    background: var(--rmpfb-toolbar);
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex; align-items: center;
    padding: 0 16px;
    height: 56px;
    gap: 4px;
    flex-shrink: 0;
    backdrop-filter: blur(12px);
    position: relative;
    z-index: 5;
}
.rmpfb-toolbar--top { border-top: none; border-bottom: 1px solid rgba(255,255,255,0.06); order: -1; }

.rmpfb-toolbar__btn {
    background: none; border: none; cursor: pointer;
    color: rgba(255,255,255,0.7);
    width: 40px; height: 40px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.rmpfb-toolbar__btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.rmpfb-toolbar__btn.active { color: var(--rmpfb-accent); background: rgba(233,69,96,0.12); }
.rmpfb-toolbar__btn:disabled { opacity: .35; cursor: default; }

.rmpfb-toolbar__sep { width: 1px; height: 24px; background: rgba(255,255,255,0.1); margin: 0 6px; flex-shrink:0; }
.rmpfb-toolbar__spacer { flex: 1; }

.rmpfb-toolbar__title {
    font-size: 13px; font-weight: 600;
    color: rgba(255,255,255,0.8);
    max-width: 240px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex-shrink: 1;
    margin-right: 2px;
}

.rmpfb-toolbar__page {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--rmpfb-muted);
    flex-shrink: 0;
}
.rmpfb-toolbar__page-input {
    width: 44px; text-align: center;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 5px; color: #fff;
    font-size: 13px; padding: 4px;
    outline: none;
}
.rmpfb-toolbar__page-input:focus { border-color: var(--rmpfb-accent); }
.rmpfb-toolbar__page-total { font-size:13px; color:var(--rmpfb-muted); white-space:nowrap; }

.rmpfb-toolbar__zoom {
    display: flex; align-items: center; gap: 2px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    padding: 2px;
}
.rmpfb-toolbar__zoom-label {
    font-size: 12px; color: var(--rmpfb-muted);
    min-width: 44px; text-align: center;
}

/* Bookmark pulse */
.rmpfb-bookmark-pulse {
    position: absolute; bottom: 70px; right: 20px;
    background: var(--rmpfb-accent); color: #fff;
    padding: 8px 14px; border-radius: 20px;
    font-size: 12px; font-weight: 600;
    box-shadow: 0 4px 20px rgba(233,69,96,0.5);
    opacity: 0; transform: translateY(8px);
    transition: opacity .3s, transform .3s;
    pointer-events: none;
    z-index: 20;
}
.rmpfb-bookmark-pulse.show { opacity: 1; transform: translateY(0); }

/* Loading overlay */
.rmpfb-loading {
    position: absolute; inset: 0;
    background: var(--rmpfb-theme);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    z-index: 30; gap: 16px;
}
.rmpfb-loading__spinner {
    width: 48px; height: 48px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--rmpfb-accent);
    border-radius: 50%;
    animation: rmpfbSpin .8s linear infinite;
}
@keyframes rmpfbSpin { to { transform: rotate(360deg); } }
.rmpfb-loading__text { font-size: 13px; color: var(--rmpfb-muted); }

/* Sidebar overlay backdrop */
.rmpfb-sidebar-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9;
    opacity: 0; pointer-events: none;
    transition: opacity .3s;
}
.rmpfb-sidebar-backdrop.visible { opacity: 1; pointer-events: all; }

/* Zoom center focus ring */
.rmpfb-zoom-focus {
    position: absolute;
    width: 60px; height: 60px;
    border-radius: 50%;
    border: 2px solid var(--rmpfb-accent);
    pointer-events: none;
    opacity: 0;
    transform: scale(1.4);
    transition: opacity .3s, transform .3s;
    z-index: 15;
}
.rmpfb-zoom-focus.ping { opacity: 1; transform: scale(1); }

/* Auto-logout warning */
.rmpfb-logout-warn {
    position: absolute; top: 70px; left: 50%;
    transform: translateX(-50%);
    background: rgba(233,69,96,0.95);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    z-index: 25;
    display: none;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

/* Print protection */
@media print {
    .rmpfb-viewer, .rmpfb-pw-modal, .rmpfb-card { display: none !important; }
    body::before {
        content: "Printing is disabled for this document.";
        font-size: 24px;
        display: block;
        text-align: center;
        padding: 100px;
    }
}

/* ── Password show/hide toggle ────────────────────────────────────────────── */
.rmpfb-pw-modal__input-row {
    position: relative;
    width: 100%;
}
.rmpfb-pw-modal__input-row .rmpfb-pw-modal__input {
    padding-right: 44px; /* make room for eye button */
}
.rmpfb-pw-modal__eye {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--rmpfb-muted);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color .15s;
    line-height: 0;
}
.rmpfb-pw-modal__eye:hover { color: #fff; }


/* ─── Modal size variants ──────────────────────────────────────────────────── */

/* Full-screen dim backdrop — sits behind the windowed viewer */
.rmpfb-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999998;           /* one below the viewer */
    background: rgba(0,0,0,0.72);
    pointer-events: all;
    cursor: pointer;
}

/* Windowed variants: shrink the viewer via inset, add rounding + shadow */
.rmpfb-viewer--large {
    inset: 5% !important;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

.rmpfb-viewer--medium {
    inset: 7.5% 12.5% !important;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

.rmpfb-viewer--small {
    inset: 10% 20% !important;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

/* Responsive fallback */
@media (max-width: 900px) {
    .rmpfb-viewer--large,
    .rmpfb-viewer--medium,
    .rmpfb-viewer--small {
        inset: 2% !important;
    }
}

/* Fullscreen state when toggled from a windowed modal */
.rmpfb-viewer--is-fullscreen {
    inset: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}


/* RMP integration overrides */
.rmpfb-card.rmp-flipbook-trigger {
    display: inline-flex;
    width: auto;
    max-width: none;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    border: 0;
    box-shadow: none;
    overflow: visible;
    user-select: none;
}
.rmpfb-card.rmp-flipbook-trigger:hover { transform: none; box-shadow: none; }
.rmp-flipbook-launch {
    display: grid;
    gap: .85rem;
    align-items: center;
    justify-items: start;
    padding: clamp(18px, 4vw, 34px);
    border: 1px solid color-mix(in srgb, var(--rmp-line, #cfe5e1) 82%, transparent);
    border-radius: var(--rmp-pdf-modal-radius, var(--rmp-radius-panel, 28px));
    background: color-mix(in srgb, var(--rmp-surface, #f7fffc) 88%, #ffffff);
}
.rmp-flipbook-launch p { margin: 0; color: var(--rmp-muted, #4d6967); max-width: 60ch; }
.rmp-flipbook-launch-actions { display:flex; flex-wrap:wrap; align-items:center; gap:.7rem; }
.rmpfb-viewer,
.rmpfb-pw-modal,
.rmpfb-modal-backdrop { z-index: 999999; }
.rmpfb-viewer {
    border-radius: var(--rmp-flipbook-radius, 0px);
}
.rmpfb-viewer--large,
.rmpfb-viewer--medium,
.rmpfb-viewer--small {
    border-radius: var(--rmp-flipbook-radius, 18px);
}
.rmpfb-toolbar { height: var(--rmp-flipbook-toolbar-height, 52px); }
.rmpfb-toolbar__btn { width: var(--rmp-flipbook-tool-size, 38px); height: var(--rmp-flipbook-tool-size, 38px); border-radius: var(--rmp-flipbook-tool-radius, 8px); }
.rmpfb-sidebar { width: var(--rmp-flipbook-sidebar-width, 320px); }
.rmpfb-pages-wrap { padding: var(--rmp-flipbook-canvas-padding, 24px); }
.rmpfb-page-container { border-radius: var(--rmp-flipbook-page-radius, 4px); }
.rmpfb-toolbar__title { max-width: min(34vw, 320px); }
body.rmp-flipbook-open { overflow: hidden; }
