/* Enhanced DataTables Styles
 * Purpose: Reusable, modernized DataTables styling extracted from the
 * clawback dashboard for consistent appearance across pages.
 * Loads AFTER tables.css to override base styles where appropriate.
 */

/* Wrapper and layout adjustments */
.dataTables_wrapper,
.tables_wrapper {
    background-color: transparent !important;
    width: 100% !important;
    overflow: visible !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}

.dataTables_wrapper thead,
.tables_wrapper thead {
    background-color: transparent !important;
    width: 100% !important;
    overflow: visible !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}

.dataTables_wrapper .top.row {
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.dataTables_wrapper .top.row .col-sm-6 {
    padding-left: 8px !important;
    padding-right: 8px !important;
}

/* Define shared DataTable loading skeleton states and container layout. */
/* Keep these selectors here so dashboards like TBV, LTV, and Commission Verification */
/* can rely on data-datatable-state without pulling feature-specific CSS files. */
[data-datatable-container],
[data-datatable-container-pending] {
    position: relative;
}

.datatable-loading-placeholder {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 2rem 1rem;
    min-height: 320px;
    border: 1px dashed #d1d5db;
    border-radius: 16px;
    background-color: #ffffff;
    color: #475569;
    text-align: center;
    font-size: 0.95rem;
    transition: opacity 0.2s ease-in-out;
}

/* Spinner variant: vertical layout with no dashed border for cleaner appearance. */
.datatable-loading-placeholder--spinner {
    flex-direction: column;
    border: none;
    background-color: #f9fafb;
}

.datatable-loading-copy {
    margin: 0;
    font-weight: 500;
}

[data-datatable-container][data-datatable-state="initializing"] .datatable-loading-placeholder,
[data-datatable-container-pending][data-datatable-state="initializing"] .datatable-loading-placeholder {
    display: flex;
}

[data-datatable-container][data-datatable-state="initializing"] [data-datatable-content],
[data-datatable-container-pending][data-datatable-state="initializing"] [data-datatable-content-pending] {
    opacity: 0;
    pointer-events: none;
}

[data-datatable-container][data-datatable-state="ready"] .datatable-loading-placeholder,
[data-datatable-container-pending][data-datatable-state="ready"] .datatable-loading-placeholder {
    display: none;
}

/* DataTables processing indicator override. */
/* Bootstrap5 theme adds .card class which inherits green background from cards.css. */
/* Override to provide a clean, modern loading indicator with spinning animation. */
.dataTables_processing.card {
    background-color: #ffffff !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 0.5rem !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
    color: #374151 !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    padding: 0.75rem 1.25rem !important;
    z-index: 100 !important;
}

/* Add spinning indicator before the text. */
.dataTables_processing.card::before {
    content: '';
    display: inline-block;
    width: 1rem;
    height: 1rem;
    margin-right: 0.5rem;
    border: 2px solid #e5e7eb;
    border-top-color: #059669;
    border-radius: 50%;
    animation: datatable-spinner 0.8s linear infinite;
    vertical-align: middle;
}

@keyframes datatable-spinner {
    to {
        transform: rotate(360deg);
    }
}

/* Search input and labels */
.dataTables_filter input {
    border: 1px solid #e5e7eb !important;
    border-radius: 0.375rem !important;
    padding: 0.375rem 0.75rem !important;
    font-size: 0.875rem !important;
    background-color: #ffffff !important;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
}

/* Focus states for inputs/selects */
.dataTables_filter input:focus,
.dataTables_length select:focus,
.priority-filter-select:focus,
.grade-filter-select:focus {
    border-color: #10b981 !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2) !important;
    outline: none !important;
}

.dataTables_filter label {
    font-size: 0.875rem !important;
    color: #374151 !important;
}

/* Length menu */
.dataTables_length select {
    border: 1px solid #e5e7eb !important;
    border-radius: 0.375rem !important;
    padding: 0.375rem 2rem 0.375rem 0.75rem !important;
    font-size: 0.875rem !important;
    background-color: #ffffff !important;
}

.dataTables_length label {
    font-size: 0.875rem !important;
    color: #374151 !important;
}

/* Info text */
.dataTables_info {
    font-size: 0.875rem !important;
    color: #6b7280 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}

/* Table header and cell improvements */
.table.dataTable th {
    background-color: #f9fafb !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    text-transform: none !important;
    text-align: left !important;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid #e5e7eb !important;
}

.table.dataTable td {
    background-color: #ffffff !important;
    color: #343a40 !important;
    font-size: 14px !important;
    line-height: 1.5;
    text-align: left !important;
    vertical-align: middle !important;
    font-variant-numeric: tabular-nums !important;
}

.table.dataTable th:first-child,
.table.dataTable td:first-child {
    padding-left: 15px !important;
}

/* Row striping override: keep rows white; use light grey on hover */
.table-striped>tbody>tr:nth-of-type(odd) {
    --bs-table-accent-bg: #ffffff !important;
}

.table-striped>tbody>tr:hover {
    --bs-table-accent-bg: #f9fafb !important;
}

/* Export button styling */
.dt-buttons .btn-export {
    background: #10b981 !important;
    background-image: none !important;
    border: none !important;
    color: #ffffff !important;
    font-size: 0.875rem !important;
    padding: 0.5rem 1rem !important;
    border-radius: 0.375rem !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08) !important;
    transform: none !important;
}

.dt-buttons .btn-export:hover {
    background: #059669 !important;
    background-image: none !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12) !important;
    transform: none !important;
}

