/*
 * S1–S3 · hyper-select (docs/ui/COMPONENTI.md): <select class="hy-select"> potenziato da Tom Select.
 * Stile interamente nostro (il CSS di Tom Select non si carica). Solo token --hy-*.
 * Il wrapper .ts-wrapper riceve la classe hy-select dal select originale: è lui il riquadro del campo (C3).
 */
.ts-hidden-accessible {
    border: 0 !important; clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; /* !important: il select originale deve restare invisibile */
    height: 1px !important; overflow: hidden !important; padding: 0 !important; position: absolute !important; width: 1px !important; white-space: nowrap !important;
}

.ts-wrapper.hy-select { position: relative; display: flex; align-items: center; padding: 0 36px 0 12px; cursor: pointer; flex: 1 1 auto; min-width: 0; } /* min-width 0: un testo lungo (es. commessa) si accorcia con i puntini invece di allargare il campo e la pagina */
.ts-wrapper.hy-select.focus { border-color: var(--hy-focus-ring); box-shadow: 0 0 0 1px var(--hy-focus-ring), 0 0 0 4px var(--hy-accent-soft); }
.ts-wrapper.hy-select.disabled { opacity: .5; background-color: var(--hy-surface-alt); cursor: not-allowed; }
.ts-wrapper.hy-select.dropdown-active { background-image: linear-gradient(-45deg, transparent 50%, var(--hy-text-muted) 50%), linear-gradient(-135deg, var(--hy-text-muted) 50%, transparent 50%); background-position: calc(100% - 13px) 50%, calc(100% - 18px) 50%; }

.ts-wrapper .ts-control { display: flex; align-items: center; flex: 1; min-width: 0; height: 100%; overflow: hidden; }
.ts-wrapper .ts-control:focus, .ts-wrapper .ts-control:focus-visible { outline: none !important; } /* il focus è mostrato dal riquadro del campo (.ts-wrapper.focus) */
.ts-wrapper .ts-control > .item { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--hy-text); }
.ts-wrapper .ts-control > input {
    flex: 1 1 auto; min-width: 2px; width: 2px; height: 100%; margin: 0; padding: 0; border: 0 !important; /* !important: vince sulle regole globali degli input di site.css */
    background: transparent !important; box-shadow: none !important; outline: none !important; color: var(--hy-text); font: inherit; cursor: pointer;
    -webkit-appearance: none; appearance: none; /* Firefox: senza, il tema nativo disegna un anello di focus sul campo interno (due linee verticali dentro il riquadro, 2026-10-23) */
}
.ts-wrapper .ts-control > input:focus, .ts-wrapper .ts-control > input:focus-visible { outline: none !important; box-shadow: none !important; }
/* cursore di testo nascosto finché si vede il segnaposto: compare appena si scrive per cercare */
.ts-wrapper .ts-control > input:placeholder-shown { caret-color: transparent; }
.ts-wrapper.has-items .ts-control > input { position: absolute; opacity: 0; }
.ts-wrapper .ts-control > input::placeholder { color: var(--hy-text-placeholder); opacity: 1; }

/* Svuota (×): solo sui campi facoltativi che lo hanno oggi */
.ts-wrapper .clear-button {
    position: absolute; right: 30px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; color: var(--hy-text-muted); opacity: 0; cursor: pointer;
}
.ts-wrapper.has-items .clear-button { opacity: 1; }
.ts-wrapper .clear-button:hover { background: var(--hy-accent-soft); color: var(--hy-text); }

