/* Styled dropdowns, see js/cselect.js */

/* Defaults and built-in variants carry no specificity, so any page rule overrides them */
:where(.cselect) {
    --cselect-accent: #11a191;
    --cselect-accent-ink: #0b7d71;
    --cselect-ink: #1f2d2b;
    --cselect-muted: #7a8785;
    /* Field sizing; variants and pages override these */
    --cselect-height: 52px;
    --cselect-padding: 0.65rem 0.7rem 0.65rem 1rem;
    --cselect-gap: 0.75rem;
    --cselect-radius: 12px;
    --cselect-border-width: 1.5px;
    --cselect-border: #dde4e3;
    --cselect-bg: #fff;
    --cselect-font-size: 0.95rem;
    --cselect-font-weight: 500;
    --cselect-shadow: 0 1px 2px rgba(15, 47, 44, 0.04);
    --cselect-ring: 0 0 0 4px rgba(17, 161, 145, 0.14);
    --cselect-chevron-size: 30px;
    --cselect-chevron-radius: 9px;
    --cselect-chevron-bg: #f2f6f5;
    --cselect-chevron-color: #5f6f6c;
}

.cselect {
    position: relative;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    container-type: inline-size;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    text-align: left;
}

.cselect[hidden] {
    display: none !important;
}

.cselect-native {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 1px !important;
    height: 1px !important;
    min-width: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    clip-path: inset(50%) !important;
}

.cselect-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---------- Field ---------- */

