/* =========================================
   Mobile Responsiveness for Funbun Docs
   ========================================= */

/* --- Tablet & Smaller (Max-width: 1024px) --- */
@media (max-width: 1024px) {
    /* Adjust Main Content Width */
    main {
        width: 100%;
        margin-left: 0;
        padding: 20px;
    }

    /* Adjust specific sections */
    .list-section ul {
        padding-left: 10px;
    }
    
    .doc-section {
        padding-bottom: 20px;
    }
    
    /* FIX: Content Width - Reset large desktop margins/paddings */
    .doc-body, .sub-inner-main, .sub-sub-inner-main, .list-section, .content-inner {
        margin-left: 0 !important;
        padding-left: 0 !important;
        margin-right: 0 !important;
        padding-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Ensure lists have *some* visual indentation but not too much */
    .doc-body ul, .doc-body ol {
        padding-left: 20px !important;
    }
    
    /* Fix potential overflow from code blocks containers */
    div[class*="language-"], pre, .code-box {
        max-width: 100% !important;
        overflow-x: auto !important;
        word-wrap: break-word !important;
    }

    /* FIX: Layout for Contact Section (Footer) */
    .contact-blog {
        padding: 30px 20px !important;
        margin-left: 0 !important; /* override space-start */
    }
    /* Header Adjustments */
    img {
        max-width: 100% !important;
        height: auto !important;
    }
    .header {
        padding-left: 0;
        height: auto;
        padding-top: 10px;
        padding-bottom: 10px;
        position: fixed;
        background-color: #fff; /* Ensure bg is opaque */
        width: 100% !important;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .page-head-inner {
        padding: 0 15px;
        width: 100%;
    }
    
    /* Wrapper to align Hamburger + Logo */
    .mobile-header-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        margin-bottom: 10px;
    }

    /* Adjust Menu Bar (Hamburger) positioning */
    .header .menu-bar {
        display: block !important;
        position: absolute; 
        left: 20px;
        top: 25px; 
        z-index: 10001; /* High z-index to sit on top */
        cursor: pointer;
        pointer-events: auto;
    }
    
    .menu-bar-icon span {
        background-color: #38080f !important; /* Ensure color is visible */
        height: 3px;
        width: 25px;
        display: block;
        margin-bottom: 5px;
    }
    
    /* Adjust Brand Logo to not overlap with hamburger */
    .brand-logo.logo-md {
        display: flex;
        align-items: center;
        justify-content: center; /* Center logo in the header space */
        width: 100%;
        margin-left: 0;
        padding-left: 0;
        margin-bottom: 15px;
        padding-top: 5px; /* Slight adjustment */
    }
    
    .logoText {
        font-size: 1.4rem;
        margin-left: 8px;
    }

    /* Navigation Tabs in Header */
    .content-tabs {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-left: 0;
        width: 100%;
    }
    
    /* Mobile Tabs Styling */
    .nav-tabs {
        width: 100%;
        margin-top: 5px;
        justify-content: center !important;
        border-bottom: 1px solid #dee2e6;
        display: flex;
        flex-wrap: nowrap; /* Keep on one line if possible */
    }
    
    .nav-item {
        flex: 1;
        text-align: center;
    }
    
    .nav-item .nav-link {
        width: 100%;
        border-radius: 0;
        padding: 10px 5px !important;
        white-space: nowrap;
    }

    /* FIX: Force main sidebar to be visible (rendered) but off-screen by default */
    body > nav {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 10002 !important; 
        width: 280px; 
        position: fixed;
        height: 100vh; /* Fallback */
        height: 100dvh; /* Modern mobile browsers */
        top: 0;
        left: 0;
        border-right: 1px solid #ddd;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        background-color: #fff !important; 
        display: flex !important;
        flex-direction: column;
        padding-top: 0 !important;
        overflow: hidden; /* Prevent body scroll */
    }
    
    /* Ensure containers are visible and reset - Specificity Boost against Bootstrap .d-none */
    .sidenav, .doc-sidebar, .doc-nav, .doc-sidebar.d-none, .d-none.d-md-flex {
        display: flex !important;
        flex-direction: column;
        flex: 1;
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0; /* Critical for flex scrolling */
        float: none !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important; 
        top: auto !important;
        left: auto !important;
    }
    
    /* Target valid ID for specificity */
    #doc-menu {
        display: block !important;
        flex: 1;
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        max-height: none !important; /* Let flex handle it */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch; /* smooth scrolling iOS */
        background: transparent !important; 
        top: auto !important;
        left: auto !important;
        float: none !important;
        box-shadow: none !important;
        margin: 0 !important;
        padding-bottom: 50px !important; /* Extra bottom space for safe scrolling */
    }
    
    /* Reset nav links color/style just in case */
    #doc-menu a.nav-link {
        color: #333 !important;
        display: block !important;
        padding: 10px 15px !important;
        font-size: 15px !important;
    }

    /* Active Sidebar State (Toggled via JS) */
    body.sidebar-open > nav {
        transform: translateX(0);
    }
}

/* --- Mobile (Max-width: 768px) --- */
@media (max-width: 768px) {
    /* ... existing styles ... */
    
    /* Content Adjustments */
    main, .content-inner {
        padding: 15px;
        margin-top: 220px !important; 
        width: 100% !important; /* Fix squashed content */
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    .main-inner {
        width: 100% !important; /* Use full width on mobile */
        padding: 0 10px;
    }
    
    /* ... existing styles ... */
}

/* --- Small Mobile (Max-width: 480px) --- */
@media (max-width: 480px) {
    .logoText {
        font-size: 1.2rem;
    }
    
    .nav-item .nav-link {
        font-size: 13px;
        padding: 8px 10px !important;
    }
    
    /* REMOVED conflicting margin-top to respect the 768px rule */
    
    /* Ensure buttons are touch friendly */
    a, button, input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* FIX: Force Iframes to be responsive and override inline sizes */
    iframe, .embed-responsive iframe, video, object {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 16/9 !important;
        max-width: 100% !important;
    }
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999; /* Below nav (9999) but above content */
    display: none;
}

body.sidebar-open .sidebar-overlay {
    display: block;
}
