/* Mira design-system theme for Tom Select. Loaded after tom-select.css (base) and
   the Tailwind build, so these rules win and the design tokens (var(--color-*),
   defined at :root by the Tailwind @theme) resolve. Mirrors the form-field chrome
   (Forms::InputComponent) and the accent chip tokens. */

/* Tom Select copies the native control's utility classes onto .ts-wrapper (border, radius,
   background, height, padding). The themed box is .ts-control, so neutralize the wrapper's
   box model — otherwise the copied border/height/padding draw a second, mis-aligned box
   around the control (a nested "double box"). Width is left intact: full-field keeps the
   copied w-full; the compact pill is sized via .ts-compact below. */
.ts-wrapper {
  font-family: var(--font-sans);
  border: 0;
  border-radius: 0;
  background-color: transparent;
  padding: 0;
  height: auto;
  min-height: 0;
}

/* The control box — matches the Input/Select field chrome. */
.ts-control {
  min-height: 2.5rem;
  gap: 0.375rem;
  padding: 0.3125rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface-card);
  color: var(--color-text-primary);
  box-shadow: none;
}

.ts-wrapper.focus .ts-control {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-focus-ring);
  outline: none;
}

/* Error state: the danger border class is copied onto the wrapper; surface it on the
   themed .ts-control box (the wrapper's own border is neutralized above). */
.ts-wrapper.border-danger .ts-control {
  border-color: var(--color-danger);
}

.ts-control > input,
.ts-control > input::placeholder {
  color: var(--color-text-muted);
  font-size: var(--text-body);
}

.ts-wrapper.disabled .ts-control {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Selected tags / chips — the accent-soft pill from the design system. */
.ts-wrapper.multi .ts-control > .item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.625rem;
  border: none;
  border-radius: 9999px;
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-size: var(--text-caption);
  font-weight: 500;
}

.ts-wrapper.multi .ts-control > .item.active {
  background: var(--color-accent);
  color: var(--color-text-on-accent);
}

.ts-wrapper .ts-control > .item .remove {
  border: none;
  padding: 0 0.25rem;
  color: inherit;
}

.ts-wrapper .ts-control > .item .remove:hover {
  background: rgba(15, 23, 42, 0.08);
}

/* Dropdown panel. */
.ts-dropdown {
  margin-top: 0.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-card);
  color: var(--color-text-primary);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

.ts-dropdown .option {
  padding: 0.5rem 0.75rem;
  font-size: var(--text-body);
}

.ts-dropdown .option:hover,
.ts-dropdown .active {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.ts-dropdown .create {
  padding: 0.5rem 0.75rem;
  color: var(--color-accent);
}

.ts-dropdown .no-results {
  padding: 0.5rem 0.75rem;
  color: var(--color-text-muted);
}

.ts-dropdown .optgroup-header {
  padding: 0.4rem 0.75rem 0.2rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Single-select keeps the component's chevron <span> as the dropdown indicator (the vendored
   Tom Select core draws no caret). Vertically center the value/placeholder, pad the control's
   right edge so it clears the chevron, and flip the chevron while the dropdown is open. */
.ts-wrapper.single .ts-control {
  align-items: center;
  padding-right: 2.25rem;
}

.ts-wrapper.single.dropdown-active ~ [data-select-chevron] svg {
  transform: rotate(180deg);
}

/* Clearable single selects (non-required: filters, optional FKs) get the clear_button ✕.
   Seat it to the left of the chevron and widen the control's right padding for both. */
.ts-wrapper.single.plugin-clear_button .ts-control {
  padding-right: 3.5rem;
}

.ts-wrapper.single.plugin-clear_button .clear-button {
  right: 2rem;
  color: var(--color-text-muted);
}

/* Compact filter-pill variant (index toolbars, e.g. "Cliente ▾"): smaller, inline, auto
   width. The select controller adds .ts-compact when the component is compact. The right
   padding keeps the value clear of the chevron (mirrors the pill's pr-8). */
.ts-wrapper.ts-compact {
  width: auto;
  display: inline-block;
  min-width: 9rem;
}

.ts-wrapper.ts-compact .ts-control {
  min-height: 2.25rem;
  padding: 0.25rem 2rem 0.25rem 0.75rem;
}
