/**
 * Premium Features CSS
 * Bookmarks, Animated Stats, Comment Reactions, 
 * Sticky TOC, Infinite Scroll
 * Note: Reading Streak & Gamification now in unified-progress.css
 */

/* ================================
   BOOKMARK BUTTON & SYSTEM
   ================================ */
.bookmark-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    color: #64748b;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.bookmark-button:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.bookmark-button.bookmarked {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

.bookmark-button.bookmarked:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.bookmark-notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #1e293b;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 99997;
    opacity: 0;
    transition: all 0.3s ease;
    font-weight: 600;
}

.bookmark-notification.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ================================
   ANIMATED STATS
   ================================ */
.stat-number,
.stat-value,
.animated-number {
    display: inline-block;
    font-variant-numeric: tabular-nums;
}

.stat-number.animated,
.stat-value.animated,
.animated-number.animated {
    animation: countUp 0.3s ease;
}

@keyframes countUp {
    from { opacity: 0.5; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ================================
   COMMENT REACTIONS
   ================================ */
.comment-reactions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

.reaction-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.reaction-btn:hover {
    background: #e2e8f0;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.reaction-btn.reacted {
    animation: reactionPop 0.6s ease;
}

@keyframes reactionPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.reaction-count {
    font-weight: 600;
    color: #64748b;
    min-width: 16px;
    text-align: center;
}

/* Dark Mode for Reactions */
body.dark-mode .comment-reactions {
    border-top-color: #334155;
}

body.dark-mode .reaction-btn {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

body.dark-mode .reaction-btn:hover {
    background: #334155;
}

body.dark-mode .reaction-count {
    color: #cbd5e1;
}

/* ================================
   STICKY TABLE OF CONTENTS
   ================================ */
.sticky-toc {
    position: fixed;
    right: 20px;
    top: 120px;
    width: 320px;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    padding: 0;
    max-height: calc(100vh - 160px);
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    backdrop-filter: blur(10px);
}

.sticky-toc.collapsed {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-color: #3b82f6;
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
}

.sticky-toc.collapsed:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(59, 130, 246, 0.5);
}

.sticky-toc.collapsed .toc-nav {
    display: none;
}

.sticky-toc.collapsed .toc-header h4 {
    display: none;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-radius: 18px 18px 0 0;
    margin: 0;
}

.sticky-toc.collapsed .toc-header {
    padding: 0;
    background: transparent;
    border-radius: 50%;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toc-header h4 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toc-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.sticky-toc.collapsed .toc-toggle {
    background: transparent;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    font-size: 1.5rem;
}

.toc-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.sticky-toc.collapsed .toc-toggle:hover {
    transform: rotate(180deg);
}

.toc-nav {
    padding: 20px 24px 24px;
    max-height: calc(100vh - 240px);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom Scrollbar */
.toc-nav::-webkit-scrollbar {
    width: 6px;
}

.toc-nav::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.toc-nav::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.toc-nav::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-item {
    margin-bottom: 4px;
    transition: all 0.3s ease;
}

.toc-h3 {
    padding-left: 16px;
}

.toc-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: #64748b;
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    position: relative;
    overflow: hidden;
    line-height: 1.5;
}

.toc-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.1), transparent);
    transition: width 0.3s ease;
}

.toc-link:hover::before {
    width: 100%;
}

.toc-link:hover {
    background: #f1f5f9;
    color: #2563eb;
    transform: translateX(4px);
    padding-left: 18px;
}

.toc-link.active {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    color: #2563eb;
    border-left-color: #3b82f6;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
}

.toc-link.active::after {
    content: '→';
    margin-left: auto;
    font-weight: bold;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Dark Mode for TOC */
body.dark-mode .sticky-toc {
    background: #1e293b;
    border-color: #334155;
}

body.dark-mode .toc-header h4 {
    color: #f1f5f9;
}

body.dark-mode .toc-toggle {
    background: #334155;
    color: #e2e8f0;
}

body.dark-mode .toc-toggle:hover {
    background: #475569;
}

body.dark-mode .toc-link {
    color: #cbd5e1;
}

body.dark-mode .toc-link:hover {
    background: #334155;
    color: #60a5fa;
}

body.dark-mode .toc-link.active {
    background: #1e3a8a;
    color: #60a5fa;
    border-left-color: #60a5fa;
}

/* ================================
   INFINITE SCROLL
   ================================ */
.infinite-scroll-trigger {
    height: 1px;
    margin: 60px 0;
}

.infinite-scroll-loading {
    text-align: center;
    padding: 40px 20px;
    display: none;
}

.infinite-scroll-loading::after {
    content: '';
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ================================
   DARK MODE
   ================================ */
body.dark-mode .bookmark-button {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

body.dark-mode .bookmark-button:hover {
    background: #334155;
    border-color: #475569;
}

body.dark-mode .bookmark-button.bookmarked {
    background: #2563eb;
    border-color: #2563eb;
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 1400px) {
    .sticky-toc {
        width: 240px;
        font-size: 0.85rem;
    }
}

@media (max-width: 1200px) {
    .sticky-toc {
        display: none; /* Hide TOC on smaller screens to prevent overlap */
    }
}

@media (max-width: 768px) {
    .comment-reactions {
        flex-wrap: wrap;
    }
    
    .bookmark-notification {
        left: 10px;
        right: 10px;
        transform: translateX(0) translateY(100px);
    }
    
    .bookmark-notification.show {
        transform: translateX(0) translateY(0);
    }
}

/* Smooth scroll for TOC links */
html {
    scroll-behavior: smooth;
}
