/* resources/css/tables.css */
/* ===== DATA TABLES-LIKE RESPONSIVE STYLES ===== */
/* Reusable responsive table styles for entire application */

/* ===== BASE TABLE STYLES ===== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    min-height: 200px;
}

.table {
    width: 100%;
    margin-bottom: 1rem;
    border-collapse: collapse;
}

.table th {
    position: relative;
    white-space: nowrap;
    font-weight: 600;
    color: #495057;
    padding: 0.75rem;
    border-bottom: 2px solid #dee2e6;
    text-align: left;
}

.table td {
    padding: 0.75rem;
    border-bottom: 1px solid #dee2e6;
    vertical-align: middle;
}

/* ===== SORTING INDICATORS ===== */
th.sortable {
    cursor: pointer;
    position: relative;
    padding-right: 1.5rem;
    user-select: none;
}

th.sortable:hover {
    background-color: #e9ecef;
}

th.sortable::after {
    content: "↕";
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    color: #6c757d;
    transition: all 0.2s ease;
}

th.sortable.asc::after {
    content: "↑";
    color: #0d6efd;
    font-weight: bold;
}

th.sortable.desc::after {
    content: "↓";
    color: #0d6efd;
    font-weight: bold;
}

/* ===== VISUAL ENHANCEMENTS ===== */
.table-hover tbody tr:hover {
    background-color: rgba(13, 110, 253, 0.05) !important;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.02);
}

.table-bordered {
    border: 1px solid #dee2e6;
}

.table-bordered th,
.table-bordered td {
    border: 1px solid #dee2e6;
}

/* ===== LOADING STATES ===== */
.table-loading {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.table-loading::before {
    content: 'Loading...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    color: #0d6efd;
    font-weight: 500;
}

/* ===== HORIZONTAL SCROLLING MODE (Tablet: 768px - 1024px) ===== */
@media (max-width: 1024px) {
    .table-responsive {
        border: 1px solid #dee2e6;
        border-radius: 0.375rem;
        background: white;
    }

    .table {
        margin-bottom: 0;
    }

    .table th,
    .table td {
        min-width: 120px;
        white-space: nowrap;
    }

    /* Fixed first column (optional) */
    .table-fixed-first th:first-child,
    .table-fixed-first td:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 2;
        box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    }

    /* Fixed action column */
    .table-fixed-actions .action-column {
        position: sticky;
        right: 0;
        background: white;
        z-index: 2;
        box-shadow: -2px 0 5px rgba(0,0,0,0.1);
    }

    /* Column priority classes */
    .col-priority-1 { display: table-cell; }
    .col-priority-2 { display: table-cell; }
    .col-priority-3 { display: table-cell; }
    .col-priority-4 { display: none; }
    .col-priority-5 { display: none; }
    .col-priority-6 { display: none; }
}

/* ===== COLUMN TOGGLE MODE (Small Tablet: 576px - 767px) ===== */
@media (max-width: 767px) {
    .table-responsive {
        overflow-x: visible;
        border: none;
    }

    .table {
        display: block;
    }

    .table thead {
        display: none;
    }

    .table tbody {
        display: block;
    }

    .table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        background: white;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        position: relative;
    }

    /* Toggle button */
    .toggle-row {
        cursor: pointer;
        background: #f8f9fa;
        border-bottom: 1px solid #dee2e6;
    }

    .toggle-row td {
        padding: 1rem;
    }

    .expand-icon {
        position: relative;
        padding-left: 1.5rem !important;
    }

    .expand-icon::before {
        content: "+";
        position: absolute;
        left: 0.5rem;
        top: 50%;
        transform: translateY(-50%);
        font-weight: bold;
        font-size: 1.1em;
        color: #0d6efd;
        transition: transform 0.2s ease;
    }

    .toggle-row.expanded .expand-icon::before {
        content: "-";
    }

    /* Hidden columns become expandable details */
    .row-details {
        display: none;
        padding: 1rem;
        background: #fafafa;
        border-top: 1px solid #e9ecef;
    }

    .row-details.active {
        display: block;
        animation: fadeIn 0.3s ease;
    }

    .detail-item {
        display: flex;
        justify-content: space-between;
        margin-bottom: 0.75rem;
        padding: 0.5rem 0;
        border-bottom: 1px solid #f1f1f1;
    }

    .detail-item:last-child {
        margin-bottom: 0;
        border-bottom: none;
    }

    .detail-label {
        font-weight: 600;
        color: #495057;
        min-width: 120px;
        flex-shrink: 0;
    }

    .detail-value {
        flex: 1;
        text-align: right;
        color: #6c757d;
    }

    /* Show all columns in details view */
    .col-priority-1,
    .col-priority-2,
    .col-priority-3,
    .col-priority-4,
    .col-priority-5,
    .col-priority-6 {
        display: none !important;
    }
}

