/* ==========================================================================
   3DSurgical — Select2 theme
   --------------------------------------------------------------------------
   Presentation-only restyle of Select2 4.1.0-rc.0. It shares the brand
   palette with css/datepicker-theme.css but deliberately NOT its geometry:
   select2 renders inline in form rows, so its border and radius track this
   project's .form-control (1px #A7A9AC via --primary-third, 2px radius)
   rather than the 8px floating-surface treatment used by the date pickers.

   Scoped to `.select2-container--default` because that is what actually
   renders: select2-bootstrap4.min.css only targets `--bootstrap4`, which
   requires `theme: 'bootstrap4'` at init, and no call site passes it.

   Loaded after css/style.css and css/style-custom.css, so it wins on source
   order alone — no `!important` anywhere in this file. That is only possible
   because the legacy overrides (which forced `border-radius: 0 !important`)
   were removed from those two files rather than fought.

   The legacy select2 block that lived (duplicated, byte for byte) in
   style.css:197-225 and style-custom.css:343-370 has been folded in here.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. Design tokens
   Mirrors css/datepicker-theme.css. Redeclared so this file stands alone if
   the two are ever loaded independently.
   -------------------------------------------------------------------------- */

:root {
    --s2-primary: #FF5500;
    --s2-primary-hover: #E64A00;
    --s2-primary-active: #CC4400;
    --s2-primary-light: #FFF3EB;
    --s2-primary-border: #FFD2BF;

    --s2-bg: #FFFFFF;
    --s2-surface: #FAFAFA;
    /* Control/panel outline. Tracks the project's own --primary-third, which
       style.css applies to every input via
           .form-control:not(.is-valid, .is-invalid) { border-color: ... !important }
       That !important overrides the theme's lighter #e9ecef, so #A7A9AC is
       what other boxes actually render. Fallback keeps this file standalone. */
    --s2-border: var(--primary-third, #A7A9AC);
    /* Hairlines *inside* the dropdown, where the control grey reads too heavy. */
    --s2-border-subtle: #E5E7EB;
    --s2-text: #1F2937;
    --s2-text-secondary: #6B7280;
    --s2-muted: #9CA3AF;
    --s2-disabled: #C7C7C7;
    --s2-danger: #DC2626;

    /* .form-control uses 2px — select2 boxes, the dropdown panel and the rows
       inside it all follow it so the controls read as one family. The date
       pickers keep their own 8px; they are floating surfaces, not form rows. */
    --s2-radius: 2px;
    --s2-radius-sm: 2px;
    --s2-shadow: 0 10px 30px rgba(0, 0, 0, .10);
    --s2-transition: all .2s ease;
    /* Bootstrap 4.6 .form-control height, so select2 aligns with its siblings. */
    --s2-height: calc(1.5em + 0.75rem + 2px);
}


/* ==========================================================================
   2. Closed control — single select
   ========================================================================== */

.select2-container--default .select2-selection--single {
    height: var(--s2-height);
    padding: 0;
    background-color: var(--s2-bg);
    border: 1px solid var(--s2-border);
    border-radius: var(--s2-radius);
    transition: var(--s2-transition);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    height: var(--s2-height);
    padding-left: 0.75rem;
    padding-right: 2rem;
    color: var(--s2-text);
    /* Bootstrap's own control line-height, minus the 2px border box. */
    line-height: calc(1.5em + 0.75rem);
    font-weight: 400;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--s2-muted);
}

.select2-container--default .select2-selection--single:hover {
    border-color: var(--s2-primary-border);
}


/* 2.1 Dropdown arrow ------------------------------------------------------- */

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: var(--s2-height);
    right: 6px;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--s2-text-secondary) transparent transparent transparent;
    transition: var(--s2-transition);
}

.select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent var(--s2-primary) transparent;
}


/* ==========================================================================
   3. Closed control — multiple select
   ========================================================================== */

.select2-container .select2-selection--multiple {
    min-height: var(--s2-height);
}

/* Padding is tuned so one row of chips lands on --s2-height exactly:
   1px border + 2px + 5px chip margin + 26px chip + 3px + 1px border = 38px.
   `.select2-selection--clearable` (3 classes) still beats this rule's
   padding-right, so the clear "×" keeps its 25px gutter. */
