/*
 * ActionSelect styles.
 *
 * Everything is expressed in the theme tokens from theme.css, so all fourteen
 * palettes work without a single per-theme override -- which is what the old
 * ~640 lines of `body[data-theme=...] ... !important` were doing by hand.
 */

.action-picker {
    display: grid;
    gap: .5rem;
    max-width: 30rem;
}

.action-picker__legend {
    font-size: .8125rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-faint);
}

/* ------------------------------------------------------------------- shell */

.action-select {
    position: relative;
    font-family: var(--font);
}

/* ----------------------------------------------------------------- trigger */

.action-select__trigger {
    display: flex;
    align-items: center;
    gap: .625rem;
    width: 100%;
    padding: .75rem .875rem;
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--r);
    cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s;
}

.action-select__trigger:hover {
    background: var(--hover);
    border-color: color-mix(in srgb, var(--accent-solid) 50%, var(--line));
}

.action-select__trigger:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-color: var(--accent-solid);
}

.action-select[data-open="true"] .action-select__trigger {
    border-color: var(--accent-solid);
    box-shadow: var(--ring);
}

.action-select__icon {
    flex: none;
    font-size: 1.125rem;
    line-height: 1;
}

.action-select__label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.action-select[data-empty="true"] .action-select__label {
    color: var(--text-faint);
    font-weight: 500;
}

.action-select__caret {
    flex: none;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    transition: transform .2s ease, color .15s;
}

.action-select[data-open="true"] .action-select__caret {
    transform: rotate(180deg);
    color: var(--accent-solid);
}

/* ------------------------------------------------------------------- popup */

.action-select__popup {
    position: absolute;
    z-index: 60;
    left: 0;
    right: 0;
    max-height: 19rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: .375rem;
    background: var(--surface-solid);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow-lg);
    /* Animate in without a layout-thrashing display toggle. */
    animation: action-select-in .14s ease-out;
}

.action-select__popup:focus-visible { outline: none; }

.action-select[data-drop="down"] .action-select__popup { top: calc(100% + .375rem); }
.action-select[data-drop="up"] .action-select__popup { bottom: calc(100% + .375rem); }

@keyframes action-select-in {
    from { opacity: 0; transform: translateY(-.25rem); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .action-select__popup { animation: none; }
    .action-select__caret { transition: none; }
}

/* ------------------------------------------------------------------ groups */

.action-select__group + .action-select__group {
    margin-top: .25rem;
    padding-top: .25rem;
    border-top: 1px solid var(--line-soft);
}

.action-select__group-label {
    padding: .5rem .625rem .3125rem;
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-faint);
}

/* ----------------------------------------------------------------- options */

.action-select__option {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .625rem;
    border-radius: var(--r-sm);
    cursor: pointer;
    color: var(--text);
    scroll-margin: .375rem;
}

.action-select__option.is-active {
    background: var(--accent);
    color: var(--on-accent);
}

.action-select__option.is-active .action-select__option-hint { color: inherit; opacity: .75; }

.action-select__option-icon {
    flex: none;
    width: 1.375rem;
    font-size: 1rem;
    line-height: 1.375rem;
    text-align: center;
}

.action-select__option-text {
    flex: 1 1 auto;
    min-width: 0;
    display: grid;
    gap: .0625rem;
}

.action-select__option-label {
    font-size: .9375rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.action-select__option-hint {
    font-size: .75rem;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.action-select__check {
    flex: none;
    display: grid;
    place-items: center;
    width: 1rem;
    opacity: 0;
    color: var(--accent-solid);
}

.action-select__option[aria-selected="true"] .action-select__check { opacity: 1; }
.action-select__option[aria-selected="true"].is-active .action-select__check { color: var(--on-accent); }

/* --------------------------------------------------------------- scrollbar */

.action-select__popup::-webkit-scrollbar { width: 8px; }
.action-select__popup::-webkit-scrollbar-track { background: transparent; }
.action-select__popup::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}
.action-select__popup::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

/* ------------------------------------------------------------ mobile tweak */

@media (max-width: 30rem) {
    .action-picker { max-width: none; }
    .action-select__popup { max-height: 60vh; }
}
