:root {
    --select-visible-rows: 6;
    --select-row-height: 2.375rem;
    --select-control-height: 2.75rem;
    --select-radius: .55rem;
    --select-surface: var(--surface);
    --select-subtle: var(--wash);
    --select-ink: var(--ink);
    --select-muted: var(--muted);
    --select-border: var(--line-strong);
    --select-line: var(--line);
    --select-accent: var(--accent);
    --select-danger: var(--accent-vermilion);
    --select-shadow: 0 12px 28px -10px rgb(16 35 69 / .27), 0 2px 6px rgb(16 35 69 / .07);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23145d93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
}

.admin-app {
    --select-control-height: 2.375rem;
    --select-radius: .5rem;
    --select-surface: var(--admin-surface);
    --select-subtle: var(--admin-subtle);
    --select-ink: var(--admin-ink);
    --select-muted: var(--admin-muted);
    --select-border: var(--admin-control-line);
    --select-line: var(--admin-line);
    --select-accent: var(--admin-accent);
    --select-danger: var(--admin-danger);
}

[data-theme="dark"] {
    --select-shadow: 0 12px 28px -8px rgb(0 0 0 / .65), 0 2px 6px rgb(0 0 0 / .25);
    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2394c9e8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
}

[data-theme="dark"] .admin-app { --select-accent: var(--scrollbar-active); }

.select-editorial { font-size: .92rem; }
.filter-bar-editorial > .select-editorial { inline-size: 8.5rem; max-inline-size: 100%; }
.filter-bar-editorial > :is(#article-author, #article-author + .ts-wrapper) { inline-size: 13rem; }
.admin-app .form-select-sm { --select-control-height: 2rem; }
.admin-table-page-size .form-select { inline-size: 4.5rem; }

/* The native field has the same closed shape when the enhancement is unavailable. */
:is(select.select-editorial, .admin-app select.form-select), .ts-control {
    box-sizing: border-box;
    min-block-size: var(--select-control-height);
    min-inline-size: 0;
    padding: .35rem .75rem;
    border: 1px solid var(--select-border);
    border-radius: var(--select-radius);
    background: var(--select-surface);
    color: var(--select-ink);
    box-shadow: none;
    line-height: 1.35;
    transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}

:is(select.select-editorial, .admin-app select.form-select):not([multiple], [size]) {
    appearance: none;
    padding-inline-end: 2.15rem;
    background-image: var(--select-arrow);
    background-repeat: no-repeat;
    background-position: right .6rem center;
    background-size: 1rem;
    text-overflow: ellipsis;
    cursor: pointer;
}

:is(select.select-editorial, .admin-app select.form-select):disabled,
.ts-wrapper.disabled .ts-control {
    background-color: var(--select-subtle);
    color: var(--select-muted);
    cursor: default;
    opacity: .68;
}

.ts-wrapper,
.admin-app .ts-wrapper.form-select {
    position: relative;
    display: block;
    min-inline-size: 0;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
}

.admin-app .form-select.admin-user-role { min-inline-size: 7.25rem; }

select.ts-hidden-accessible {
    position: absolute !important;
    inline-size: 1px !important;
    block-size: 1px !important;
    min-inline-size: 0 !important;
    min-block-size: 0 !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0 !important;
    white-space: nowrap;
}

.ts-control {
    position: relative;
    display: flex;
    align-items: center;
    gap: .3rem;
    padding-inline-end: 2.15rem;
    cursor: pointer;
}

.ts-control::after {
    position: absolute;
    inset-inline-end: .87rem;
    inset-block-start: calc(50% - .23rem);
    inline-size: .46rem;
    block-size: .46rem;
    border-inline-end: 1.5px solid;
    border-block-end: 1.5px solid;
    color: var(--select-accent);
    content: "";
    pointer-events: none;
    transform: translateY(-.11rem) rotate(45deg);
}

.ts-wrapper.dropdown-active .ts-control::after { transform: translateY(.11rem) rotate(225deg); }
.ts-wrapper.single .item { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ts-wrapper.multi .ts-control { flex-wrap: wrap; }
.ts-wrapper.multi:not(.has-items) .ts-control::before { color: var(--select-muted); content: attr(data-placeholder); }
.ts-control .items-placeholder { display: none; }

@media (hover: hover) {
    :is(select.select-editorial, .admin-app select.form-select):not(:disabled):hover,
    .ts-wrapper:not(.disabled) .ts-control:hover {
        border-color: var(--select-accent);
        background-color: color-mix(in srgb, var(--select-accent) 3%, var(--select-surface));
    }
}

:is(select.select-editorial, .admin-app select.form-select):focus,
.ts-wrapper.focus .ts-control,
.ts-wrapper .ts-control:focus-visible {
    border-color: var(--select-accent);
    outline: 2px solid var(--select-accent);
    outline-offset: 1px;
    box-shadow: none;
}

.ts-control[aria-invalid="true"] { border-color: var(--select-danger); }
.ts-wrapper.plugin-dropdown_input.dropdown-active .ts-control:not(:focus) { outline: none; }

.ts-wrapper.multi .item {
    display: inline-flex;
    align-items: center;
    max-inline-size: 100%;
    min-block-size: 1.75rem;
    padding-inline: .45rem .15rem;
    border-radius: .3rem;
    background: color-mix(in srgb, var(--select-accent) 9%, var(--select-surface));
    overflow-wrap: anywhere;
}

.ts-wrapper.multi .item:is(.active, .ts-drag-over) {
    box-shadow: inset 0 0 0 1px var(--select-accent);
}

.ts-wrapper.multi .ts-dragging { opacity: .45; }
.ts-wrapper .item[draggable="true"] { cursor: grab; }
.ts-wrapper .item .remove {
    display: grid;
    place-items: center;
    min-inline-size: 1.5rem;
    min-block-size: 1.5rem;
    margin-inline-start: .25rem;
    border-radius: .25rem;
    color: var(--select-accent);
    font-size: 1.1rem;
    text-decoration: none;
}

.ts-wrapper .item .remove:hover { background: var(--select-surface); }
.ts-wrapper.disabled .item .remove { pointer-events: none; }

.ts-dropdown {
    position: fixed;
    z-index: 1060;
    display: none;
    box-sizing: border-box;
    inline-size: max-content;
    padding: .3rem;
    border: 1px solid var(--select-line);
    border-radius: calc(var(--select-radius) + .2rem);
    background: var(--select-surface);
    color: var(--select-ink);
    box-shadow: var(--select-shadow);
    text-align: start;
}

.ts-dropdown.plugin-dropdown_input { --select-dropdown-min-width: 16rem; }

.ts-dropdown-content {
    max-block-size: min(calc(var(--select-row-height) * var(--select-visible-rows)), var(--select-available-height, 100vh));
    overflow: hidden auto;
    overscroll-behavior-y: contain;
    scroll-snap-type: y mandatory;
    outline: 0;
}

.ts-dropdown-content::-webkit-scrollbar { width: 8px; }
.ts-dropdown-content::-webkit-scrollbar-thumb { min-height: 1.5rem; border-width: 2px; }

.ts-dropdown .option {
    box-sizing: border-box;
    block-size: var(--select-row-height);
    padding-inline: .65rem 1.85rem;
    overflow: hidden;
    border-radius: .35rem;
    line-height: var(--select-row-height);
    text-overflow: ellipsis;
    white-space: nowrap;
    scroll-snap-align: start;
}

.ts-dropdown [data-selectable] { cursor: pointer; }
.ts-dropdown [data-disabled] { color: var(--select-muted); cursor: default; opacity: .68; }
.ts-dropdown .option:is(.active, .selected) {
    background: var(--select-subtle);
    background: color-mix(in srgb, var(--select-accent) 9%, var(--select-surface));
}

.ts-dropdown .option.selected { position: relative; color: var(--select-accent); font-weight: 600; }
.ts-dropdown .option.selected::after {
    position: absolute;
    inset-inline-end: .72rem;
    inset-block-start: calc(50% - .24rem);
    inline-size: .63rem;
    block-size: .34rem;
    border-inline-start: 1.5px solid;
    border-block-end: 1.5px solid;
    content: "";
    transform: rotate(-45deg);
}

.ts-dropdown .option.active { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--select-accent) 30%, transparent); }
.ts-dropdown .option .highlight { background: transparent; color: var(--select-accent); font-weight: 700; }
.ts-dropdown :is(.optgroup-header, .no-results) { padding: .5rem .65rem; color: var(--select-muted); }

