/* Responsive Table System for All Devices */

/* Base responsive table styles */
.responsive-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.375rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    margin-bottom: 1rem;
}

.responsive-table {
    width: 100%;
    min-width: 100%;
    margin-bottom: 0;
    background-color: transparent;
    border-collapse: collapse;
}

.responsive-table th,
.responsive-table td {
    padding: 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid #dee2e6;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 200px;
}

.responsive-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
    position: sticky;
    top: 0;
    z-index: 10;
}

.responsive-table tbody tr:hover {
    background-color: rgba(0, 123, 255, 0.05);
}

/* Mobile-first responsive breakpoints */
@media (max-width: 575.98px) {
    /* Extra small devices (phones) */
    .responsive-table-wrapper {
        margin: 0 -15px;
        border-radius: 0;
    }
    
    .responsive-table th,
    .responsive-table td {
        padding: 0.5rem 0.25rem;
        font-size: 0.875rem;
        max-width: 120px;
    }
    
    /* Hide less important columns on mobile */
    .responsive-table .d-none-mobile {
        display: none !important;
    }
    
    /* Stack table content vertically for very small screens */
    .mobile-card-table {
        display: none;
    }
    
    .mobile-card-view {
        display: block;
    }
    
    .mobile-card {
        background: white;
        border: 1px solid #dee2e6;
        border-radius: 0.375rem;
        margin-bottom: 1rem;
        padding: 1rem;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    }
    
    .mobile-card-header {
        font-weight: 600;
        color: #495057;
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid #dee2e6;
    }
    
    .mobile-card-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.25rem 0;
        border-bottom: 1px solid #f8f9fa;
    }
    
    .mobile-card-row:last-child {
        border-bottom: none;
    }
    
    .mobile-card-label {
        font-weight: 500;
        color: #6c757d;
        font-size: 0.875rem;
        flex: 0 0 40%;
    }
    
    .mobile-card-value {
        flex: 1;
        text-align: right;
        font-size: 0.875rem;
    }
}

@media (min-width: 576px) {
    /* Small devices and up - show table, hide cards */
    .mobile-card-view {
        display: none;
    }
    
    .mobile-card-table {
        display: table;
    }
}

@media (max-width: 767.98px) {
    /* Small devices (tablets) */
    .responsive-table th,
    .responsive-table td {
        padding: 0.625rem 0.5rem;
        font-size: 0.9rem;
        max-width: 150px;
    }
    
    .responsive-table .d-none-tablet {
        display: none !important;
    }
}

@media (max-width: 991.98px) {
    /* Medium devices (small laptops) */
    .responsive-table th,
    .responsive-table td {
        max-width: 180px;
    }
    
    .responsive-table .d-none-laptop {
        display: none !important;
    }
}

@media (min-width: 1200px) {
    /* Large devices and up */
    .responsive-table th,
    .responsive-table td {
        max-width: none;
    }
}

/* Action buttons responsive design */
.action-buttons {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

@media (max-width: 575.98px) {
    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Status badges responsive */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.25rem;
    text-align: center;
    white-space: nowrap;
}

@media (max-width: 575.98px) {
    .status-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
}

/* Priority indicators */
.priority-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}

.priority-high { background-color: #dc3545; }
.priority-medium { background-color: #ffc107; }
.priority-low { background-color: #28a745; }
.priority-critical { background-color: #6f42c1; }

/* Responsive pagination */
.responsive-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (max-width: 575.98px) {
    .responsive-pagination .page-item:not(.active):not(.disabled) {
        display: none;
    }
    
    .responsive-pagination .page-item.active,
    .responsive-pagination .page-item.disabled,
    .responsive-pagination .page-item:first-child,
    .responsive-pagination .page-item:last-child {
        display: block;
    }
}

/* Search and filter responsive */
.responsive-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: end;
}

@media (max-width: 767.98px) {
    .responsive-filters {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .responsive-filters .form-group,
    .responsive-filters .input-group {
        width: 100%;
    }
}

/* Loading states */
.table-loading {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2rem;
    height: 2rem;
    margin: -1rem 0 0 -1rem;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Empty state */
.table-empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.table-empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.table-empty-state h5 {
    margin-bottom: 0.5rem;
    color: #495057;
}

.table-empty-state p {
    margin-bottom: 0;
    font-size: 0.9rem;
}

/* Touch-friendly elements */
@media (hover: none) and (pointer: coarse) {
    .responsive-table tbody tr {
        cursor: pointer;
    }
    
    .responsive-table tbody tr:active {
        background-color: rgba(0, 123, 255, 0.1);
    }
    
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Accessibility improvements */
.responsive-table th {
    user-select: none;
}

.responsive-table td[data-sort] {
    cursor: pointer;
}

.responsive-table .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .responsive-table th {
        background-color: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }
    
    .responsive-table td {
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .responsive-table tbody tr:hover {
        background-color: rgba(255, 255, 255, 0.05);
    }
    
    .mobile-card {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .mobile-card-header {
        color: #e2e8f0;
        border-color: #4a5568;
    }
    
    .mobile-card-label {
        color: #a0aec0;
    }
}
