/* Everlast HR System - Mobile Buttons & Forms Fix for ALL Roles */
/* This file ensures all buttons, forms, and clickable elements work properly on mobile for ALL user roles */

/* ===== BASE MOBILE FIXES (Tablets and below - ALL ROLES) ===== */
@media (max-width: 991.98px) {
    
    /* ===== CRITICAL: Ensure ALL buttons are clickable ===== */
    /* Fix z-index and pointer-events for ALL buttons across the app */
    .btn,
    button,
    a.btn,
    .btn[href],
    input[type="button"],
    input[type="submit"],
    input[type="reset"],
    .table .btn,
    .table button,
    .table a.btn,
    .card .btn,
    .card button,
    .modal .btn,
    .modal button,
    .form-control:focus,
    .dropdown-toggle,
    .nav-link,
    .page-link,
    .pagination .page-link,
    .badge[role="button"],
    [role="button"],
    [onclick],
    a[href],
    .clickable,
    .btn-group .btn,
    .btn-group button {
        position: relative !important;
        z-index: 10 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(0, 93, 153, 0.2) !important;
        -webkit-touch-callout: none !important;
        user-select: none !important;
        -webkit-user-select: none !important;
        cursor: pointer !important;
        min-height: 44px !important; /* Touch-friendly size */
        min-width: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Ensure buttons in tables are clickable */
    .table-responsive .btn,
    .table-responsive button,
    .table-responsive a.btn {
        position: relative !important;
        z-index: 15 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
    }
    
    /* Fix for buttons inside cards */
    .card .btn,
    .card button,
    .card a.btn {
        position: relative !important;
        z-index: 5 !important;
        pointer-events: auto !important;
    }
    
    /* Fix for buttons inside modals */
    .modal .btn,
    .modal button,
    .modal a.btn {
        position: relative !important;
        z-index: 1055 !important;
        pointer-events: auto !important;
    }
    
    /* Fix for dropdown toggles */
    .dropdown-toggle,
    .dropdown .btn,
    .dropdown button {
        position: relative !important;
        z-index: 1000 !important;
        pointer-events: auto !important;
    }
    
    /* Fix for navigation links */
    .nav-link,
    .sidebar .nav-link,
    .navbar .nav-link {
        position: relative !important;
        z-index: 5 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
    }
    
    /* Fix for pagination */
    .pagination .page-link,
    .page-link {
        position: relative !important;
        z-index: 5 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* ===== FORMS - Ensure all form elements are clickable and responsive ===== */
    .form-control,
    .form-select,
    .form-check-input,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    textarea,
    select {
        position: relative !important;
        z-index: 1 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        min-height: 44px !important; /* Touch-friendly */
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.75rem !important;
        border: 2px solid #e5e7eb !important;
        border-radius: 0.5rem !important;
        box-sizing: border-box !important;
    }
    
    /* Form labels */
    .form-label,
    label {
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        margin-bottom: 0.5rem !important;
        display: block !important;
        color: #374151 !important;
    }
    
    /* Form groups */
    .form-group,
    .mb-3,
    .mb-4 {
        margin-bottom: 1rem !important;
        width: 100% !important;
    }
    
    /* Checkboxes and radio buttons */
    .form-check-input {
        min-width: 20px !important;
        min-height: 20px !important;
        width: 20px !important;
        height: 20px !important;
        margin-top: 0.25rem !important;
        cursor: pointer !important;
        pointer-events: auto !important;
        z-index: 5 !important;
    }
    
    .form-check-label {
        margin-left: 0.5rem !important;
        cursor: pointer !important;
        pointer-events: auto !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
    }
    
    /* File inputs */
    input[type="file"] {
        min-height: 44px !important;
        padding: 0.5rem !important;
        cursor: pointer !important;
        pointer-events: auto !important;
        z-index: 5 !important;
    }
    
    /* ===== BUTTON GROUPS - Stack vertically on mobile ===== */
    .btn-group,
    .btn-group-vertical,
    .action-buttons,
    .d-flex.gap-1,
    .d-flex.gap-2 {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        width: 100% !important;
    }
    
    .btn-group .btn,
    .btn-group button,
    .action-buttons .btn,
    .action-buttons button {
        width: 100% !important;
        margin: 0 !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* ===== MODAL FIXES - Ensure buttons in modals are clickable ===== */
    .modal {
        z-index: 1055 !important;
    }
    
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
        width: calc(100% - 1rem) !important;
        z-index: 1056 !important;
    }
    
    .modal-content {
        z-index: 1057 !important;
        position: relative !important;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        position: relative !important;
        z-index: 1 !important;
    }
    
    .modal-footer .btn,
    .modal-footer button {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
        z-index: 10 !important;
        pointer-events: auto !important;
    }
    
    /* ===== DROPDOWN FIXES ===== */
    .dropdown-menu {
        z-index: 1050 !important;
        position: absolute !important;
        pointer-events: auto !important;
    }
    
    .dropdown-item {
        min-height: 44px !important;
        padding: 0.75rem 1rem !important;
        pointer-events: auto !important;
        z-index: 1 !important;
        cursor: pointer !important;
        touch-action: manipulation !important;
        display: flex !important;
        align-items: center !important;
    }
    
    /* ===== TABLE BUTTONS - Enhanced touch targets ===== */
    .table .btn,
    .table button,
    .table a.btn {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem !important;
        min-height: 38px !important;
        min-width: 38px !important;
        margin: 0.25rem !important;
        z-index: 15 !important;
        pointer-events: auto !important;
    }
    
    /* ===== OVERLAY FIXES - Ensure overlays don't block buttons ===== */
    .mobile-overlay,
    .sidebar-overlay {
        z-index: 1049 !important;
        pointer-events: auto !important;
    }
    
    /* IMPORTANT:
       Do NOT disable pointer-events on the whole content area.
       If `body.sidebar-open` gets stuck on some pages, it can make the app feel "dead" on mobile.
       The overlay already blocks interaction visually/behaviorally. */
    
    /* ===== FIXED ELEMENTS - Ensure they don't block buttons ===== */
    .mobile-header,
    .navbar,
    .header {
        z-index: 1040 !important;
        position: sticky !important;
        top: 0 !important;
    }
    
    /* Ensure buttons in header are clickable */
    .mobile-header .btn,
    .mobile-header button,
    .navbar .btn,
    .navbar button {
        z-index: 1041 !important;
        pointer-events: auto !important;
    }
    
    /* ===== SIDEBAR FIXES ===== */
    .sidebar {
        z-index: 1050 !important;
    }
    
    .sidebar .nav-link,
    .sidebar button,
    .sidebar .btn {
        z-index: 1 !important;
        pointer-events: auto !important;
    }
    
    /* ===== CARD BUTTONS ===== */
    .card-header .btn,
    .card-header button,
    .card-body .btn,
    .card-body button {
        z-index: 5 !important;
        pointer-events: auto !important;
    }
    
    /* ===== ALERT BUTTONS ===== */
    .alert .btn,
    .alert button,
    .alert .btn-close {
        z-index: 5 !important;
        pointer-events: auto !important;
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* ===== BADGE BUTTONS ===== */
    .badge[role="button"],
    .badge.btn {
        z-index: 5 !important;
        pointer-events: auto !important;
        min-height: 38px !important;
        min-width: 38px !important;
        padding: 0.5rem 0.75rem !important;
    }
    
    /* ===== LINK BUTTONS ===== */
    a.btn,
    a[href].btn,
    a[role="button"] {
        z-index: 5 !important;
        pointer-events: auto !important;
        text-decoration: none !important;
    }
    
    /* ===== PREVENT DOUBLE-TAP ZOOM ===== */
    button,
    .btn,
    a.btn,
    input[type="button"],
    input[type="submit"],
    input[type="reset"] {
        touch-action: manipulation !important;
    }
    
    /* ===== SPACING FOR BUTTONS ===== */
    .btn + .btn,
    button + button,
    .btn + button,
    button + .btn {
        margin-left: 0.5rem !important;
        margin-right: 0.5rem !important;
    }
    
    /* ===== FLEX CONTAINER BUTTONS ===== */
    .d-flex .btn,
    .d-flex button {
        margin: 0.25rem !important;
    }
    
    /* ===== FORM SUBMIT BUTTONS ===== */
    form .btn[type="submit"],
    form button[type="submit"],
    form input[type="submit"],
    .submit-btn,
    #submit-btn {
        width: 100% !important;
        margin-top: 1rem !important;
        z-index: 10 !important;
        pointer-events: auto !important;
    }
    
    /* ===== SEARCH AND FILTER BUTTONS ===== */
    .search-btn,
    .filter-btn,
    .search-form .btn,
    .filter-form .btn {
        width: 100% !important;
        margin-top: 0.5rem !important;
        z-index: 10 !important;
        pointer-events: auto !important;
    }
    
    /* ===== ACTION BUTTONS IN TABLES ===== */
    .table .action-buttons,
    .table .btn-group {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        justify-content: center !important;
    }
    
    .table .action-buttons .btn,
    .table .btn-group .btn {
        flex: 0 0 auto !important;
        min-width: 80px !important;
    }
}

/* ===== SMALL MOBILE DEVICES (Phones) ===== */
@media (max-width: 575.98px) {
    /* Even larger touch targets on small phones */
    .btn,
    button,
    a.btn {
        min-height: 48px !important;
        min-width: 48px !important;
        padding: 0.875rem 1rem !important;
        font-size: 0.9rem !important;
    }
    
    .btn-sm {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 0.75rem 0.875rem !important;
    }
    
    /* Forms on small phones */
    .form-control,
    .form-select,
    input,
    textarea,
    select {
        min-height: 48px !important;
        padding: 0.875rem !important;
        font-size: 16px !important;
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets on touch devices */
    .btn,
    button,
    a.btn {
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover,
    button:hover {
        transform: none !important;
    }
    
    /* Active state for touch feedback */
    .btn:active,
    button:active {
        transform: scale(0.98) !important;
        opacity: 0.9 !important;
    }
}

/* ===== ROLE-SPECIFIC FIXES - Ensure ALL roles get the same fixes ===== */
/* No role-specific restrictions - all fixes apply to all roles */
body[data-user-role] .btn,
body[data-user-role] button,
body[data-user-role] a.btn,
body[data-user-role] .form-control,
body[data-user-role] .form-select {
    position: relative !important;
    z-index: 10 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
}

/* ===== CRITICAL: Override any conflicting styles ===== */
@media (max-width: 991.98px) {
    /* Force buttons to be clickable - highest priority */
    * .btn,
    * button,
    * a.btn {
        pointer-events: auto !important;
        z-index: 10 !important;
    }
    
    /* Ensure interactive elements are always clickable */
    a,
    input,
    textarea,
    select,
    label,
    .nav-link,
    .dropdown-toggle,
    .page-link,
    .form-check-label,
    .form-control,
    .form-select,
    .dropdown-item,
    [role="button"],
    [onclick],
    .clickable {
        pointer-events: auto !important;
    }
}
