/* Document Reader Styles */

/* Prevent the global navbar from sticking on this reader page */
header.sticky {
    position: relative !important;
}

/* Hide number input arrows for page navigation */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Anti-Piracy: applied to prevent any flash of selectable text */
* {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
}

/* Destroy content on Ctrl+P Print-to-PDF */
@media print {
    body { display: none !important; }
}

body.cinema-mode {
    overflow-x: hidden;
}

body.cinema-mode .global-nav, 
body.cinema-mode header.sticky,
body.cinema-mode footer,
body.cinema-mode #main-navbar {
    display: none !important;
}

body.cinema-mode #reader-main-container {
    max-width: 1400px !important;
    width: 100% !important;
    padding-top: 0 !important;
}

/* Options Menu Dropdown */
#optionsMenu {
    transition: opacity 0.2s ease;
}

#optionsMenu.hidden {
    display: none;
}

#optionsMenu.opacity-0 {
    opacity: 0;
}

#optionsMenu.pointer-events-none {
    pointer-events: none;
}

#reader-main-container {
    transition: max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1), width 0.5s ease;
}

/* PDF and Native Content Container: Allow horizontal scrolling when zoomed */
#pdf-container, 
#secure-content-container {
    transition: width 0.3s ease;
}

/* PDF Wrapper: Parent container for scrolling */
#pdf-container {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Eye Care Tint: Premium 'Midnight Paper' theme */
/* Smart invert: white pages become soft dark + text stays highly legible */
body.tint-enabled #pdf-container canvas {
    filter: invert(0.92) hue-rotate(180deg) brightness(0.92) contrast(0.88);
    border-radius: 2px;
    box-shadow:
        0 0 0 1px rgba(255,255,255,0.04),
        0 4px 24px rgba(0,0,0,0.6),
        0 1px 4px rgba(0,0,0,0.4);
}

#pdf-container canvas {
    transition: filter 0.5s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.5s ease;
}

/* Smooth scrolling behavior for mobile */
@supports (overflow-x: auto) {
    #pdf-container,
    #secure-content-container {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* Ensure proper spacing for scrollbar on mobile */
@media (max-width: 640px) {
    #pdf-container,
    #secure-content-container {
        padding-bottom: 1rem;
    }
}

/* Native mode: anti-piracy measure to prevent selection */
#secure-content-container,
#secure-content-container * {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
}

/* Table of Contents Sidebar (theme-aware) */
#toc-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    background: hsl(var(--background) / 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-right: 1px solid hsl(var(--border));
    z-index: 35;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
}
.dark #toc-sidebar {
    background: hsl(var(--background) / 0.92);
    border-right-color: hsl(var(--border) / 0.6);
}
#toc-sidebar.open {
    transform: translateX(0);
}
#toc-sidebar .toc-header {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 1rem 1rem 0.75rem;
    background: hsl(var(--background) / 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid hsl(var(--border));
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#toc-sidebar .toc-header h3 {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: hsl(var(--muted-foreground));
}
#toc-sidebar .toc-close {
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: calc(var(--radius) - 2px);
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: all 0.15s ease;
}
#toc-sidebar .toc-close:hover {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}
#toc-sidebar .toc-list {
    list-style: none;
    padding: 0.5rem;
}
#toc-sidebar .toc-list li {
    margin: 0;
}
#toc-sidebar .toc-list a {
    display: block;
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
    color: hsl(var(--foreground) / 0.75);
    text-decoration: none;
    border-radius: calc(var(--radius) - 2px);
    transition: all 0.15s ease;
    line-height: 1.4;
    border-left: 2px solid transparent;
    margin-bottom: 1px;
    font-weight: 500;
}
#toc-sidebar .toc-list a:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
    border-left-color: hsl(var(--ring) / 0.4);
}
#toc-sidebar .toc-list a.active {
    background: hsl(var(--primary) / 0.1);
    color: hsl(var(--foreground));
    border-left-color: hsl(var(--primary));
    font-weight: 600;
}
.dark #toc-sidebar .toc-list a.active {
    background: hsl(var(--primary) / 0.15);
}
#toc-sidebar .toc-list .toc-h2 { padding-left: 1.25rem; }
#toc-sidebar .toc-list .toc-h3 { padding-left: 2rem; font-size: 0.76rem; color: hsl(var(--foreground) / 0.6); }
#toc-sidebar .toc-list .toc-h4 { padding-left: 2.75rem; font-size: 0.72rem; color: hsl(var(--foreground) / 0.5); }

/* TOC toggle button */
#toc-toggle-btn {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 36;
    width: 1.75rem;
    height: 3.5rem;
    background: hsl(var(--background) / 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid hsl(var(--border));
    border-left: none;
    border-radius: 0 calc(var(--radius)) calc(var(--radius)) 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
}
#toc-toggle-btn.visible {
    opacity: 1;
    pointer-events: auto;
}
#toc-toggle-btn:hover {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}
#toc-toggle-btn.shifted {
    left: 260px;
}

/* Push content when TOC is open */
body.toc-open #reader-main-container {
    margin-left: 260px;
}

@media (max-width: 768px) {
    #toc-sidebar {
        width: 240px;
    }
    body.toc-open #reader-main-container {
        margin-left: 0;
    }
    #toc-toggle-btn.shifted {
        left: 240px;
    }
}

/* TOC Toggle Switch Styling */
#tocToggleSwitch.active {
    background: hsl(var(--primary));
}
#tocToggleSwitch.active #tocToggleKnob {
    transform: translateX(1rem);
}

/* AI Assistant Toggle Switch Styling */
#aiToggleSwitch.active {
    background: hsl(var(--primary));
}
#aiToggleSwitch.active #aiToggleKnob {
    transform: translateX(1rem);
}

/* Notes Toggle Switch Styling */
#notesToggleSwitch.active {
    background: hsl(var(--primary));
}
#notesToggleSwitch.active #notesToggleKnob {
    transform: translateX(1rem);
}
