/*
 * combobox.css — search and pick: a customer, an article, a technician.
 *
 * <div class="app-field">
 *   <label class="app-field-label" id="id-label" for="id">Kunde</label>
 *   <div class="app-combobox">
 *     <div class="app-field-group">
 *       <input class="app-field-control" id="id" type="text" role="combobox" aria-autocomplete="list"
 *              aria-expanded aria-controls="id-list" aria-activedescendant autocomplete="off"
 *              aria-describedby="id-hint id-error" aria-invalid disabled>
 *       <span class="app-combobox-icon" aria-hidden="true">[icon: search]</span>
 *     </div>
 *     <div class="app-combobox-popup">
 *       <ul class="app-combobox-list" id="id-list" role="listbox" aria-labelledby="id-label" aria-busy>
 *         <li class="app-select-option" id role="option" aria-selected data-active aria-disabled>
 *           <span class="app-combobox-option-text">
 *             <span class="app-select-option-label">Muster GmbH</span>
 *             <span class="app-combobox-option-detail">K-1042 · Linz</span>
 *           </span>
 *           <span class="app-select-option-check" aria-hidden="true">[icon: check]</span>
 *         </li>
 *       </ul>
 *       <p class="app-combobox-message" role="status">Keine Treffer</p>
 *     </div>
 *   </div>
 *   hint, error
 * </div>
 *
 * The select's twin: the same field group, option rows and popup, with an input to type into.
 * The screen searches (the wrapper reports the text, a moment after the last key) and hands the
 * options back; meanwhile the popup says it is searching, and afterwards how it went when
 * nothing matched. The value is only ever one of the options: leaving the field puts the chosen
 * option's label back. An option with a detail line is two lines in 44.
 */
@layer components {
    .app-combobox {
        position: relative;
        min-inline-size: 0;
    }

    .app-combobox-icon {
        display: inline-flex;
        flex: none;
        color: var(--app-color-text-subtle);
    }

    .app-combobox-popup {
        position: absolute;
        inset-block-start: calc(100% + var(--app-space-popover-offset));
        inset-inline: 0;
        z-index: var(--app-z-select);
        display: none;
        max-block-size: var(--app-select-list-height);
        overflow-y: auto;
        padding: var(--app-space-list-inset);
        border-radius: var(--app-radius-popover);
        background: var(--app-color-surface-raised);
        box-shadow:
            0 0 0 var(--app-border-width) var(--app-color-line),
            var(--app-shadow-popover);
    }

    .app-combobox:has([role="combobox"][aria-expanded="true"]) .app-combobox-popup {
        display: block;
    }

    .app-combobox-list:empty,
    .app-combobox-message:empty {
        display: none;
    }

    .app-combobox-option-text {
        display: flex;
        flex-direction: column;
        min-inline-size: 0;
    }

    .app-combobox-option-detail {
        overflow: hidden;
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        font-weight: var(--app-text-body-weight);
        line-height: var(--app-text-help-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-combobox-option-detail:empty {
        display: none;
    }

    .app-select-option:has(.app-combobox-option-detail:not(:empty)) {
        padding-block: var(--app-space-list-inset);
    }

    .app-combobox-message {
        display: flex;
        align-items: center;
        min-block-size: var(--app-control-height);
        padding: 0 var(--app-space-option-x);
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
    }

    /* Forced colours (a Windows contrast theme): shadows and backgrounds are gone, so frames
       are outlines and a chosen state is the system highlight. */
    @media (forced-colors: active) {
        .app-combobox-popup {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }
    }
}
