/* RTL Table Fixes */

/* Basic table direction and alignment */
html[dir="rtl"] table {
    text-align: right;
}

/* Table headers */
html[dir="rtl"] th {
    text-align: right;
}

/* Table cells */
html[dir="rtl"] td {
    text-align: right;
}

/* Table captions */
html[dir="rtl"] caption {
    text-align: right;
}

/* Adjust padding for RTL */
html[dir="rtl"] .table th,
html[dir="rtl"] .table td {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
}

/* First column padding */
html[dir="rtl"] .table th:first-child,
html[dir="rtl"] .table td:first-child {
    padding-right: 1.5rem;
}

/* Last column padding */
html[dir="rtl"] .table th:last-child,
html[dir="rtl"] .table td:last-child {
    padding-left: 1.5rem;
}

/* Bordered tables */
html[dir="rtl"] .table-bordered th,
html[dir="rtl"] .table-bordered td {
    border-right: 0;
    border-left: 1px solid #dee2e6;
}

html[dir="rtl"] .table-bordered th:first-child,
html[dir="rtl"] .table-bordered td:first-child {
    border-right: 1px solid #dee2e6;
}

/* Striped tables */
html[dir="rtl"] .table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.05);
}

/* Hover tables */
html[dir="rtl"] .table-hover tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.075);
}

/* Table button groups */
html[dir="rtl"] td .btn-group {
    flex-direction: row-reverse;
}

/* Checkboxes in tables */
html[dir="rtl"] td .form-check,
html[dir="rtl"] th .form-check {
    padding-left: 0;
    padding-right: 1.25rem;
}

html[dir="rtl"] td .form-check-input,
html[dir="rtl"] th .form-check-input {
    margin-left: 0;
    margin-right: -1.25rem;
}

/* Pagination for tables */
html[dir="rtl"] .pagination {
    padding-right: 0;
    flex-direction: row-reverse;
}

/* Mobile responsive tables */
@media (max-width: 767.98px) {
    html[dir="rtl"] .mobile-table {
        display: block;
        width: 100%;
    }
    
    html[dir="rtl"] .mobile-table thead {
        display: none;
    }
    
    html[dir="rtl"] .mobile-table tbody {
        display: block;
        width: 100%;
    }
    
    html[dir="rtl"] .mobile-table tr {
        display: block;
        width: 100%;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 0.25rem;
    }
    
    html[dir="rtl"] .mobile-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
        border: none;
        border-bottom: 1px solid #dee2e6;
        padding: 0.75rem;
    }
    
    html[dir="rtl"] .mobile-table td:last-child {
        border-bottom: none;
    }
    
    html[dir="rtl"] .mobile-table td::before {
        content: attr(data-label);
        font-weight: bold;
        margin-left: 1rem;
        margin-right: 0;
        text-align: right;
    }
    
    html[dir="rtl"] .mobile-table td .btn-group {
        margin-right: auto;
        margin-left: 0;
    }
}

/* Sort icons in table headers */
html[dir="rtl"] .table th.sortable::after {
    margin-right: 0.25rem;
    margin-left: 0;
}

/* Table icons */
html[dir="rtl"] .table td .bi,
html[dir="rtl"] .table th .bi {
    margin-right: 0;
    margin-left: 0.25rem;
}

/* Fixed header tables */
html[dir="rtl"] .table-fixed-header th {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: #fff;
}

/* Card tables */
html[dir="rtl"] .card .table {
    margin-bottom: 0;
}

/* Table dropdowns */
html[dir="rtl"] .table .dropdown-menu {
    text-align: right;
    right: auto;
    left: 0;
}

/* Badges in tables */
html[dir="rtl"] .table .badge {
    margin-right: 0;
    margin-left: 0.25rem;
}

/* Contextual table rows */
html[dir="rtl"] .table-contextual-bg tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.075);
}

/* Table captions */
html[dir="rtl"] .table caption {
    caption-side: top;
    text-align: right;
}

/* Table with complex elements */
html[dir="rtl"] .table .complex-cell {
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
}

/* Small tables */
html[dir="rtl"] .table-sm th,
html[dir="rtl"] .table-sm td {
    padding: 0.3rem;
}

/* Data tables pagination */
html[dir="rtl"] .dataTables_paginate .paginate_button {
    float: right;
}

/* Table footer */
html[dir="rtl"] .table tfoot td {
    text-align: right;
}

/* Table with actions column */
html[dir="rtl"] .table .actions-column {
    text-align: left;
}

/* Table with progress bars */
html[dir="rtl"] .table .progress-cell .progress {
    direction: ltr; /* Progress bars always fill left-to-right */
}

/* Nested tables */
html[dir="rtl"] .table .nested-table {
    margin: 0;
    padding-right: 1rem;
}

/* Table with images */
html[dir="rtl"] .table .img-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

html[dir="rtl"] .table .img-cell img {
    margin-right: 0;
    margin-left: 0.5rem;
}

/* Table with tabs */
html[dir="rtl"] .table-tabs .nav-tabs {
    padding-right: 0;
}

/* Table footer with pagination */
html[dir="rtl"] .table-footer {
    display: flex;
    flex-direction: row-reverse;
    justify-content: space-between;
    align-items: center;
}

/* Table info text */
html[dir="rtl"] .table-info-text {
    text-align: right;
}