.cx-list-search {
    position: relative;
    /* Search bar width matches the filter dropdown panel below it (they share this width); the toolbar keeps it centered. */
    width: 560px;
    max-width: 100%;
    min-width: 12rem;
    font-family: var(--cx-font-family);
}

.cx-list-search-surface {
    display: flex;
    align-items: center;
    height: 30px;
    min-height: 30px;
    overflow: hidden;
    color: var(--cx-color-text);
    background: var(--cx-color-surface);
    border: 1px solid var(--cx-color-input);
    border-radius: var(--cx-radius-sm);
}

.cx-list-search-surface:focus-within {
    border-color: var(--cx-color-primary);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--cx-color-primary) 14%, transparent);
}

.cx-list-search-icon {
    flex: 0 0 auto;
    padding-inline-start: var(--cx-space-2);
    color: var(--cx-color-text-muted);
}

.cx-list-search-input {
    flex: 1 1 10rem;
    min-width: 5rem;
    height: 100%;
    padding: 0 var(--cx-space-2);
    color: var(--cx-color-text);
    background: transparent;
    border: 0;
    outline: 0;
    font: inherit;
    font-size: var(--cx-font-size-sm);
}

.cx-list-search-trigger {
    align-self: stretch;
    flex: 0 0 28px;
    color: var(--cx-color-text-muted);
    background: var(--cx-color-surface-muted);
    border: 0;
    border-inline-start: 1px solid var(--cx-color-border);
    cursor: pointer;
}

.cx-list-search-trigger:hover,
.cx-list-search-trigger[aria-expanded="true"] {
    color: var(--cx-color-text);
    background: var(--cx-color-border);
}

.cx-list-search-trigger:focus-visible,
.cx-list-search-option:focus-visible,
.cx-list-active-filter:focus-visible {
    outline: 2px solid var(--cx-color-primary);
    outline-offset: -2px;
}

.cx-list-search-panel {
    position: absolute;
    z-index: var(--cx-z-dropdown);
    inset-block-start: calc(100% + var(--cx-space-1));
    /* Span the full width of the search bar so the dropdown is exactly as wide as the input above it. */
    inset-inline: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--cx-space-4);
    width: auto;
    max-width: calc(100vw - var(--cx-space-6));
    padding: var(--cx-space-2);
    background: var(--cx-color-surface);
    border: 1px solid var(--cx-color-border);
    border-radius: var(--cx-radius-md);
    box-shadow: var(--cx-shadow-md);
}

.cx-list-search-panel[hidden] {
    display: none;
}

.cx-list-search-panel-section:only-child {
    grid-column: 1 / -1;
}

.cx-list-search-panel-title {
    margin: 0 0 var(--cx-space-2);
    color: var(--cx-color-text-muted);
    font-size: var(--cx-font-size-eyebrow);
    font-weight: var(--cx-font-weight-semibold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.cx-list-search-options {
    display: flex;
    flex-direction: column;
    gap: var(--cx-space-1);
}

.cx-list-search-option {
    min-height: 28px;
    padding: var(--cx-space-1) var(--cx-space-2);
    color: var(--cx-color-text);
    text-align: start;
    background: transparent;
    border: 0;
    border-radius: var(--cx-radius-sm);
    cursor: pointer;
    font: inherit;
    font-size: var(--cx-font-size-sm);
}

.cx-list-search-option:hover {
    background: var(--cx-color-surface-muted);
}

.cx-list-search-option--active {
    color: var(--cx-color-primary);
    background: var(--cx-color-primary-soft);
    font-weight: var(--cx-font-weight-semibold);
}

.cx-list-search-option--active::before {
    content: "✓";
    margin-inline-end: var(--cx-space-2);
}

.cx-list-active-filters {
    display: flex;
    flex: 0 1 auto;
    min-width: 0;
    gap: var(--cx-space-1);
    padding-inline-start: var(--cx-space-1);
}

.cx-list-active-filters:empty {
    display: none;
}

.cx-list-active-filter {
    flex: 0 1 auto;
    max-width: 10rem;
    height: 22px;
    display: inline-flex;
    align-items: center;
    overflow: hidden;
    padding: 0 6px;
    color: var(--cx-color-text);
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--cx-color-surface);
    border: 1px solid var(--cx-color-border);
    border-radius: var(--cx-radius-sm);
    cursor: pointer;
    font: inherit;
    font-size: var(--cx-font-size-xs);
}

@media (max-width: 48rem) {
    .cx-list-search {
        order: 3;
        flex: 1 0 100%;
        width: 100%;
        max-width: none;
    }

    .cx-list-search-panel {
        min-width: 0;
        max-width: calc(100vw - var(--cx-space-6));
        grid-template-columns: minmax(0, 1fr);
    }
}
