/* ============================================
   THE HELPING HAND - MOBILE RESPONSIVE STYLES
   ============================================ */

/* ============================================
   GLOBAL MOBILE ADJUSTMENTS
   ============================================ */

/* Improve touch targets for mobile */
@media (max-width: 767.98px) {
    .btn {
        min-height: 44px;
        padding: 0.5rem 1rem;
    }
    
    .btn-sm {
        min-height: 38px;
        padding: 0.375rem 0.75rem;
    }
    
    .form-control, .form-select {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
    
    /* Improve card spacing on mobile */
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    /* Stack filter controls vertically on mobile */
    .card-header {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .card-header .d-flex {
        flex-wrap: wrap;
        width: 100%;
    }
    
    /* Full width search on mobile */
    .app-search {
        width: 100%;
    }
    
    .app-search input,
    .app-search select {
        width: 100%;
    }
    
    /* Improve table responsiveness */
    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    
    /* Stack stat cards */
    .row-cols-md-4 > .col,
    .row-cols-md-3 > .col {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Stack widget cards */
    .row-cols-md-2 > .col {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Improve modal sizing */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    /* Hide less important columns on mobile */
    .d-mobile-none {
        display: none !important;
    }
    
    /* Improve dropdown menus */
    .dropdown-menu {
        max-width: calc(100vw - 2rem);
    }
    
    /* Bulk actions bar mobile */
    #bulkActionsBar .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    #bulkActionsBar .d-flex .d-flex {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    /* Page title adjustments */
    .page-title-head {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }
    
    .page-title-head .d-flex {
        width: 100%;
        flex-wrap: wrap;
    }
}

/* ============================================
   SMALL MOBILE (< 576px)
   ============================================ */

@media (max-width: 575.98px) {
    /* Single column stats */
    .row-cols-md-4 > .col,
    .row-cols-md-3 > .col,
    .row-cols-md-2 > .col {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Smaller padding */
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    /* Compact table cells */
    .table td, .table th {
        padding: 0.5rem 0.25rem;
        font-size: 0.8125rem;
    }
    
    /* Hide action text, show only icons */
    .btn-action-text {
        display: none;
    }
    
    /* Compact filter row */
    .filter-row .col-md-3 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Notification dropdown full width */
    .dropdown-menu-lg {
        width: calc(100vw - 1rem) !important;
        max-width: 100% !important;
    }
    
    /* Kanban board horizontal scroll */
    .kanban-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 1rem;
    }

    .kanban-board {
        min-width: 280px;
    }
}

/* ============================================
   TABLET (768px - 991.98px)
   ============================================ */

@media (min-width: 768px) and (max-width: 991.98px) {
    /* Two column layout for stats */
    .row-cols-md-4 > .col {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Adjust filter controls */
    #filterControls {
        flex-wrap: wrap;
    }

    #filterControls .app-search {
        flex: 0 0 calc(50% - 0.5rem);
    }
}

/* ============================================
   DASHBOARD MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Dashboard cards */
    #taskCountCard .card-body,
    #projectCountCard .card-body {
        padding: 1rem;
    }

    #taskCountCard h3,
    #projectCountCard h3 {
        font-size: 1.5rem;
    }

    /* Timeline improvements */
    .timeline-item {
        padding-left: 2rem;
    }

    .timeline-item::before {
        left: 0.5rem;
    }

    /* Schedule card */
    .schedule-item {
        padding: 0.75rem;
    }
}

