/**
 * CSI Punnakkadu - Modern Ultra-Readable PDF Document Reader Stylesheet
 * 3D Book Page-Turning Physics Animation & High-DPI Crisp Rendering
 */

/* ==========================================================================
   1. Reader Fullscreen Modal Overlay with Spring Zoom Entrance
   ========================================================================== */
.csi-pdf-reader-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999999 !important;
    display: none;
    flex-direction: column;
    background: #080d1a;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.97);
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s ease;
    user-select: none;
    overflow: hidden;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #f8fafc;
}

.csi-pdf-reader-modal.active {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: scale(1) !important;
}

/* ==========================================================================
   2. Top Acrylic Navigation Bar
   ========================================================================== */
.csi-pdf-navbar {
    height: 56px;
    background: rgba(15, 23, 42, 0.96);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
}

.csi-nav-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.csi-nav-doc-badge {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.csi-doc-pdf-tag {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
    color: #ffffff;
    font-size: 0.68rem;
    font-weight: 800;
    padding: 3px 6px;
    border-radius: 4px;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.csi-nav-doc-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.csi-nav-doc-title {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.csi-nav-doc-sub {
    font-size: 0.72rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}

.csi-nav-divider {
    width: 1px;
    height: 22px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0 0.25rem;
}

/* Center Pagination */
.csi-nav-center {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 3px 8px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.csi-page-counter-box {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: #94a3b8;
}

.csi-page-input {
    width: 42px;
    height: 26px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #ffffff;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    outline: none;
    transition: all 0.2s ease;
}

.csi-page-input:focus {
    background: rgba(255, 255, 255, 0.18);
    border-color: var(--secondary, #c8102e);
    box-shadow: 0 0 0 2px rgba(200, 16, 46, 0.35);
}

.csi-page-slash {
    opacity: 0.5;
}

.csi-total-pages-count {
    color: #f1f5f9;
    font-weight: 700;
}

/* Right Nav Controls */
.csi-nav-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.csi-nav-btn {
    background: transparent;
    border: none;
    color: #cbd5e1;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.csi-nav-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    transform: translateY(-1px);
}

.csi-nav-btn.active {
    background: var(--secondary, #c8102e);
    color: #ffffff;
    box-shadow: 0 2px 10px rgba(200, 16, 46, 0.4);
}

.csi-nav-btn:disabled {
    opacity: 0.25;
    cursor: not-allowed;
    transform: none;
}

/* Tooltip on hover */
.csi-nav-btn::before,
.csi-nav-btn-action::before,
.csi-stage-turn-btn::before {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background: #090d16;
    color: #f8fafc;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 4px 9px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    pointer-events: none;
    opacity: 0;
    transition: all 0.2s ease;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    z-index: 120;
}

.csi-nav-btn:hover::before,
.csi-nav-btn-action:hover::before,
.csi-stage-turn-btn:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.csi-nav-btn-action {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #ffffff;
    padding: 0.38rem 0.85rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.csi-nav-btn-action:hover {
    background: var(--secondary, #c8102e);
    border-color: var(--secondary, #c8102e);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(200, 16, 46, 0.35);
}

.csi-nav-close-btn {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.csi-nav-close-btn:hover {
    background: #ef4444;
    color: #ffffff;
    border-color: #ef4444;
    transform: rotate(90deg) scale(1.05);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}

/* ==========================================================================
   3. Main Workspace & Sidebar
   ========================================================================== */
.csi-pdf-workspace {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Sidebar Drawer */
.csi-pdf-sidebar {
    width: 250px;
    background: rgba(15, 23, 42, 0.98);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
    z-index: 50;
}

.csi-pdf-sidebar.collapsed {
    margin-left: -250px;
}

.csi-sidebar-header {
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.csi-sidebar-header h4 {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 700;
    color: #ffffff;
}

.csi-sidebar-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.csi-sidebar-close:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.csi-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.csi-sidebar-thumb-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.csi-sidebar-thumb-item:hover {
    transform: translateY(-3px) scale(1.02);
}

.csi-sidebar-thumb-box {
    width: 140px;
    aspect-ratio: 1 / 1.414;
    background: #ffffff;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    border: 2px solid transparent;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.csi-sidebar-thumb-box canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.csi-sidebar-thumb-item.active .csi-sidebar-thumb-box {
    border-color: var(--secondary, #c8102e);
    box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.45);
}

.csi-sidebar-thumb-num {
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
    margin-top: 0.35rem;
}

.csi-sidebar-thumb-item.active .csi-sidebar-thumb-num {
    color: #fca5a5;
}

/* ==========================================================================
   4. 3D Book Page Stage & Authentic Page Turning Physics
   ========================================================================== */
.csi-pdf-scroll-stage {
    flex: 1;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 45%, #1e293b 0%, #0c1220 60%, #030712 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    box-sizing: border-box;
    perspective: 2400px;
    perspective-origin: 50% 50%;
}

.csi-pdf-pages-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Floating Stage Turn Arrows */
.csi-stage-turn-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 60;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
}

.csi-stage-turn-btn:hover:not(:disabled) {
    background: var(--secondary, #c8102e);
    border-color: var(--secondary, #c8102e);
    color: #ffffff;
    transform: translateY(-50%) scale(1.12);
    box-shadow: 0 12px 35px rgba(200, 16, 46, 0.5);
}

.csi-stage-turn-btn:disabled {
    opacity: 0.15;
    cursor: not-allowed;
    pointer-events: none;
}

.csi-turn-prev {
    left: 1.5rem;
}

.csi-turn-next {
    right: 1.5rem;
}

/* 3D Book Page Wrapper */
.csi-pdf-page-wrapper {
    position: absolute;
    background: #ffffff;
    box-shadow: 0 25px 65px -10px rgba(0, 0, 0, 0.9),
                0 10px 25px rgba(0, 0, 0, 0.6),
                0 0 1px 1px rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    overflow: hidden;
    display: none;
    justify-content: center;
    align-items: center;
    max-height: calc(100vh - 100px);
    max-width: calc(100vw - 160px);
    margin: 0 auto;
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.csi-pdf-page-wrapper.page-active {
    display: flex;
    z-index: 20;
    transform: rotateY(0deg) translateZ(0);
}

/* --------------------------------------------------------------------------
   3D Book Page Turn Animations
   -------------------------------------------------------------------------- */

/* Forward Page Turn: Current page flips out to the left */
@keyframes csiBookFlipForwardOut {
    0% {
        transform-origin: left center;
        transform: rotateY(0deg) translateZ(10px);
        opacity: 1;
        box-shadow: 0 25px 65px rgba(0, 0, 0, 0.8);
    }
    50% {
        transform-origin: left center;
        transform: rotateY(-45deg) skewY(-2deg) scale(0.98);
        box-shadow: -20px 25px 50px rgba(0, 0, 0, 0.6);
    }
    100% {
        transform-origin: left center;
        transform: rotateY(-90deg) skewY(-4deg) scale(0.95);
        opacity: 0;
        box-shadow: -40px 30px 60px rgba(0, 0, 0, 0.3);
    }
}

/* Forward Page Turn: Next page flips into view from the right */
@keyframes csiBookFlipForwardIn {
    0% {
        transform-origin: left center;
        transform: rotateY(90deg) skewY(4deg) scale(0.95);
        opacity: 0;
        box-shadow: 40px 30px 60px rgba(0, 0, 0, 0.3);
    }
    50% {
        transform-origin: left center;
        transform: rotateY(45deg) skewY(2deg) scale(0.98);
        opacity: 1;
        box-shadow: 20px 25px 50px rgba(0, 0, 0, 0.6);
    }
    100% {
        transform-origin: left center;
        transform: rotateY(0deg) skewY(0deg) scale(1);
        opacity: 1;
        box-shadow: 0 25px 65px -10px rgba(0, 0, 0, 0.9), 0 10px 25px rgba(0, 0, 0, 0.6);
    }
}

/* Backward Page Turn: Current page flips out to the right */
@keyframes csiBookFlipBackwardOut {
    0% {
        transform-origin: right center;
        transform: rotateY(0deg) translateZ(10px);
        opacity: 1;
        box-shadow: 0 25px 65px rgba(0, 0, 0, 0.8);
    }
    50% {
        transform-origin: right center;
        transform: rotateY(45deg) skewY(2deg) scale(0.98);
        box-shadow: 20px 25px 50px rgba(0, 0, 0, 0.6);
    }
    100% {
        transform-origin: right center;
        transform: rotateY(90deg) skewY(4deg) scale(0.95);
        opacity: 0;
        box-shadow: 40px 30px 60px rgba(0, 0, 0, 0.3);
    }
}

/* Backward Page Turn: Previous page flips into view from the left */
@keyframes csiBookFlipBackwardIn {
    0% {
        transform-origin: right center;
        transform: rotateY(-90deg) skewY(-4deg) scale(0.95);
        opacity: 0;
        box-shadow: -40px 30px 60px rgba(0, 0, 0, 0.3);
    }
    50% {
        transform-origin: right center;
        transform: rotateY(-45deg) skewY(-2deg) scale(0.98);
        opacity: 1;
        box-shadow: -20px 25px 50px rgba(0, 0, 0, 0.6);
    }
    100% {
        transform-origin: right center;
        transform: rotateY(0deg) skewY(0deg) scale(1);
        opacity: 1;
        box-shadow: 0 25px 65px -10px rgba(0, 0, 0, 0.9), 0 10px 25px rgba(0, 0, 0, 0.6);
    }
}

.csi-pdf-page-wrapper.flip-forward-out {
    display: flex !important;
    z-index: 25;
    animation: csiBookFlipForwardOut 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.csi-pdf-page-wrapper.flip-forward-in {
    display: flex !important;
    z-index: 30;
    animation: csiBookFlipForwardIn 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.csi-pdf-page-wrapper.flip-backward-out {
    display: flex !important;
    z-index: 25;
    animation: csiBookFlipBackwardOut 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.csi-pdf-page-wrapper.flip-backward-in {
    display: flex !important;
    z-index: 30;
    animation: csiBookFlipBackwardIn 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.csi-pdf-page-wrapper canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: high-quality;
    background: #ffffff;
}

.csi-pdf-page-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: #64748b;
    gap: 0.5rem;
}

.csi-pdf-page-badge {
    position: absolute;
    bottom: 10px;
    right: 12px;
    background: rgba(15, 23, 42, 0.85);
    color: #ffffff;
    font-size: 0.72rem;
    padding: 3px 9px;
    border-radius: 6px;
    font-weight: 600;
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    z-index: 10;
}

/* Interactive Dog-Ear Corner Curls */
.csi-page-corner-curl {
    position: absolute;
    bottom: 0;
    width: 48px;
    height: 48px;
    cursor: pointer;
    z-index: 30;
    transition: all 0.2s ease;
}

.csi-curl-right {
    right: 0;
    background: linear-gradient(135deg, transparent 50%, rgba(200, 16, 46, 0.15) 50%, rgba(0, 0, 0, 0.12) 100%);
    border-bottom-right-radius: 4px;
}

.csi-curl-right:hover {
    width: 58px;
    height: 58px;
    background: linear-gradient(135deg, transparent 50%, var(--secondary, #c8102e) 50%, rgba(185, 28, 28, 0.9) 100%);
    box-shadow: -4px -4px 10px rgba(0, 0, 0, 0.2);
}

.csi-curl-left {
    left: 0;
    background: linear-gradient(225deg, transparent 50%, rgba(200, 16, 46, 0.15) 50%, rgba(0, 0, 0, 0.12) 100%);
    border-bottom-left-radius: 4px;
}

.csi-curl-left:hover {
    width: 58px;
    height: 58px;
    background: linear-gradient(225deg, transparent 50%, var(--secondary, #c8102e) 50%, rgba(185, 28, 28, 0.9) 100%);
    box-shadow: 4px -4px 10px rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   5. Loader Spinner
   ========================================================================== */
.csi-pdf-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    z-index: 150;
    background: rgba(15, 23, 42, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 2rem 2.5rem;
    border-radius: 16px;
    backdrop-filter: blur(16px);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.7);
    text-align: center;
}

.csi-pdf-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--secondary, #c8102e);
    border-radius: 50%;
    animation: csiPdfSpin 0.85s linear infinite;
}

.csi-loader-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #f8fafc;
    margin: 0;
}

.csi-loader-sub {
    font-size: 0.78rem;
    color: #94a3b8;
    margin: 0;
}

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

/* ==========================================================================
   6. Responsive Styles
   ========================================================================== */
@media (max-width: 992px) {
    .csi-pdf-sidebar {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
    }
    .csi-pdf-sidebar.collapsed {
        transform: translateX(-100%);
        margin-left: 0;
    }
    .csi-turn-prev { left: 0.75rem; }
    .csi-turn-next { right: 0.75rem; }
}

@media (max-width: 768px) {
    .csi-pdf-navbar {
        padding: 0 0.75rem;
        height: 50px;
    }
    .csi-hide-mobile {
        display: none !important;
    }
    .csi-stage-turn-btn {
        width: 40px;
        height: 40px;
    }
    .csi-pdf-page-wrapper {
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 80px);
    }
    .csi-nav-doc-sub {
        display: none;
    }
    .csi-nav-doc-title {
        max-width: 140px;
        font-size: 0.85rem;
    }
}
