/* ============================================================
   Dropdowns — trigger, menu panel, items, group headers, chips
   ============================================================
   Powered by js/dropdown.js. State classes (.is-hover, .is-focus,
   etc.) on the trigger are used in documentation to freeze visual
   states; the JS skips elements with these classes.
*/

/* ─── Component wrapper ─── */
.dropdown {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 320px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ─── Label above trigger ─── */
.dropdown-label {
    font-size: 0.75rem;       /* 12px Text xs/Medium */
    font-weight: 500;
    line-height: 1rem;        /* 16px */
    color: var(--text-secondary);
}

/* ─── Trigger button ─── */
.dropdown-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    height: 40px;             /* md size default */
    padding: 8px 12px;
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    background: var(--bg-primary);
    font-family: inherit;
    font-size: 0.875rem;      /* 14px Text sm/Regular */
    font-weight: 400;
    line-height: 1.25rem;     /* 20px */
    color: var(--text-placeholder);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dropdown-trigger:focus {
    outline: none;
}

/* Trigger value text — the selection or placeholder */
.dropdown-value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* When the trigger is in a "filled" state */
.dropdown-trigger.is-filled .dropdown-value,
.dropdown-trigger.is-filled {
    color: var(--text-primary);
}

/* Chevron icon */
.dropdown-chevron {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    color: var(--text-tertiary);
    transition: transform 0.2s ease;
}

.dropdown-trigger[aria-expanded="true"] .dropdown-chevron {
    transform: rotate(180deg);
}

/* ─── Closed trigger states ─── */

/* Default — no extra rules; uses base */

/* Hover (real + frozen) */
.dropdown-trigger:not([disabled]):not(.is-disabled):hover,
.dropdown-trigger.is-hover {
    border-color: var(--border-primary);
}

/* Focus ring (real + frozen) */
.dropdown-trigger:not([disabled]):not(.is-disabled):focus-visible,
.dropdown-trigger.is-focus {
    border-color: var(--border-brand);
    box-shadow: 0 0 0 4px var(--brand-25);
}

/* Disabled (real + frozen) */
.dropdown-trigger[disabled],
.dropdown-trigger.is-disabled {
    border-color: var(--border-disabled);
    background: var(--bg-disabled-subtle);
    color: var(--text-disabled);
    cursor: not-allowed;
}

/* Error */
.dropdown-trigger.is-error {
    border-color: var(--border-error);
}

.dropdown-trigger.is-error:focus-visible,
.dropdown-trigger.is-error.is-focus {
    box-shadow: 0 0 0 4px var(--error-100);
}

.dropdown-error-message {
    font-size: 0.75rem;       /* 12px */
    color: var(--text-error-primary);
    line-height: 1rem;
    margin-top: -2px;
}

.dropdown-hint {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    line-height: 1rem;
    margin-top: -2px;
}

/* ─── Sizes ─── */
.dropdown[data-size="sm"] .dropdown-trigger {
    height: 32px;
    padding: 6px 10px;
    font-size: 0.875rem;
    border-radius: 6px;
}

.dropdown[data-size="sm"] .dropdown-chevron {
    width: 14px;
    height: 14px;
}

/* ═══════════════════════════════════════════════════
   Menu panel
   ═══════════════════════════════════════════════════ */

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    max-height: 320px;
    padding: 8px;
    border: 1px solid var(--border-secondary);
    border-radius: 8px;
    background: var(--bg-primary);
    box-shadow: 0 2px 4px -2px rgba(16, 24, 40, 0.06),
                0 4px 8px -2px rgba(16, 24, 40, 0.10);
    overflow-y: auto;
    overflow-x: hidden;
    display: none;
}

/* Open via JS or static .is-open modifier (for docs anatomy demos) */
.dropdown-menu.is-open {
    display: block;
}

/* Dark-mode shadow tweak */
[data-theme="dark"] .dropdown-menu {
    box-shadow: 0 2px 4px -2px rgba(0, 0, 0, 0.5),
                0 4px 8px -2px rgba(0, 0, 0, 0.6);
}

/* ═══════════════════════════════════════════════════
   Menu items
   ═══════════════════════════════════════════════════ */

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.dropdown-item--icon,
.dropdown-item--checkbox {
    gap: 8px;
}

/* Item leading icon */
.dropdown-item-icon {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    color: inherit;
}

