/*
 * THE LISTBOX BODY — Base UI's `Combobox` supplies the keyboard model, the
 * highlight and the filtering; this sheet supplies the surface. Two washes, one
 * weight apart, so `[data-selected]` and `[data-highlighted]` stay tellable.
 *
 * The scroll lives on the list rather than on the root, so a search field and a
 * select-all band stay OUTSIDE it and a long list scrolls under both.
 */
@layer theme, base, lotics, components, utilities;
@layer lotics.tokens, lotics.reset, lotics.components;

@layer lotics.components {
  .lotics-option-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    /* The capture input below is absolute, so the anatomy anchors it itself:
       otherwise focusing it scrolls the page to whatever ancestor is positioned. */
    position: relative;
    min-width: 0;
    gap: var(--lotics-space-4);
    max-height: 480px;
  }

  /* On a phone the body fills the sheet it was opened into rather than capping
     itself part-way down it. */
  .lotics-option-list[data-compact] {
    flex: 1;
    max-height: none;
  }


  /* The shell paints the field; the input only holds the words — the same split
     and the same tokens `TextInput` uses. */
  .lotics-option-list__search {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    flex-shrink: 0;
    min-width: 0;
    height: var(--lotics-control-height);
    border-width: 1px;
    border-style: solid;
    border-color: var(--input);
    border-radius: var(--lotics-radius-control);
    background-color: var(--popover);
    transition-property: border-color, outline-color;
    transition-duration: var(--lotics-duration-fast);
    transition-timing-function: var(--lotics-ease-standard);
  }

  .lotics-option-list__search:hover {
    border-color: var(--lotics-border-hover);
  }

  .lotics-option-list__search:focus-within {
    outline-width: var(--lotics-ring-width);
    outline-style: solid;
    outline-color: var(--ring);
    outline-offset: 0;
  }

  .lotics-option-list__search-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-start;
    width: 20px;
    height: 20px;
    margin-block-start: var(--lotics-space-8);
    margin-inline-start: var(--lotics-space-8);
    --lotics-icon-color: var(--lotics-ink-inactive);
  }

  .lotics-option-list__input {
    flex: 1;
    min-width: 0;
    align-self: stretch;
    margin: 0;
    padding-block: var(--lotics-space-8);
    padding-inline-start: var(--lotics-space-6);
    padding-inline-end: var(--lotics-space-8);
    border-width: 0;
    border-style: solid;
    border-color: transparent;
    border-radius: 0;
    background-color: transparent;
    color: var(--lotics-ink-default);
    font-family: var(--font-sans);
    font-size: var(--lotics-input-text);
    line-height: var(--lotics-input-leading);
    letter-spacing: var(--lotics-input-tracking);
    font-weight: var(--lotics-weight-regular);
    appearance: none;
    outline-style: none;
    cursor: text;
  }

  .lotics-option-list__input::placeholder {
    color: var(--lotics-ink-placeholder);
    /* Firefox dims a placeholder by default; the ink role already is the dim. */
    opacity: 1;
  }

  /* The CAPTURE input of a field-less list: focusable, and 1×1 rather than
     `display: none`, which no browser focuses. */
  .lotics-option-list__input[data-hidden] {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    opacity: 0;
    pointer-events: none;
  }


  .lotics-option-list__list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 1;
    min-width: 0;
    min-height: 0;
    max-height: 320px;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* 2, where a field's chips sit at 4: a row here needs only enough space to
       stop two tinted rows reading as one block. */
    gap: var(--lotics-space-2);
  }

  .lotics-option-list__item {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-shrink: 0;
    gap: var(--lotics-space-8);
    min-height: var(--lotics-control-height);
    padding-block: var(--lotics-space-8);
    padding-inline: var(--lotics-space-8);
    border-radius: var(--lotics-radius-control);
    background-color: transparent;
    color: var(--lotics-ink-default);
    /* A menu option SETS a value rather than acting on its own, so it keeps the
       arrow. */
    cursor: default;
    user-select: none;
    outline-style: none;
    transition: background-color var(--lotics-duration-fast) var(--lotics-ease-standard);
  }

  /* The keyboard/pointer row, one weight under the chosen one. */
  .lotics-option-list__item[data-highlighted] {
    background-color: var(--lotics-wash-hover);
  }

  /* The CHOSEN row wins, so a highlighted neighbour never outranks it. An OPAQUE
     colour is safe because the ground under it is one; on the canvas a row still
     takes the alpha wash. */
  .lotics-option-list__item[data-selected] {
    background-color: var(--accent);
    color: var(--accent-foreground);
  }

  .lotics-option-list__item[data-disabled] {
    opacity: 0.6;
    color: var(--lotics-ink-inactive);
  }

  .lotics-option-list__item-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1;
    min-width: 0;
    gap: var(--lotics-space-2);
  }

  .lotics-option-list__item-description {
    min-width: 0;
  }

  .lotics-option-list__status {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding-block: var(--lotics-space-16);
    padding-inline: var(--lotics-space-8);
  }

  /* Base UI keeps the element mounted so it can announce; an EMPTY one takes no
     room. */
  .lotics-option-list__status:empty {
    display: none;
  }

  /* The footer band. The 8px inset matches an option row's, so a Button's SURFACE
     starts on the same edge as the rows above it. */
  .lotics-option-list__footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-shrink: 0;
    gap: var(--lotics-space-16);
    padding-block: var(--lotics-space-4) 0;
    padding-inline: var(--lotics-space-8);
    border-block-start-width: 1px;
    border-block-start-style: solid;
    border-block-start-color: var(--border);
  }

  /* The MULTI footer sits above the popup's own bottom inset with a band of its
     own; the single-select Clear is the panel's last row and takes the panel's. */
  .lotics-option-list__footer[data-multi] {
    padding-block: var(--lotics-space-4);
  }
}
