/* 
   ====================================================
   PART 1: CodeCanvas Responsive System
   ==================================================== 
*/

/* PART 2: GLOBAL LAYOUT FIXES */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

html, body {
    overflow-x: hidden; /* Prevent horizontal scroll globally */
    width: 100%;
}

.container {
    max-width: 100%;
    margin: 0 auto;
    padding-left: 16px;
    padding-right: 16px;
}

/* Mobile Nav Foundation */
.mobile-menu {
    display: none;
}

.mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-nav-backdrop.is-active {
    opacity: 1;
    visibility: visible;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    z-index: 1003;
    width: 40px;
    height: 40px;
    position: relative;
    transition: background 0.2s ease;
    border-radius: 6px;
    margin-right: -10px; /* Offset padding to align with container edge */
}

.mobile-menu-btn:hover {
    background: rgba(0,0,0,0.05);
}

.mobile-menu-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background-color: var(--color-text-primary, #000);
    position: absolute;
    left: 9px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-menu-btn span:nth-child(1) { top: 14px; }
.mobile-menu-btn span:nth-child(2) { top: 20px; width: 16px; right: 9px; left: auto; }
.mobile-menu-btn span:nth-child(3) { top: 26px; }

.mobile-menu-btn.is-active span:nth-child(1) {
    top: 20px;
    transform: rotate(45deg);
}

.mobile-menu-btn.is-active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-btn.is-active span:nth-child(3) {
    top: 20px;
    transform: rotate(-45deg);
}


/* ====================================================
   LAPTOP BREAKPOINT (<= 1024px)
   ==================================================== */
@media (max-width: 1024px) {
    /* Dashboard Layout Adjustments */
    .dashboard-container {
        flex-direction: column !important; /* Stack sidebar and main */
    }

    .dashboard-sidebar {
        /* Hide sidebar by default on mobile, make it a collapsible drawer */
        position: fixed;
        top: 72px; /* Header height */
        left: -280px; 
        width: 280px;
        height: calc(100vh - 72px);
        background: var(--color-bg, #fff);
        z-index: 1002;
        transition: transform 0.3s ease;
        overflow-y: auto;
        border-right: 1px solid var(--color-border);
    }

    .dashboard-sidebar.is-open {
        transform: translateX(280px);
    }

    .dashboard-main {
        padding: 24px 16px;
        width: 100%;
    }

    .projects-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}


/* ====================================================
   TABLET BREAKPOINT (<= 768px)
   ==================================================== */
@media (max-width: 768px) {
    /* Header & Navigation System */
    .header-content, 
    .dashboard-header-content {
        display: flex !important;
        justify-content: space-between !important;
        width: 100% !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    .mobile-menu-btn {
        display: flex !important;
        margin-left: auto !important; /* Force to far right */
        order: 10; /* Always appear last */
    }

    .logo {
        flex-shrink: 0;
        z-index: 1004; /* Keep above dropdowns if any */
    }

    /* Hide desktop nav & actions in header */
    .header-content .nav, 
    .header-content .header-actions {
        display: none !important;
    }

    /* Slide-in Mobile Menu Styling */
    .mobile-menu {
        position: fixed;
        top: 0;
        right: -300px; /* Slide-in from right */
        width: 300px;
        height: 100vh;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        box-shadow: -10px 0 30px rgba(0,0,0,0.05);
        z-index: 1002;
        padding: 80px 24px 24px;
        transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
        display: flex;
        flex-direction: column;
        overflow-y: auto;
    }

    .mobile-menu.is-active {
        transform: translateX(-300px);
    }

    /* Re-show the cloned nav & actions inside the mobile-menu container */
    .mobile-menu .nav,
    .mobile-menu .header-actions {
        display: flex !important;
    }

    .mobile-menu .nav {
        flex-direction: column;
        gap: 16px;
    }

    .mobile-menu .nav-item {
        width: 100%;
    }

    .mobile-menu .dropdown {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        border: none;
        padding-left: 16px;
        border-left: 2px solid var(--color-border);
        margin-top: 8px;
        display: none; 
    }

    .mobile-menu .nav-item:hover .dropdown,
    .mobile-menu .nav-item.active .dropdown {
        display: block;
    }

    .mobile-menu .header-actions {
        flex-direction: column;
        gap: 12px;
        margin-top: 24px;
        padding-top: 24px;
        border-top: 1px solid var(--color-border);
    }
    
    .mobile-menu .btn {
        width: 100%;
        text-align: center;
    }

    /* Auth Pages Adjustments */
    .auth-container {
        padding: 24px 16px;
        align-items: flex-start;
        padding-top: 60px; /* Center forms vertically but closer to top on mobile */
    }

    .auth-box {
        padding: 0;
    }

    .auth-form {
        padding: 24px 16px;
    }

    .auth-box h1 {
        font-size: 28px;
    }

    .form-group input {
        font-size: 16px !important; /* Avoid zoom issues */
        padding: 14px 12px; /* Stack inputs & larger tap targets */
    }
    
    .btn {
        padding: 14px 20px; /* Larger tap targets */
    }

    /* Dashboard Tables & Grids */
    .projects-grid, 
    .templates-grid, 
    .features-grid, 
    .steps {
        grid-template-columns: 1fr !important; /* Stack single column */
    }

    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Portfolio Template Responsiveness (generic global fixes) */
    .hero, .hero-section, .banner {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
        text-align: center !important;
    }
    .hero-content {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }
    .hero img, .hero-image, .hero-illustration img {
        margin-top: 2rem !important;
        width: 100% !important;
    }
    
    .grid, .columns, .row, .services-grid, .portfolio-grid {
        display: grid !important;
        grid-template-columns: 1fr !important; /* 3/4 column -> 1 column */
        gap: 2rem !important;
    }

    .section, section {
        padding-top: 3rem !important;
        padding-bottom: 3rem !important;
    }

    /* Clamp Typography for headings across all templates */
    h1 { font-size: clamp(2rem, 6vw, 3.5rem) !important; line-height: 1.1 !important; }
    h2 { font-size: clamp(1.5rem, 5vw, 2.5rem) !important; line-height: 1.2 !important; }
    h3 { font-size: clamp(1.25rem, 4vw, 1.75rem) !important; }
    p, li, span, a { font-size: clamp(1rem, 2.5vw, 1.25rem); }

    .btn, button { 
        width: 100% !important; /* Buttons full-width on mobile */
        margin-bottom: 12px;
    }
}


/* ====================================================
   MOBILE BREAKPOINT (<= 480px)
   ==================================================== */
@media (max-width: 480px) {
    .dashboard-page-header h1 {
        font-size: 24px;
    }
    
    .hero-headline {
        font-size: clamp(2rem, 8vw, 2.5rem) !important;
    }
}
