/* ─── Select-Input (accordion row) ─── */

.select-input {
    box-sizing: border-box;
    overflow: hidden;
    border: var(--border-width-default) solid var(--color-border-soft);
    border-radius: var(--radius-xl);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

.select-input--open {
    border-radius: var(--radius-4xl);
}

.select-input__trigger {
    box-sizing: border-box;
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) repeat(3, minmax(0, 1fr)) auto;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 32px;
    padding: 8px 16px;
    border: 0;
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    color: var(--color-slate-600);
    cursor: pointer;
    text-align: left;
    font-family: var(--font-heading);
}

.select-input--open .select-input__trigger {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.select-input__trigger:focus-visible {
    outline: 2px solid var(--color-primary-soft);
    outline-offset: 2px;
}

.select-input__cell {
    min-width: 0;
    overflow: hidden;
    color: var(--color-slate-600);
    font-size: 12px;
    font-weight: 400;
    line-height: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.select-input__caret {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 16px;
    flex: none;
    color: var(--color-slate-600);
    transition: transform var(--transition-fast);
}

.select-input__caret svg {
    display: block;
}

.select-input--open .select-input__caret {
    transform: rotate(180deg);
}

.select-input__panel {
    display: none;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    border-top: 1px solid #ebedef;
    background: var(--color-surface);
    border-radius: 0 0 var(--radius-4xl) var(--radius-4xl);
}

.select-input--open .select-input__panel {
    display: flex;
}

.select-input__fields {
    display: grid;
    gap: 8px;
}

.select-input__control {
    box-sizing: border-box;
    width: 100%;
    min-height: 32px;
    padding: 8px 14px;
    border: var(--border-width-default) solid var(--color-slate-400);
    border-radius: var(--radius-xl);
    background: var(--color-surface-muted);
    font-family: var(--font-heading);
    font-size: 12px;
    line-height: 16px;
    color: var(--color-slate-600);
}

.select-input__control::placeholder {
    color: var(--color-slate-400);
    opacity: 1;
}

.select-input__textarea {
    min-height: 134px;
    resize: vertical;
}

.select-input__section {
    display: grid;
    gap: 8px;
}

.select-input__section-title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
    color: var(--color-slate-600);
}

.select-input__section-copy {
    margin: 0;
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 16px;
    color: var(--color-slate-400);
}

.select-input__section-list {
    margin: 0;
    padding: 0 0 0 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 16px;
    color: var(--color-slate-600);
}

.select-input__actions,
.select-input__add-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 12px;
}

.select-input__actions {
    align-items: center;
}

.select-input__action {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    min-width: 184px;
    padding: 0 16px;
    border: var(--border-width-default) solid var(--color-primary);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    color: var(--color-primary);
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 700;
    line-height: 16px;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.select-input__action:hover {
    transform: translateY(-1px);
}

.select-input__action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.select-input__action--secondary {
    border-color: var(--color-slate-400);
    color: var(--color-slate-400);
}

.select-input__action--secondary:hover {
    border-color: var(--color-slate-600);
    color: var(--color-slate-600);
}

.select-input__action--danger {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: #ffffff;
}

.select-input__action--danger:hover {
    background: #d63a2c;
    border-color: #d63a2c;
}

.select-input__add-row {
    flex-direction: column;
    align-items: stretch;
}

.select-input__select {
    width: 100%;
}

.select-input__action--add {
    align-self: flex-end;
}

.select-input__roles-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 32px;
}

.select-input__role {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 16px;
    color: var(--color-slate-600);
}

.select-input__role input[type="checkbox"] {
    width: 12px;
    height: 12px;
    margin: 0;
    flex: none;
    accent-color: var(--color-primary);
}

.select-input__role input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.select-input__error {
    margin: 0;
    color: #dc2626;
    font-family: var(--font-body);
    font-size: 12px;
    line-height: 16px;
}

.select-input__hint {
    margin: 0;
    color: var(--color-slate-400);
    font-family: var(--font-body);
    font-size: 11px;
    line-height: 14px;
}

.select-input__field {
    display: grid;
    gap: 4px;
}

.select-input__label {
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: 600;
    line-height: 14px;
    color: var(--color-slate-600);
    letter-spacing: 0.01em;
}

.select-input__required-mark {
    color: #dc2626;
    font-weight: 700;
    margin-left: 2px;
}

.select-input__control--required:invalid:not(:placeholder-shown) {
    border-color: #fca5a5;
    background-color: #fff7f7;
}

.select-input .select {
    gap: 6px;
}

.select-input .select__trigger {
    min-height: 32px;
    padding: 8px 14px;
    border-radius: var(--radius-xl);
}

.select-input .select__value {
    font-size: 12px;
    line-height: 16px;
}