.select2-container--default .select2-selection--multiple {
    padding: 2px 4px 3px;
    background-color: var(--s2-bg);
    border: 1px solid var(--s2-border);
    border-radius: var(--s2-radius);
    transition: var(--s2-transition);
}

.select2-container--default .select2-selection--multiple:hover {
    border-color: var(--s2-primary-border);
}


/* 3.1 Selected value chips ------------------------------------------------- */

/* The plugin absolutely positions the remove button at `left:0` and reserves
   space for it with `padding-left:20px` on the chip. This theme moves the
   button to the trailing edge instead, so the padding is mirrored to the
   right. Both values are set as longhands — a `padding` shorthand here would
   silently drop the reserved gutter and let the button sit on the label. */
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    margin-top: 5px;
    margin-left: 6px;
    padding-top: 3px;
    padding-bottom: 3px;
    padding-left: 12px;
    padding-right: 26px;
    background-color: var(--s2-primary-light);
    border: 1px solid var(--s2-primary-border);
    border-radius: 999px;
    color: var(--s2-primary);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    transition: var(--s2-transition);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice:hover {
    background-color: var(--s2-primary-border);
}

/* Let the chip's own padding govern spacing — the plugin adds its own here. */
.select2-container--default .select2-selection--multiple .select2-selection__choice__display {
    padding-left: 0;
    padding-right: 0;
    color: var(--s2-primary);
}

/* Remove ("×") — repositioned to the trailing edge, full chip height, with
   the plugin's divider border dropped for a cleaner token. */
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    left: auto;
    right: 0;
    top: 0;
    bottom: 0;
    width: 22px;
    padding: 0;
    border: none;
    border-radius: 0 999px 999px 0;
    background-color: transparent;
    color: var(--s2-primary);
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    transition: var(--s2-transition);
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover,
.select2-container--default .select2-selection--multiple .select2-selection__choice__remove:focus {
    background-color: var(--s2-primary-border);
    color: var(--s2-danger);
    outline: none;
}

/* RTL: mirror the gutter and put the button back on the left. */
.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
    margin-left: 0;
    margin-right: 6px;
    padding-left: 26px;
    padding-right: 12px;
}

.select2-container--default[dir="rtl"] .select2-selection--multiple .select2-selection__choice__remove {
    left: 0;
    right: auto;
    border: none;
    border-radius: 999px 0 0 999px;
}


/* 3.2 Inline search field (multi-select) ----------------------------------- */

.select2-container .select2-search--inline .select2-search__field {
    height: 26px;
    margin-top: 4px;
    padding-left: 0.5rem;
    font-family: inherit;
    font-size: 14px;
    color: var(--s2-text);
}

.select2-container .select2-search--inline .select2-search__field::placeholder {
    color: var(--s2-muted);
}


/* ==========================================================================
   4. Focus & open states
   --------------------------------------------------------------------------
   select2-bootstrap4.min.css ships a live `.select2-container *:focus{outline:0}`
   rule (it is not scoped to --bootstrap4), which strips keyboard focus from
   every control on the 29 views that load it. These rules put it back.
   ========================================================================== */

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple {
    border: 1px solid var(--s2-primary);
    box-shadow: 0 0 0 0.2rem rgba(255, 85, 0, .15);
    outline: 0;
}

/* Visible ring for keyboard users specifically. */
.select2-container--default .select2-selection--single:focus,
.select2-container--default .select2-selection--multiple:focus,
.select2-container--default .select2-selection__choice__remove:focus,
.select2-container--default .select2-selection__clear:focus {
    outline: 2px solid var(--s2-primary);
    outline-offset: 2px;
}

/* Square off the edge that meets the open dropdown. */
.select2-container--default.select2-container--open.select2-container--below .select2-selection--single,
.select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.select2-container--default.select2-container--open.select2-container--above .select2-selection--single,
.select2-container--default.select2-container--open.select2-container--above .select2-selection--multiple {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}


/* 4.1 Clear ("×") on a single select --------------------------------------- */

.select2-container--default .select2-selection__clear {
    margin-right: 4px;
    color: var(--s2-muted);
    font-weight: 700;
    background-color: transparent;
    border: none;
    transition: var(--s2-transition);
}