/* ============================================
   TASK & PROJECT LIST MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    /* Task list cards */
    .task-list-item {
        flex-direction: column;
        align-items: flex-start !important;
    }

    .task-list-item .task-actions {
        margin-top: 0.5rem;
        width: 100%;
        justify-content: flex-end;
    }

    /* Project list improvements */
    .project-row {
        flex-direction: column;
    }

    .project-row .project-info {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .project-row .project-actions {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }

    /* Hide less important table columns */
    .table .col-hide-mobile {
        display: none;
    }

    /* Task Details Mobile Fixes */
    #projectDetailsDisplay .card-header {
        padding: 1rem !important;
        position: relative;
        z-index: 1;
        flex-direction: row !important; /* Override the general card-header rule */
    }

    #projectDetailsDisplay .card-header .row {
        margin: 0;
    }

    #projectDetailsDisplay .card-header .col {
        padding: 0.5rem;
    }

    /* Prevent any pseudo-elements from blocking clicks */
    #projectDetailsDisplay .card-header::before,
    #projectDetailsDisplay .card-header::after,
    #projectDetailsDisplay::before,
    #projectDetailsDisplay::after {
        pointer-events: none !important;
    }

    /* Ensure buttons are clickable on mobile */
    #projectDetailsDisplay .btn,
    #projectDetailsDisplay .dropdown {
        position: relative;
        z-index: 100 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    }

    /* Specific button fixes */
    .task-action-btn {
        position: relative !important;
        z-index: 101 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        cursor: pointer !important;
        -webkit-user-select: none;
        user-select: none;
    }

    #taskClockInBtn,
    #taskClockOutBtn,
    #taskCreateProjectBtn {
        min-width: 120px;
        position: relative !important;
        z-index: 101 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
    }

    /* Stack task header buttons vertically on small screens */
    #projectDetailsDisplay .card-header .d-flex.align-items-center.gap-2 {
        flex-wrap: wrap;
        gap: 0.5rem !important;
        position: relative;
        z-index: 100;
    }

    /* Ensure dropdown menu is accessible */
    #projectDetailsDisplay .dropdown-menu {
        z-index: 1060;
    }

    /* Fix for nested rows causing layout issues */
    #projectDetailsDisplay .card-header .row .row {
        width: 100%;
    }

    /* Ensure task title doesn't overlap buttons */
    #projectDetailsDisplay .card-header h3 {
        max-width: 100%;
        word-wrap: break-word;
        margin-bottom: 0.5rem;
    }

    /* Avatar adjustments */
    #projectDetailsDisplay .avatar-xxl {
        width: 50px;
        height: 50px;
    }

    #projectDetailsDisplay .avatar-xxl img {
        height: 40px !important;
    }

    /* Task Details Tabs Mobile */
    .nav-task-tabs {
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .nav-task-tabs .nav-item {
        flex-shrink: 0;
    }

    .nav-task-tabs .nav-link {
        padding: 0.75rem 1rem;
        white-space: nowrap;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* Ensure tab content is accessible */
    .tab-content {
        position: relative;
        z-index: 1;
    }

    /* Fix for select dropdowns in task details */
    #projectDetailsDisplay select,
    #projectDetailsDisplay .form-select,
    #projectDetailsDisplay .form-control {
        touch-action: manipulation;
        pointer-events: auto;
    }

    /* Ensure button container is above everything */
    #projectDetailsDisplay .d-flex.align-items-center.gap-2,
    #projectDetailsDisplay .d-flex.flex-column.flex-md-row {
        position: relative !important;
        z-index: 1000 !important;
        pointer-events: auto !important;
    }

    /* Ensure all buttons in task details are touchable */
    #projectDetailsDisplay button,
    #projectDetailsDisplay .btn,
    #projectDetailsDisplay a.btn {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        position: relative;
        z-index: 2;
    }

    /* Fix for dropdown menus */
    #projectDetailsDisplay .dropdown-toggle {
        pointer-events: auto;
    }

    /* Ensure card body content is accessible */
    #projectDetailsDisplay .card-body {
        position: relative;
        z-index: 1;
    }
}

/* ============================================
   FORMS MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Form groups stack vertically */
    .row.g-3 > [class*="col-md-"],
    .row.g-2 > [class*="col-md-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Improve form labels */
    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.25rem;
    }

    /* Date pickers */
    .flatpickr-calendar {
        width: calc(100vw - 2rem) !important;
        max-width: 320px;
    }

    /* Summernote editor */
    .note-editor {
        min-height: 150px;
    }

    .note-toolbar {
        flex-wrap: wrap;
    }

    /* Ensure all interactive elements are touchable */
    button, .btn, a.btn, select, input, textarea {
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    /* Remove any pointer-events: none that might block clicks */
    * {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }

    input, textarea, select, button, a {
        -webkit-user-select: auto;
        -moz-user-select: auto;
        -ms-user-select: auto;
        user-select: auto;
    }
}

/* ============================================
   MODAL MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Full screen modals on mobile */
    .modal-fullscreen-mobile {
        width: 100vw;
        max-width: none;
        height: 100%;
        margin: 0;
    }

    .modal-fullscreen-mobile .modal-content {
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    .modal-fullscreen-mobile .modal-body {
        overflow-y: auto;
    }

    /* Modal footer buttons */
    .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 100px;
    }
}

/* ============================================
   NAVIGATION MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 991.98px) {
    /* Improve topbar spacing */
    .app-topbar {
        padding: 0.5rem 0.75rem;
    }

    /* Compact topbar items */
    .topbar-item {
        margin: 0 0.25rem;
    }

    /* User dropdown compact */
    .nav-user .topbar-link {
        padding: 0.25rem;
    }

    /* Breadcrumb improvements */
    .breadcrumb {
        font-size: 0.8125rem;
        flex-wrap: wrap;
    }

    .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 0.25rem;
    }
}

/* ============================================
   TIMECARD MOBILE IMPROVEMENTS
   ============================================ */

@media (max-width: 767.98px) {
    /* Timecard list */
    .timecard-item {
        flex-direction: column;
    }

    .timecard-item .timecard-info {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .timecard-item .timecard-hours {
        font-size: 1.25rem;
    }

    /* Clock in/out buttons */
    .clock-btn {
        width: 100%;
        padding: 1rem;
        font-size: 1.125rem;
    }

}

/* Timecard Approval Filters - Prevent shrinking below current size */
#filter-employee,
#filter-foreman,
#filter-status,
#filter-date-from,
#filter-date-to {
    min-width: 150px;
}

