/* Universal Book Reader Styles - Independent of Theme */

/* TOC and Bookmark Toggle Buttons */
.toc-toggle,
.bookmarks-toggle {
    position: fixed;
    top: 20px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 24px;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.toc-toggle {
    left: 20px;
}

.bookmarks-toggle {
    right: 20px;
}

.toc-toggle:hover,
.bookmarks-toggle:hover {
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transform: scale(1.05);
}

/* TOC Sidebar */
.toc-sidebar {
    position: fixed;
    top: 0;
    left: -350px;
    width: 350px;
    height: 100%;
    background: white;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 1100;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.toc-sidebar.open {
    left: 0;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color, #dee2e6);
    background: #f8f9fa;
}

.toc-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color, #333);
}

.toc-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.toc-close:hover {
    background: #e9ecef;
    color: #333;
}

.toc-content {
    padding: 10px 0;
}

.toc-chapter {
    display: block;
    padding: 12px 20px;
    color: var(--text-color, #333);
    text-decoration: none;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.toc-chapter:hover {
    background: #f8f9fa;
}

.toc-chapter-title {
    font-weight: 500;
    font-size: 14px;
}

.toc-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    transition: opacity 0.3s ease;
}

.toc-overlay.show {
    display: block;
}

/* Bookmarks Sidebar */
.bookmarks-sidebar {
    position: fixed;
    top: 0;
    right: -350px;
    width: 350px;
    height: 100%;
    background: white;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 1100;
    transition: right 0.3s ease;
    overflow-y: auto;
}

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

.bookmarks-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color, #dee2e6);
    background: #f8f9fa;
}

.bookmarks-sidebar-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color, #333);
}

.bookmarks-sidebar-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.bookmarks-sidebar-close:hover {
    background: #e9ecef;
    color: #333;
}

.bookmarks-sidebar-content {
    padding: 10px 0;
}

/* Bookmark items in sidebar */
.bookmarks-sidebar .bookmark-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
}

.bookmarks-sidebar .bookmark-item:hover {
    background: #f8f9fa;
}

.bookmarks-sidebar .bookmark-item:last-child {
    border-bottom: none;
}

.bookmarks-sidebar .bookmark-info {
    flex: 1;
    min-width: 0;
}

.bookmarks-sidebar .bookmark-title {
    font-weight: 500;
    font-size: 13px;
    color: #333;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bookmarks-sidebar .bookmark-meta {
    font-size: 11px;
    color: #666;
}

.bookmarks-sidebar .bookmark-actions {
    display: flex;
    gap: 5px;
    margin-left: 10px;
}

.bookmarks-sidebar .bookmark-delete {
    background: #dc3545;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.bookmarks-sidebar .bookmark-delete:hover {
    background: #c82333;
}

.bookmarks-sidebar .no-bookmarks {
    padding: 40px 20px;
    text-align: center;
    color: #666;
    font-style: italic;
}

.bookmarks-sidebar .no-bookmarks div:first-child {
    font-size: 48px;
    margin-bottom: 10px;
}

.bookmarks-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    transition: opacity 0.3s ease;
}

.bookmarks-overlay.show {
    display: block;
}

/* Bookmark System */
.bookmark-container {
    position: relative;
}

/* Ensure bookmark group has relative positioning for JavaScript reference */
.bookmark-group {
    position: relative !important;
    display: inline-block !important;
}

/* Ensure nav controls maintain proper layout */
.nav-controls {
    display: flex !important;
    align-items: center !important;
}

.nav-btn {
    flex-shrink: 0 !important;
}

/* Universal bookmark dropdown styles that override theme positioning */
.bookmarks-dropdown {
    position: fixed !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    min-width: 300px !important;
    max-height: 400px !important;
    overflow-y: auto !important;
    background: white !important;
    border: 1px solid var(--border-color, #dee2e6) !important;
    border-radius: 0.375rem !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
    z-index: 999999 !important;
    margin: 0 !important;
    pointer-events: auto !important;
    user-select: none !important;
    /* Display is controlled by JavaScript - no CSS override */
}

.bookmarks-dropdown.dropdown-up {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15) !important;
}

/* Bookmark dropdown content styling */
.bookmarks-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 15px !important;
    border-bottom: 1px solid var(--border-color, #dee2e6) !important;
    background: #f8f9fa !important;
    border-radius: 0.375rem 0.375rem 0 0 !important;
}

