/* =========================================================
   Select2 x Bootstrap 5 — Single & Multiple
   ========================================================= */

/* --- Single select -------------------------------------------------------- */
.select2-container .select2-selection--single {
  height: calc(2.3rem + 2px); /* roughly .form-control-lg height */
  padding: 0.375rem 0.75rem; /* Bootstrap input padding */
  border: 1px solid #ced4da;
  border-radius: 0.375rem;
  background-color: #fff;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  font-size: 1rem;
  line-height: 1.5;
  box-shadow: none;
  display: flex;
  align-items: center;
}

.select2-container .select2-selection--single .select2-selection__rendered {
  padding-left: 0;
  padding-right: 0;
  line-height: 2.2rem; /* vertical align text */
}

.select2-container--default .select2-selection--single:focus,
.select2-container--default .select2-selection--single.select2-selection--focus,
.select2-container--default.select2-container--focus
  .select2-selection--single {
  border-color: #86b7fe;
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.select2-container--default
  .select2-selection--single
  .select2-selection__arrow {
  height: calc(2.5rem + 2px);
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
}

/* Disabled */
.select2-container--default.select2-container--disabled
  .select2-selection--single {
  background-color: #e9ecef;
  color: #6c757d;
}

/* Invalid (single) */
.is-invalid + .select2-container .select2-selection--single {
  border-color: #dc3545;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='red'%3e%3cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M12 8v4m0 4h.01'%3e%3c/path%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* --- Multiple select (tags) ---------------------------------------------- */
.select2-container--default .select2-selection--multiple {
  min-height: calc(2.3rem + 2px);
  padding: 0.375rem 2rem 0.375rem 0.75rem; /* extra right room for global clear × */
  border: 1px solid #ced4da;
  border-radius: 0.375rem;
  background-color: #fff;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  font-size: 1rem;
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  box-shadow: none;
  position: relative;
}

/* Focus ring (when any inner input has focus) */
.select2-container--default .select2-selection--multiple:focus,
.select2-container--default
  .select2-selection--multiple.select2-selection--focus,
.select2-container--default.select2-container--focus
  .select2-selection--multiple {
  border-color: #86b7fe;
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Disabled */
.select2-container--default.select2-container--disabled
  .select2-selection--multiple {
  background-color: #e9ecef;
  color: #6c757d;
}

/* Invalid (multiple) — border & keep tags as-is */
.is-invalid + .select2-container .select2-selection--multiple {
  border-color: #dc3545;
}

/* Inner search field (the caret area) */
.select2-container--default
  .select2-selection--multiple
  .select2-search__field {
  margin: 0;
  padding: 0;
  height: auto;
  line-height: 1.5;
  font-size: 1rem;
  border: none !important;
  outline: none !important;
  flex: 1 0 auto;
}

/* Global clear × (allowClear:true) */
.select2-container--default
  .select2-selection--multiple
  .select2-selection__clear {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  color: #6c757d;
  opacity: 0.8;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.select2-container--default
  .select2-selection--multiple
  .select2-selection__clear:hover {
  opacity: 1;
}

/* --- Tag chip ------------------------------------------------------------- */
.select2-container--default
  .select2-selection--multiple
  .select2-selection__choice {
  /* badge-like look */
  background-color: var(--bs-primary);
  color: #fff;
  border: 0;
  border-radius: var(--bs-border-radius);
  /* roomy sizing */
  padding: 0.45em 0.9em;
  margin-top: 0.35rem;
  margin-right: 0.35rem;
  /* robust layout for text + close button */
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

/* Text comes first */
.select2-container--default
  .select2-selection--multiple
  .select2-selection__choice__display {
  order: 1;
  padding: 0;
  margin: 0;
}

/* Close button on the RIGHT with a square, comfy hitbox */
.select2-container--default
  .select2-selection--multiple
  .select2-selection__choice__remove {
  order: 2;
  position: static;
  float: none;
  border: 0;
  margin: 0 0 0 0.25rem;
  padding: 0;

  width: 1.25rem;
  min-width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  border-radius: 0.25rem;
  font-size: 0.95rem;
  line-height: 1;
  color: #fff;
  opacity: 0.9;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.18);
}
.select2-container--default
  .select2-selection--multiple
  .select2-selection__choice__remove:hover {
  background: rgba(255, 255, 255, 0.28);
  opacity: 1;
}
