/* ===================================================================
   StaseeMultiSelect (scripts/multiselect.js): a port of the first dashboard's xSELECT.
   A button with coloured chips, a panel with search, "Select all" / "Clear", the items and a footer.
   =================================================================== */

.xselect {
    --ms-field: var(--glass-field, color-mix(in srgb, var(--color-bg) 72%, transparent));
    --ms-pop: var(--glass-pop, color-mix(in srgb, var(--color-bg) 94%, transparent));
    --ms-line: var(--color-border);
    --ms-soft: var(--color-border-soft);
    --ms-hover: color-mix(in srgb, var(--color-text) 6%, transparent);
    --ms-accent: var(--color-green);
    --ms-accent-ink: #15803d;

    position: relative;
    width: 100%;
    min-width: 0;
    font-family: var(--font-sans);
}

:root[data-theme="dark"] .xselect {
    --ms-accent-ink: var(--color-green);
}

.xselect-label {
    margin-bottom: 6px;
    color: var(--color-text-soft);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
}

/* ===== the button ===== */

.xselect-button {
    display: flex;
    align-items: center;
    width: 100%;
    height: 38px;
    padding-inline: 10px 6px;
    border: 1px solid var(--ms-line);
    border-radius: 12px;
    background: var(--ms-field);
    color: var(--color-text);
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}

.xselect-button:hover {
    border-color: color-mix(in srgb, var(--color-text) 28%, transparent);
}

.xselect-button:focus-visible {
    outline: 2px solid var(--ms-accent);
    outline-offset: 2px;
}

.xselect.opened .xselect-button {
    border-color: var(--ms-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ms-accent) 18%, transparent);
}

.xselect-arrow {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 28px;
    color: var(--color-text-muted);
    transition: transform .15s;
}

.xselect-arrow .material-symbols-outlined {
    font-size: 22px;
}

.xselect.opened .xselect-arrow {
    transform: rotate(180deg);
}

.xselect-values {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}

.xselect-placeholder {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ----- a chip: the colour of the item at 10% ----- */

.xselect-chip {
    --chip-color: var(--color-green);
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 7px;
    height: 26px;
    max-width: 100%;
    padding-inline: 5px 9px;
    border: 1px solid color-mix(in srgb, var(--chip-color) 22%, transparent);
    border-radius: 13px;
    background: color-mix(in srgb, var(--chip-color) 11%, transparent);
    font-size: 13px;
    font-weight: 600;
    transition: background .15s, border-color .15s;
}

.xselect-chip:hover {
    background: color-mix(in srgb, var(--chip-color) 20%, transparent);
}

.xselect-chip-text {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xselect-chip-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 5px;
    object-fit: contain;
}

img.xselect-chip-icon {
    background: #fff;
    padding: 1px;
}

.xselect-chip-icon.material-symbols-outlined,
.xselect-chip-glyph .material-symbols-outlined {
    font-size: 18px;
}

.xselect-chip-avatar {
    /* the initials sit in the middle of their circle or square */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border-radius: 50%;
    color: #fff;
    font-size: 9.5px;
    font-weight: 800;
    letter-spacing: .2px;
}

.xselect-chip-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 0;
    margin-inline-start: 0;
    overflow: hidden;
    opacity: 0;
    transform: scale(.8);
    transition: width .15s, margin .15s, opacity .15s, transform .15s;
}

.xselect-chip-remove .material-symbols-outlined {
    font-size: 16px;
}

.xselect-chip:hover .xselect-chip-remove {
    width: 16px;
    margin-inline-start: 2px;
    opacity: .65;
    transform: scale(1);
}

.xselect-chip-remove:hover {
    opacity: 1 !important;
}

/* no hover on a touch screen: the cross is always there */
@media (hover: none) {
    .xselect-chip-remove {
        width: 16px;
        margin-inline-start: 2px;
        opacity: .65;
        transform: none;
    }
}

.xselect-chip-more {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    height: 24px;
    padding-inline: 8px;
    border-radius: 14px;
    background: var(--ms-hover);
    color: var(--color-text-soft);
    font-size: 13px;
    font-weight: 700;
}

/* ===== the panel ===== */

.xselect-popup {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-start: 0;
    z-index: 1000;
    width: 100%;
    min-width: min(300px, calc(100vw - 24px));
    overflow: hidden;
    border: 1px solid var(--ms-line);
    border-radius: 12px;
    background: var(--ms-pop);
    box-shadow: 0 12px 40px rgba(15, 23, 42, .16);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    backdrop-filter: blur(20px) saturate(1.4);
    color: var(--color-text);
}

:root[data-theme="dark"] .xselect-popup {
    box-shadow: 0 14px 40px rgba(0, 0, 0, .55);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .xselect-popup {
        background: var(--color-bg);
    }
}

.xselect-popup[hidden] {
    display: none;
}

