/* zsybcom combobox — progressive enhancement around a native <select>.
   The original <select> is kept in DOM (visually hidden) so form submission
   and screen readers still work; the visible UI is a button trigger and a
   floating popover with search + keyboard-navigable list.

   Sizing matches the task-bar slot reserved by topbar.css
   (180px wide, 30px tall) so there is no layout shift on enhancement. */

/* Hide the bare native select until combobox.js wraps it (avoids a flash
   of the unstyled native picker between DOM parse and enhancement). */
select[data-combobox]:not(.cb-source) {
    visibility: hidden;
    width: 100%;
    height: 26px;
}

.combobox {
    position: relative;
    display: inline-flex;
    height: 30px;
    box-sizing: border-box;
}

/* The native select is kept in the DOM but pulled out of layout. Bootstrap
   sometimes injects rules that re-show it, so we force it small + invisible
   without using display:none (form submission + a11y stay intact). */
.combobox>select.cb-source {
    position: absolute !important;
    left: 0;
    top: 0;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    clip: rect(0 0 0 0);
    overflow: hidden;
    z-index: -1;
}

/* ── Trigger ─────────────────────────────────────────────────────────── */
.combobox-trigger {
    display: inline-flex;
    flex: 1 1 auto;
    align-items: center;
    height: fit-content;
    width: 100%;
    padding: var(--p2);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    line-height: 1;
    text-align: left;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: border-color 100ms ease, background 100ms ease;
}

.combobox-trigger:hover {
    border-color: var(--text-3);
}

.combobox-trigger:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 25%, transparent);
}

.cb-text {
    flex: 1 1 auto;
    max-width: var(--w12);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.25rem;
}

.cb-text.is-placeholder {
    color: var(--text-3);
}

.cb-chev {
    color: var(--text-3);
    font-size: var(--font-xs);
    pointer-events: none;
    transition: transform 160ms ease;
}

.combobox[data-open="true"] .cb-chev {
    transform: rotate(180deg);
}

/* ── Popover ─────────────────────────────────────────────────────────── */
.cb-popover {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 220px;
    max-width: 360px;
    width: max-content;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius, 6px);
    box-shadow: 0 8px 24px rgba(20, 17, 12, 0.12);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cb-popover[hidden] {
    display: none;
}

/* Search row */
.cb-search {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.cb-search i {
    color: var(--text-3);
    font-size: 11px;
}

.cb-search input {
    flex: 1 1 auto;
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    padding: 2px 0;
}

.cb-search input::placeholder {
    color: var(--text-3);
}

/* Option list */
.cb-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
    max-height: 580px;
    overflow-y: auto;
}

.cb-option {
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cb-option[hidden] {
    display: none;
}

.cb-option[aria-selected="true"] {
    background: color-mix(in oklab, var(--accent) 12%, transparent);
    color: var(--accent-text, var(--accent));
    font-weight: 500;
}

.cb-option.is-active,
.cb-option:hover {
    background: var(--surface-2);
}

.cb-option[aria-selected="true"].is-active {
    background: color-mix(in oklab, var(--accent) 22%, transparent);
}

.cb-empty {
    padding: 14px 12px;
    text-align: center;
    color: var(--text-3);
    font-size: 12px;
}