.ts-dropdown .dropdown-input-wrap { padding: .15rem .15rem .35rem; }
.ts-dropdown .dropdown-input {
    inline-size: 100%;
    min-block-size: var(--select-control-height);
    padding: .4rem .65rem;
    border: 1px solid var(--select-border);
    border-radius: .35rem;
    background: var(--select-subtle);
    color: var(--select-ink);
    font: inherit;
}

.ts-dropdown .dropdown-input::placeholder { color: var(--select-muted); opacity: 1; }
.ts-dropdown .dropdown-input:focus { outline: 2px solid var(--select-accent); outline-offset: -2px; }

@media (max-width: 575px) {
    .filter-bar-editorial > .input-editorial { flex-basis: 100%; min-inline-size: 0; }
    .filter-bar-editorial > .select-editorial { flex: 1 1 8rem; }
}

@media (pointer: coarse) {
    :root { --select-row-height: 2.75rem; }
    .admin-app, .admin-app .form-select-sm { --select-control-height: 2.75rem; }
    .ts-dropdown .dropdown-input { font-size: 1rem; }
    .ts-wrapper .item .remove { min-inline-size: 2.25rem; min-block-size: 2.25rem; }
}

@media (prefers-reduced-motion: reduce) {
    :is(select.select-editorial, .admin-app select.form-select), .ts-control { transition: none; }
}

@media (forced-colors: active) {
    :is(select.select-editorial, .admin-app select.form-select):not([multiple], [size]) {
        appearance: auto;
        background-image: none;
    }
    .ts-dropdown .option.active { outline: 1px solid Highlight; outline-offset: -1px; }
}
