/**
 * eZBooks E-Book Reader Styles
 * Targets the epub-reader.php template class names
 */

:root {
    --reader-bg: #ffffff;
    --reader-text: #333333;
    --reader-accent: #F59E51;
    --reader-accent2: #3A0353;
    --reader-border: #e8e6dc;
    --reader-toolbar-bg: #1a0a26;
    --reader-toolbar-text: #f5f0fa;
}

/* Reader Themes */
#epub-reader.theme-light { --reader-bg: #faf9f5; --reader-text: #1a1a1a; }
#epub-reader.theme-sepia  { --reader-bg: #f4ecd8; --reader-text: #5b4636; }
#epub-reader.theme-dark   { --reader-bg: #1a1a1a; --reader-text: #cccccc; --reader-border: #333; }

/* ── Main container: full-screen overlay ── */
#epub-reader,
.ezbooks-epub-reader {
    position: fixed !important;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--reader-bg);
    z-index: 999999;
    font-family: 'Poppins', Georgia, serif;
    overflow: hidden;
}

/* ── Header toolbar ── */
.ezbooks-reader-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    height: 54px;
    background: var(--reader-toolbar-bg);
    color: var(--reader-toolbar-text);
    z-index: 10;
    flex-shrink: 0;
    gap: 12px;
}

.reader-header-left,
.reader-header-center,
.reader-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.reader-header-left  { flex: 1; min-width: 0; }
.reader-header-center { flex-shrink: 0; }
.reader-header-right { justify-content: flex-end; }

.reader-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
    color: var(--reader-toolbar-text);
    margin: 0;
}

/* Page counter */
.ezbooks-page-current,
.ezbooks-page-separator,
.ezbooks-page-total {
    font-size: 13px;
    color: rgba(245,240,250,0.7);
    font-family: 'Poppins', sans-serif;
}
.ezbooks-page-separator { margin: 0 2px; }

/* Toolbar buttons */
.ezbooks-reader-header button {
    width: 38px;
    height: 38px;
    border: none;
    background: transparent;
    color: var(--reader-toolbar-text);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 0;
}
.ezbooks-reader-header button:hover {
    background: rgba(245, 158, 81, 0.2);
    color: #F59E51;
}
.ezbooks-reader-header button .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}
.ezbooks-close-reader {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    color: var(--reader-toolbar-text) !important;
    text-decoration: none !important;
    flex-shrink: 0;
    transition: background 0.2s;
}
.ezbooks-close-reader:hover {
    background: rgba(245,158,81,0.2);
    color: #F59E51 !important;
}
.ezbooks-close-reader .dashicons { font-size: 20px; width: 20px; height: 20px; }

/* ── Main reader area ── */
.ezbooks-reader-main {
    flex: 1;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    position: relative;
    background: var(--reader-bg);
}

/* Prev/Next page buttons */
.ezbooks-prev-page,
.ezbooks-next-page {
    width: 48px;
    flex-shrink: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(58,3,83,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    z-index: 2;
}
.ezbooks-prev-page:hover,
.ezbooks-next-page:hover {
    background: rgba(58,3,83,0.05);
    color: #3A0353;
}
.ezbooks-prev-page .dashicons,
.ezbooks-next-page .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
}

/* EPUB viewer */
.ezbooks-epub-viewer,
#epub-viewer {
    flex: 1;
    overflow: hidden;
    height: 100%;
}

/* ── Progress bar ── */
.ezbooks-reader-progress {
    height: 3px;
    background: rgba(58,3,83,0.12);
    flex-shrink: 0;
}
.ezbooks-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3A0353, #F59E51);
    transition: width 0.3s ease;
    width: 0%;
}

/* ── Loading overlay ── */
.ezbooks-reader-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--reader-bg);
    z-index: 5;
    gap: 14px;
    color: #804A8A;
    font-size: 15px;
}
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #ede5f5;
    border-top-color: #3A0353;
    border-radius: 50%;
    animation: ezbooks-spin 0.8s linear infinite;
}
@keyframes ezbooks-spin { to { transform: rotate(360deg); } }

/* ── Panel overlay ── */
.ezbooks-panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 50;
}
.ezbooks-panel-overlay.show { display: block; }

/* ── Panels (TOC, Bookmarks, Search, Settings) ── */
.ezbooks-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    width: 320px;
    background: #ffffff;
    box-shadow: 4px 0 24px rgba(58,3,83,0.18);
    z-index: 60;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
}
.ezbooks-panel-settings {
    left: auto;
    right: 0;
    transform: translateX(100%);
    box-shadow: -4px 0 24px rgba(58,3,83,0.18);
}
.ezbooks-panel-search {
    left: 0;
}
.ezbooks-panel.open {
    transform: translateX(0);
}

/* Panel header */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0e6f8;
    background: linear-gradient(135deg, #3A0353 0%, #804A8A 100%);
    color: #fff;
    flex-shrink: 0;
}
.panel-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    font-family: 'Poppins', sans-serif;
}
.ezbooks-add-bookmark {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    background: rgba(245,158,81,0.2);
    border: 1px solid rgba(245,158,81,0.5);
    border-radius: 20px;
    color: #F59E51;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.ezbooks-add-bookmark:hover {
    background: #F59E51;
    color: #3A0353;
    border-color: #F59E51;
}

