/**
 * Real Flip - PERFECT CENTER ALIGNMENT VERSION 2.1.0
 * 
 * COMPLETE FIXES:
 * ✅ Perfect page center alignment (all zoom levels)
 * ✅ 75-90% zoom optimization
 * ✅ Responsive width management
 * ✅ Flexbox perfect centering
 * ✅ Controls always visible and centered
 * ✅ Fullscreen mode optimized
 * ✅ ESC button hint in fullscreen
 * 
 * @package Real_Flip
 * @version 2.1.0
 * @author P Adhil Khan
 */

/* ========================================
   PERFECT PAGE CENTER ALIGNMENT - FIX #1
   ======================================== */

/* Body-level centering */
body .rf-outer-wrapper {
    display: flex !important;
    justify-content: center !important;
    align-items: flex-start !important;
    width: 100% !important;
    margin: 0 auto !important;
    padding: 20px 0 !important;
}

/* Main container perfect centering */
body .rf-container {
    display: block !important;
    margin: 0 auto !important;
    position: relative !important;
}

/* ========================================
   ZOOM OPTIMIZATION 75-90% - FIX #2
   ======================================== */

/* Wrapper for perfect centering */
.rf-outer-wrapper {
    max-width: 1600px !important;
    width: 100% !important;
    text-align: center !important;
    padding: 30px 20px !important;
    box-sizing: border-box !important;
    display: flex !important;
    justify-content: center !important;
    align-items: flex-start !important;
}

/* ========================================
   MAIN CONTAINER - FIX #3
   ======================================== */

.rf-container {
    /* Perfect centering */
    position: relative;
    margin: 0 auto !important;
    padding: 30px;
    
    /* Optimized width for all zoom levels */
    max-width: 1400px !important;
    width: 92% !important;
    
    /* Display settings */
    box-sizing: border-box;
    display: block;
    
    /* Styling */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: visible;
}

/* Dark theme variant */
.rf-container[data-theme="dark"] {
    background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
}

/* ========================================
   FULLSCREEN MODE - FIX #4
   ======================================== */

.rf-container.rf-fullscreen {
    /* Full viewport */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    
    /* Full dimensions */
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    
    /* Reset margins */
    margin: 0 !important;
    padding: 20px !important;
    border-radius: 0 !important;
    
    /* Z-index and overflow */
    z-index: 999999 !important;
    overflow: auto !important;
    
    /* Flexbox for perfect layout */
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
}

/* Fullscreen: Flipbook centered */
.rf-container.rf-fullscreen .rf-flipbook-wrapper {
    flex: 1 1 auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: visible !important;
    width: 100% !important;
    min-height: auto !important;
}

/* Fullscreen: Controls visible at bottom */
.rf-container.rf-fullscreen .rf-controls {
    position: relative !important;
    z-index: 999999 !important;
    background: rgba(0, 0, 0, 0.85) !important;
    margin: 15px auto 0 !important;
    flex-shrink: 0 !important;
    width: auto !important;
    max-width: 95% !important;
}

/* Fullscreen: Thumbnails visible */
.rf-container.rf-fullscreen .rf-thumbnail-scrubber {
    position: relative !important;
    z-index: 999999 !important;
    flex-shrink: 0 !important;
    width: 100% !important;
    max-width: 95% !important;
    margin: 15px auto 0 !important;
}

/* Fullscreen: ESC hint */
.rf-container.rf-fullscreen::before {
    content: '⌨️ Press ESC to exit fullscreen';
    position: fixed;
    top: 25px;
    right: 25px;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    z-index: 9999999;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    animation: fadeInOut 4s ease-in-out infinite;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; transform: translateY(-10px); }
    10%, 90% { opacity: 1; transform: translateY(0); }
}

/* ========================================
   LOGO - FIX #5
   ======================================== */

.rf-logo {
    text-align: center;
    margin: 0 auto 25px;
    display: block;
    width: 100%;
}

.rf-logo img {
    max-width: 250px;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* ========================================
   LOADING STATE - FIX #6
   ======================================== */

.rf-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #fff;
    z-index: 100;
    width: 300px;
}

.rf-loading-spinner {
    width: 70px;
    height: 70px;
    margin: 0 auto 25px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: rf-spin 1s linear infinite;
}

@keyframes rf-spin {
    to { transform: rotate(360deg); }
}

.rf-loading-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
}

.rf-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    margin-top: 20px;
    overflow: hidden;
}

.rf-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #34d399);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

/* ========================================
   FLIPBOOK WRAPPER - FIX #7 (PERFECT CENTER)
   ======================================== */

.rf-flipbook-wrapper {
    /* Perfect centering with flexbox */
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    
    /* Dimensions */
    margin: 0 auto 25px !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 500px;
    
    /* Positioning */
    position: relative;
    overflow: visible;
    
    /* Spacing */
    padding: 40px 20px;
    box-sizing: border-box;
}

