/*
 * Styling for the searchable select (ui--searchable-select). The markup and class names come from
 * TomSelect; the look is rebuilt here on semantic tokens so it matches ui/select.css and follows
 * theme/mode overrides. The vendored TomSelect stylesheet is deliberately not shipped.
 *
 * The single !important guards .ts-hidden-accessible's width: these selects carry `expand`, and
 * ui/select.css's `select.expand` outranks a lone class, so it would stretch the hidden source-of-truth
 * select to full width. What hides it is position plus clip-path, not its width. Every other rule
 * here wins on specificity alone.
 */

.ts-wrapper {
  position: relative;
  display: flex;
  min-width: 100px;
  max-width: 200px;
}

.ts-wrapper.expand {
  width: 100%;
  max-width: 100%;
}

@media (min-width: 1240px) {
  .ts-wrapper {
    max-width: 275px;
  }
}

.ts-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 40px;
  padding: 4px 35px 4px 12px;
  border: solid 1px var(--color-border-primary);
  border-radius: 2px;
  background: var(--color-bg-primary);
  color: var(--color-text-secondary);
  font-size: 16px;
  line-height: 24px;
  cursor: text;
}

.ts-wrapper.single .ts-control {
  cursor: pointer;
  background: var(--color-bg-primary) var(--select-chevron) no-repeat;
  background-position-x: calc(100% - 8px);
  background-position-y: center;
}

.ts-wrapper.focus .ts-control {
  border-color: var(--color-border-brand);
}

.ts-wrapper.disabled .ts-control {
  background-color: var(--color-bg-disabled);
  color: var(--color-text-tertiary);
  cursor: default;
}

.ts-wrapper.disabled .ts-control * {
  cursor: default;
}

.ts-control > input[type="text"] {
  flex: 1 1 auto;
  min-width: 7rem;
  height: auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0 none;
  border-radius: 0;
  background: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

.ts-control > input[type="text"]:focus {
  outline: none;
}

.ts-wrapper.input-hidden .ts-control > input {
  opacity: 0;
  position: absolute;
  left: -10000px;
}

/* Selected values in a multi select. */

.ts-wrapper.multi .ts-control > .item {
  display: inline-flex;
  align-items: center;
  padding: 0 2px 0 8px;
  border: solid 1px var(--color-border-brand);
  border-radius: var(--border-radius-xs);
  background: var(--color-bg-brand-primary);
  color: var(--color-text-brand-primary);
  font-size: var(--font-size-sm);
  line-height: 22px;
}

.ts-wrapper.multi .ts-control > .item.active {
  background: var(--color-bg-brand-secondary);
}

.ts-wrapper.multi.disabled .ts-control > .item {
  border-color: var(--color-border-disabled);
  background: var(--color-bg-disabled);
  color: var(--color-text-tertiary);
}

.ts-wrapper.plugin-remove_button .item .remove {
  padding: 0 6px;
  color: inherit;
  text-decoration: none;
}

.ts-wrapper.plugin-remove_button .item .remove:hover {
  color: var(--color-text-brand-secondary);
}

.ts-wrapper.plugin-remove_button.disabled .item .remove {
  display: none;
}

.ts-wrapper.plugin-clear_button .clear-button {
  position: absolute;
  top: 50%;
  right: 26px;
  transform: translateY(-50%);
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--color-text-tertiary);
  font-size: var(--font-size-lg);
  line-height: 1;
  cursor: pointer;
  transition: opacity 0.2s;
}

.ts-wrapper.plugin-clear_button.focus.has-items .clear-button,
.ts-wrapper.plugin-clear_button:not(.disabled):hover.has-items .clear-button {
  opacity: 1;
}

/* Dropdown. */

.ts-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  z-index: 20;
  width: 100%;
  margin: 0;
  border: solid 1px var(--color-border-primary);
  border-radius: 2px;
  background: var(--color-bg-primary);
  color: var(--color-text-secondary);
  font-size: 16px;
  line-height: 24px;
}

.ts-dropdown-content {
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.ts-dropdown .option,
.ts-dropdown .no-results {
  padding: 8px 12px;
}

.ts-dropdown .option {
  color: var(--color-text-disabled);
  cursor: default;
}

.ts-dropdown [data-selectable].option {
  color: var(--color-text-secondary);
  cursor: pointer;
}

.ts-dropdown .active {
  background-color: var(--color-bg-brand-primary);
  color: var(--color-text-brand-primary);
}

.ts-dropdown .selected {
  font-weight: var(--weight-medium);
}

.ts-dropdown [data-selectable] .highlight {
  border-radius: 1px;
  background: var(--color-bg-brand-secondary);
}

.ts-dropdown .no-results {
  color: var(--color-text-tertiary);
}

/* The original select stays in the DOM as the source of truth, visually hidden. */

.ts-hidden-accessible {
  position: absolute;
  width: 1px !important;
  height: 1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
}
