:where(.combobox-options) {
  padding: 0;
  border: 0;
}

:where(.combobox-options [role='listbox']) {
  max-height: var(--options-max-height, 15rem);
  margin: 0;
  overflow-y: auto;
}

/* The end of every option keeps room for the check, so labels don't shift when it shows */
:where(.combobox-options [role='option']) {
  position: relative;
  margin: 0;
  padding: var(--option-padding, 0.25lh 0.5lh);
  padding-inline-end: 2.5em;
  cursor: pointer;
}

/* The search status lines up with the options */
:where(.combobox-options .combobox-status) {
  padding: var(--option-padding, 0.25lh 0.5lh);
}

/* Keeps the pointer cursor over an option's own markup */
:where(.combobox-options [role='option'] > *) {
  pointer-events: none;
}

/* An option a full selection refuses. It stays in the list so the person can still read it. */
:where(.combobox-options [aria-disabled='true']) {
  opacity: 0.4;
  cursor: not-allowed;
}

/* The selection — what was chosen. Comes before the band, so the band shows over the tint when both land on one option. Without --font-weight-selected, the weight stays inherited. */
:where(.combobox-options [aria-selected='true']) {
  font-weight: var(--font-weight-selected);
  background: var(
    --bg-selected-color,
    color-mix(in oklab, currentcolor 7%, transparent)
  );
}

/* The band — where the keyboard or pointer is. Defaults to the platform's own colors for the current item in a list. */
:where(
  .combobox-options [data-highlighted],
  .combobox-options [role='option']:focus
) {
  color: var(--text-highlighted-color, HighlightText);
  background: var(--bg-highlighted-color, Highlight);
}

/* prepareOptions copies the check into every option, and only a selected option shows it */
:where(.combobox-options .option-check) {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0.75em;
  display: flex;
  align-items: center;
  visibility: hidden;

  svg {
    width: 1em;
    height: 1em;
  }
}

:where(.combobox-options [aria-selected='true'] .option-check) {
  visibility: visible;
}

/* The create option, shown while the typed text matches nothing */
:where(.combobox-options [data-create]) {
  font-style: italic;
}

/* Highlight pseudo-elements only take properties that don't affect layout, so the match can be recoloured but never bolded. font-weight here is silently ignored. */
::highlight(match) {
  color: var(--text-match-color, #7c3aed);
  text-decoration: underline;
}

/* The chips and the input share one box, and wrap onto the next line once the row fills up */
:where(.combobox .input-group) {
  @apply focus-within;
  flex-wrap: wrap;
  align-items: center;
}

/* Each chip joins the box's own row, so the field can sit after the last one */
:where(.combobox .chips) {
  display: contents;
}

/* With chips, the box holds the padding, so the chips and the field's text start at the same edge */
:where(.combobox .input-group:has(.chip)) {
  gap: 0.25lh;
  padding: var(--padding);

  .input {
    padding: 0;
  }
}

/* The field wraps to its own row once its placeholder or text no longer fits */
:where(.combobox .input-group .input) {
  flex: 1 1 var(--field-min-width, max-content);
  field-sizing: content;
  min-width: 0;
}

/* The Select's button reads like a text field, with a caret at the end. The text's track has no minimum, so long text can't widen a container that sizes to its content. */
:where(.select-trigger) {
  display: grid;
  grid-template-columns: minmax(0, max-content) auto;
  justify-content: space-between;
  align-items: center;
  gap: 0.5em;
  text-align: start;
  cursor: pointer;

  svg {
    flex-shrink: 0;
    width: 1em;
    height: 1em;
  }
}

/* A long placeholder or label ends in an ellipsis instead of pushing the caret out */
:where(.select-trigger-text) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:where(.select-placeholder) {
  opacity: 0.5;
}

:where(.chips .chip) {
  display: flex;
  align-items: center;
  gap: 0.125em;
  margin: 0;
  padding-inline: 0.5em 0.125em;
  border-radius: calc(var(--radius, 0.25rem) / 2);
  color: var(--text-chip-color, inherit);
  background: var(
    --bg-chip-color,
    color-mix(in oklab, currentcolor 10%, transparent)
  );
}

:where(.chips .chip-remove-button) {
  display: grid;
  place-items: center;
  width: 1.25em;
  height: 1.25em;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: inherit;
  background: none;
  opacity: 0.6;
  cursor: pointer;

  svg {
    width: 0.75em;
    height: 0.75em;
  }

  &:hover,
  &:focus-visible {
    background: color-mix(in oklab, currentcolor 15%, transparent);
    opacity: 1;
  }
}