.cselect .cselect-trigger {
    display: flex;
    align-items: center;
    gap: var(--cselect-gap);
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: var(--cselect-height);
    margin: 0;
    padding: var(--cselect-padding);
    border: var(--cselect-border-width) solid var(--cselect-border);
    border-radius: var(--cselect-radius);
    background: var(--cselect-bg);
    color: var(--cselect-ink);
    font: inherit;
    font-size: var(--cselect-font-size);
    font-weight: var(--cselect-font-weight);
    line-height: 1.35;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    cursor: pointer;
    box-shadow: var(--cselect-shadow);
    transform: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

@media (hover: hover) {
    .cselect .cselect-trigger:not(:disabled):hover {
        border-color: rgba(17, 161, 145, 0.55);
        box-shadow: 0 2px 8px -2px rgba(15, 47, 44, 0.1);
    }

    .cselect .cselect-trigger:not(:disabled):hover .cselect-chevron {
        background: rgba(17, 161, 145, 0.1);
        color: var(--cselect-accent-ink);
    }
}

.cselect .cselect-trigger:focus {
    outline: none;
}

.cselect .cselect-trigger:focus-visible,
.cselect.is-open .cselect-trigger {
    border-color: var(--cselect-accent);
    box-shadow: var(--cselect-ring);
}

.cselect.is-invalid .cselect-trigger {
    border-color: #dc3545;
    background-color: #fffafa;
}

.cselect.is-invalid .cselect-trigger:focus-visible,
.cselect.is-invalid.is-open .cselect-trigger {
    box-shadow: 0 0 0 4px rgba(220, 53, 69, 0.12);
}

.cselect .cselect-trigger:disabled {
    background: #f5f7f7;
    border-color: #e6ebea;
    color: #9aa5a3;
    cursor: not-allowed;
    box-shadow: none;
}

.cselect-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cselect.is-empty .cselect-value {
    color: #8a9795;
    font-weight: 400;
}

.cselect.is-disabled .cselect-value {
    color: #a7b0af;
}

.cselect-value-detail {
    color: var(--cselect-muted);
    font-weight: 400;
}

.cselect-value-detail::before {
    content: "\00b7";
    margin: 0 0.4em;
    color: #b6c0be;
}

/* Narrow fields show just the main label; the list still shows the detail */
@container (max-width: 440px) {
    .cselect-value-detail {
        display: none;
    }
}

.cselect.just-changed .cselect-value {
    animation: cselect-value-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes cselect-value-in {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: none; }
}

.cselect-chevron {
    flex: none;
    display: grid;
    place-items: center;
    width: var(--cselect-chevron-size);
    height: var(--cselect-chevron-size);
    border-radius: var(--cselect-chevron-radius);
    background: var(--cselect-chevron-bg);
    color: var(--cselect-chevron-color);
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.18s ease, color 0.18s ease;
}

.cselect.is-open .cselect-chevron {
    transform: rotate(180deg);
    background: rgba(17, 161, 145, 0.12);
    color: var(--cselect-accent-ink);
}

.cselect .cselect-trigger:disabled .cselect-chevron {
    background: #eef1f1;
    color: #b8c0bf;
}

/* ---------- Variants ---------- */

/* Toolbars, filters, time pickers */
:where(.cselect--compact) {
    --cselect-height: 38px;
    --cselect-padding: 0.3rem 0.4rem 0.3rem 0.75rem;
    --cselect-gap: 0.45rem;
    --cselect-radius: 10px;
    --cselect-font-size: 0.88rem;
    --cselect-ring: 0 0 0 3px rgba(17, 161, 145, 0.16);
    --cselect-chevron-size: 24px;
    --cselect-chevron-radius: 7px;
}

.cselect--compact .cselect-chevron svg {
    width: 12px;
    height: 12px;
}

/* Just the arrow, no chip: fields that sit among plain text inputs */
:where(.cselect--plain) {
    --cselect-chevron-bg: transparent;
    --cselect-chevron-size: 20px;
}

@media (hover: hover) {
    .cselect--plain .cselect-trigger:not(:disabled):hover .cselect-chevron,
    .cselect--inline .cselect-trigger:not(:disabled):hover .cselect-chevron {
        background: transparent;
    }
}

.cselect--plain.is-open .cselect-chevron,
.cselect--inline.is-open .cselect-chevron {
    background: transparent;
}

/* Borderless, inside a control that draws its own outline and focus ring */
:where(.cselect--inline) {
    --cselect-height: 0;
    --cselect-padding: 0 8px 0 6px;
    --cselect-gap: 4px;
    --cselect-radius: 0;
    --cselect-border: transparent;
    --cselect-bg: transparent;
    --cselect-shadow: none;
    --cselect-ring: none;
    --cselect-font-size: 0.84rem;
    --cselect-font-weight: 600;
    --cselect-ink: #2c3e50;
    --cselect-chevron-size: 16px;
    --cselect-chevron-bg: transparent;
    --cselect-chevron-color: #00796b;
}

.cselect--inline {
    width: auto;
    height: 100%;
    container-type: normal; /* sized by its text */
}

.cselect--inline .cselect-trigger {
    height: 100%;
}

/* Current value and invisible copies of every option share one grid cell: the widest sets the width */
.cselect--inline .cselect-value {
    display: grid;
    grid-template-columns: minmax(0, max-content);
}

.cselect--inline .cselect-value > * {
    grid-area: 1 / 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.cselect-value-sizer {
    visibility: hidden;
}

.cselect--inline .cselect-chevron svg {
    width: 12px;
    height: 12px;
}

.cselect.cselect--inline .cselect-trigger:not(:disabled):hover,
.cselect.cselect--inline .cselect-trigger:focus-visible,
.cselect.cselect--inline.is-open .cselect-trigger {
    border-color: transparent;
    box-shadow: none;
}

/* ---------- Popover ---------- */

.cselect-panel {
    --cselect-accent: #11a191;
    --cselect-accent-ink: #0b7d71;
    --cselect-ink: #1f2d2b;
    --cselect-muted: #7a8785;
    position: fixed;
    z-index: 49000; /* under the fixed header (50000), over page content; js raises it over pop-ups */
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    margin: 0;
    padding: 6px;
    border: 1px solid rgba(15, 47, 44, 0.08);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 22px 48px -16px rgba(15, 47, 44, 0.34), 0 4px 14px rgba(15, 47, 44, 0.07);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-style: normal;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
    transform-origin: 50% 0;
    transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cselect-panel.is-above {
    transform: translateY(6px) scale(0.98);
    transform-origin: 50% 100%;
}

.cselect-panel.is-open {
    opacity: 1;
    transform: none;
}

.cselect-panel.is-closing {
    transition-duration: 0.12s;
}

.cselect-list {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    outline: none;
    scrollbar-width: thin;
    scrollbar-color: #cfd8d6 transparent;
}

.cselect-list::-webkit-scrollbar {
    width: 6px;
}

.cselect-list::-webkit-scrollbar-thumb {
    border-radius: 3px;
    background: #cfd8d6;
}

.cselect-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    padding: 0.62rem 0.7rem 0.62rem 0.8rem;
    border-radius: 10px;
    color: var(--cselect-ink);
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.35;
    cursor: pointer;
    transition: background-color 0.12s ease, color 0.12s ease;
    -webkit-tap-highlight-color: transparent;
}

.cselect-option + .cselect-option {
    margin-top: 2px;
}

.cselect-option.is-active {
    background: #f1f7f6;
}

.cselect-option[aria-selected="true"] {
    background: rgba(17, 161, 145, 0.08);
    color: var(--cselect-accent-ink);
    font-weight: 600;
}

.cselect-option[aria-selected="true"].is-active {
    background: rgba(17, 161, 145, 0.13);
}

.cselect-option[aria-disabled="true"] {
    color: #b0b9b8;
    cursor: not-allowed;
}

.cselect-option-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cselect-option-detail {
    color: var(--cselect-muted);
    font-size: 0.8rem;
    font-weight: 400;
}

.cselect-check {
    flex: none;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--cselect-accent);
    color: #fff;
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 0.15s ease, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.cselect-option[aria-selected="true"] .cselect-check {
    opacity: 1;
    transform: scale(1);
}

.cselect-group {
    margin: 0;
    padding: 0.7rem 0.8rem 0.3rem;
    color: var(--cselect-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1.3;
    text-transform: uppercase;
}

.cselect-group:not(:first-child) {
    margin-top: 6px;
    border-top: 1px solid #edf1f0;
    padding-top: 0.8rem;
}

.cselect-empty {
    padding: 0.9rem;
    color: var(--cselect-muted);
    font-size: 0.88rem;
    text-align: center;
}

/* ---------- Search box (data-cselect-search) ---------- */

.cselect-search {
    flex: none;
    position: relative;
    display: flex;
    align-items: center;
    margin: 0 0 6px;
    color: #8a9795;
}

.cselect-search svg {
    position: absolute;
    left: 12px;
    pointer-events: none;
    transition: color 0.15s ease;
}

.cselect-search:focus-within svg {
    color: var(--cselect-accent);
}

.cselect-panel .cselect-search-input {
    box-sizing: border-box;
    width: 100%;
    height: 40px;
    margin: 0;
    padding: 0 12px 0 36px;
    border: 1px solid #e3eae9;
    border-radius: 10px;
    outline: none;
    background: #f6f9f9;
    box-shadow: none;
    color: var(--cselect-ink);
    font: inherit;
    font-size: 0.9rem;
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.cselect-panel .cselect-search-input::placeholder {
    color: #94a29f;
}

.cselect-panel .cselect-search-input:focus {
    border-color: var(--cselect-accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(17, 161, 145, 0.14);
}

.cselect-match {
    padding: 0;
    border-radius: 3px;
    background: rgba(17, 161, 145, 0.16);
    color: inherit;
    font-weight: 700;
}

.cselect-panel--sheet .cselect-search {
    margin: 0 0 8px;
}

/* 16px, so iOS doesn't zoom in on focus */
.cselect-panel--sheet .cselect-search-input {
    height: 46px;
    font-size: 16px;
}

/* Compact fields get a denser menu on desktop */
.cselect-panel--compact:not(.cselect-panel--sheet) .cselect-option,
.cselect-panel--inline:not(.cselect-panel--sheet) .cselect-option {
    padding: 0.5rem 0.6rem 0.5rem 0.7rem;
    border-radius: 8px;
    font-size: 0.87rem;
}

.cselect-panel--compact:not(.cselect-panel--sheet) .cselect-check,
.cselect-panel--inline:not(.cselect-panel--sheet) .cselect-check {
    width: 18px;
    height: 18px;
}

/* ---------- Bottom sheet (phones) ---------- */

html.cselect-scroll-lock,
html.cselect-scroll-lock body {
    overflow: hidden !important;
    overscroll-behavior: none;
}

html.cselect-scroll-gutter {
    scrollbar-gutter: stable;
}

.cselect-layer {
    position: fixed;
    inset: 0;
    z-index: 60010; /* with the page's pop-ups, above the header; js raises it over pop-ups */
    margin: 0;
    overscroll-behavior: contain;
}

.cselect-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(18, 22, 26, 0.45);
    opacity: 0;
    transition: opacity 0.28s ease;
}

.cselect-layer.is-open .cselect-backdrop {
    opacity: 1;
}

.cselect-layer.is-closing .cselect-backdrop {
    transition-duration: 0.22s;
}

.cselect-panel.cselect-panel--sheet {
    position: absolute;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto !important;
    max-height: min(78vh, 560px);
    max-height: min(78dvh, 560px);
    padding: 0 10px calc(12px + env(safe-area-inset-bottom, 0px));
    border: none;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -14px 40px -12px rgba(0, 0, 0, 0.28);
    opacity: 1;
    transform: translateY(100%);
    transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1);
}

.cselect-layer.is-open .cselect-panel--sheet {
    transform: none;
}

.cselect-layer.is-closing .cselect-panel--sheet {
    transform: translateY(100%) !important;
    transition: transform 0.26s cubic-bezier(0.4, 0, 1, 1);
}

.cselect-panel--sheet.is-dragging {
    transition: none;
}

.cselect-sheet-head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 4px 12px 8px;
    touch-action: none;
    cursor: grab;
}

.cselect-grabber {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 38px;
    height: 4px;
    margin-left: -19px;
    border-radius: 999px;
    background: #d5dcdb;
}

.cselect-sheet-title {
    flex: 1;
    min-width: 0;
    color: var(--cselect-ink);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}

.cselect-close {
    flex: none;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #f1f4f4;
    color: #4b5a58;
    cursor: pointer;
    transition: background-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.cselect-close:hover,
.cselect-close:focus-visible {
    background: #e5ebea;
    outline: none;
}

.cselect-panel--sheet .cselect-list {
    padding-bottom: 4px;
}

.cselect-panel--sheet .cselect-option {
    min-height: 54px;
    padding: 0.75rem 0.85rem;
    font-size: 0.97rem;
}

.cselect-panel--sheet .cselect-option + .cselect-option {
    margin-top: 4px;
}

.cselect-panel--sheet .cselect-check {
    width: 22px;
    height: 22px;
}

@media (max-width: 600px) {
    :where(.cselect) {
        --cselect-height: 50px;
        --cselect-font-size: 0.92rem;
    }

    :where(.cselect--compact) {
        --cselect-height: 44px;
        --cselect-font-size: 0.9rem;
    }

    :where(.cselect--inline) {
        --cselect-height: 0;
        --cselect-font-size: 0.82rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cselect-panel,
    .cselect-panel.cselect-panel--sheet,
    .cselect-backdrop,
    .cselect-chevron,
    .cselect-check {
        transition: none !important;
    }

    .cselect.just-changed .cselect-value {
        animation: none;
    }
}