.xselect-popup.is-up {
    top: auto;
    bottom: calc(100% + 6px);
}

.xselect-search {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding-inline: 12px 8px;
    border-bottom: 1px solid var(--ms-line);
}

.xselect-search-icon {
    display: grid;
    place-items: center;
    color: var(--color-text-muted);
}

.xselect-search-icon .material-symbols-outlined {
    font-size: 22px;
}

.xselect-search input {
    flex: 1;
    min-width: 60px;
    height: 40px;
    border: 0;
    outline: 0;
    background: none;
    color: var(--color-text);
    font: inherit;
    font-size: 14px;
}

.xselect-search input::placeholder {
    color: var(--color-text-muted);
}

.xselect-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-inline-start: auto;
}

.xselect-button-small {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding-inline: 9px;
    border: 1px solid var(--ms-line);
    border-radius: 13px;
    background: var(--ms-hover);
    color: var(--color-text-soft);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: .15s;
}

.xselect-button-small:hover {
    border-color: color-mix(in srgb, var(--ms-accent) 40%, transparent);
    background: color-mix(in srgb, var(--ms-accent) 12%, transparent);
    color: var(--ms-accent-ink);
}

.xselect-button-small .material-symbols-outlined {
    font-size: 16px;
}

.xselect-clear {
    padding: 4px 6px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--color-text-soft);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: .15s;
}

.xselect-clear:hover {
    color: #dc2626;
}

.xselect-clear[hidden] {
    display: none;
}

.xselect-body {
    max-height: min(300px, 50vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    outline: none;
}

.xselect-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    /* the same on both sides, and the same in every row: the colour bar is out of the
       flow (below), so a coloured item lines its checkbox up with a colourless one */
    padding-inline: 12px;
    cursor: pointer;
}

.xselect-item:hover,
.xselect-item.is-active {
    background: var(--ms-hover);
}

/* the colour bar paints the edge of the row and takes no room of its own: in the flow it
   pushed the checkbox 8px to the side, so rows with and without a colour did not line up */
.xselect-item-color {
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: 4px;
}

.xselect-item-icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 7px;
    object-fit: contain;
}

img.xselect-item-icon {
    background: #fff;
    padding: 1px;
}

.xselect-item-icon.xselect-chip-avatar {
    font-size: 11.5px;
    letter-spacing: .3px;
}

.xselect-item-icon.material-symbols-outlined,
.xselect-item-icon.xselect-chip-glyph .material-symbols-outlined {
    font-size: 20px;
}

.xselect-item-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.xselect-item-name {
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xselect-item-sub {
    overflow: hidden;
    color: var(--color-text-muted);
    font-size: 11.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xselect-item-count {
    flex: none;
    color: var(--color-text-muted);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

.xselect-empty {
    padding: 18px;
    color: var(--color-text-muted);
    font-size: 13px;
    text-align: center;
}

.xselect-check {
    position: relative;
    display: block;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    border: 2px solid color-mix(in srgb, var(--color-text) 26%, transparent);
    border-radius: 6px;
    transition: .15s;
}

.xselect-item.selected .xselect-check {
    border-color: var(--ms-accent);
    background: var(--ms-accent);
}

.xselect-item.selected .xselect-check::after {
    content: "";
    position: absolute;
    inset-inline-start: 2px;
    top: 1px;
    width: 7px;
    height: 4px;
    border-bottom: 2px solid #fff;
    border-left: 2px solid #fff;
    transform: rotate(-45deg);
}

.xselect-footer {
    display: flex;
    gap: 6px;
    padding: 6px;
    border-top: 1px solid var(--ms-line);
}

.xselect-footer-button {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    white-space: nowrap;
    height: 36px;
    padding-inline: 12px;
    border-radius: 8px;
    color: var(--ms-accent-ink);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: .15s;
}

.xselect-footer-button:hover {
    background: color-mix(in srgb, var(--ms-accent) 12%, transparent);
}

.xselect-footer-button.is-disabled {
    color: var(--color-text-muted);
    cursor: default;
}

.xselect-footer-button.is-disabled:hover {
    background: none;
}

.xselect-footer-button:focus-visible {
    outline: 2px solid var(--ms-accent);
    outline-offset: -2px;
}

.xselect-footer-icon {
    display: grid;
    place-items: center;
}

.xselect-footer-icon .material-symbols-outlined {
    font-size: 20px;
}

/* ===== the tooltip with the items that did not fit ("+N") ===== */

.xselect-tooltip {
    position: fixed;
    z-index: 10000;
    display: none;
    min-width: 180px;
    padding: 6px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-bg);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 13px;
}

.xselect-tooltip-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 32px;
    padding-inline: 8px;
}

.xselect-tooltip-dot {
    width: 10px;
    height: 10px;
    flex: none;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .08);
}