/* Lista aperta (desktop): pannello fisso posizionato da hyper-select.js sotto o sopra il campo */
.ts-dropdown {
    position: fixed; z-index: var(--hy-z-dropdown); display: flex; flex-direction: column; min-width: 220px; max-height: 320px;
    border-radius: var(--hy-radius-md); border: 1px solid var(--hy-glass-border);
    background: var(--hy-surface-raised); color: var(--hy-text); box-shadow: var(--hy-shadow-2);
    font: var(--hy-weight-regular) var(--hy-text-md) var(--hy-font-sans); overflow: hidden; cursor: default;
}
/* Tom Select apre il pannello con display:block in linea: serve flex perché l'elenco scorra dentro l'altezza massima */
.ts-wrapper.dropdown-active .ts-dropdown { display: flex !important; }
.ts-dropdown .dropdown-input-wrap { flex: none; padding: 8px; border-bottom: 1px solid var(--hy-border); }
.ts-dropdown .dropdown-input {
    width: 100%; height: 32px; padding: 0 10px; border-radius: var(--hy-radius-md);
    border: 1px solid var(--hy-border-control) !important; background: var(--hy-control-bg) !important; color: var(--hy-text); font: inherit; /* !important: vince su site.css */
}
.ts-dropdown .dropdown-input:focus { outline: none; border-color: var(--hy-focus-ring) !important; box-shadow: 0 0 0 3px var(--hy-accent-soft) !important; }
.ts-dropdown .ts-dropdown-content { flex: 1; min-height: 0; overflow-y: auto; padding: 4px; scroll-behavior: auto; }
.ts-dropdown .option, .ts-dropdown .no-results, .ts-dropdown .create {
    display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 10px; border-radius: var(--hy-radius-sm);
}
.ts-dropdown .option { cursor: pointer; }
.ts-dropdown .option .hy-opt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ts-dropdown .option .hy-opt__sub { color: var(--hy-text-muted); font-size: var(--hy-text-sm); }
.ts-dropdown .option.active { background: var(--hy-accent-soft); color: var(--hy-text); }
.ts-dropdown .option.selected { font-weight: var(--hy-weight-strong); }
.ts-dropdown .option.selected::after { content: "\f00c"; font-family: "Font Awesome 6 Free"; font-weight: 900; font-size: 12px; color: var(--hy-accent-text); }
.ts-dropdown .option[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.ts-dropdown .highlight { font-weight: var(--hy-weight-bold); color: var(--hy-accent-text); background: none; }
.ts-dropdown .no-results { color: var(--hy-text-muted); }
.ts-dropdown .optgroup-header { padding: 10px 10px 4px; color: var(--hy-text-muted); font-size: var(--hy-text-xs); font-weight: var(--hy-weight-strong); text-transform: uppercase; letter-spacing: .04em; }
.ts-dropdown .spinner { display: none; }

/* Intestazione e velatura dello sheet: visibili solo su smartphone */
.hy-select-sheet__head, .hy-select-backdrop { display: none; }

/* Lista aperta (smartphone): sheet dal basso (D31) */
@media (max-width: 767.98px) {
    .ts-dropdown {
        left: 0 !important; right: 0 !important; bottom: var(--hy-kb, 0px) !important; top: auto !important; width: 100% !important; /* !important: annulla la posizione calcolata per il desktop; --hy-kb = altezza della tastiera (hyper-select.js) */
        max-height: calc(var(--hy-vvh, 100dvh) * .85); z-index: var(--hy-z-modal); border-radius: var(--hy-radius-lg) var(--hy-radius-lg) 0 0; border-bottom: 0;
        padding-bottom: env(safe-area-inset-bottom); box-shadow: var(--hy-shadow-3);
    }
    .hy-select-sheet__head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 8px 16px; border-bottom: 1px solid var(--hy-border); }
    .hy-select-sheet__head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--hy-border-control); }
    .hy-select-sheet__title { flex: 1; margin: 0; font: var(--hy-weight-strong) var(--hy-text-lg) var(--hy-font-heading); }
    .ts-dropdown .dropdown-input { height: 44px; font-size: 16px; }
    .ts-dropdown .option, .ts-dropdown .no-results { min-height: 48px; }
    .ts-wrapper.dropdown-active .hy-select-backdrop {
        display: block; position: fixed; inset: 0; z-index: var(--hy-z-modal); background: var(--hy-backdrop);
    }
    .ts-wrapper.dropdown-active .ts-dropdown { z-index: calc(var(--hy-z-modal) + 1); }
}

/* S2 · Multiselect: nel campo chiuso un riepilogo compatto ("Operatori (3)", O2) al posto dei valori */
.ts-wrapper.hy-select--multi .ts-control > .item { display: none; }
.hy-select__summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--hy-text); }
.hy-select__summary.is-placeholder { color: var(--hy-text-placeholder); }
.ts-wrapper.hy-select--multi .ts-control > input { position: absolute; opacity: 0; }
.ts-wrapper.hy-select--multi.input-active .ts-control > input { position: static; opacity: 1; }
.hy-select__all {
    flex: none; display: block; width: 100%; padding: 8px 14px; border: 0; border-bottom: 1px solid var(--hy-border);
    background: transparent; color: var(--hy-accent-text); font: var(--hy-weight-strong) var(--hy-text-sm) var(--hy-font-sans); text-align: left; cursor: pointer;
}
.hy-select__all:hover { background: var(--hy-accent-soft); }
.ts-dropdown .option input[type="checkbox"] { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--hy-accent); pointer-events: none; }
.ts-wrapper.hy-select--multi .ts-dropdown .option.selected::after { content: none; }
.hy-select-sheet__foot { display: none; }
@media (max-width: 767.98px) {
    .ts-wrapper.hy-select--multi .hy-select-sheet__foot { display: block; flex: none; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hy-border); }
    .ts-dropdown .option input[type="checkbox"] { width: 20px; height: 20px; }
}
