/**
 * Tabel Responsif dengan CSS3 & Bootstrap 5
 * Styling modern untuk tabel dengan dukungan responsive lengkap
 */

/* ===== Bootstrap 5 Table Base ===== */
/* Menggunakan Bootstrap 5 table classes sebagai base */

/* ===== Custom Table Styling dengan CSS3 ===== */

/* Table Container - Responsive Wrapper */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling iOS */
    margin: var(--spacing-md) 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

/* Modern Table Styling */
.table {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--color-white);
    font-size: 16px; /* Aksesibilitas - minimum 16px */
    line-height: 1.6;
    color: var(--color-gray-800);
}

/* Table Header */
.table thead {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: var(--color-white);
    position: sticky;
    top: 0;
    z-index: 10;
}

.table thead th {
    padding: var(--spacing-md);
    font-weight: 600;
    text-align: left;
    vertical-align: middle;
    border: none;
    font-size: 0.9375rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: var(--font-sans);
}

.table thead th:first-child {
    border-top-left-radius: var(--radius-lg);
}

.table thead th:last-child {
    border-top-right-radius: var(--radius-lg);
}

/* Table Body */
.table tbody {
    background: var(--color-white);
}

.table tbody tr {
    transition: background-color var(--transition-fast);
    border-bottom: 1px solid var(--color-gray-200);
}

.table tbody tr:last-child {
    border-bottom: none;
}

.table tbody tr:hover {
    background-color: var(--color-gray-100);
    cursor: pointer;
}

.table tbody td {
    padding: var(--spacing-md);
    vertical-align: middle;
    border: none;
    font-size: 16px; /* Aksesibilitas */
    color: var(--color-gray-700);
}

/* Table Footer */
.table tfoot {
    background: var(--color-gray-100);
    font-weight: 600;
}

.table tfoot td {
    padding: var(--spacing-md);
    border-top: 2px solid var(--color-gray-300);
}

/* ===== Bootstrap 5 Table Variants ===== */

/* Striped Table */
.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--color-gray-50);
}

.table-striped tbody tr:nth-of-type(odd):hover {
    background-color: var(--color-gray-100);
}

/* Bordered Table */
.table-bordered {
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table-bordered th,
.table-bordered td {
    border: 1px solid var(--color-gray-300);
}

/* Hover Table */
.table-hover tbody tr:hover {
    background-color: rgba(30, 111, 92, 0.05); /* Primary color dengan opacity */
    color: var(--color-primary-dark);
}

/* Small Table */
.table-sm th,
.table-sm td {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.875rem;
}

/* Dark Table */
.table-dark {
    background-color: var(--color-secondary);
    color: var(--color-white);
}

.table-dark thead {
    background: linear-gradient(135deg, var(--color-secondary) 0%, var(--color-gray-800) 100%);
}

.table-dark tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* ===== Responsive Table Styles ===== */

/* Mobile (< 768px) */
@media (max-width: 767px) {
    .table-responsive {
        margin: var(--spacing-sm) 0;
        border-radius: var(--radius-md);
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        font-size: 14px; /* Sedikit lebih kecil di mobile, tetap readable */
        min-width: 600px; /* Minimum width untuk horizontal scroll */
    }
    
    .table thead th {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 0.75rem;
        white-space: nowrap;
    }
    
    .table tbody td {
        padding: var(--spacing-xs) var(--spacing-sm);
        font-size: 14px; /* Tetap readable */
        white-space: nowrap;
    }
    
    /* Stack table di mobile untuk beberapa kasus */
    .table-stack-mobile {
        display: block;
    }
    
    .table-stack-mobile thead {
        display: none;
    }
    
    .table-stack-mobile tbody,
    .table-stack-mobile tr,
    .table-stack-mobile td {
        display: block;
        width: 100%;
    }
    
    .table-stack-mobile tr {
        margin-bottom: var(--spacing-md);
        border: 1px solid var(--color-gray-300);
        border-radius: var(--radius-md);
        padding: var(--spacing-sm);
        background: var(--color-white);
        box-shadow: var(--shadow-sm);
    }
    
    .table-stack-mobile td {
        border: none;
        padding: var(--spacing-xs) 0;
        text-align: left !important;
        position: relative;
        padding-left: 50%;
    }
    
    .table-stack-mobile td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: var(--spacing-xs);
        white-space: nowrap;
        font-weight: 600;
        color: var(--color-primary);
    }
}

/* Tablet (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .table {
        font-size: 15px;
    }
    
    .table thead th {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 0.875rem;
    }
    
    .table tbody td {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: 15px;
    }
}

/* Desktop (> 1024px) */
@media (min-width: 1025px) {
    .table {
        font-size: 16px; /* Full size di desktop */
    }
}

/* ===== Table Utilities ===== */

/* Text Alignment */
.table th.text-center,
.table td.text-center {
    text-align: center;
}

.table th.text-end,
.table td.text-end {
    text-align: right;
}

/* Vertical Alignment */
.table th.align-middle,
.table td.align-middle {
    vertical-align: middle;
}

.table th.align-top,
.table td.align-top {
    vertical-align: top;
}

.table th.align-bottom,
.table td.align-bottom {
    vertical-align: bottom;
}

/* ===== Modern Table Features ===== */

/* Sticky Header (CSS3) */
.table-sticky thead {
    position: sticky;
    top: 120px; /* Sesuai dengan header fixed */
    z-index: 100;
}

/* Empty State */
.table-empty {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--color-gray-500);
}

.table-empty i {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

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

.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;
}

/* ===== Print Styles ===== */
@media print {
    .table-responsive {
        overflow: visible;
        box-shadow: none;
    }
    
    .table {
        font-size: 10pt;
        page-break-inside: avoid;
    }
    
    .table thead {
        display: table-header-group;
    }
    
    .table tbody tr {
        page-break-inside: avoid;
    }
}

/* ===== Accessibility ===== */

/* Focus styles untuk keyboard navigation */
.table tbody tr:focus {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .table {
        border: 2px solid var(--color-gray-800);
    }
    
    .table thead th {
        background: var(--color-gray-800);
        color: var(--color-white);
    }
    
    .table tbody tr {
        border-bottom: 2px solid var(--color-gray-800);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .table tbody tr {
        transition: none;
    }
}

