/* ==========================================
   Magazine Viewer Styles
   ========================================== */

/* Body Overrides for Viewer */
.viewer-body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #545454;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ==========================================
   Loading Screen
   ========================================== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #545454 0%, #B39783 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.loading-content {
    text-align: center;
    color: white;
}

.spinner {
    width: 60px;
    height: 60px;
    margin: 0 auto 2rem;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #B39783;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-bar {
    width: 300px;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    margin: 1.5rem auto;
    overflow: hidden;
}

.loading-progress {
    height: 100%;
    background: linear-gradient(90deg, #B39783, #929392);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

#loadingText {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-top: 1rem;
}

/* ==========================================
   Viewer Container
   ========================================== */
.viewer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #545454;
    display: flex;
    flex-direction: column;
    z-index: 9999;
}

/* ==========================================
   Toolbar
   ========================================== */
.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background-color: #545454;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-left {
    flex: 1;
}

.toolbar-center {
    flex: 0 0 auto;
}

.toolbar-right {
    flex: 1;
    justify-content: flex-end;
}

.toolbar-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-btn svg {
    display: block;
}

.viewer-title {
    color: white;
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Page Indicator */
.page-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    font-size: 0.95rem;
    padding: 0 1rem;
}

.page-input {
    width: 50px;
    padding: 0.4rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 4px;
    font-size: 0.9rem;
}

.page-input:focus {
    outline: none;
    border-color: #B39783;
    background: rgba(255, 255, 255, 0.15);
}

/* Remove spinner arrows from number input */
.page-input::-webkit-inner-spin-button,
.page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ==========================================
   Main Viewer Area
   ========================================== */
.viewer-main {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flipbook-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flipbook {
    position: relative;
    perspective: 2000px;
    display: flex;
    gap: 2px;
    background: transparent;
    align-items: center;
    justify-content: center;
}

.page {
    position: relative;
    background: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center;
}

/* Cover page styling - shown alone, centered */
.page.page-cover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    margin: 0 auto;
}

.page canvas {
    display: block !important;
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 1 !important;
}

/* Page flip animation */
.page.flipping {
    animation: pageFlip 0.6s ease-in-out;
}

@keyframes pageFlip {
    0% {
        transform: rotateY(0deg);
    }

    50% {
        transform: rotateY(-90deg);
    }

    100% {
        transform: rotateY(0deg);
    }
}

.page.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ==========================================
   Scroll View (Mobile Fallback)
   ========================================== */
.scroll-view {
    width: 100%;
    height: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    display: flex;
    flex-direction: row;
}

#scrollPages {
    padding: 0;
    display: flex;
    flex-direction: row;
    height: 100%;
}

.scroll-page {
    background: #000;
    /* Dark background for better contrast in full screen */
    margin: 0;
    box-shadow: none;
    min-width: 100vw;
    width: 100vw;
    height: 100%;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.scroll-page canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* ==========================================
   Thumbnail Sidebar
   ========================================== */
.thumbnail-sidebar {
    position: absolute;
    top: 0;
    right: -300px;
    width: 280px;
    height: 100%;
    background: #545454;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
    transition: right 0.3s ease;
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.thumbnail-sidebar.open {
    right: 0;
}

.thumbnail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.thumbnail-header h4 {
    color: white;
    margin: 0;
    font-size: 1.1rem;
}

.close-thumbnails {
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.close-thumbnails:hover {
    opacity: 1;
}

.thumbnail-grid {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.thumbnail-item {
    position: relative;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.thumbnail-item:hover {
    border-color: #B39783;
    transform: translateY(-2px);
}

.thumbnail-item.active {
    border-color: #B39783;
}

.thumbnail-item canvas {
    display: block;
    width: 100%;
    height: auto;
}

.thumbnail-number {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    text-align: center;
    padding: 0.3rem;
    font-size: 0.75rem;
}

/* ==========================================
   Mobile Controls
   ========================================== */
.mobile-controls {
    display: none;
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(179, 151, 131, 0.9);
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    align-items: center;
    gap: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 150;
}

.mobile-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 0.7rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mobile-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

.mobile-page-indicator {
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    min-width: 60px;
    text-align: center;
}

/* ==========================================
   Error Screen
   ========================================== */
.error-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #545454 0%, #B39783 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.error-content {
    text-align: center;
    color: white;
    max-width: 500px;
    padding: 2rem;
}

.error-content svg {
    color: #B39783;
    margin-bottom: 1.5rem;
}

.error-content h2 {
    margin-bottom: 1rem;
}

.error-content p {
    margin-bottom: 2rem;
    opacity: 0.8;
}

.error-content .btn {
    margin: 0.5rem;
}

/* ==========================================
   Responsive Design
   ========================================== */

/* Tablet and Below */
@media (max-width: 1024px) {
    .toolbar-left .viewer-title {
        display: none;
    }

    .toolbar-center {
        gap: 0.3rem;
    }

    .page-indicator {
        padding: 0 0.5rem;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .viewer-toolbar {
        padding: 0.75rem 1rem;
    }

    .toolbar-left,
    .toolbar-right {
        flex: 0;
    }

    .toolbar-center {
        flex: 1;
        justify-content: center;
    }

    /* Hide some buttons on mobile */
    #zoomOut,
    #zoomIn,
    #toggleThumbnails {
        display: none;
    }

    .toolbar-btn {
        padding: 0.5rem;
    }

    .toolbar-btn svg {
        width: 20px;
        height: 20px;
    }

    .mobile-controls {
        display: flex;
    }

    .thumbnail-sidebar {
        width: 100%;
        right: -100%;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .flipbook {
        width: 100% !important;
        height: auto !important;
    }

    .page {
        width: 100% !important;
    }
}

/* Very Small Mobile */
@media (max-width: 480px) {
    .page-input {
        width: 40px;
        padding: 0.3rem;
        font-size: 0.85rem;
    }

    .page-indicator {
        font-size: 0.85rem;
    }

    .loading-bar {
        width: 250px;
    }
}

/* ==========================================
   Fullscreen Mode
   ========================================== */
.viewer-container:fullscreen {
    background: #1a1a1a;
}

.viewer-container:-webkit-full-screen {
    background: #1a1a1a;
}

.viewer-container:-moz-full-screen {
    background: #1a1a1a;
}

/* ==========================================
   Print Styles
   ========================================== */
@media print {

    .viewer-toolbar,
    .thumbnail-sidebar,
    .mobile-controls,
    .loading-screen {
        display: none !important;
    }

    .viewer-main {
        background: white;
    }
}

/* ==========================================
   Zoom States
   ========================================== */
.flipbook-wrapper.zoomed {
    overflow: auto;
    cursor: grab;
}

.flipbook-wrapper.zoomed:active {
    cursor: grabbing;
}

.flipbook-wrapper.zoomed .flipbook {
    transform-origin: center center;
}

/* ==========================================
   Accessibility
   ========================================== */
.toolbar-btn:focus,
.mobile-btn:focus,
.page-input:focus {
    outline: 2px solid #B39783;
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {

    .page,
    .page.flipping,
    .thumbnail-item,
    .toolbar-btn,
    .mobile-btn {
        animation: none !important;
        transition: none !important;
    }
}


/* ==========================================
   Interactive Elements
   ========================================== */
.interactive-zone {
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.interactive-zone:hover {
    border-color: #B39783;
    /* Primary Color */
    background-color: rgba(179, 151, 131, 0.1);
    /* Primary color with low opacity */
    box-shadow: 0 0 10px rgba(179, 151, 131, 0.3);
}