.timecard-approvals .btn-sm {
    min-width: 100px;
}

/* Force timecard filters to stack below 1400px */
@media (max-width: 1399px) {
    .timecard-approvals .row > [class*="col-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* ============================================
   UTILITY CLASSES FOR MOBILE
   ============================================ */

/* Show only on mobile */
.d-mobile-only {
    display: none !important;
}

@media (max-width: 767.98px) {
    .d-mobile-only {
        display: block !important;
    }

    .d-mobile-flex {
        display: flex !important;
    }

    .d-mobile-inline {
        display: inline !important;
    }

    /* Text utilities */
    .text-mobile-center {
        text-align: center !important;
    }

    .text-mobile-sm {
        font-size: 0.8125rem !important;
    }

    /* Spacing utilities */
    .p-mobile-2 {
        padding: 0.5rem !important;
    }

    .m-mobile-0 {
        margin: 0 !important;
    }

    .mb-mobile-2 {
        margin-bottom: 0.5rem !important;
    }

    /* Width utilities */
    .w-mobile-100 {
        width: 100% !important;
    }
}

/* ============================================
   SWIPE GESTURES SUPPORT
   ============================================ */

@media (max-width: 767.98px) {
    /* Enable horizontal scroll with snap */
    .swipe-container {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .swipe-container::-webkit-scrollbar {
        display: none;
    }

    .swipe-item {
        scroll-snap-align: start;
        flex-shrink: 0;
    }
}

/* ============================================
   PULL TO REFRESH INDICATOR
   ============================================ */

.pull-to-refresh {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    z-index: 1000;
    background: var(--bs-primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0 0 0.5rem 0.5rem;
    transition: transform 0.3s ease;
    display: none;
}

@media (max-width: 991.98px) {
    .pull-to-refresh {
        display: block;
    }

    .pull-to-refresh.visible {
        transform: translateX(-50%) translateY(0);
    }
}

/* ============================================
   FLOATING ACTION BUTTON (FAB)
   ============================================ */

.fab-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 1000;
    display: none;
}

@media (max-width: 991.98px) {
    .fab-container {
        display: block;
    }
}

.fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1ab394 0%, #0acf97 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(26, 179, 148, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.fab-main:hover,
.fab-main:focus {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(26, 179, 148, 0.5);
}

.fab-main:active {
    transform: scale(0.95);
}

.fab-main.open {
    transform: rotate(45deg);
}

.fab-menu {
    position: absolute;
    bottom: 70px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.fab-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.fab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.fab-item-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    color: #333;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.fab-item-btn:hover {
    background: #f8f9fa;
    transform: scale(1.1);
}

.fab-item-label {
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
}

/* ============================================
   NOTIFICATION ENHANCEMENTS
   ============================================ */

/* Notification badge pulse animation */
@keyframes notificationPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 6px rgba(220, 53, 69, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

#notificationBadge {
    animation: notificationPulse 2s infinite;
}

#notificationBadge:empty,
#notificationBadge[style*="display: none"] {
    animation: none;
}

/* Notification dropdown improvements */
.dropdown-menu-lg {
    max-height: 80vh;
}

.notify-item {
    transition: background-color 0.2s ease;
    border-left: 3px solid transparent;
}

.notify-item:hover {
    background-color: rgba(26, 179, 148, 0.05);
}

.notify-item.unread {
    background-color: rgba(26, 179, 148, 0.08);
    border-left-color: #1ab394;
}

.notify-item.unread:hover {
    background-color: rgba(26, 179, 148, 0.12);
}

/* Notification time styling */
.notify-item .text-muted.small,
.notify-item small.text-muted {
    font-size: 11px;
}

/* Notification icon styling */
.notify-item .avatar-sm {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile notification dropdown */
@media (max-width: 575.98px) {
    .dropdown-menu-lg {
        width: calc(100vw - 20px) !important;
        max-width: 100%;
        left: 10px !important;
        right: 10px !important;
    }

    .notify-item {
        padding: 12px 15px;
    }

    .notify-item .avatar-sm {
        width: 32px;
        height: 32px;
    }
}

/* Toast notification improvements */
.swal2-toast {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
}

.swal2-toast.swal2-show {
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   DASHBOARD CUSTOMIZATION
   ============================================ */

/* Ensure hidden dashboard widgets stay hidden */
.col[style*="display: none"] {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

/* Dashboard widget toggle list */
#dashboardWidgetsList .list-group-item {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#dashboardWidgetsList .list-group-item:hover {
    background-color: rgba(26, 179, 148, 0.05);
}

#dashboardWidgetsList .form-check-input:checked {
    background-color: #1ab394;
    border-color: #1ab394;
}