/* Panel content area */
.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* TOC */
.ezbooks-toc-list {
    list-style: none;
    padding: 8px 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}
.ezbooks-toc-item {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 14px;
    color: #3A0353;
    border-left: 3px solid transparent;
    transition: all 0.15s;
    line-height: 1.4;
}
.ezbooks-toc-item:hover {
    background: #f0e6f8;
    border-left-color: #804A8A;
}
.ezbooks-toc-item.active {
    background: #ede5f5;
    border-left-color: #F59E51;
    font-weight: 600;
}

/* Bookmarks */
.ezbooks-bookmarks-list {
    list-style: none;
    padding: 8px 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
}
.no-bookmarks {
    text-align: center;
    color: #aaa;
    padding: 32px 16px;
    font-size: 14px;
}
.ezbooks-bookmark-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0e6f8;
    transition: background 0.15s;
}
.ezbooks-bookmark-item:hover { background: #f8f4fd; }
.bookmark-info { flex: 1; min-width: 0; }
.bookmark-title { font-size: 14px; font-weight: 500; color: #3A0353; }
.bookmark-note { font-size: 12px; color: #888; margin-top: 2px; }
.ezbooks-bookmark-delete {
    background: transparent;
    border: none;
    color: #ccc;
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.2s;
    line-height: 1;
}
.ezbooks-bookmark-delete:hover { color: #e53e3e; }

/* Search panel */
.ezbooks-search-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid #f0e6f8;
}
.ezbooks-search-input {
    width: 100%;
    padding: 9px 14px;
    border: 1.5px solid #d9c8e8;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    color: #333;
    box-sizing: border-box;
}
.ezbooks-search-input:focus { border-color: #804A8A; }
.ezbooks-search-form .ezbooks-btn-primary {
    background: linear-gradient(135deg, #3A0353, #804A8A);
    color: #fff;
    border: 2px solid #F59E51;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.ezbooks-search-form .ezbooks-btn-link {
    background: transparent;
    border: none;
    color: #804A8A;
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    padding: 4px;
}
.ezbooks-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}
.ezbooks-search-result {
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0e6f8;
    font-size: 13px;
    color: #444;
    transition: background 0.15s;
    line-height: 1.5;
}
.ezbooks-search-result:hover { background: #f8f4fd; }
.ezbooks-search-result mark {
    background: rgba(245,158,81,0.35);
    color: inherit;
    border-radius: 2px;
}

/* Settings panel */
.setting-group {
    margin-bottom: 22px;
}
.setting-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #804A8A;
    margin-bottom: 10px;
    font-family: 'Poppins', sans-serif;
}
.setting-group select {
    width: 100%;
    padding: 9px 14px;
    border: 1.5px solid #d9c8e8;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    background: #faf7fd;
    outline: none;
    cursor: pointer;
}
.setting-group select:focus { border-color: #804A8A; }
.setting-slider {
    display: flex;
    align-items: center;
    gap: 10px;
}
.setting-slider input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    background: #e0d0ec;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.setting-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: #3A0353;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #F59E51;
}
.setting-slider span {
    font-size: 13px;
    font-weight: 600;
    color: #3A0353;
    min-width: 40px;
    text-align: right;
}

/* ── Notices ── */
.ezbooks-reader-notice {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    z-index: 99999;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.ezbooks-reader-notice.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.ezbooks-notice-success { background: #1e7e34; color: #fff; }
.ezbooks-notice-error   { background: #c0392b; color: #fff; }

/* ── Error state ── */
.ezbooks-reader-error {
    text-align: center;
    padding: 80px 32px;
    color: #804A8A;
}
.ezbooks-reader-error p {
    font-size: 16px;
    margin-bottom: 20px;
}
.ezbooks-reader-error .ezbooks-btn {
    display: inline-block;
    padding: 10px 24px;
    background: linear-gradient(135deg, #3A0353, #804A8A);
    color: #fff !important;
    border: 2px solid #F59E51;
    border-radius: 8px;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 14px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .reader-title { display: none; }
    .ezbooks-panel,
    .ezbooks-panel-settings { width: 100%; }
    .ezbooks-prev-page,
    .ezbooks-next-page { width: 36px; }
}


/* ═══════════════════════════════════════════════════════════════════════
   PDF FLIPBOOK READER
   ═══════════════════════════════════════════════════════════════════════ */

/* Main container */
#pdf-reader,
.ezbooks-pdf-reader {
    position: fixed !important;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: #1a0a26;
    z-index: 999999;
    font-family: 'Poppins', sans-serif;
    overflow: hidden;
}

/* Theme variants */
#pdf-reader.theme-dark  { background: #110820; }
#pdf-reader.theme-light { background: #3d3d4e; }
#pdf-reader.theme-sepia { background: #3a2a1a; }

/* ── Viewer area ── */
.ezbooks-pdf-viewer {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* Ambient glow behind the book */
.ezbooks-pdf-viewer::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse 60% 50% at 50% 50%, rgba(90, 20, 120, 0.35) 0%, transparent 70%);
    pointer-events: none;
}

/* ── Flipbook viewport (zoom + pan wrapper) ── */
.ezbooks-flipbook-viewport {
    display: flex;
    align-items: center;
    justify-content: center;
    /* transform applied by JS for zoom + pan */
    transition: transform 0.2s ease;
    will-change: transform;
    z-index: 2;
}

/* ── Pan overlay (shown when zoomed in) ── */
.ezbooks-zoom-pan-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none; /* enabled by JS when zoom > 1 */
    user-select: none;
    -webkit-user-select: none;
}

/* ── Flipbook container ── */
.ezbooks-flipbook-container {
    position: relative;
    /* StPageFlip sets width/height via inline style */
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.04),
        0 8px 40px rgba(0, 0, 0, 0.7),
        0 24px 80px rgba(0, 0, 0, 0.5);
    border-radius: 2px;
}

/* Override StPageFlip inner canvas borders */
.ezbooks-flipbook-container .stf__wrapper,
.ezbooks-flipbook-container canvas {
    border-radius: 1px;
}

/* ── Side navigation arrows ── */
.ezbooks-flip-prev,
.ezbooks-flip-next {
    position: relative;
    width: 50px;
    height: 50px;
    flex-shrink: 0;
    background: rgba(245, 158, 81, 0.1);
    border: 2px solid rgba(245, 158, 81, 0.25);
    border-radius: 50%;
    color: #F59E51;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s;
    z-index: 5;
    margin: 0 12px;
}
.ezbooks-flip-prev:hover,
.ezbooks-flip-next:hover {
    background: rgba(245, 158, 81, 0.25);
    border-color: #F59E51;
    transform: scale(1.1);
    box-shadow: 0 0 16px rgba(245, 158, 81, 0.3);
}
.ezbooks-flip-prev .dashicons,
.ezbooks-flip-next .dashicons {
    font-size: 22px;
    width: 22px;
    height: 22px;
}

/* ── Zoom controls ── */
.ezbooks-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 20px;
    padding: 2px 6px;
}
.ezbooks-zoom-controls button {
    width: 28px !important;
    height: 28px !important;
    background: transparent !important;
    border: none !important;
    border-radius: 50% !important;
    padding: 0 !important;
}
.ezbooks-zoom-controls button:hover {
    background: rgba(245,158,81,0.25) !important;
}
.ezbooks-zoom-label {
    font-size: 12px;
    font-weight: 600;
    color: rgba(245,240,250,0.85);
    min-width: 38px;
    text-align: center;
    font-family: 'Poppins', sans-serif;
    letter-spacing: 0.3px;
}

/* ── Page input in PDF header ── */
.page-input-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}
#page-input {
    width: 52px;
    height: 30px;
    padding: 0 8px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    color: #f5f0fa;
    font-size: 13px;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}
#page-input::-webkit-outer-spin-button,
#page-input::-webkit-inner-spin-button { -webkit-appearance: none; }
#page-input:focus { border-color: #F59E51; }
.page-separator {
    color: rgba(245, 240, 250, 0.5);
    font-size: 13px;
}
.ezbooks-page-total {
    font-size: 13px;
    color: rgba(245, 240, 250, 0.7);
}

/* ── Loading progress bar ── */
.ezbooks-loading-progress {
    width: 220px;
    height: 4px;
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}
.ezbooks-loading-bar {
    height: 100%;
    background: linear-gradient(90deg, #3A0353, #F59E51);
    border-radius: 2px;
    width: 0%;
    transition: width 0.2s ease;
}

/* ── Thumbnails grid (uses pre-rendered images) ── */
.ezbooks-thumbnails-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}
.ezbooks-thumbnail {
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.15s;
    background: #f5f5f5;
    position: relative;
}
.ezbooks-thumbnail:hover  { border-color: #804A8A; transform: scale(1.03); }
.ezbooks-thumbnail.active { border-color: #F59E51; }
.ezbooks-thumbnail .thumb-img {
    width: 100%;
    display: block;
    aspect-ratio: 1 / 1.414;
    object-fit: cover;
}
.ezbooks-thumbnail .thumb-page {
    display: block;
    text-align: center;
    font-size: 11px;
    color: #888;
    padding: 3px 0 5px;
    background: #fff;
}
.ezbooks-thumbnail.active .thumb-page {
    color: #3A0353;
    font-weight: 700;
}

/* ── PDF Responsive ── */
@media (max-width: 600px) {
    .ezbooks-flip-prev,
    .ezbooks-flip-next {
        width: 38px;
        height: 38px;
        margin: 0 5px;
    }
    .ezbooks-flip-prev .dashicons,
    .ezbooks-flip-next .dashicons {
        font-size: 18px;
        width: 18px;
        height: 18px;
    }
    .ezbooks-thumbnails-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