.select-input .select__panel {
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.select-input .select--open {
    gap: 0;
}

.select-input .select--open .select__trigger {
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

@media (max-width: 760px) {
    .select-input__actions,
    .select-input__add-row {
        justify-content: stretch;
    }

    .select-input__action {
        width: 100%;
        min-width: 0;
    }

    .select-input__roles-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

/* ─── Native <select> dropdown styling ─── */

select.ds-select,
.select-input__select,
.select-input .select-input__control:is(select),
.kb-create select,
.kb-section select,
.select-input__panel select,
.users-create select,
.kb-field:is(select) {
    box-sizing: border-box;
    width: 100%;
    min-height: 45px;
    padding: 12px 44px 12px 16px;
    border: 1px solid var(--color-border-soft);
    border-radius: 24px;
    background-color: var(--color-surface-muted);
    color: var(--color-slate-800);
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 500;
    line-height: 16px;
    cursor: pointer;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    /* Caret painted in --color-primary (#0ea5e9) so it matches the buttons. */
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none'><path d='M6 9l6 6 6-6' stroke='%230ea5e9' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/></svg>") !important;
    background-repeat: no-repeat;
    background-position: right 16px center;
    background-size: 16px 16px;
    transition:
      border-color var(--transition-fast),
      box-shadow var(--transition-fast),
      background-color var(--transition-fast),
      transform var(--transition-fast);
}


select.ds-select::-ms-expand,
.select-input__select::-ms-expand,
.kb-create select::-ms-expand,
.kb-section select::-ms-expand,
.select-input__panel select::-ms-expand,
.kb-field:is(select)::-ms-expand {
    display: none;
}

select.ds-select::placeholder,
.select-input__select::placeholder,
.kb-create select::placeholder,
.kb-section select::placeholder,
.select-input__panel select::placeholder,
.kb-field:is(select)::placeholder {
    color: var(--color-slate-400);
    opacity: 1;
}

select.ds-select:hover,
.select-input__select:hover,
.select-input .select-input__control:is(select):hover,
.kb-create select:hover,
.kb-section select:hover,
.select-input__panel select:hover,
.kb-field:is(select):hover {
    border-color: var(--color-primary-soft);
    background-color: var(--color-surface-soft);
}

select.ds-select:focus,
select.ds-select:focus-visible,
.select-input__select:focus,
.select-input__select:focus-visible,
.select-input .select-input__control:is(select):focus,
.kb-create select:focus,
.kb-create select:focus-visible,
.kb-section select:focus,
.kb-section select:focus-visible,
.select-input__panel select:focus,
.select-input__panel select:focus-visible,
.kb-field:is(select):focus,
.kb-field:is(select):focus-visible {
    outline: 0;
    border-color: var(--color-primary);
    box-shadow:
      0 0 0 4px rgba(14, 165, 233, 0.18),
      var(--shadow-glass);
    background-color: var(--color-surface);
}

select.ds-select:disabled,
.select-input__select:disabled,
.kb-create select:disabled,
.kb-section select:disabled,
.select-input__panel select:disabled,
.kb-field:is(select):disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background-color: var(--color-surface-alt);
    border-color: var(--color-border-soft);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none'><path d='M6 9l6 6 6-6' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/></svg>") !important;
}

/* Style the <option> elements (limited cross-browser, but Chromium/Firefox
   pick this up). */
select.ds-select option,
.select-input__select option,
.kb-create select option,
.kb-section select option,
.select-input__panel select option,
.kb-field:is(select) option {
    color: var(--color-slate-900);
    background-color: var(--color-surface);
    padding: 8px 14px;
    font-family: var(--font-heading);
    font-size: 13px;
    font-weight: 500;
}

select.ds-select option:hover,
.select-input__select option:hover,
.kb-create select option:hover,
.kb-section select option:hover,
.select-input__panel select option:hover,
.kb-field:is(select) option:hover {
    background-color: var(--color-surface-soft);
}

select.ds-select option:checked,
.select-input__select option:checked,
.kb-create select option:checked,
.kb-section select option:checked,
.select-input__panel select option:checked,
.kb-field:is(select) option:checked {
    background: linear-gradient(0deg, var(--color-primary-soft), var(--color-primary-soft));
    color: var(--color-slate-900);
}

/* Compact variant — used inside the inline "Add KB" row on the Users page,
   where the select sits next to a small "Add" button and full 45px height
   would feel oversized. Mirrors the smaller .select-input__control sizing.
   We DON'T compact selects in .kb-section (Knowledge Bases page) because
   they sit alongside full-height .kb-field inputs. */
.select-input__add-row select.ds-select,
.select-input__add-row .select-input__select {
    min-height: 36px;
    padding: 8px 38px 8px 14px;
    border-radius: var(--radius-xl);
    font-size: 12px;
    line-height: 16px;
    background-position: right 12px center;
    background-size: 14px 14px;
}
