/**
 * Mobile Responsive Overrides
 * Critical mobile styles with high specificity
 * Ensures proper display on GitHub Pages
 */

/* Mobile Menu Toggle - Always visible on mobile */
@media screen and (max-width: 768px) {
    .mobile-menu-toggle {
        display: block !important;
        background: transparent !important;
        border: none !important;
        color: #ffffff !important;
        font-size: 1.5rem !important;
        padding: 0.5rem !important;
        cursor: pointer !important;
        margin-right: 1rem !important;
        flex-shrink: 0 !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998 !important;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.mobile-overlay.active {
    display: block !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* Responsive breakpoints with high specificity */
@media screen and (max-width: 1024px) {
    #sidebar,
    .sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        transform: translateX(-100%) !important;
        z-index: 9999 !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3) !important;
        transition: transform 0.3s ease !important;
        width: 320px !important;
    }
    
    #sidebar.mobile-open,
    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }
    
    #main-content,
    .main-container {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    .mobile-overlay {
        display: block !important;
    }
}

@media screen and (max-width: 768px) {
    #header,
    .header {
        padding: 1rem !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        min-height: auto !important;
        display: flex !important;
        align-items: center !important;
    }
    
    .header-title {
        flex: 1 !important;
        min-width: 0 !important;
        order: 2 !important;
    }
    
    .header-title h1 {
        font-size: 1.125rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin: 0 !important;
        color: #ffffff !important;
    }
    
    .header-subtitle {
        display: none !important;
    }
    
    #search-container,
    .search-container {
        display: none !important;
    }
    
    .header-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        width: 100% !important;
        justify-content: space-between !important;
        order: 3 !important;
        margin-top: 0.5rem !important;
    }
    
    .header-actions .module-btn {
        font-size: 0.85rem !important;
        padding: 6px 10px !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-width: calc(50% - 0.25rem) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 5px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
    }
    
    .header-actions .module-btn i {
        font-size: 0.9rem !important;
        flex-shrink: 0 !important;
    }
    
    .header-actions .module-btn span {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
}

@media screen and (max-width: 480px) {
    #sidebar,
    .sidebar {
        width: 280px !important;
        max-width: 85% !important;
    }
    
    #header,
    .header {
        padding: 0.5rem !important;
        gap: 0.25rem !important;
    }
    
    .mobile-menu-toggle {
        padding: 0.25rem !important;
        font-size: 1.25rem !important;
        margin-right: 0.5rem !important;
    }
    
    .header-title h1 {
        font-size: 0.95rem !important;
        line-height: 1.2 !important;
    }
    
    .header-actions {
        gap: 4px !important;
        margin-top: 0.25rem !important;
    }
    
    .header-actions .module-btn {
        font-size: 0.75rem !important;
        padding: 5px 6px !important;
        flex: 1 1 0 !important;
        max-width: none !important;
        min-width: 0 !important;
    }
    
    .header-actions .module-btn span {
        display: none !important;
    }
    
    .header-actions .module-btn i {
        margin: 0 !important;
        font-size: 1rem !important;
    }
    
    #content,
    .content {
        padding: 1rem !important;
    }
    
    .section-body {
        padding: 1rem !important;
    }
}

/* Extra small screens */
@media screen and (max-width: 360px) {
    .header-actions .module-btn {
        font-size: 0.7rem !important;
        padding: 4px 4px !important;
    }
    
    .header-actions .module-btn i {
        font-size: 0.9rem !important;
    }
    
    .header-title h1 {
        font-size: 0.85rem !important;
    }
}

/* Ensure mobile menu toggle is clickable */
.mobile-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.1) !important;
}

.mobile-menu-toggle:active {
    background: rgba(255, 255, 255, 0.2) !important;
}

/* Fix for iOS Safari */
@supports (-webkit-touch-callout: none) {
    .mobile-menu-toggle {
        -webkit-tap-highlight-color: transparent;
    }
    
    #sidebar {
        -webkit-transform: translateX(-100%);
    }
    
    #sidebar.mobile-open {
        -webkit-transform: translateX(0);
    }
}

/* Ensure visibility of navigation elements */
#navigation {
    height: 100%;
    overflow-y: auto;
}

/* Fix z-index stacking on mobile */
@media screen and (max-width: 768px) {
    #toast-container {
        z-index: 10000 !important;
    }
    
    .modal-container {
        z-index: 10001 !important;
    }
}