/* Excel icon spacing for export button */
.fa-file-excel-o {
    margin-left: 0 !important;
    margin-right: 5px !important;
}

/* Sorting arrows: side-by-side positioning and active state */
table.dataTable thead .sorting,
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
    background-position: center right !important;
    padding-right: 2rem !important;
    position: relative;
}


/* ? This is the default position for the rules table which should ONLY be used when there are two lines of text in the column */
table.dataTable>thead .sorting:before,
table.dataTable>thead .sorting:after,
table.dataTable>thead .sorting_asc:before,
table.dataTable>thead .sorting_asc:after,
table.dataTable>thead .sorting_desc:before,
table.dataTable>thead .sorting_desc:after {
    position: absolute !important;
    transform: translateY(-50%) !important;
    font-size: 14px !important;
    opacity: 0.5 !important;
    top: 46% !important;
}

/* ----------------------------------------------------
 * Two-line header adjustment class
 * Purpose: When a table's header cells wrap to two lines, lower the
 *          DataTables sorting icons so they visually align with text.
 * Usage:   Add class `two-line-headers` to the target <table> element.
 *          Example: <table class="dataTable two-line-headers"> ...
 * ---------------------------------------------------- */
table.two-line-headers.dataTable>thead .sorting:before,
table.two-line-headers.dataTable>thead .sorting:after,
table.two-line-headers.dataTable>thead .sorting_asc:before,
table.two-line-headers.dataTable>thead .sorting_asc:after,
table.two-line-headers.dataTable>thead .sorting_desc:before,
table.two-line-headers.dataTable>thead .sorting_desc:after {
    top: 53% !important;
}

table.dataTable>thead .sorting:before,
table.dataTable>thead .sorting_asc:before,
table.dataTable>thead .sorting_desc:before {
    right: 3px !important;
}

table.dataTable>thead .sorting:after,
table.dataTable>thead .sorting_asc:after,
table.dataTable>thead .sorting_desc:after {
    right: 12px !important;
}

table.dataTable>thead .sorting_asc:before {
    opacity: 1 !important;
    color: #6B7280 !important;
}

table.dataTable>thead .sorting_desc:after {
    opacity: 1 !important;
    color: #6B7280 !important;
}

/* Pagination button styling */
.dataTables_wrapper .dataTables_paginate,
.dataTables_wrapper .dataTables_paginate .paginate_button {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button,
.dataTables_wrapper .dataTables_paginate .paginate_button:hover,
.dataTables_wrapper .dataTables_paginate .paginate_button:active,
.dataTables_wrapper .dataTables_paginate .paginate_button:focus {
    display: inline-block !important;
    background: white !important;
    background-color: white !important;
    color: #495057 !important;
    text-decoration: none !important;
    cursor: pointer !important;
    font-size: 13px !important;
    min-width: 35px !important;
    box-shadow: none !important;
    line-height: 1.5 !important;
    user-select: none !important;
    vertical-align: middle !important;
    text-align: center !important;
    transition: none !important;
    outline: none !important;
    background-image: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    border-radius: 0.375rem !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: #e9ecef !important;
    border-color: #ced4da !important;
    color: #212529 !important;
    text-decoration: none !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:active,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:focus {
    background: #28a745 !important;
    background-color: #28a745 !important;
    border-color: #28a745 !important;
    color: white !important;
    font-weight: normal !important;
    text-decoration: none !important;
    cursor: default !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:active,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:focus {
    background: #f8f9fa !important;
    background-color: #f8f9fa !important;
    color: #adb5bd !important;
    border-color: #e9ecef !important;
    cursor: default !important;
    text-decoration: none !important;
}

.dataTables_wrapper .dataTables_paginate .page-link:focus {
    box-shadow: none !important;
}
