/**
 * Custom Choices.js Styling to Match Project Theme
 */

/* Container and outer wrapper */
.choices {
  position: relative;
  z-index: 1;
  isolation: auto !important;
  margin-bottom: 0;
  font-size: 1rem;
  width: 100%;
  font-family: var(--app-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif) !important;
}

/* Only the OPEN dropdown gets a high z-index so its list paints
   above all sibling dropdowns that come after it in the DOM. */
.choices.is-open {
  z-index: 9999 !important;
}

.choices.is-open .choices__inner {
  border-color: var(--bs-primary, #696cff);
  box-shadow: 0 0 0 0.2rem rgba(105, 108, 255, 0.25);
}

.choices__inner {
  display: flex;
  align-items: center;
  width: 100%;
  background-color: #fff;
  padding: 0.375rem 0.75rem;
  border: 1px solid #dee2e6;
  border-radius: 0.25rem;
  font-size: 1rem;
  min-height: 2.5rem;
  overflow: hidden;
  transition: all 0.15s ease;
  box-sizing: border-box;
}

/* Hide native select once Choices.js has taken over */
select.searchable-select {
  position: absolute !important;
  opacity: 0 !important;
  height: 0 !important;
  width: 0 !important;
  pointer-events: none !important;
  overflow: hidden !important;
}

/* Focus state */
.choices__inner:focus-within {
  border-color: var(--bs-primary, #696cff);
  box-shadow: 0 0 0 0.2rem rgba(105, 108, 255, 0.25);
}

/* Search input */
.choices__input {
  background-color: transparent;
  font-size: inherit;
  border: none;
  outline: none;
  padding: 0.375rem 0;
  margin: 0;
  width: 100%;
  display: inline-block;
  vertical-align: middle;
}

.choices__input::placeholder {
  color: #6c757d;
  opacity: 1;
}

.choices__input:focus {
  outline: none;
}

/* List */
.choices__list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.choices__list--single {
  display: inline;
}

.choices__list--multiple {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Items (selected) */
.choices__item {
  display: inline-block;
  vertical-align: middle;
  background-color: transparent;
  color: #212529;
  border-radius: 0;
  font-size: 0.875rem;
  padding: 0;
  word-break: break-all;
  margin-right: 0;
  margin-bottom: 0;
  border: none;
}

.choices__item.is-selected {
  background-color: transparent;
  color: #212529;
  border-color: transparent;
}

.choices__item--selectable {
  cursor: pointer;
}

/* Remove button */
.choices__button {
  text-indent: -9999px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border: 0;
  background-color: transparent;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='%23fff' d='M11.414 1.414L6.828 6 11.414 10.586A2 2 0 1 1 10.586 11.414L6 6.828 1.414 11.414A2 2 0 1 1 .586 10.586L5.172 6 .586 1.414A2 2 0 1 1 1.414.586L6 5.172 10.586.586A2 2 0 1 1 11.414 1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-left: 0.4rem;
  padding: 0;
}

.choices__button:hover,
.choices__button:focus {
  outline: none;
}

/* Dropdown list — grows to fit its longest option, never narrower than trigger */
.choices__list--dropdown {
  visibility: hidden;
  z-index: 10000 !important;
  position: absolute;
  top: 100%;
  left: 0;
  right: auto;           /* don't constrain the right edge to the trigger */
  width: auto;           /* let content determine width */
  min-width: max-content;/* expand to fit the longest option label */
  max-width: min(360px, 90vw); /* cap at 360px, never wider than viewport */
  margin-top: 0.25rem;
  border: 1px solid #dee2e6;
  background-color: #fff;
  border-radius: 0.25rem;
  overflow: hidden;
  will-change: visibility;
  max-height: 500px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.choices.is-open .choices__list--dropdown {
  visibility: visible;
}

/* Dropdown items — show full text, wrap to 2 lines max if needed */
.choices__list--dropdown .choices__item {
  position: relative;
  padding: 0.5rem 1rem;
  width: 100%;
  margin: 0;
  background-color: #fff;
  color: #000;
  cursor: pointer;
  user-select: none;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  border: none;
  border-bottom: 1px solid #e9ecef;
  line-height: 1.5;
  box-sizing: border-box;
}

.choices__list--dropdown .choices__item:last-child {
  border-bottom: none;
}

.choices__list--dropdown .choices__item--selectable:hover {
  background-color: #f8f9fa;
}

.choices__list--dropdown .choices__item--selectable.is-highlighted {
  background-color: #f8f9fa;
  color: #000;
}

.choices__list--dropdown .choices__item.is-selected {
  background-color: #fff;
  color: #212529;
}

/* Placeholder */
.choices__placeholder {
  opacity: 1;
  color: #6c757d;
  font-weight: 400;
}

/* Hide the empty placeholder option from the dropdown list */
.choices__list--dropdown .choices__item[data-value=""],
.choices__list[aria-expanded] .choices__item[data-value=""] {
  display: none !important;
}

/* Disabled state */
.choices.is-disabled .choices__inner {
  background-color: #e9ecef;
  border-color: #dee2e6;
  cursor: not-allowed;
  opacity: 0.65;
}

.choices.is-disabled .choices__input {
  cursor: not-allowed;
  color: #6c757d;
}

.choices.is-disabled .choices__item {
  color: #6c757d;
}

select:disabled {
  background-color: #e9ecef;
  border-color: #dee2e6;
  cursor: not-allowed;
  opacity: 0.65;
}

input:disabled,
textarea:disabled {
  background-color: #e9ecef;
  border-color: #dee2e6;
  cursor: not-allowed;
  opacity: 0.65;
  color: #6c757d;
}

/* No results/choices */
.choices__no-results,
.choices__no-choices {
  display: block;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: #999;
  text-align: center;
}

/* Group heading */
.choices__group {
  overflow: hidden;
}

.choices__heading {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  padding: 0.75rem 1rem;
  color: #7a8699;
  background-color: #f7f8fa;
}

/* Loading */
.choices.is-loading .choices__inner::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='%23696cff' stroke-width='2' opacity='0.3'/%3E%3Cpath d='M12 2a10 10 0 0 1 10 10' fill='none' stroke='%23696cff' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  margin-left: 0.5rem;
  animation: choices-loading 1s linear infinite;
}

@keyframes choices-loading {
  to {
    transform: rotate(360deg);
  }
}

/* Bootstrap form validation states */
.form-control.is-invalid ~ .choices,
.form-select.is-invalid ~ .choices {
  border-color: #dc3545;
}

.form-control.is-invalid ~ .choices .choices__inner {
  border-color: #dc3545;
}

.form-control.is-invalid ~ .choices .choices__inner:focus-within {
  border-color: #dc3545;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* Hide unwanted elements/icons in dropdown */
.choices__list--dropdown .choices__item::before,
.choices__list--dropdown .choices__item::after {
  display: none !important;
  content: none !important;
}

/* Hide buttons, SVGs, images, and icon elements in dropdown items */
.choices__list--dropdown .choices__item button,
.choices__list--dropdown .choices__item svg,
.choices__list--dropdown .choices__item img,
.choices__list--dropdown .choices__item i,
.choices__list--dropdown .choices__item [class*="fa-"],
.choices__list--dropdown .choices__item [class*="icon"] {
  display: none !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
}

/* Hide title/tooltip for items */
.choices__list--dropdown .choices__item[title] {
  position: relative;
}

.choices__list--dropdown .choices__item[title]:hover::after {
  display: none !important;
}

/* Prevent any pseudo-element content from showing */
.choices__list--dropdown .choices__item {
  color: #000;
  overflow: hidden;
}

/* Hide specific Unicode characters that might appear in item text */
/* This targets eye/magnifying glass emojis (👁🔍) and similar */
.choices__list--dropdown .choices__item {
  font-size: calc(1rem - 0px);
}

/* Use text rendering to hide specific character widths */
.choices__list--dropdown .choices__item {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Hide eye icon characters by using zero-width styling */
.choices__list--dropdown .choices__item::before,
.choices__list--dropdown .choices__item::after {
  font-size: 0 !important;
}

/* Hide overlapping password toggle buttons when dropdown is open */
.choices.is-open ~ .form-group button.btn[type="button"] {
  visibility: hidden;
  pointer-events: none;
}

/* ── Filter-bar select: ensure selected text never overlaps the arrow ──── */

/* Give single-select inner containers right padding so the caret has room */
.choices[data-type*=select-one] .choices__inner {
  padding-right: 2.5rem !important;
}

/* The list--single also needs to be constrained so it doesn't bleed into the arrow area */
.choices[data-type*=select-one] .choices__list.choices__list--single {
  padding-right: 0 !important;
  overflow: hidden !important;
}

/* Make the selected-item text truncate with ellipsis rather than wrapping */
.choices[data-type*=select-one] .choices__item.choices__item--selectable {
  display: block !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
  max-width: 100% !important;
  padding-right: 0 !important;
}

/* Ensure the Choices.js caret arrow is always visible and right-aligned */
.choices[data-type*=select-one]::after {
  content: '' !important;
  height: 0 !important;
  width: 0 !important;
  border-style: solid !important;
  border-color: #6c757d transparent transparent !important;
  border-width: 5px 5px 0 !important;
  position: absolute !important;
  right: 11px !important;
  top: 50% !important;
  margin-top: -2.5px !important;
  pointer-events: none !important;
}

/* Ensure filter-bar selects always fill their column width */
.filter-bar-select {
  width: 100%;
  min-width: 0;
}

/* Responsive adjustments */
@media (max-width: 576px) {
  .choices__inner {
    min-height: 2.5rem;
    padding: 0.5rem;
  }

  .choices__list--dropdown {
    max-height: 350px;
  }
}

/* Fix: color-mix() unsupported in this browser; override bg-label-* with rgba fallbacks */
.badge.bg-label-primary   { background-color: rgba(var(--bs-primary-rgb),   0.16) !important; color: var(--bs-primary)   !important; }
.badge.bg-label-secondary { background-color: rgba(var(--bs-secondary-rgb), 0.16) !important; color: var(--bs-secondary) !important; }
.badge.bg-label-success   { background-color: rgba(var(--bs-success-rgb),   0.16) !important; color: var(--bs-success)   !important; }
.badge.bg-label-danger    { background-color: rgba(var(--bs-danger-rgb),    0.16) !important; color: var(--bs-danger)    !important; }
.badge.bg-label-warning   { background-color: rgba(var(--bs-warning-rgb),   0.16) !important; color: var(--bs-warning)   !important; }
.badge.bg-label-info      { background-color: rgba(var(--bs-info-rgb),      0.16) !important; color: var(--bs-info)      !important; }
.badge.bg-label-dark      { background-color: rgba(var(--bs-dark-rgb),      0.16) !important; color: var(--bs-dark)      !important; }
