/**
 * DevSyntax - JavaScript Enhancement Styles
 * Styles for JS-powered features
 */

/* ========================================
   1. STICKY HEADER
   ======================================== */
header {
    transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

header.is-sticky {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    background-color: var(--white);
}

/* ========================================
   2. MOBILE MENU
   ======================================== */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    font-size: var(--text-2xl);
    color: var(--text-primary);
    transition: transform 0.2s ease;
}

.mobile-menu-btn:hover {
    transform: scale(1.1);
}

.mobile-menu {
    display: none;
}

body.mobile-menu-open {
    overflow: hidden;
}

@media (max-width: 1023px) {
    .mobile-menu-btn {
        display: block;
    }
    
    .mobile-menu {
        display: block;
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: var(--white);
        box-shadow: var(--shadow-2xl);
        padding: var(--space-6);
        z-index: 2000;
        transition: right 0.3s ease-in-out;
        overflow-y: auto;
    }
    
    .mobile-menu.is-open {
        right: 0;
    }
    
    /* Overlay */
    body.mobile-menu-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1500;
    }
}

/* ========================================
   3. STICKY SIDEBAR / TOC
   ======================================== */
.toc {
    position: sticky;
    top: 120px;
    transition: position 0.2s ease;
}

@media (max-width: 1023px) {
    .toc {
        position: relative !important;
        top: auto !important;
    }
}

/* ========================================
   4. TOC ACTIVE LINK
   ======================================== */
.toc-links a {
    display: block;
    padding: var(--space-2) var(--space-3);
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    font-size: var(--text-sm);
}

.toc-links a:hover {
    color: var(--color-primary-600);
    background-color: var(--color-primary-50);
    border-left-color: var(--color-primary-300);
}

.toc-links a.active {
    color: var(--color-primary-700);
    background-color: var(--color-primary-100);
    border-left-color: var(--color-primary-600);
    font-weight: var(--font-semibold);
}

/* ========================================
   5. READING PROGRESS BAR
   ======================================== */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background-color: var(--bg-secondary);
    z-index: 9999;
}

.reading-progress-bar {
    height: 100%;
    background: linear-gradient(
        90deg,
        var(--color-primary-600) 0%,
        var(--color-info-500) 50%,
        var(--color-success-500) 100%
    );
    width: 0%;
    transition: width 0.1s ease-out;
}

/* ========================================
   6. SMOOTH SCROLL BEHAVIOR
   ======================================== */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* Focus target after smooth scroll */
[tabindex="-1"]:focus {
    outline: 2px dashed var(--color-primary-500);
    outline-offset: 4px;
}

/* ========================================
   7. LAZY LOADING IMAGES
   ======================================== */
img.lazy {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

img.lazy:not(.lazy) {
    opacity: 1;
}

/* Placeholder while loading */
img.lazy {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 0%,
        var(--bg-tertiary) 50%,
        var(--bg-secondary) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========================================
   8. COPY CODE BUTTON
   ======================================== */
.code-block-wrapper {
    position: relative;
}

.copy-code-btn {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-primary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.copy-code-btn:hover {
    background: var(--color-primary-600);
    color: var(--white);
    border-color: var(--color-primary-600);
}

.copy-code-btn.copied {
    background: var(--color-success-600);
    color: var(--white);
    border-color: var(--color-success-600);
}

/* ========================================
   9. FOCUS VISIBLE (Keyboard Navigation)
   ======================================== */
body:not(.user-is-tabbing) button:focus,
body:not(.user-is-tabbing) a:focus,
body:not(.user-is-tabbing) input:focus {
    outline: none;
}

body.user-is-tabbing button:focus,
body.user-is-tabbing a:focus,
body.user-is-tabbing input:focus {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

/* ========================================
   10. LOADING STATES
   ======================================== */
.is-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid var(--color-primary-300);
    border-top-color: var(--color-primary-600);
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

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

/* ========================================
   11. TRANSITIONS FOR JS-ADDED CLASSES
   ======================================== */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

.fade-out {
    animation: fadeOut 0.3s ease-out;
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

.slide-down {
    animation: slideDown 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

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

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ========================================
   12. PRINT STYLES
   ======================================== */
@media print {
    .reading-progress,
    .mobile-menu-btn,
    .copy-code-btn,
    .ad-unit {
        display: none !important;
    }
    
    header {
        position: static !important;
        box-shadow: none !important;
    }
}

