/* Tom Select, in Capsule's tokens.
 *
 * Tom Select builds its own DOM at runtime, so none of this can be a Tailwind utility — it has
 * to be written against the classes the library emits. Everything reads var(--color-*), which
 * the Tailwind build declares per theme, so the widget follows light and dark with the rest of
 * the page. It used to be a wall of hard-coded slate and blue hex, which meant a dark dropdown
 * on a white page the moment anyone chose the light theme.
 *
 * Shapes are matched to CapsuleHelper::FIELD_BASE — same height, radius, border and ground —
 * so a Tom Select control sits in a form beside a plain input without a seam.
 */

.ts-wrapper {
  position: relative;
  display: block;
  width: 100%;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--color-text);
}

.ts-control {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  box-sizing: border-box;
  min-height: 2.75rem; /* 44px — matches field_classes' min-h-11 */
  width: 100%;
  background-color: var(--color-void);
  color: var(--color-text);
  border: 1px solid var(--color-line-strong);
  border-radius: 0.25rem;
  padding: 0.375rem 0.5rem;
  cursor: text;
  transition: border-color 0.12s;
}

.ts-wrapper.single .ts-control {
  cursor: pointer;
}

.ts-wrapper.disabled .ts-control,
.ts-control.is-disabled {
  background: var(--color-raise);
  color: var(--color-faint);
  cursor: not-allowed;
  opacity: 0.7;
}

.ts-control input {
  color: inherit;
  background: transparent;
  border: 0;
  outline: none;
  padding: 0 0.25rem;
  margin: 0.125rem 0;
  line-height: 1.4;
  min-width: 2ch;
}

.ts-control input::placeholder {
  color: var(--color-faint);
}

/* A selected item is the accent badge: a /10 tint and a border in the accent. */
.ts-control .item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.375rem;
  margin: 0.125rem;
  border-radius: 3px;
  border: 1px solid color-mix(in srgb, var(--color-holo) 35%, transparent);
  background-color: color-mix(in srgb, var(--color-holo) 10%, transparent);
  color: var(--color-holo);
  font-size: 0.8125rem;
  font-weight: 600;
}

.ts-control .item .remove {
  opacity: 0.85;
  cursor: pointer;
  font-weight: 700;
}

.ts-control .item .remove:hover {
  opacity: 1;
}

.ts-dropdown,
.ts-dropdown.form-control {
  position: absolute;
  box-sizing: border-box;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background: var(--color-hull);
  color: var(--color-text);
  border: 1px solid var(--color-line-strong);
  border-radius: 0.25rem;
  box-shadow: 0 10px 25px rgb(0 0 0 / 0.25), 0 4px 10px rgb(0 0 0 / 0.15);
  z-index: 60; /* above the panel it opens over; the account menu is 50 and never overlaps one */
  overflow: hidden;
}

.ts-dropdown [data-selectable] {
  cursor: pointer;
}

.ts-dropdown .create {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--color-line);
  color: var(--color-dim);
}

.ts-dropdown-content {
  max-height: 16rem;
  overflow-y: auto;
}

.ts-dropdown .option,
.ts-dropdown .optgroup-header {
  padding: 0.5rem 0.75rem;
  line-height: 1.25rem;
  font-size: 0.8125rem;
}

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

/* raise is the surface the design language names for hover, and it is opaque — a translucent
   wash here would REPLACE the dropdown's ground rather than sit on it. */
.ts-dropdown .option.active,
.ts-dropdown .option.selected,
.ts-dropdown .option:hover {
  background: var(--color-raise);
  color: var(--color-text);
}

.ts-dropdown .optgroup-header {
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-dim);
  background: var(--color-raise);
}

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

.ts-wrapper .ts-loading-spinner {
  margin-left: 0.5rem;
  border: 2px solid var(--color-line);
  border-top-color: var(--color-holo);
  border-radius: 50%;
  width: 1rem;
  height: 1rem;
  animation: ts-spin 0.7s linear infinite;
}

@keyframes ts-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .ts-wrapper .ts-loading-spinner {
    animation-duration: 2s;
  }
}

/* Clear button plugin */
.ts-control .clear-button {
  margin-left: 0.25rem;
  cursor: pointer;
  color: var(--color-faint);
}

.ts-control .clear-button:hover {
  color: var(--color-text);
}

/* Dropdown caret for single select */
.ts-wrapper.single .ts-control::after {
  content: "";
  border-style: solid;
  border-width: 0.3rem 0.3rem 0 0.3rem;
  border-color: var(--color-dim) transparent transparent transparent;
  display: block;
  position: absolute;
  top: 50%;
  right: 0.75rem;
  transform: translateY(-50%);
  pointer-events: none;
}

/* Ensure the control fills the container width */
.ts-control,
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
  width: 100%;
}

/* Hide the original select element */
.ts-hidden-accessible {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
}
