/* ==========================================================================
   The dropdown (assets/js/select.js): every <select> of the project, kept out
   of sight and drawn as a button with a list of ours. Loaded by every layout
   that loads the script.

   The button wears the select's own classes (form-select, form-control ...),
   so it keeps the size the page gave the select; only the open list, and the
   button of components/candidate/select (.cp-select__button), are drawn here.

   Colours come from the panel's tokens (--cp-*): candidate.css defines them,
   site.css and admin.css map them onto their own palettes. The fallbacks are
   for a page with none of the three.
   ========================================================================== */

[x-cloak] {
    display: none !important;
}

.cp-select {
    position: relative;
    /* flow-root: the select's own margins stay inside, where the button copies them */
    display: flow-root;
    min-width: 0;
}

.cp-select.is-inline {
    display: inline-block;
    vertical-align: middle;
}

.cp-select[hidden] {
    display: none !important;
}

/* The real select, once its button is drawn (until then it is shown as it is): left in
   its place at its own size - so a table column, a flex row or a grid cell lays out as
   it did - and still the field the form sends and where `required` points. Keyed on the
   button rather than on a mark on the select, which a Livewire re-render would wipe. */
.cp-select:has(> .cp-select__ui > .cp-select__trigger) > select {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* drawn over the select: its classes give it the select's look and margins, the
   frame's edges give it the select's size */
.cp-select__trigger {
    position: absolute !important;
    inset: 0;
    z-index: 1;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: auto !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    text-align: left;
    cursor: pointer;
    /* the select's own chevron is drawn by .cp-select__chevron */
    background-image: none !important;
    padding-right: 12px !important;
}

.cp-select__trigger:disabled {
    cursor: not-allowed;
    opacity: .7;
}

.cp-select__trigger:focus-visible,
.cp-select__trigger[aria-expanded="true"] {
    outline: 0;
    border-color: var(--cp-primary, #198754) !important;
    box-shadow: 0 0 0 3px var(--cp-primary-soft, #e8f3ee);
}

.cp-select.is-invalid .cp-select__trigger {
    border-color: var(--bs-red, #dc3545) !important;
}

.cp-select__value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cp-select__value.is-placeholder {
    color: var(--cp-text-muted, #6c757d);
}

.cp-select__chevron {
    flex: 0 0 auto;
    color: var(--cp-text-muted, #6c757d);
    transition: transform .2s ease;
}

.cp-select__trigger[aria-expanded="true"] .cp-select__chevron {
    transform: rotate(180deg);
}

/* components/candidate/select: a filter's button (the candidate panel, the home page, admin filters) */
.cp-select:has(> select.cp-select__button) {
    width: 220px;
    font-size: .9rem;
}

.cp-select__button {
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--cp-border, #d5ddd9);
    border-radius: var(--cp-radius-sm, 8px);
    background-color: var(--cp-surface, #ffffff);
    color: var(--cp-text, #1b2420);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.cp-select__button:hover {
    border-color: var(--cp-primary-line, #cfe0d7);
}

/* ---------- the open list (drawn on <body>, fixed under its button) ---------- */

.cp-select__list {
    position: fixed;
    z-index: 1070;
    display: flex;
    flex-direction: column;
    max-width: min(480px, calc(100vw - 16px));
    max-height: 320px;
    padding: 6px;
    background: var(--cp-surface, #ffffff);
    border: 1px solid var(--cp-border, #d5ddd9);
    border-radius: var(--cp-radius, 12px);
    box-shadow: 0 12px 28px rgba(16, 24, 40, .12);
    color: var(--cp-text, #1b2420);
    font-size: .9rem;
    opacity: 0;
    transform: translateY(-6px) scale(.98);
    transform-origin: top center;
    transition: opacity .16s ease-out, transform .16s ease-out;
}

.cp-select__list.is-upward {
    transform: translateY(6px) scale(.98);
    transform-origin: bottom center;
}

.cp-select__list.is-shown {
    opacity: 1;
    transform: none;
}

.cp-select__search {
    flex: 0 0 auto;
    padding: 2px 2px 6px;
}

.cp-select__search input {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--cp-border, #d5ddd9);
    border-radius: var(--cp-radius-sm, 8px);
    background: var(--cp-surface-muted, #f9fbfa);
    color: inherit;
    font: inherit;
}

.cp-select__search input:focus {
    outline: 0;
    border-color: var(--cp-primary, #198754);
    box-shadow: 0 0 0 3px var(--cp-primary-soft, #e8f3ee);
}

.cp-select__options {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}

.cp-select__option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px;
    border-radius: var(--cp-radius-sm, 8px);
    cursor: pointer;
}

.cp-select__text {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* the option under the mouse or the arrow keys */
.cp-select__option.is-active {
    background: var(--cp-surface-muted, #f4f6f5);
}

.cp-select__option.is-selected {
    background: var(--cp-primary-soft, #e8f3ee);
    color: var(--cp-primary-dark, #146c43);
    font-weight: 600;
}

.cp-select__option.is-placeholder {
    color: var(--cp-text-muted, #6c757d);
}

.cp-select__option.is-disabled {
    color: var(--cp-text-muted, #6c757d);
    opacity: .55;
    cursor: not-allowed;
}

.cp-select__check {
    flex: 0 0 auto;
    visibility: hidden;
    color: var(--cp-primary, #198754);
}

.cp-select__option.is-selected .cp-select__check {
    visibility: visible;
}

/* a multiple select: each option shows a box to tick */
.cp-select__list.is-multiple .cp-select__check {
    visibility: visible;
    width: 18px;
    height: 18px;
    padding: 2px;
    border: 1.5px solid var(--cp-border, #c3ccc7);
    border-radius: 5px;
    color: transparent;
}

.cp-select__list.is-multiple .cp-select__option.is-selected .cp-select__check {
    border-color: var(--cp-primary, #198754);
    background: var(--cp-primary, #198754);
    color: #ffffff;
}

.cp-select__group {
    padding: 10px 10px 4px;
    color: var(--cp-text-muted, #6c757d);
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.cp-select__empty {
    padding: 12px 10px;
    color: var(--cp-text-muted, #6c757d);
    text-align: center;
}

@media (prefers-reduced-motion: reduce) {
    .cp-select__list,
    .cp-select__chevron {
        transition: none;
    }
}
