/**
 * Dark theme: consistent input surfaces app-wide (forms, DataTables search, etc.)
 *
 * DataTables layout uses selectors like `div.dt-container div.dt-search input` (high
 * element specificity); include matching rules so dark backgrounds win when unfocused.
 */
[data-bs-theme="dark"] div.dt-container div.dt-search input {
  background-color: #222529;
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] div.dt-container div.dt-search input:focus {
  background-color: #222529;
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background-color: #222529;
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
  background-color: #222529;
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .form-control::placeholder {
  color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .form-control:disabled,
[data-bs-theme="dark"] .form-select:disabled {
  background-color: #222529;
  opacity: 0.65;
}

[data-bs-theme="dark"] .form-control[readonly]:not([disabled]):not(.form-control-plaintext) {
  background-color: #222529;
}

[data-bs-theme="dark"] .form-control-plaintext {
  background-color: transparent;
}

/* Chrome / Edge autofill should match dark inputs */
[data-bs-theme="dark"] .form-control:-webkit-autofill,
[data-bs-theme="dark"] .form-control:-webkit-autofill:hover,
[data-bs-theme="dark"] .form-control:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px #222529 inset;
  -webkit-text-fill-color: var(--bs-body-color);
  caret-color: var(--bs-body-color);
  transition: background-color 99999s ease-out 0s;
}

/* Select2 (bootstrap-5 theme): match dark form surfaces — dropdown is portaled to body but stays under html[data-bs-theme] */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
  background-color: #222529 !important;
  border-color: var(--bs-border-color) !important;
  color: var(--bs-body-color) !important;
  min-height: calc(1.5em + 0.75rem + 2px);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5.select2-container--focus .select2-selection,
[data-bs-theme="dark"] .select2-container--bootstrap-5.select2-container--open .select2-selection {
  border-color: #86b7fe !important;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__placeholder {
  color: var(--bs-secondary-color) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__rendered {
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice {
  background-color: #343a40 !important;
  border-color: var(--bs-border-color) !important;
  color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__choice__remove,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__choice__remove:hover {
  color: var(--bs-secondary-color) !important;
  border-color: transparent !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__clear {
  color: var(--bs-secondary-color) !important;
}

[data-bs-theme="dark"] .select2-dropdown {
  background-color: #222529 !important;
  border-color: var(--bs-border-color) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results > .select2-results__options {
  background-color: #222529;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option {
  background-color: #222529;
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted.select2-results__option--selectable {
  background-color: #0d6efd !important;
  color: #fff !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option[aria-selected="true"] {
  background-color: #343a40;
  color: var(--bs-body-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
  background-color: #222529 !important;
  border-color: var(--bs-border-color) !important;
  color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field:focus {
  border-color: #86b7fe;
  outline: 0;
}

/* Subtle primary badges inside tables: drop tinted fill in dark mode (rows already provide surface) */
[data-bs-theme="dark"] .table .badge.bg-primary-subtle {
  background-color: transparent !important;
}
