/*
 * Combobox: a control-sized row holding a text input and a trailing caret trigger, or Select's trigger button with the
 * input in the popup; its listbox reuses Select's popup and item rules.
 */

@layer dx-components {
  /* The root takes no box, so its label and control are laid out as the parent's children. */
  .dx-combobox {
    display: contents;
  }
  :is(.dx-field, .dx-container[data-layout='stack']) > .dx-combobox > .dx-control {
    margin-block: var(--dx-control-inset);
  }

  .dx-combobox-control {
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
    padding-inline-end: 0;
    background: var(--color-input-bg);
  }
  /*
   * A wrapping row (a multiple selection's chips): one inset of padding round lines one tag tall, so a single line is
   * control-tall; the caret takes a tag-tall cell at the end of the last line.
   */
  .dx-combobox-control[data-wrap] {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--dx-control-size);
    padding-block: var(--dx-control-inset);
    gap: var(--dx-control-inset) var(--dx-gap-size);
  }
  /* Text in the row (a placeholder) is one tag tall, not a block, so an empty control is as tall as an Input. */
  .dx-combobox-control > .dx-typography {
    padding-block: 0;
  }
  .dx-combobox-control[data-wrap] > .dx-combobox-trigger {
    height: calc(var(--dx-control-size) - 2 * var(--dx-control-inset));
    margin-inline-start: auto;
  }
  /* An outline, not an inset shadow: it paints above the trigger's own fill instead of under it. */
  .dx-combobox-control:has(> .dx-combobox-input:focus-visible) {
    outline: var(--dx-focus-ring-width) solid var(--dx-focus-ring-color);
    outline-offset: calc(-1 * var(--dx-focus-ring-width));
  }

  .dx-combobox-input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    color: inherit;
  }

  /* A block-wide end cell, so the caret centres on the column of the row's trailing actions. */
  .dx-combobox-trigger {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: var(--dx-block-size);
    height: 100%;
    padding: 0;
    border: none;
    border-radius: inherit;
    background: transparent;
    color: inherit;
    cursor: pointer;
  }
  /* The clear trigger is `hidden` while there is no value, which the grid display above would otherwise override. */
  .dx-combobox-trigger[hidden] {
    display: none;
  }
  .dx-combobox-trigger:hover:not(:disabled) {
    background: var(--color-hover-surface);
  }

  /* The empty state and the loading row. */
  .dx-combobox-empty {
    display: flex;
    align-items: center;
    gap: var(--dx-gap-size);
    height: var(--dx-block-size);
    padding-inline: var(--dx-gap-size);
    color: var(--color-fg-muted);
  }

  /*
   * A popup with a search field: a dialog framing the field above a ScrollArea of the options, so they never scroll
   * beneath it; sized as a scrolling popup is.
   */
  .dx-combobox-frame {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    max-width: var(--available-width, none);
    max-height: min(var(--available-height, 20rem), 20rem);
    padding-block: 0;
    overflow: hidden;
    --scroll-thumb-inset: var(--dx-focus-ring-width);
  }
  .dx-combobox-frame > .dx-scroll-root > .dx-scroll-viewport {
    padding: var(--dx-control-inset);
    scroll-padding-block: var(--dx-control-inset);
  }
  .dx-combobox-frame > .dx-scroll-root[data-overflow-y] > .dx-scroll-viewport {
    padding-inline-end: calc(var(--dx-scroll-width) + 2 * var(--scroll-thumb-inset));
  }

  /* The popup's search field, above the scrolling options. */
  .dx-combobox-search {
    display: block;
    width: 100%;
    height: var(--dx-block-size);
    padding-inline: var(--dx-gap-size);
    border: none;
    border-block-end: 1px solid var(--color-separator);
    border-radius: 0;
    outline: none;
    background: var(--surface-bg);
    font: inherit;
    color: inherit;
  }

  /*
   * A row with a description is a grid: the icon cell, the text over its description in the growing column, then the
   * indicator; it grows by the description's line.
   */
  .dx-combobox-item:has(> .dx-combobox-item-description) {
    --dx-combobox-text-column: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: var(--dx-gap-size);
    align-items: center;
    height: auto;
    min-height: var(--dx-block-size);
    padding-block: calc((var(--dx-block-size) - var(--dx-line-height)) / 2);
  }
  .dx-combobox-item:has(> .dx-combobox-item-description):has(> .dx-icon:first-child) {
    --dx-combobox-text-column: 2;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }
  .dx-combobox-item:has(> .dx-combobox-item-description) > * {
    grid-row: 1 / -1;
  }
  .dx-combobox-item:has(> .dx-combobox-item-description) > [data-part='item-text'] {
    grid-row: 1;
    grid-column: var(--dx-combobox-text-column);
  }
  .dx-combobox-item > .dx-combobox-item-description {
    grid-row: 2;
    grid-column: var(--dx-combobox-text-column);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-fg-muted);
  }
}
