/* ==========================================================================
   Custom Select — brand-styled, searchable replacement for a native <select>
   Backed by a hidden input; see custom_select_controller.js
   ========================================================================== */
.custom-select {
  position: relative;
  width: 100%;
}

/* == Trigger (mirrors .form__select) == */
.custom-select__trigger {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface-sunken);
  font-size: var(--font-size-medium);
  font-family: var(--font-family-base);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast), background-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.custom-select__trigger:hover {
  border-color: var(--color-border-strong);
}

.custom-select--open .custom-select__trigger,
.custom-select__trigger:focus-visible {
  outline: none;
  background-color: var(--color-surface);
  border-color: var(--color-primary-green);
  box-shadow: var(--focus-ring);
}

.custom-select__value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select__placeholder {
  color: var(--color-text-faint);
}

.custom-select__chevron {
  width: 1.5em;
  height: 1.5em;
  flex-shrink: 0;
  color: var(--color-text-muted);
  transition: transform var(--transition-fast);
}

.custom-select--open .custom-select__chevron {
  transform: rotate(180deg);
}

.custom-select--loading .custom-select__trigger {
  cursor: progress;
}

/* == Menu == */
.custom-select__menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  max-height: 280px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* == Search box == */
.custom-select__search {
  position: relative;
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.custom-select__search-icon {
  position: absolute;
  left: calc(var(--space-2) + var(--space-2));
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-faint);
  pointer-events: none;
}

.custom-select__search-input {
  width: 100%;
  height: 34px;
  padding: 0 var(--space-3) 0 var(--space-8);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-surface-sunken);
  font-family: var(--font-family-base);
  font-size: var(--font-size-medium);
  color: var(--color-text);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast),
    background-color var(--transition-fast);
}

.custom-select__search-input:focus {
  outline: none;
  background-color: var(--color-surface);
  border-color: var(--color-primary-green);
  box-shadow: var(--focus-ring);
}

/* == Options == */
.custom-select__options {
  padding: var(--space-1);
  overflow-y: auto;
}

.custom-select__option {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  font-size: var(--font-size-medium);
  font-family: var(--font-family-base);
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.custom-select__option:hover {
  background-color: var(--tint-navy-06);
}

.custom-select__option--selected {
  background-color: var(--tint-green-16);
  color: var(--color-primary-dark);
  font-weight: 600;
}

.custom-select__empty {
  padding: var(--space-4);
  text-align: center;
  font-size: var(--font-size-small);
  color: var(--color-text-muted);
}

/* The way to a value that is not on the list yet (see the partial's `creatable`).
   Sits under the options, divided from them, and reads as the action it is rather
   than as one more option to scan past. */
.custom-select__create {
  display: block;
  width: 100%;
  padding: var(--space-3);
  border: none;
  border-top: 1px solid var(--color-border);
  background: none;
  font-size: var(--font-size-medium);
  font-family: var(--font-family-bold);
  color: var(--color-primary-dark);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.custom-select__create:hover {
  background-color: var(--tint-green-16);
}

/* == Multi-select == */
.custom-select__trigger--multi {
  height: auto;
  min-height: 40px;
  padding: var(--space-1) var(--space-2);
  align-items: center;
}

.custom-select__chips {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  padding: var(--space-1) 0;
}

.custom-select__chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-1) 2px var(--space-2);
  border-radius: var(--radius-full);
  background-color: var(--tint-green-16);
  border: 1px solid var(--tint-green-28);
  color: var(--color-primary-dark);
  font-size: var(--font-size-small);
  line-height: 1.4;
  max-width: 100%;
}

.custom-select__chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select__chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: none;
  border-radius: var(--radius-full);
  background: none;
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.custom-select__chip-remove:hover {
  background-color: var(--tint-green-28);
  color: var(--color-primary-dark);
}

.custom-select__option--check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.custom-select__check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--color-primary-green);
  font-size: 13px;
  opacity: 0;
}

.custom-select__option--selected .custom-select__check {
  opacity: 1;
}
