/* ==========================================================================
   RESPONSIVE — All @media queries, mobile/tablet breakpoints, print styles
   Split from custom.css
   ========================================================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .card {
        border-width: 2px;
    }
    .btn {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Hide search on mobile */
@media (max-width: 768px) { .header-search { display: none; } }

/* Mobile: hide floating previews */
@media (max-width: 767px) {
    .directory-preview { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .directory-preview { transition: none !important; }
}

/* Header settings hide on mobile */
@media (max-width: 768px) {
    .header-settings {
        display: none;
    }
}

/* Tool cards stack on tablet */
@media (max-width: 991px) {
    .trading-tools-row {
        flex-direction: column;
    }
}

/* Tablet Responsive (768px - 991px) */
@media (max-width: 991px) and (min-width: 768px) {
    /* Feature cards - 2 per row on tablet */
    .g-3 > .col-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Model architecture - 2 per row */
    .perf-card .col-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Explore buttons - 2 per row */
    .g-3 > .col-3 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 0.5rem;
    }

    /* Backtest metrics - 3 per row */
    .perf-card .col-2 {
        flex: 0 0 33.333%;
        max-width: 33.333%;
        text-align: center;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -260px;
        transition: left 0.3s ease;
        z-index: 1000;
    }

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

    .main-content {
        margin-left: 0 !important;
        padding: 0.75rem !important;
        padding-top: 4rem !important;  /* Space for menu button */
    }

    .mobile-menu-btn {
        display: block !important;
        position: fixed;
        top: 1rem;
        right: 1rem;  /* Move to top-right */
        left: auto !important;
        z-index: 1001;
    }

    .hero-section {
        padding: 1.5rem !important;
    }

    .hero-stats {
        flex-wrap: wrap;
        justify-content: center;
    }

    .hero-stat {
        width: 50%;
        margin-bottom: 1rem;
        text-align: center;
    }

    .hero-title {
        font-size: 2rem !important;
        text-align: center;
    }

    .hero-subtitle {
        text-align: center;
    }

    /* Feature cards - 2 per row on mobile */
    .g-3 > .col-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .feature-card {
        margin-bottom: 1rem;
        padding: 1rem;
    }

    .feature-icon {
        font-size: 1.1rem !important;
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .feature-header {
        gap: 0.5rem;
    }

    /* Model architecture - 2 per row */
    .perf-card .col-4 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 1rem;
    }

    /* Explore buttons - 2 per row, centered */
    .g-3 > .col-3 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 0.5rem;
    }

    .g-3 > .col-3 .btn {
        width: 100%;
    }

    /* Backtest metrics - 2 per row, centered */
    .perf-card .row {
        justify-content: center;
    }

    .perf-card .col-2 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 0.75rem;
        text-align: center;
    }

    .live-ticker {
        display: none;
    }

    /* Tech badges - centered and wrapped */
    .tech-badge {
        font-size: 0.75rem;
        padding: 0.4rem 0.75rem;
    }

    /* Header adjustments */
    .header {
        padding: 0.75rem !important;
    }

    .header-settings {
        display: none;
    }

    /* Mobile header */
    .mobile-header {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        z-index: 998;
        padding: 0 1rem;
        align-items: center;
        justify-content: space-between;
    }

    .content-wrapper {
        margin-top: 70px;
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Scrollable tables */
    .dash-spreadsheet-container {
        overflow-x: auto;
    }

    /* Smaller chart heights */
    .js-plotly-plot {
        min-height: 250px;
    }

    /* Stack time filters */
    .time-range-filters {
        flex-wrap: wrap;
        gap: 0.375rem;
    }

    .time-filter-btn {
        flex: 1 1 30%;
        min-width: calc(33.333% - 0.5rem);
        text-align: center;
    }
}

@media (max-width: 576px) {
    /* Extra small screens - 1 card per row for features */
    .g-3 > .col-4 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Model architecture - still 2 per row */
    .perf-card .col-4 {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Explore buttons - 1 per row on very small screens */
    .g-3 > .col-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .hero-stat {
        width: 50%;
    }

    .sidebar-brand-text {
        display: none;
    }

    h2 {
        font-size: 1.5rem;
    }

    .hero-title {
        font-size: 1.75rem !important;
    }

    /* Trading tools - stack vertically */
    .trading-tools-row {
        flex-direction: column;
    }
}

/* Desktop: hide mobile elements */
@media (min-width: 769px) {
    .mobile-header {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* ===============================================================
   MOBILE RESPONSIVENESS (additional breakpoints)
   =============================================================== */

@media (max-width: 768px) {
    /* Hero section */
    .hero-title { font-size: 1.5rem !important; }
    .hero-stats {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
    }
    .hero-stat { min-width: 45% !important; }

    /* About page - robot + form stack vertically */
    .contact-card > div > div[style*="display: flex"] {
        flex-direction: column !important;
        align-items: center !important;
    }
    #contact-3d-container {
        width: 240px !important;
        height: 240px !important;
    }

    /* Directory cards - full width on mobile */
    .directory-col { flex: 0 0 100% !important; max-width: 100% !important; }

    /* Start Here guide - stack links vertically */
    .start-here-links { flex-direction: column !important; }

    /* Code metrics badge strip - wrap tighter */
    .hero-section + div .perf-card + div {
        gap: 0.35rem !important;
    }

    /* Sidebar overlay on mobile — uses .mobile-open toggled by JS callback */
    .sidebar {
        position: fixed !important;
        z-index: 1000 !important;
        left: -260px !important;
        transition: left 0.3s ease !important;
    }
    .sidebar.mobile-open { left: 0 !important; }

    /* Blog timeline cards */
    .blog-card, .timeline-card {
        padding: 1rem !important;
    }

    /* How It Works - stack steps vertically */
    .chart-container.anim-ready {
        min-width: 100% !important;
    }
}

@media (max-width: 480px) {
    .hero-title { font-size: 1.25rem !important; }
    .hero-stat { min-width: 100% !important; }
    .page-title { font-size: 1.3rem !important; }
    #contact-3d-container {
        width: 200px !important;
        height: 200px !important;
    }
}

/* Print Styles for PDF Export */
@media print {
    .sidebar, .header, .main-header, .live-ticker, .auto-refresh-switch,
    .refresh-slider, .toast-container, .mobile-menu-btn,
    .offcanvas, .offcanvas-backdrop, .modal-backdrop {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    body {
        background: white !important;
        color: black !important;
    }

    .card {
        break-inside: avoid;
        border: 1px solid #ccc !important;
        background: white !important;
    }

    .hero-section {
        background: #f0f0f0 !important;
        color: black !important;
    }

    h1, h2, h3, h4, h5, h6 {
        color: black !important;
    }

    .hero-title, .sidebar-brand-text-only, .header-title.header-gradient,
    .umbrella-brand-logo, .umbrella-brand-sub {
        -webkit-text-fill-color: black !important;
        background: none !important;
    }

    .js-plotly-plot {
        break-inside: avoid;
    }

    @page {
        margin: 1cm;
        size: A4 portrait;
    }
}