/* ===== CARD VIEW MODE (Mobile: ≤ 575px) ===== */
@media (max-width: 575px) {
    .table-responsive {
        border: none;
    }

    .table tr {
        margin-bottom: 0.75rem;
        border-radius: 0.375rem;
    }

    .toggle-row td {
        padding: 0.75rem;
    }

    .row-details {
        padding: 0.75rem;
    }

    .detail-item {
        flex-direction: column;
        margin-bottom: 0.5rem;
        padding: 0.25rem 0;
    }

    .detail-label {
        min-width: auto;
        margin-bottom: 0.25rem;
        font-size: 0.875rem;
    }

    .detail-value {
        text-align: left;
        font-size: 0.95rem;
    }

    /* Action buttons stack vertically */
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.5rem;
    }

    .action-buttons .btn {
        width: 100%;
        margin: 0;
        justify-content: center;
    }
}

/* ===== UTILITY CLASSES ===== */
/* Column priority classes for controlling visibility */
.col-priority-1 { display: table-cell; } /* Always visible */
.col-priority-2 { display: table-cell; } /* Visible on desktop/tablet */
.col-priority-3 { display: table-cell; } /* Visible on desktop */
.col-priority-4 { display: table-cell; } /* Hidden on mobile */
.col-priority-5 { display: table-cell; } /* Optional columns */
.col-priority-6 { display: table-cell; } /* Rarely used columns */

/* Responsive visibility utilities */
.visible-desktop { display: table-cell; }
.visible-tablet { display: none; }
.visible-mobile { display: none; }

.hidden-desktop { display: none; }
.hidden-tablet { display: table-cell; }
.hidden-mobile { display: table-cell; }

@media (max-width: 1024px) {
    .visible-desktop { display: none; }
    .visible-tablet { display: table-cell; }

    .hidden-desktop { display: table-cell; }
    .hidden-tablet { display: none; }

    .col-priority-3,
    .col-priority-4,
    .col-priority-5,
    .col-priority-6 {
        display: none;
    }
}

@media (max-width: 767px) {
    .visible-tablet { display: none; }
    .visible-mobile { display: block; }

    .hidden-tablet { display: none; }
    .hidden-mobile { display: block; }

    /* All columns hidden in card view, shown in details */
    .col-priority-1,
    .col-priority-2,
    .col-priority-3,
    .col-priority-4,
    .col-priority-5,
    .col-priority-6 {
        display: none !important;
    }
}

/* Table size variants */
.table-sm th,
.table-sm td {
    padding: 0.5rem;
    font-size: 0.875rem;
}

.table-lg th,
.table-lg td {
    padding: 1rem;
    font-size: 1.05rem;
}

/* Table color variants */
.table-primary { background-color: rgba(13, 110, 253, 0.05); }
.table-success { background-color: rgba(25, 135, 84, 0.05); }
.table-danger { background-color: rgba(220, 53, 69, 0.05); }
.table-warning { background-color: rgba(255, 193, 7, 0.05); }
.table-info { background-color: rgba(13, 202, 240, 0.05); }

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

.table tr {
    transition: all 0.2s ease;
}

/* Print styles */
@media print {
    .table-responsive {
        overflow: visible !important;
        border: none !important;
    }

    .table {
        display: table !important;
        width: 100% !important;
    }

    .table thead {
        display: table-header-group !important;
    }

    .table th,
    .table td {
        display: table-cell !important;
        border: 1px solid #ddd !important;
    }

    .toggle-row,
    .row-details,
    .action-buttons {
        display: none !important;
    }

    .col-priority-1,
    .col-priority-2,
    .col-priority-3,
    .col-priority-4,
    .col-priority-5,
    .col-priority-6 {
        display: table-cell !important;
    }
}
