/* Bootstrap 5.3 CSS variable overrides for dark mode.
   --bs-table-bg was changed to var(--bs-body-bg) in 5.3, causing white table cells.
   All rules are scoped to [data-bs-theme="dark"] — no light mode impact. */

[data-bs-theme="dark"] {
    --bs-table-bg: transparent;
    --bs-body-bg: #1e293b;
    --bs-body-color: #e2e8f0;
    --bs-emphasis-color: #f8fafc;
    --bs-emphasis-color-rgb: 248, 250, 252;
    --bs-secondary-color: #94a3b8;
    --bs-border-color: #334155;
}

/* Bootstrap 5.3 does not update .text-secondary via :root — explicit override required */
[data-bs-theme="dark"] .text-secondary {
    color: #94a3b8 !important;
}

/* DataTables controls — datatables-bootstrap5-tweaks.css has hardcoded light colors */
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length label,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter label {
    color: #93c5fd;
    background: #1e293b;
    border-color: #334155;
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length select.form-select,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter input.form-control {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #334155 !important;
    color: #93c5fd !important;
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: #1d4ed8 !important;
    color: #e2e8f0 !important;
    border: none !important;
}

/* btn-outline-secondary — medium gray (#6c757d) is hard to see on dark backgrounds */
[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: #cbd5e1;
    --bs-btn-border-color: #475569;
    --bs-btn-hover-color: #f1f5f9;
    --bs-btn-hover-bg: #334155;
    --bs-btn-hover-border-color: #64748b;
    --bs-btn-active-color: #f1f5f9;
    --bs-btn-active-bg: #334155;
    --bs-btn-active-border-color: #64748b;
}

/* Native <select> — color-scheme tells the browser to render the control in dark mode natively,
   fixing placeholder/disabled option text that CSS color alone cannot override */
[data-bs-theme="dark"] .form-select {
    color-scheme: dark;
    color: #e2e8f0 !important;
    background-color: #0f172a !important;
    border-color: #334155 !important;
}

[data-bs-theme="dark"] .form-select option {
    background-color: #0f172a;
    color: #e2e8f0;
}

[data-bs-theme="dark"] .form-select option:disabled {
    color: #64748b;
}

/* Select2 — select2-bootstrap-5-theme does not respond to data-bs-theme */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
    background-color: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    color: #e2e8f0;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice {
    background-color: #1e3a5f;
    border-color: #334155;
    color: #e2e8f0;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__remove {
    color: #94a3b8;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
    background-color: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-search .select2-search__field {
    background-color: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option {
    color: #e2e8f0;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: #1d4ed8;
    color: #f1f5f9;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option[aria-selected="true"] {
    background-color: #1e3a5f;
    color: #e2e8f0;
}

/* Table rows — ensure contrast against card background (#1e293b) */
[data-bs-theme="dark"] table.dataTable tbody tr {
    background-color: #0f172a;
}

[data-bs-theme="dark"] table.dataTable tbody tr:hover {
    background-color: #1e3a5f;
}