.rf-flipbook {
    /* Centering */
    margin: 0 auto !important;
    display: block !important;
    
    /* Styling */
    background: transparent;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5);
    position: relative;
    transform-origin: center center;
    transition: transform 0.3s ease;
    z-index: 10;
    
    /* Max dimensions */
    max-width: 100%;
    max-height: 100%;
}

.rf-flipbook .page {
    background: #fff;
    border: 1px solid #ddd;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
}

.rf-flipbook .page canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

/* ========================================
   CONTROLS - FIX #8 (ALWAYS VISIBLE + CENTERED)
   ======================================== */

.rf-controls {
    /* Perfect centering */
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    
    /* Layout */
    gap: 15px;
    padding: 18px 25px;
    flex-wrap: wrap;
    
    /* Dimensions */
    margin: 25px auto !important;
    max-width: fit-content !important;
    width: auto !important;
    
    /* Styling */
    background: rgba(0, 0, 0, 0.25);
    border-radius: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    
    /* Positioning */
    position: relative;
    z-index: 100;
}

.rf-controls-left,
.rf-controls-center,
.rf-controls-right,
.rf-controls-extra {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

/* ========================================
   BUTTONS - FIX #9
   ======================================== */

.rf-btn {
    /* Layout */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    
    /* Dimensions */
    min-width: 46px;
    height: 46px;
    padding: 10px 18px;
    
    /* Styling */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    
    /* Transitions */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Positioning */
    position: relative;
    z-index: 101;
}

.rf-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.rf-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.rf-btn .rf-icon {
    font-size: 20px;
    line-height: 1;
}

.rf-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ========================================
   PAGE COUNTER - FIX #10
   ======================================== */

.rf-page-input-wrapper {
    /* Layout */
    display: flex !important;
    align-items: center !important;
    gap: 8px;
    
    /* Styling */
    background: rgba(255, 255, 255, 0.95);
    padding: 10px 18px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    
    /* Positioning */
    position: relative;
    z-index: 101;
}

.rf-page-input {
    width: 55px;
    padding: 8px 12px;
    border: 2px solid #667eea;
    border-radius: 8px;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
    color: #2c3e50;
    background: #fff;
    outline: none;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.rf-page-input:focus {
    border-color: #764ba2;
    box-shadow: 0 0 0 4px rgba(118, 75, 162, 0.15);
    transform: scale(1.05);
}

.rf-page-total {
    font-size: 17px;
    font-weight: 700;
    color: #2c3e50;
    white-space: nowrap;
    line-height: 1;
}

/* ========================================
   THUMBNAILS - FIX #11
   ======================================== */

.rf-thumbnail-scrubber {
    margin: 25px auto;
    max-width: 100%;
    width: 100%;
    overflow: hidden;
    position: relative;
    z-index: 100;
}

.rf-thumbnail-track {
    /* Layout */
    display: flex;
    gap: 15px;
    padding: 20px;
    
    /* Scrolling */
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    
    /* Alignment */
    align-items: center;
    justify-content: flex-start;
    
    /* Dimensions */
    max-width: 100%;
    width: 100%;
    
    /* Styling */
    background: rgba(0, 0, 0, 0.25);
    border-radius: 14px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Scrollbar styling */
.rf-thumbnail-track::-webkit-scrollbar {
    height: 10px;
}

.rf-thumbnail-track::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

.rf-thumbnail-track::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.rf-thumbnail-track::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
    background-clip: padding-box;
}

.rf-thumbnail {
    /* Layout */
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    
    /* Dimensions */
    width: 90px;
    height: auto;
    
    /* Styling */
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    
    /* Interaction */
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 101;
}

.rf-thumbnail canvas {
    display: block;
    width: 100%;
    height: auto;
}

.rf-thumbnail:hover {
    transform: scale(1.15) translateY(-8px);
    border-color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.4);
    z-index: 102;
}

.rf-thumbnail.active {
    border-color: #10b981;
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.7);
    transform: scale(1.1);
    z-index: 102;
}

