/**
 * Mobile Responsive Fixes for Projects List
 * This file contains specific fixes for mobile issues:
 * - Overlay blocking interactions
 * - Buttons not clickable
 * - UI elements inaccessible on small screens
 * - Modal display issues
 * - Dropdown accessibility
 */

/* ==========================================
   FIX 1: Remove blocking overlay on mobile
   ========================================== */
@media (max-width: 768px) {
    /* Hide the overlay by default */
    .layout-overlay.layout-menu-toggle {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
        z-index: 1080 !important;
    }
    
    /* When menu is actually open, show overlay */
    html.layout-menu-expanded .layout-overlay.layout-menu-toggle,
    body.layout-menu-expanded .layout-overlay.layout-menu-toggle {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
}

/* ==========================================
   FIX 2: Ensure buttons are clickable
   ========================================== */
@media (max-width: 768px) {
    /* All interactive elements must have proper z-index */
    .btn,
    button,
    a[href],
    [onclick],
    [role="button"],
    input[type="submit"],
    input[type="button"],
    input[type="reset"] {
        position: relative !important;
        z-index: 100 !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(0, 123, 255, 0.3);
        cursor: pointer !important;
        pointer-events: auto !important;
    }
    
    /* Ensure button groups work properly */
    .btn-group {
        z-index: 101 !important;
    }
    
    .btn-group .btn {
        z-index: 102 !important;
    }
}

/* ==========================================
   FIX 3: Projects table mobile optimization
   ========================================== */
@media (max-width: 768px) {
    /* Reduce font size for better fit */
    #projects_table {
        font-size: 12px;
    }
    
    /* Make table header sticky */
    #projects_table thead th {
        position: sticky;
        top: 0;
        background-color: #fff;
        z-index: 50 !important;
        padding: 8px 4px !important;
    }
    
    /* Compact table cells */
    #projects_table td,
    #projects_table th {
        padding: 6px 4px !important;
        white-space: nowrap;
    }
    
    /* Action buttons in table */
    #projects_table .btn-sm {
        padding: 4px 6px;
        font-size: 11px;
        margin: 1px;
        min-height: auto;
    }
    
    /* Dropdown actions in table */
    #projects_table .dropdown-menu {
        z-index: 1060 !important;
        min-width: 150px;
    }
    
    #projects_table .dropdown-toggle {
        padding: 4px 8px;
        font-size: 14px;
    }
}

/* ==========================================
   FIX 4: Filter inputs mobile friendly
   ========================================== */
@media (max-width: 768px) {
    /* Make filter inputs full width */
    .col-md-4 .form-control,
    .col-md-4 .form-select {
        width: 100%;
        font-size: 14px;
        min-height: 40px;
    }
    
    /* Add spacing between filters */
    .row .col-md-4 {
        margin-bottom: 12px;
    }
    
    /* Select2 mobile optimization */
    .select2-container {
        width: 100% !important;
    }
    
    .select2-container .select2-selection--multiple {
        min-height: 40px;
    }
    
    .select2-dropdown {
        z-index: 1070 !important;
    }
}

/* ==========================================
   FIX 5: Action buttons at top
   ========================================== */
@media (max-width: 768px) {
    /* Ensure top action buttons are visible */
    .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    /* Make action buttons stack on mobile */
    .btn-sm {
        min-height: 44px;
        min-width: 44px;
        padding: 8px 12px;
        margin: 2px;
    }
    
    /* Ensure view switcher buttons work */
    .btn-group-sm > .btn {
        padding: 8px 10px;
    }
}

/* ==========================================
   FIX 6: Modal and Offcanvas z-index
   ========================================== */
@media (max-width: 768px) {
    /* Ensure modals appear above everything including layout-overlay */
    .modal {
        z-index: 10000 !important;
        pointer-events: auto !important;
    }
    
    .modal-backdrop {
        z-index: 9999 !important;
        pointer-events: auto !important;
    }
    
    .modal-dialog {
        z-index: 10001 !important;
        pointer-events: auto !important;
    }
    
    .modal-content {
        z-index: 10002 !important;
        pointer-events: auto !important;
    }
    
    .modal-footer {
        z-index: 10003 !important;
        pointer-events: auto !important;
    }
    
    /* Ensure buttons inside modals are clickable */
    .modal .btn,
    .modal button,
    .modal [type="button"],
    .modal [type="submit"] {
        z-index: 10004 !important;
        position: relative !important;
        pointer-events: auto !important;
        cursor: pointer !important;
    }
    
    /* Offcanvas must be above overlay */
    .offcanvas {
        z-index: 1090 !important;
    }
    
    .offcanvas-backdrop {
        z-index: 1089 !important;
    }
    
    /* Dropdown menus */
    .dropdown-menu {
        z-index: 1060 !important;
    }
}

/* ==========================================
   FIX 7: Content wrapper and layout
   ========================================== */
