/* 
   Responsive Design Enhancements for Options Trading Strategy Website
   Created: April 19, 2025
*/

/* ===== MOBILE NAVIGATION ===== */
@media (max-width: 768px) {
    /* Create hamburger menu for mobile */
    .mobile-menu-toggle {
        display: block;
        position: absolute;
        top: 1.5rem;
        right: 1.5rem;
        font-size: 1.5rem;
        color: var(--text-light);
        cursor: pointer;
        z-index: 1001;
    }
    
    nav ul {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background-color: var(--primary-color);
        flex-direction: column;
        justify-content: center;
        align-items: center;
        z-index: 1000;
    }
    
    nav ul.active {
        display: flex;
    }
    
    nav ul li {
        margin: 1rem 0;
    }
    
    nav ul li a {
        font-size: 1.2rem;
    }
    
    /* Adjust header layout */
    header .container {
        flex-direction: column;
        padding: 1rem 0;
    }
    
    .logo {
        margin-bottom: 1rem;
        text-align: center;
    }
}

/* ===== RESPONSIVE LAYOUT ADJUSTMENTS ===== */
@media (max-width: 992px) {
    /* Adjust section padding */
    section {
        padding: 3rem 0;
    }
    
    /* Adjust hero section */
    #hero {
        padding: 8rem 0 4rem;
    }
    
    .hero-content h2 {
        font-size: 2.8rem;
    }
    
    .hero-content p {
        font-size: 1.2rem;
    }
    
    /* Adjust overview section */
    .overview-content {
        flex-direction: column;
    }
    
    .overview-text, .overview-stats {
        min-width: 100%;
    }
    
    /* Adjust performance section */
    .performance-charts {
        flex-direction: column;
    }
    
    .chart {
        min-width: 100%;
        margin-bottom: 2rem;
    }
    
    /* Adjust strategy components */
    .strategy-components {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
    
    /* Adjust implementation section */
    .implementation-content {
        flex-direction: column;
    }
    
    .implementation-steps, .implementation-timeline {
        min-width: 100%;
    }
    
    /* Adjust resources section */
    .resources-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

@media (max-width: 576px) {
    /* Further adjustments for small screens */
    .container {
        width: 95%;
    }
    
    /* Adjust hero section */
    .hero-content h2 {
        font-size: 2.2rem;
    }
    
    .hero-content p {
        font-size: 1rem;
    }
    
    /* Adjust stat boxes */
    .overview-stats {
        flex-direction: column;
    }
    
    .stat-box {
        min-width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Adjust performer cards */
    .performer-card {
        min-width: 100%;
        margin-bottom: 1rem;
    }
    
    /* Adjust tables */
    .comparison-table {
        font-size: 0.9rem;
    }
    
    table th, table td {
        padding: 0.75rem;
    }
    
    /* Adjust footer */
    .footer-content {
        flex-direction: column;
        text-align: center;
    }
    
    .footer-links ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .footer-links ul li {
        margin: 0 0.5rem;
    }
}

/* ===== RESPONSIVE IMAGES ===== */
@media (max-width: 768px) {
    .chart img {
        max-width: 100%;
        height: auto;
    }
}

/* ===== RESPONSIVE FORMS ===== */
@media (max-width: 768px) {
    /* Adjust calculator form */
    .calculator-form {
        padding: 1.5rem;
    }
    
    .calculator-section {
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
    }
    
    .calculator-result {
        flex-direction: column;
        gap: 1rem;
    }
    
    .score-display {
        width: 100%;
        padding: 1rem;
    }
    
    .score-interpretation {
        width: 100%;
        text-align: center;
    }
    
    /* Adjust visualizer */
    .visualizer-display {
        flex-direction: column;
        padding: 1.5rem;
    }
    
    .chart-container, .setup-details {
        min-width: 100%;
    }
}

/* ===== RESPONSIVE TYPOGRAPHY ===== */
@media (max-width: 576px) {
    h1 {
        font-size: 1.8rem;
    }
    
    h2 {
        font-size: 1.6rem;
    }
    
    h3 {
        font-size: 1.4rem;
    }
    
    h4 {
        font-size: 1.2rem;
    }
    
    p {
        font-size: 0.95rem;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
    
    .btn-small {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    header, footer, .btn, .btn-small {
        display: none;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background-color: #fff;
    }
    
    .container {
        width: 100%;
        max-width: 100%;
        padding: 0;
        margin: 0;
    }
    
    section {
        padding: 1rem 0;
        page-break-inside: avoid;
    }
    
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
    
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
    
    table {
        page-break-inside: avoid;
    }
    
    a:after {
        content: " (" attr(href) ")";
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) {
    /* Optimize for touch devices */
    .btn, .btn-small {
        padding-top: 12px;
        padding-bottom: 12px;
    }
    
    nav ul li a {
        padding: 0.75rem;
    }
    
    .component, .stat-box, .performer-card, .resource-card {
        transform: none !important;
    }
    
    /* Increase tap target sizes */
    .collapsible-header {
        padding: 1.25rem;
    }
    
    .form-control {
        padding: 0.85rem;
    }
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #000;
        --secondary-color: #0000EE;
        --accent-color: #CC0000;
        --light-color: #FFF;
        --dark-color: #000;
        --success-color: #006600;
        --warning-color: #CC6600;
        --danger-color: #CC0000;
        --text-color: #000;
        --text-light: #FFF;
    }
    
    body {
        background-color: #FFF;
    }
    
    a, button, .btn, .btn-small {
        text-decoration: underline;
    }
}

/* ===== MOBILE MENU JAVASCRIPT ===== */
document.addEventListener('DOMContentLoaded', function() {
    // Create mobile menu toggle button
    const header = document.querySelector('header .container');
    const nav = document.querySelector('nav');
    const navUl = document.querySelector('nav ul');
    
    const mobileMenuToggle = document.createElement('div');
    mobileMenuToggle.className = 'mobile-menu-toggle';
    mobileMenuToggle.innerHTML = '<i class="fas fa-bars"></i>';
    header.appendChild(mobileMenuToggle);
    
    // Toggle mobile menu
    mobileMenuToggle.addEventListener('click', function() {
        navUl.classList.toggle('active');
        
        // Change icon based on menu state
        if (navUl.classList.contains('active')) {
            mobileMenuToggle.innerHTML = '<i class="fas fa-times"></i>';
        } else {
            mobileMenuToggle.innerHTML = '<i class="fas fa-bars"></i>';
        }
    });
    
    // Close menu when clicking a link
    const navLinks = document.querySelectorAll('nav ul li a');
    navLinks.forEach(link => {
        link.addEventListener('click', function() {
            navUl.classList.remove('active');
            mobileMenuToggle.innerHTML = '<i class="fas fa-bars"></i>';
        });
    });
    
    // Close menu when clicking outside
    document.addEventListener('click', function(event) {
        if (!nav.contains(event.target) && !mobileMenuToggle.contains(event.target)) {
            navUl.classList.remove('active');
            mobileMenuToggle.innerHTML = '<i class="fas fa-bars"></i>';
        }
    });
    
    // Responsive image loading
    function handleResponsiveImages() {
        const windowWidth = window.innerWidth;
        const images = document.querySelectorAll('img[data-src-mobile]');
        
        images.forEach(img => {
            if (windowWidth <= 768 && img.hasAttribute('data-src-mobile')) {
                img.src = img.getAttribute('data-src-mobile');
            } else if (img.hasAttribute('data-src-desktop')) {
                img.src = img.getAttribute('data-src-desktop');
            }
        });
    }
    
    // Initial call and resize listener
    handleResponsiveImages();
    window.addEventListener('resize', handleResponsiveImages);
    
    // Adjust table display for small screens
    function handleResponsiveTables() {
        const windowWidth = window.innerWidth;
        const tables = document.querySelectorAll('table');
        
        tables.forEach(table => {
            if (windowWidth <= 576) {
                if (!table.classList.contains('responsive-table')) {
                    table.classList.add('responsive-table');
                    
                    // Get headers
                    const headers = Array.from(table.querySelectorAll('th')).map(th => th.textContent);
                    
                    // Add data attributes to cells
                    const rows = table.querySelectorAll('tbody tr');
                    rows.forEach(row => {
                        const cells = row.querySelectorAll('td');
                        cells.forEach((cell, index) => {
                            if (headers[index]) {
                                cell.setAttribute('data-label', headers[index]);
                            }
                        });
                    });
                }
            } else {
                table.classList.remove('responsive-table');
            }
        });
    }
    
    // Initial call and resize listener
    handleResponsiveTables();
    window.addEventListener('resize', handleResponsiveTables);
    
    // Add CSS for responsive tables
    const style = document.createElement('style');
    style.textContent = `
        @media (max-width: 576px) {
            .responsive-table thead {
                display: none;
            }
            
            .responsive-table tbody tr {
                display: block;
                margin-bottom: 1rem;
                border: 1px solid #eee;
                border-radius: var(--border-radius);
            }
            
            .responsive-table tbody td {
                display: block;
                text-align: right;
                padding: 0.75rem;
                border-bottom: 1px solid #eee;
            }
            
            .responsive-table tbody td:last-child {
                border-bottom: none;
            }
            
            .responsive-table tbody td:before {
                content: attr(data-label);
                float: left;
                font-weight: 600;
            }
        }
    `;
    document.head.appendChild(style);
});