.rf-thumbnail-number {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* ========================================
   RESPONSIVE DESIGN - FIX #12
   ======================================== */

/* Large screens (1400px+) */
@media (min-width: 1400px) {
    .rf-container {
        max-width: 1500px !important;
        width: 88% !important;
    }
}

/* Desktop (1200px - 1399px) */
@media (min-width: 1200px) and (max-width: 1399px) {
    .rf-container {
        max-width: 1300px !important;
        width: 90% !important;
    }
}

/* Tablets (768px - 1199px) */
@media (min-width: 768px) and (max-width: 1199px) {
    .rf-container {
        max-width: 95% !important;
        width: 95% !important;
        padding: 25px;
    }
    
    .rf-flipbook-wrapper {
        min-height: 450px;
        padding: 35px 15px;
    }
    
    .rf-controls {
        gap: 12px;
        padding: 15px 20px;
    }
    
    .rf-btn {
        min-width: 42px;
        height: 42px;
        padding: 8px 14px;
    }
    
    .rf-thumbnail {
        width: 75px;
    }
}

/* Mobile (max 767px) */
@media (max-width: 767px) {
    .rf-outer-wrapper {
        padding: 15px 10px !important;
    }
    
    .rf-container {
        padding: 20px;
        margin: 0 auto;
        width: 96% !important;
        max-width: 100% !important;
    }
    
    .rf-flipbook-wrapper {
        min-height: 400px;
        padding: 30px 10px;
    }
    
    .rf-controls {
        gap: 10px;
        padding: 15px;
        flex-direction: column;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .rf-controls-left,
    .rf-controls-center,
    .rf-controls-right,
    .rf-controls-extra {
        width: 100%;
        justify-content: center;
        gap: 8px;
    }
    
    .rf-btn {
        padding: 8px 14px;
        font-size: 15px;
        min-width: 40px;
        height: 40px;
    }
    
    .rf-page-input-wrapper {
        padding: 8px 15px;
    }
    
    .rf-page-input {
        width: 45px;
        font-size: 15px;
        padding: 6px 10px;
    }
    
    .rf-page-total {
        font-size: 15px;
    }
    
    .rf-thumbnail {
        width: 65px;
    }
    
    /* Fullscreen ESC hint smaller */
    .rf-container.rf-fullscreen::before {
        font-size: 13px;
        padding: 10px 18px;
        top: 15px;
        right: 15px;
    }
}

/* Small mobile (max 480px) */
@media (max-width: 480px) {
    .rf-outer-wrapper {
        padding: 10px 5px !important;
    }
    
    .rf-container {
        padding: 15px;
        margin: 0 auto;
        border-radius: 15px;
        width: 98% !important;
    }
    
    .rf-flipbook-wrapper {
        min-height: 300px;
        padding: 25px 8px;
    }
    
    .rf-controls {
        gap: 8px;
        padding: 12px;
    }
    
    .rf-btn {
        padding: 6px 12px;
        font-size: 14px;
        min-width: 38px;
        height: 38px;
    }
    
    .rf-btn .rf-icon {
        font-size: 16px;
    }
    
    .rf-page-input-wrapper {
        padding: 6px 12px;
    }
    
    .rf-page-input {
        width: 40px;
        font-size: 14px;
        padding: 5px 8px;
    }
    
    .rf-page-total {
        font-size: 14px;
    }
    
    .rf-thumbnail {
        width: 55px;
    }
    
    .rf-thumbnail-track {
        gap: 10px;
        padding: 15px;
    }
}

/* ========================================
   ZOOM LEVEL OPTIMIZATION - FIX #13
   ======================================== */

/* For browser zoom 75% */
@media screen and (min-resolution: 96dpi) and (max-resolution: 120dpi) {
    .rf-container {
        max-width: 1500px !important;
        width: 85% !important;
    }
}

/* For browser zoom 90% */
@media screen and (min-resolution: 120dpi) and (max-resolution: 144dpi) {
    .rf-container {
        max-width: 1400px !important;
        width: 88% !important;
    }
}

/* ========================================
   DARK MODE - FIX #14
   ======================================== */

.rf-container[data-theme="dark"] .rf-page-input-wrapper {
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.rf-container[data-theme="dark"] .rf-page-input {
    background: #2c3e50;
    border-color: #667eea;
    color: #fff;
}

.rf-container[data-theme="dark"] .rf-page-total {
    color: #fff;
}

.rf-container[data-theme="dark"] .rf-thumbnail {
    border-color: rgba(255, 255, 255, 0.2);
}

.rf-container[data-theme="dark"] .rf-thumbnail:hover {
    border-color: rgba(255, 255, 255, 0.6);
}

/* ========================================
   UTILITY CLASSES - FIX #15
   ======================================== */

.rf-hidden {
    display: none !important;
}

.rf-text-center {
    text-align: center !important;
}

.rf-flex-center {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
}

.rf-margin-auto {
    margin-left: auto !important;
    margin-right: auto !important;
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .rf-controls,
    .rf-thumbnail-scrubber,
    .rf-logo {
        display: none !important;
    }
    
    .rf-container {
        box-shadow: none !important;
        background: #fff !important;
    }
    
    .rf-flipbook-wrapper {
        padding: 0 !important;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

.rf-btn:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 3px;
}

.rf-page-input:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

.rf-thumbnail:focus-visible {
    outline: 3px solid #10b981;
    outline-offset: 3px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .rf-btn {
        border: 2px solid #fff;
    }
    
    .rf-thumbnail {
        border-width: 4px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
