/* ==========================================================================
   MODERN DARK-VIEWER STYLES FOR PDF2HTMLEX
   Enhanced dark mode experience for magazine viewer
   ========================================================================== */

/* ==========================================================================
   1. BASE DARK MODE OVERRIDES
   ========================================================================== */

html.dark-mode body,
html.dark-mode #page-container {
    /* Remove original background image and apply dark theme */
    background-image: none !important;
    background-color: #1a1d23 !important;
    color: #c9d1d9;
}

/* Smooth dark gradient for better reading experience */
html.dark-mode body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, #1a1d23 0%, #22272e 50%, #0d1117 100%);
    z-index: -1;
    pointer-events: none;
}

/* ==========================================================================
   2. MAGAZINE PAGES
   ========================================================================== */

html.dark-mode .pf {
    /* Reduce brightness to prevent eye strain */
    filter: brightness(0.88) contrast(1.05);
    
    /* Modern border styling */
    border: 1px solid #30363d !important;
    border-radius: 4px;
    
    /* Enhanced shadow for depth */
    box-shadow: 
        0 4px 16px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.05) !important;
    
    /* Smooth transitions */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hover effect for pages */
html.dark-mode .pf:hover {
/*    filter: brightness(0.92) contrast(1.05);
    box-shadow: 
        0 8px 24px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(255, 255, 255, 0.08) !important;
    transform: translateY(-2px);/*
}

/* Loading state */
html.dark-mode .pf.loading {
    filter: brightness(0.7) contrast(1);
    opacity: 0.6;
}

/* ==========================================================================
   3. VIEWER CONTROLS & BUTTONS
   ========================================================================== */

html.dark-mode .UrlButton,
html.dark-mode .DestButton {
    background-color: rgba(56, 139, 253, 0.15) !important;
    border: 1px solid rgba(56, 139, 253, 0.3) !important;
    color: #58a6ff !important;
    border-radius: 6px;
    padding: 8px 12px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html.dark-mode .UrlButton:hover,
html.dark-mode .DestButton:hover {
    background-color: rgba(56, 139, 253, 0.25) !important;
    border-color: rgba(56, 139, 253, 0.5) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(56, 139, 253, 0.2);
}

html.dark-mode .UrlButton:active,
html.dark-mode .DestButton:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(56, 139, 253, 0.15);
}

/* ==========================================================================
   4. TEXT LAYERS & ANNOTATIONS
   ========================================================================== */

html.dark-mode .textLayer {
    /* Improve text readability */
    color: #c9d1d9 !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

html.dark-mode .textLayer > span {
    background-color: transparent !important;
    color: inherit !important;
}

/* Text selection styling */
html.dark-mode .textLayer ::selection {
    background-color: rgba(56, 139, 253, 0.4);
    color: #ffffff;
}

html.dark-mode .textLayer ::-moz-selection {
    background-color: rgba(56, 139, 253, 0.4);
    color: #ffffff;
}

/* Links in text layer */
html.dark-mode .textLayer a {
    color: #58a6ff !important;
    text-decoration: none;
    border-bottom: 1px solid rgba(88, 166, 255, 0.3);
    transition: all 0.2s;
}

html.dark-mode .textLayer a:hover {
    color: #79c0ff !important;
    border-bottom-color: rgba(121, 192, 255, 0.6);
}

/* ==========================================================================
   5. SIDEBAR & THUMBNAILS
   ========================================================================== */

html.dark-mode #sidebar {
    background-color: #161b22 !important;
    border-right: 1px solid #30363d !important;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
}

html.dark-mode .thumbnail {
    background-color: #21262d !important;
    border: 2px solid #30363d !important;
    border-radius: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html.dark-mode .thumbnail:hover {
    border-color: #58a6ff !important;
    box-shadow: 0 0 0 2px rgba(56, 139, 253, 0.2);
    transform: scale(1.05);
}

html.dark-mode .thumbnail.selected {
    border-color: #58a6ff !important;
    background-color: #0d419d !important;
    box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.3);
}

/* ==========================================================================
   6. NAVIGATION & CONTROLS
   ========================================================================== */

html.dark-mode #controls {
    background-color: rgba(22, 27, 34, 0.95) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid #30363d !important;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
}

html.dark-mode #controls button {
    background: linear-gradient(135deg, #21262d 0%, #30363d 100%) !important;
    border: 1px solid #30363d !important;
    color: #c9d1d9 !important;
    border-radius: 6px;
    padding: 8px 16px;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html.dark-mode #controls button:hover {
    background: linear-gradient(135deg, #30363d 0%, #3d444d 100%) !important;
    border-color: #58a6ff !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

html.dark-mode #controls button:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

html.dark-mode #controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Page number input */
html.dark-mode #page-num {
    background-color: #0d1117 !important;
    border: 1px solid #30363d !important;
    color: #c9d1d9 !important;
    border-radius: 6px;
    padding: 6px 12px;
    font-weight: 500;
}

html.dark-mode #page-num:focus {
    border-color: #58a6ff !important;
    box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.15);
    outline: none;
}