.bookmarks-header h4 {
    margin: 0 !important;
    font-size: 14px !important;
    color: var(--text-primary, #333) !important;
}

.close-dropdown {
    background: none !important;
    border: none !important;
    font-size: 18px !important;
    cursor: pointer !important;
    color: #666 !important;
    padding: 0 !important;
    width: 24px !important;
    height: 24px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 3px !important;
}

.close-dropdown:hover {
    background: #e9ecef !important;
    color: #333 !important;
}

.bookmark-actions-section {
    padding: 10px 15px !important;
    border-bottom: 1px solid var(--border-color, #dee2e6) !important;
}

.save-bookmark-btn {
    width: 100% !important;
    padding: 8px 12px !important;
    background: #007bff !important;
    color: white !important;
    border: none !important;
    border-radius: 0.25rem !important;
    cursor: pointer !important;
    font-size: 0.875rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.5rem !important;
}

.save-bookmark-btn:hover {
    background: #0056b3 !important;
}

.bookmarks-list {
    max-height: 250px !important;
    overflow-y: auto !important;
}

/* Bookmark items for the main bookmarks dropdown */
.bookmarks-dropdown .bookmark-item {
    padding: 12px 15px !important;
    border-bottom: 1px solid var(--border-color, #eee) !important;
    cursor: pointer !important;
    transition: background-color 0.2s !important;
    display: block !important;
}

.bookmarks-dropdown .bookmark-item:hover {
    background: var(--hover-bg, #f8f9fa) !important;
}

.bookmarks-dropdown .bookmark-item:last-child {
    border-bottom: none !important;
}

/* Legacy bookmark dropdown support */
.bookmark-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 280px;
    max-height: 400px;
    overflow-y: auto;
    background: white;
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 0.375rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
}

.bookmark-dropdown.show {
    display: block;
}

.bookmark-item {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color, #eee);
    cursor: pointer;
    transition: background-color 0.2s;
}

.bookmark-item:hover {
    background: var(--hover-bg, #f8f9fa);
}

.bookmark-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bookmark-preview {
    font-size: 0.875rem;
    color: var(--text-muted, #6b7280);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bookmark-meta {
    font-size: 0.75rem;
    color: var(--text-muted, #9ca3af);
    margin-top: 0.25rem;
}

/* Chapter Navigation */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2rem 0;
    margin-top: 3rem;
    border-top: 1px solid var(--border-color, #eee);
}

.chapter-nav-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--secondary-bg, #f8f9fa);
    border: 1px solid var(--border-color, #dee2e6);
    border-radius: 0.375rem;
    text-decoration: none;
    color: var(--text-color, #374151);
    transition: all 0.2s;
}

.chapter-nav-button:hover {
    background: var(--hover-bg, #e9ecef);
    transform: translateY(-1px);
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Adjust toggle buttons for mobile */
    .toc-toggle,
    .bookmarks-toggle {
        width: 44px;
        height: 44px;
        font-size: 20px;
        top: 15px;
    }

    .toc-toggle {
        left: 15px;
    }

    .bookmarks-toggle {
        right: 15px;
    }

    /* Full width sidebars on mobile */
    .toc-sidebar,
    .bookmarks-sidebar {
        width: 85vw;
        max-width: 300px;
    }

    .toc-sidebar {
        left: -85vw;
    }

    .bookmarks-sidebar {
        right: -85vw;
    }

    .nav-buttons {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .toc-dropdown,
    .bookmark-dropdown {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90vw;
        max-width: 400px;
        max-height: 70vh;
    }
    
    .chapter-nav {
        flex-direction: column;
        gap: 1rem;
    }
    
    .chapter-nav-button {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    /* Smaller toggle buttons for very small screens */
    .toc-toggle,
    .bookmarks-toggle {
        width: 40px;
        height: 40px;
        font-size: 18px;
        top: 10px;
    }

    .toc-toggle {
        left: 10px;
    }

    .bookmarks-toggle {
        right: 10px;
    }

    /* Even narrower sidebars */
    .toc-sidebar,
    .bookmarks-sidebar {
        width: 90vw;
        max-width: none;
    }

    .book-nav {
        padding: 0.75rem;
    }
    
    .nav-buttons {
        justify-content: center;
    }
    
    .bookmark-item,
    .toc-item {
        padding: 1rem;
    }
}

/* Print Styles */
@media print {
    .book-nav,
    .reading-progress,
    .toc-dropdown,
    .bookmark-dropdown,
    .chapter-nav {
        display: none !important;
    }
}