.select2-container--default .select2-selection__clear:hover {
    color: var(--s2-danger);
}


/* ==========================================================================
   5. Disabled state
   ========================================================================== */

.select2-container--default.select2-container--disabled .select2-selection--single,
.select2-container--default.select2-container--disabled .select2-selection--multiple {
    background-color: var(--s2-surface);
    border-color: var(--s2-border);
    color: var(--s2-muted);
    cursor: not-allowed;
    opacity: .8;
}

.select2-container--default.select2-container--disabled .select2-selection--single .select2-selection__rendered {
    color: var(--s2-muted);
}

.select2-container--default.select2-container--disabled .select2-selection__choice__remove {
    display: none;
}


/* ==========================================================================
   6. Dropdown panel
   ========================================================================== */

.select2-dropdown {
    background-color: var(--s2-bg);
    border: 1px solid var(--s2-border);
    border-radius: var(--s2-radius);
    box-shadow: var(--s2-shadow);
    /* Preserved from the legacy override — this project deliberately keeps the
       panel low in its stacking context. Do not raise without checking modals. */
    z-index: 2;
}

.select2-container--open .select2-dropdown--below {
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.select2-container--open .select2-dropdown--above {
    border-bottom: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}


/* 6.1 Search box inside the dropdown --------------------------------------- */

.select2-search--dropdown {
    padding: 8px;
    border-bottom: 1px solid var(--s2-border-subtle);
    background-color: var(--s2-surface);
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    padding: 6px 10px;
    border: 1px solid var(--s2-border);
    border-radius: var(--s2-radius-sm);
    background-color: var(--s2-bg);
    color: var(--s2-text);
    font-size: 13px;
    transition: var(--s2-transition);
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--s2-primary);
    outline: 2px solid var(--s2-primary);
    outline-offset: 1px;
}


/* 6.2 Result rows ---------------------------------------------------------- */

.select2-results__options {
    padding: 6px;
}

.select2-results__option {
    padding: 8px 10px 8px 0.8rem;
    border-radius: var(--s2-radius-sm);
    color: var(--s2-text);
    font-size: 13px;
    transition: var(--s2-transition);
}

/* Hover / arrow-key cursor. */
.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: var(--s2-primary-light);
    color: var(--s2-primary);
    font-weight: 600;
}

/* Already-chosen value. */
.select2-container--default .select2-results__option[aria-selected=true],
.select2-container--default .select2-results__option--selected {
    background-color: var(--s2-primary);
    color: #FFFFFF;
    font-weight: 600;
}

/* Chosen AND under the cursor — must stay last to beat both rules above. */
.select2-container--default .select2-results__option--selected.select2-results__option--highlighted,
.select2-container--default .select2-results__option[aria-selected=true].select2-results__option--highlighted {
    background-color: var(--s2-primary-hover);
    color: #FFFFFF;
}

.select2-container--default .select2-results__option--disabled,
.select2-container--default .select2-results__option[aria-disabled=true] {
    color: var(--s2-disabled);
    opacity: .6;
    cursor: not-allowed;
}


/* 6.3 Groups, messages and nesting ----------------------------------------- */

.select2-container--default .select2-results__group {
    padding: 8px 10px 4px;
    color: var(--s2-text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.select2-results__message {
    padding: 10px 12px;
    color: var(--s2-text-secondary);
    font-size: 13px;
}

/* Nested/grouped option indentation is left to the plugin — its own
   `--default`-scoped cascade (1em, 2em, 3em…) outranks anything set here. */

.select2-results > .select2-results__options {
    /* Plugin caps this at 200px; a touch more list is visible before scrolling. */
    max-height: 260px;
}


/* ==========================================================================
   7. Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {

    .select2-container--default .select2-selection--single,
    .select2-container--default .select2-selection--multiple,
    .select2-container--default .select2-selection--single .select2-selection__arrow b,
    .select2-container--default .select2-selection__choice,
    .select2-container--default .select2-selection__choice__remove,
    .select2-container--default .select2-selection__clear,
    .select2-container--default .select2-search--dropdown .select2-search__field,
    .select2-results__option {
        transition: none;
    }
}