@media (max-width: 768px) {
    /* Ensure content is accessible */
    .content-wrapper {
        position: relative !important;
        z-index: 1 !important;
    }
    
    .layout-page {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Container fluid padding */
    .container-fluid {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
}

/* ==========================================
   FIX 8: Touch-friendly interactions
   ========================================== */
@media (max-width: 768px) {
    /* Minimum touch target size (44x44px recommended) */
    .btn,
    button,
    a,
    [role="button"],
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Dropdown items touch-friendly */
    .dropdown-item {
        padding: 12px 16px;
        min-height: 44px;
    }
    
    /* Menu items */
    .menu-link {
        padding: 12px 16px;
        min-height: 44px;
    }
}

/* ==========================================
   FIX 9: Breadcrumb responsive
   ========================================== */
@media (max-width: 768px) {
    .breadcrumb {
        flex-wrap: wrap;
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .breadcrumb-item {
        margin-bottom: 4px;
    }
    
    .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 4px;
    }
}

/* ==========================================
   FIX 10: Page header responsive
   ========================================== */
@media (max-width: 768px) {
    .d-flex.justify-content-between.mb-2.mt-4 {
        flex-direction: column;
        gap: 12px;
    }
    
    .d-flex.justify-content-between.mb-2.mt-4 > div {
        width: 100%;
    }
    
    /* Ensure buttons are visible */
    .action_create_projects {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ==========================================
   FIX 11: Loading spinner
   ========================================== */
@media (max-width: 768px) {
    .bx-loader-alt.bx-spin {
        font-size: 24px;
    }
}

/* ==========================================
   FIX 12: Empty state
   ========================================== */
@media (max-width: 768px) {
    .empty-state {
        padding: 20px 10px;
    }
    
    .empty-state img {
        max-width: 150px;
        height: auto;
    }
    
    .empty-state h5 {
        font-size: 16px;
    }
    
    .empty-state p {
        font-size: 13px;
    }
}

/* ==========================================
   FIX 13: PWA Settings Page Responsive
   ========================================== */
@media (max-width: 768px) {
    /* PWA settings tabs - scrollable on mobile */
    #pwaTabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 4px;
    }
    #pwaTabs::-webkit-scrollbar {
        display: none;
    }
    #pwaTabs .nav-item {
        flex-shrink: 0;
    }
    #pwaTabs .nav-link {
        white-space: nowrap;
        padding: 10px 14px;
        font-size: 13px;
    }
    
    /* PWA form rows stack on mobile */
    #pwaSettingsForm .row.g-4 > .col-md-6,
    #pwaSettingsForm .row.g-4 > .col-md-4,
    #pwaSettingsForm .row.g-4 > .col-12 {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    /* PWA status badges */
    #pwaStatus .col-md-3 {
        margin-bottom: 8px;
    }
    
    /* PWA action cards stack */
    #actions .col-md-4 {
        margin-bottom: 12px;
    }
    
    /* PWA logo preview */
    #logoPreview {
        max-width: 80px !important;
        max-height: 80px !important;
    }
    
    /* PWA color pickers */
    .form-control-color {
        width: 50px !important;
        height: 40px !important;
    }
}

/* ==========================================
   FIX 14: General Form Responsive
   ========================================== */
@media (max-width: 768px) {
    .card-body {
        padding: 16px !important;
    }
    
    .tab-content {
        padding: 16px !important;
    }
    
    /* Form labels compact */
    .form-label {
        font-size: 13px;
        margin-bottom: 4px;
    }
    
    /* Input groups responsive */
    .input-group {
        flex-wrap: wrap;
    }
    
    .input-group > .form-control,
    .input-group > .form-select {
        min-width: 120px;
    }
    
    /* Color input + code display */
    .d-flex.align-items-center.gap-3 {
        flex-wrap: wrap;
        gap: 8px !important;
    }
}

/* ==========================================
   FIX 15: Table Responsive Enhancements
   ========================================== */
@media (max-width: 768px) {
    /* General table improvements for mobile */
    .table-responsive {
        border: 0;
        margin-bottom: 0;
    }
    
    /* Card header responsive */
    .card-header {
        padding: 12px 16px !important;
    }
    
    .card-header h6 {
        font-size: 14px;
    }
    
    /* Badge responsive */
    .badge {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    /* Status indicators */
    #pwaStatus .col-md-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ==========================================
   FIX 16: Small Screen (480px and below)
   ========================================== */
@media (max-width: 480px) {
    #pwaStatus .col-md-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    .nav-tabs .nav-link {
        font-size: 12px;
        padding: 8px 10px;
    }
    
    .card-body {
        padding: 12px !important;
    }
    
    .tab-content {
        padding: 12px !important;
    }
    
    /* Full width buttons on very small screens */
    .d-flex.justify-content-end.gap-2 {
        flex-direction: column;
        gap: 8px !important;
    }
    
    .d-flex.justify-content-end.gap-2 .btn {
        width: 100%;
    }
}

/* ==========================================
   FIX 17: Responsive Shortcut Cards
   ========================================== */
@media (max-width: 768px) {
    .shortcut-card .row.g-2 > div {
        margin-bottom: 6px;
    }
    
    .shortcut-card .row.g-2 > .col-md-3,
    .shortcut-card .row.g-2 > .col-md-2 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}
