/*
 * COMBOBOX COMPONENT DOCUMENTATION
 * ================================
 *
 * This stylesheet implements the TomSelect library which enhances standard select elements
 * with search, autocomplete, and custom styling.
 *
 * PROPER USAGE:
 * -------------
 * 1. Apply the data-controller="combobox" attribute DIRECTLY to the SELECT or INPUT element:
 *    <select data-controller="combobox">...</select>
 *    
 * 2. Do NOT apply the data-controller to a wrapper div:
 *    INCORRECT: <div data-controller="combobox"><select>...</select></div>
 *    The controller expects to be attached to a form element, not a container.
 *
 * 3. Do NOT manually add the "tomselected" or "ts-hidden-accessible" classes - these
 *    are added automatically by the TomSelect initialization process.
 *
 * 4. When using option groups, make sure to use grouped_options_for_select in Rails:
 *    CORRECT: grouped_options_for_select([["Group Name", [["Option1", 1], ["Option2", 2]]]])
 *    INCORRECT: options_for_select([["Group Name", [["Option1", 1], ["Option2", 2]]]])
 *    Using the wrong helper will result in non-functional dropdowns, with groups showing as options.
 *
 * HOW IT WORKS:
 * -------------
 * 1. The combobox_controller.js initializes TomSelect on the element it's attached to
 * 2. TomSelect hides the original SELECT element using the CSS at the bottom of this file
 * 3. TomSelect creates its own custom UI elements as siblings to the original element
 * 4. These custom elements are styled using the CSS rules in this file
 *
 * TROUBLESHOOTING:
 * ----------------
 * - If nothing appears: Make sure data-controller="combobox" is on the SELECT element itself
 * - If you see "Cannot read properties of undefined (reading 'trim')": 
 *   The controller is attached to a non-form element instead of the SELECT
 * - If the dropdown styling looks wrong: Check the CSS paths for select-arrow.svg
 * - If only option groups show but no options: You're using options_for_select with nested arrays
 *   instead of grouped_options_for_select. Change to grouped_options_for_select.
 *
 * CSS CLASSES:
 * ------------
 * - ts-wrapper: The main wrapper created by TomSelect
 * - ts-control: The input/display area 
 * - ts-dropdown: The dropdown menu that appears when clicked
 */

@import url("https://esm.sh/tom-select@2.4.3/dist/css/tom-select.min.css");

.ts-control {
  align-items: center;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--rounded-md);
  min-block-size: var(--size-9);
  color: var(--color-text);
  display: inline-flex;
  font-size: var(--text-sm);
  line-height: inherit;
  padding: var(--size-1_5) var(--size-3);

  > input {
    color: inherit; font-size: inherit;
  }
}

.ts-dropdown {
  border: 1px solid var(--color-border);
  border-radius: var(--rounded-md);
  box-shadow: var(--shadow-md);
  color: var(--color-text);
  font-size: var(--text-sm);
  line-height: inherit;

  /* Setup transition */
  transition-behavior: allow-discrete;
  transition-duration: var(--time-150);
  transition-property: display, opacity, transform;

  /* Exit stage to */
  opacity: 0;
  transform: var(--scale-95);

  /* On stage */
  .dropdown-active & {
    opacity: 1; transform: var(--scale-100);
  }

  /* Enter stage from */
  @starting-style {
    .dropdown-active & {
      opacity: 0; transform: var(--scale-95);
    }
  }

  .ts-dropdown-content:not(:has(.optgroup)) {
    padding: var(--size-1);
  }

  .optgroup:not(:first-child) {
    border-block-start-width: var(--border);
  }

  .optgroup {
    padding: var(--size-1);
  }

  .optgroup-header {
    background-color: inherit;
    color: var(--color-text-subtle);
    font-size: var(--text-xs);
    padding: var(--size-1_5) var(--size-2);
  }

  .create {
    padding: var(--size-1_5) var(--size-2);
  }

  .option {
    border: 1px solid transparent;
    border-radius: var(--rounded-md);
    padding: var(--size-1_5) var(--size-2);
  }

  .active {
    background-color: var(--color-secondary);
    color: inherit !important;
  }

  .highlight {
    background-color: transparent !important;
  }

  .spinner {
    margin: var(--size-1_5) 0 0;
  }

  .spinner::after {
    border-block-color: var(--color-border-dark);
  }
}

.ts-wrapper.single .ts-control {
  background-color: var(--color-bg) !important;
  background-image: url("/assets/select-arrow-008fd2da.svg") !important;
  background-position: center right var(--size-2) !important;
  background-repeat: no-repeat !important;
  background-size: var(--size-4) auto !important;
}

.ts-wrapper.multi .ts-control > .item {
  background: var(--color-secondary);
  border-radius: var(--rounded-md);
  color: inherit;
  line-height: var(--leading-tight);
}

.disabled .ts-control {
  opacity: var(--opacity-50);
}

.disabled .ts-control * {
  cursor: not-allowed !important;
}

.invalid .ts-control {
  border-color: var(--color-negative);
}

[data-controller~="combobox"] {
  clip: rect(0 0 0 0); position: absolute;
}