/* Item label text */
.dropdown-item-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Optional secondary/shortcut text on the right */
.dropdown-item-secondary {
    flex: 0 0 auto;
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ─── Item states ─── */

.dropdown-item:hover,
.dropdown-item.is-hover,
.dropdown-item.is-active {
    background: var(--bg-secondary-hover);
    color: var(--text-primary);
}

.dropdown-item[aria-selected="true"],
.dropdown-item.is-selected {
    background: var(--bg-brand-secondary);
    color: var(--text-primary);
    font-weight: 500;
}

.dropdown-item[aria-disabled="true"],
.dropdown-item.is-disabled {
    background: transparent;
    color: var(--text-disabled);
    cursor: not-allowed;
    pointer-events: none;
}

/* ─── Highlight item type — used for emphasized rows ─── */

.dropdown-item--highlight {
    font-weight: 500;
    color: var(--text-brand-primary);
}

.dropdown-item--highlight[aria-selected="true"],
.dropdown-item--highlight.is-selected {
    background: var(--bg-brand-secondary);
}

/* ─── Checkbox item type ─── */

.dropdown-item--checkbox .checkbox-box {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border: 1px solid var(--border-secondary);
    border-radius: 2px;
    background: var(--bg-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: transparent;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.dropdown-item--checkbox .checkbox-box i {
    font-size: 10px;
    color: var(--text-primary-on-brand);
}

.dropdown-item--checkbox[aria-selected="true"] .checkbox-box,
.dropdown-item--checkbox.is-selected .checkbox-box {
    background: var(--bg-brand-solid);
    border-color: var(--bg-brand-solid);
    color: var(--text-primary-on-brand);
}

/* Reveal the check icon on selection.
   Standalone Checkbox sets `.checkbox-box i { display: none }` and only flips
   to `display: block` when a sibling `<input type=checkbox>` is `:checked`.
   Dropdown items track selection via aria-selected / .is-selected, so we
   override here. */
.dropdown-item--checkbox[aria-selected="true"] .checkbox-box i,
.dropdown-item--checkbox.is-selected .checkbox-box i {
    display: block;
}

/* ─── Divider ─── */
.dropdown-divider {
    height: 1px;
    margin: 4px 0;
    background: var(--border-secondary);
}

/* ─── Group header ─── */
.dropdown-group {
    display: block;
}

.dropdown-group-header {
    padding: 10px 8px 6px;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.25rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-secondary);
    margin-bottom: 4px;
}

/* ─── Search input inside menu ─── */
.dropdown-search-wrapper {
    padding: 4px 4px 8px;
    border-bottom: 1px solid var(--border-secondary);
    margin-bottom: 4px;
    position: relative;
}

.dropdown-search-icon {
    position: absolute;
    left: 14px;
    top: calc(4px + (32px / 2));    /* center within 32px input, plus wrapper top padding */
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-tertiary);
    pointer-events: none;
}

.dropdown-search {
    width: 100%;
    height: 32px;
    padding: 6px 10px 6px 32px;
    border: 1px solid var(--border-secondary);
    border-radius: 6px;
    background: var(--bg-primary);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--text-primary);
}

.dropdown-search:focus {
    outline: none;
    border-color: var(--border-brand);
    box-shadow: 0 0 0 3px var(--brand-25);
}

.dropdown-no-results {
    padding: 12px 8px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    display: none;
}

.dropdown-menu.has-no-results .dropdown-no-results {
    display: block;
}

/* ═══════════════════════════════════════════════════
   Multi-select tag chips inside trigger
   ═══════════════════════════════════════════════════ */

.dropdown[data-dropdown="chips"] .dropdown-trigger {
    height: auto;
    min-height: 40px;
    padding: 4px 12px 4px 4px;
    flex-wrap: wrap;
    gap: 4px;
}

.dropdown-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1 1 auto;
    min-width: 0;
}

.dropdown-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 4px 1px 8px;
    border: 1px solid var(--border-secondary);
    border-radius: 4px;
    background: var(--bg-secondary-hover);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1rem;
    color: var(--text-secondary);
}

.dropdown-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 10px;
    cursor: pointer;
    border-radius: 2px;
}

.dropdown-chip-remove:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown[data-dropdown="chips"] .dropdown-trigger .dropdown-value {
    flex: 0 0 auto;
    color: var(--text-placeholder);
}

.dropdown[data-dropdown="chips"] .dropdown-chips:not(:empty) + .dropdown-value {
    display: none;
}
