/* ================================================
   Quran Library - Flipbook Viewer Styles
   Fullscreen modal, toolbar, TOC, thumbnails,
   RTL flipbook, zoom, loading
   ================================================ */

/* Viewer Modal Overlay */
.ql-viewer-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--ql-viewer-bg, #1a1a2e);
    z-index: 999999;
    flex-direction: column;
}

.ql-viewer-modal.active {
    display: flex;
}

/* Toolbar */
.ql-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10;
    flex-shrink: 0;
    direction: ltr;
}

.ql-toolbar button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
}

.ql-toolbar button:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.ql-toolbar button.active {
    background: rgba(31, 168, 126, 0.5);
    border-color: #1fa87e;
}

.ql-toolbar-separator {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.2);
    margin: 0 4px;
}

/* Page input */
.ql-page-input-group {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #ccc;
    font-size: 13px;
}

.ql-page-input-group input {
    width: 50px;
    height: 30px;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    color: #fff;
    font-size: 13px;
    padding: 0;
}

.ql-page-input-group input:focus {
    outline: none;
    border-color: #1fa87e;
    background: rgba(255, 255, 255, 0.15);
}

/* Close button */
.ql-close-btn {
    position: absolute;
    right: 12px;
    top: 8px;
    background: rgba(180, 40, 40, 0.7) !important;
    border-color: rgba(200, 50, 50, 0.5) !important;
    font-size: 18px !important;
    z-index: 11;
}

.ql-close-btn:hover {
    background: rgba(200, 40, 40, 0.9) !important;
}

/* Viewer body */
.ql-viewer-body {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

/* Flipbook container */
.ql-flipbook-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.ql-flipbook-wrapper {
    transform-origin: center center;
    transition: transform 0.2s ease;
}

/* turn.js flipbook */
.ql-flipbook {
    margin: 0 auto;
}

.ql-flipbook .page-wrapper {
    background: #fff;
    overflow: hidden;
}

.ql-flipbook .page-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
}

/* Navigation arrows overlaid on flipbook area */
.ql-nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    border: none;
    width: 44px;
    height: 80px;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    border-radius: 6px;
    transition: background 0.2s;
}

.ql-nav-arrow:hover {
    background: rgba(0, 0, 0, 0.65);
}

.ql-nav-prev {
    left: 15px;
}

.ql-nav-next {
    right: 15px;
}

/* Side Panels (TOC, Thumbnails) */
.ql-side-panel {
    position: absolute;
    top: 0;
    width: 300px;
    height: 100%;
    background: rgba(20, 20, 40, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 8;
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.3);
}

.ql-side-panel.left {
    left: 0;
}

.ql-side-panel.right {
    right: 0;
    box-shadow: -2px 0 15px rgba(0, 0, 0, 0.3);
}

.ql-side-panel.visible {
    display: flex;
}

.ql-panel-header {
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ql-panel-header h3 {
    color: #fff;
    margin: 0;
    font-size: 15px;
}

.ql-panel-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.ql-panel-close:hover {
    color: #fff;
}

.ql-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

/* TOC styles */
.ql-toc-category {
    margin-bottom: 15px;
}

.ql-toc-category-title {
    color: #1fa87e;
    font-size: 14px;
    font-weight: 700;
    padding: 8px 10px;
    margin: 0;
    direction: rtl;
}

.ql-toc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    color: #ddd;
    font-size: 13px;
    cursor: pointer;
    border-radius: 5px;
    transition: background 0.15s;
    direction: rtl;
}

.ql-toc-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.ql-toc-item.active {
    background: rgba(31, 168, 126, 0.2);
    color: #1fa87e;
}

.ql-toc-item-page {
    color: #888;
    font-size: 11px;
    flex-shrink: 0;
    margin-right: 10px;
}

/* Thumbnails */
.ql-thumbs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 5px;
}

.ql-thumb-item {
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.15s;
    background: rgba(255, 255, 255, 0.05);
}

.ql-thumb-item:hover {
    border-color: rgba(255, 255, 255, 0.3);
    transform: scale(1.03);
}

.ql-thumb-item.active {
    border-color: #1fa87e;
}

.ql-thumb-item img {
    width: 100%;
    display: block;
}

.ql-thumb-label {
    text-align: center;
    color: #aaa;
    font-size: 11px;
    padding: 3px;
}

/* Loading spinner */
.ql-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 6;
}

.ql-loading.hidden {
    display: none;
}

.ql-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: #1fa87e;
    border-radius: 50%;
    animation: ql-spin 0.8s linear infinite;
}

.ql-loading-text {
    color: #aaa;
    font-size: 14px;
}

@keyframes ql-spin {
    to { transform: rotate(360deg); }
}

/* Page title overlay */
.ql-page-title-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 8px;
    color: #aaa;
    font-size: 13px;
    background: linear-gradient(transparent, rgba(0,0,0,0.4));
    pointer-events: none;
    direction: rtl;
}

/* Scrollbar for panels */
.ql-panel-body::-webkit-scrollbar {
    width: 6px;
}

.ql-panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.ql-panel-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.ql-panel-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Fullscreen adjustments */
.ql-viewer-modal:-webkit-full-screen {
    background: var(--ql-viewer-bg, #1a1a2e);
}

.ql-viewer-modal:fullscreen {
    background: var(--ql-viewer-bg, #1a1a2e);
}

/* Mobile */
@media (max-width: 768px) {
    .ql-toolbar {
        gap: 3px;
        padding: 6px 8px;
        flex-wrap: wrap;
    }

    .ql-toolbar button {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .ql-side-panel {
        width: 260px;
    }

    .ql-nav-arrow {
        width: 36px;
        height: 60px;
        font-size: 18px;
    }

    .ql-nav-prev { left: 5px; }
    .ql-nav-next { right: 5px; }
}