/* ==========================================================================
   7. LOADING INDICATOR
   ========================================================================== */

html.dark-mode #loading-indicator {
    background-color: rgba(22, 27, 34, 0.95) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid #30363d !important;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

html.dark-mode #loading-indicator::after {
    content: '';
    display: block;
    width: 40px;
    height: 40px;
    margin: 10px auto;
    border: 4px solid #30363d;
    border-top-color: #58a6ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==========================================================================
   8. SCROLLBAR STYLING
   ========================================================================== */

html.dark-mode ::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

html.dark-mode ::-webkit-scrollbar-track {
    background: #0d1117;
    border-radius: 6px;
}

html.dark-mode ::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 6px;
    border: 2px solid #0d1117;
}

html.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: #484f58;
}

html.dark-mode ::-webkit-scrollbar-corner {
    background: #0d1117;
}

/* Firefox scrollbar */
html.dark-mode * {
    scrollbar-width: thin;
    scrollbar-color: #30363d #0d1117;
}

/* ==========================================================================
   9. SEARCH HIGHLIGHT
   ========================================================================== */

html.dark-mode .highlight {
    background-color: rgba(210, 153, 34, 0.4) !important;
    border-radius: 2px;
    box-shadow: 0 0 4px rgba(210, 153, 34, 0.6);
}

html.dark-mode .highlight.selected {
    background-color: rgba(210, 153, 34, 0.7) !important;
    box-shadow: 0 0 8px rgba(210, 153, 34, 0.8);
}

/* ==========================================================================
   10. TOOLTIPS & POPOVERS
   ========================================================================== */

html.dark-mode .tooltip {
    background-color: #21262d !important;
    border: 1px solid #30363d !important;
    color: #c9d1d9 !important;
    border-radius: 6px;
    padding: 8px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    font-size: 13px;
    font-weight: 500;
}

html.dark-mode .tooltip::before {
    border-top-color: #30363d !important;
}

/* ==========================================================================
   11. PRINT MODE ADJUSTMENTS
   ========================================================================== */

@media print {
    html.dark-mode body,
    html.dark-mode #page-container {
        background-color: white !important;
        color: black !important;
    }
    
    html.dark-mode .pf {
        filter: none !important;
        border-color: #ccc !important;
        box-shadow: none !important;
    }
    
    html.dark-mode #controls,
    html.dark-mode #sidebar {
        display: none !important;
    }
}

/* ==========================================================================
   12. REDUCED MOTION SUPPORT
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    html.dark-mode *,
    html.dark-mode *::before,
    html.dark-mode *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==========================================================================
   13. HIGH CONTRAST MODE
   ========================================================================== */

@media (prefers-contrast: high) {
    html.dark-mode .pf {
        filter: brightness(0.95) contrast(1.2) !important;
        border-width: 2px !important;
    }
    
    html.dark-mode .UrlButton,
    html.dark-mode .DestButton,
    html.dark-mode #controls button {
        border-width: 2px !important;
    }
}

/* ==========================================================================
   14. FOCUS INDICATORS
   ========================================================================== */

html.dark-mode *:focus-visible {
    outline: 3px solid #58a6ff;
    outline-offset: 2px;
    border-radius: 4px;
}

/* ==========================================================================
   15. CUSTOM SCROLLING AREA
   ========================================================================== */

html.dark-mode #page-container {
    /* Smooth scrolling */
    scroll-behavior: smooth;
    
    /* Better performance */
    will-change: scroll-position;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   16. PAGE TRANSITIONS
   ========================================================================== */

html.dark-mode .pf {
    /* Fade in effect for pages */
    animation: fadeInPage 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeInPage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   17. RESPONSIVE ADJUSTMENTS
   ========================================================================== */

@media (max-width: 768px) {
    html.dark-mode .pf {
        filter: brightness(0.9) contrast(1.05);
        border-radius: 2px;
    }
    
    html.dark-mode #controls {
        padding: 8px;
    }
    
    html.dark-mode #controls button {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    html.dark-mode #sidebar {
        width: 180px;
    }
}

@media (max-width: 480px) {
    html.dark-mode .pf {
        filter: brightness(0.92) contrast(1.03);
        margin: 8px 0;
    }
    
    html.dark-mode #controls button {
        padding: 5px 10px;
        font-size: 12px;
    }
}
