/* ============================================================
   Guest skin · Select2 (krajee-bs5 theme)
   Loaded AFTER the vendor theme via GuestSelect2Asset.

   Mirrors .g-control exactly: 42px, 9px radius, constant 1px border.
   Active states add the second pixel with an inset shadow and the glow
   with an outer shadow, so the box never resizes (no jerk).

   Markup contract (see registration views):
     .gl-select2[.gl-select2--icon]
       .gl-select2__shell > .gl-select2__icon + {select} + .select2-container
     pluginOptions: dropdownCssClass => 'gl-select2-dropdown'
   ============================================================ */

/* ---------- Shell ----------
   Reserves the final 42px box before Select2 initialises, so the field
   does not jump when the vendor loading placeholder is swapped out. */
.gl-select2 {
    --s2-border: var(--g-border);
    --s2-inner: transparent;
    --s2-ring: transparent;
    --s2-bg: var(--g-surface);
}

.gl-select2__shell {
    position: relative;
    min-height: 42px;
    border-radius: 9px;
    background: var(--g-surface);
    box-shadow: inset 0 0 0 1px var(--g-border);
}

.gl-select2 .kv-plugin-loading { display: none; }

.gl-select2__icon {
    position: absolute;
    top: 0;
    left: .75rem;
    z-index: 2;
    display: flex;
    height: 42px;
    align-items: center;
    color: var(--g-text-faint);
    font-size: 15px;
    pointer-events: none;
    transition: color .18s var(--g-ease);
}

/* ---------- Selection (paint rule) ----------
   High specificity on purpose: it must beat every Krajee rule that sets
   border/shadow/radius directly (open, focus, below/above, validation).
   State rules below only change the --s2-* variables it reads. */
/* `!important` is required here to beat Krajee's own state and sizing rules.
   Scoped to .gl-select2, so only guest-skinned fields are affected. */
.gl-select2 .select2-container.select2-container--krajee-bs5 span.select2-selection.select2-selection--single {
    position: relative !important;
    display: flex !important;
    width: 100% !important;
    height: 42px !important;
    align-items: center;
    padding: 0 2.4rem 0 .75rem !important;
    border: 1px solid var(--g-border) !important;   /* default; state rules recolour */
    border-radius: 9px !important;
    background-color: var(--g-surface) !important;   /* default; state rules override */
    background-image: none !important;
    box-shadow: none !important;                     /* default; state rules override */
    color: var(--g-text) !important;
    font-size: .85rem !important;
    font-weight: 400 !important;
    line-height: 1.4 !important;
    outline: 0;
    cursor: pointer;
    /* This box is a control, not prose. Without this, double-clicking it
       selects the rendered label and paints a full-height highlight band
       inside the field — exactly what a native <select> never does. */
    user-select: none !important;
    -webkit-user-select: none !important;
    transition: border-color .18s var(--g-ease), box-shadow .18s var(--g-ease), background-color .18s var(--g-ease) !important;
}

.gl-select2--icon .select2-container.select2-container--krajee-bs5 span.select2-selection.select2-selection--single {
    padding-left: 2.6rem !important;
}

.gl-select2 .select2-container.select2-container--krajee-bs5 span.select2-selection.select2-selection--clearable {
    padding-right: 3.75rem !important;
}

/* Custom chevron (vendor's background-image chevron is removed above) */
.gl-select2 .select2-container--krajee-bs5 .select2-selection--single::after {
    position: absolute;
    top: 50%;
    right: .95rem;
    width: 7px;
    height: 7px;
    margin-top: -5px;
    border: solid var(--g-text-faint);
    border-width: 0 1.5px 1.5px 0;
    content: "";
    transform: rotate(45deg);
    transition: transform .18s var(--g-ease), margin-top .18s var(--g-ease);
}

.gl-select2 .select2-container--open .select2-selection--single::after {
    margin-top: -1px;
    transform: rotate(-135deg);
}

.gl-select2 .select2-container--krajee-bs5 .select2-selection--single .select2-selection__arrow {
    display: none;
}

/* The 42px shell centres this with flex; a 40px line-height would make the
   text's line box (and any selection/highlight) as tall as the field. */
.gl-select2 .select2-container--krajee-bs5 .select2-selection--single .select2-selection__rendered {
    flex: 1;
    min-width: 0;
    padding: 0 !important;
    /* Value text matches every other control in the form (--g-text), so the
       Select2 selection reads the same as a typed input or native select.
       The filled/valid state is carried by the border and icon, not the text. */
    color: var(--g-text) !important;
    font-size: .85rem;
    font-weight: 500;
    line-height: 1.4 !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Placeholder (no value chosen yet) stays a neutral faint grey, not the
   accent — the accent is reserved for an actual selection. */
.gl-select2 .select2-container--krajee-bs5 .select2-selection--single .select2-selection__rendered:has(.select2-selection__placeholder),
.gl-select2 .select2-container--krajee-bs5 .select2-selection--single .select2-selection__placeholder {
    color: var(--g-text-faint) !important;
    font-weight: 400;
}

/* Clear (×) button. Position explicitly because Krajee's themes vary. */
.gl-select2 .select2-container--krajee-bs5 .select2-selection--single .select2-selection__clear {
    position: absolute !important;
    top: 50% !important;
    right: 2.15rem !important;
    z-index: 2 !important;
    display: grid;
    width: 22px;
    height: 22px;
    margin: -11px 0 0;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--g-text-faint);
    font-size: 1rem !important;
    font-weight: 400;
    line-height: 1;
    text-shadow: none;
    opacity: 1;
    cursor: pointer;
    transition: background-color .16s var(--g-ease), color .16s var(--g-ease);
}

.gl-select2 .select2-container--krajee-bs5 .select2-selection--single .select2-selection__clear:hover {
    background: var(--g-surface-2);
    color: var(--g-text);
}

/* ---------- States ----------
   Set border-color / background / shadow DIRECTLY with !important because
   Krajee's theme writes those same paint properties at high specificity.
   Every rule shares one specificity so precedence = source order:
   hover < focus/open < filled/valid < focused-filled < danger < focused-danger < disabled.
   Danger covers bootstrap5 (`select.is-invalid` sibling) and yii\widgets (`.has-error`). */

/* State rules carry the SAME leading chain as the paint rule
   (.gl-select2 ... span.select2-selection.select2-selection--single) so they
   match its specificity (0,5,2) and win on source order. The `.gl-select2`
   state-driver prefix adds a class, keeping each ≥ the paint rule. */
.gl-select2:hover .select2-container--krajee-bs5 span.select2-selection.select2-selection--single {
    border-color: var(--g-border-strong) !important;
}

.gl-select2 .select2-container--krajee-bs5.select2-container--focus span.select2-selection.select2-selection--single,
.gl-select2 .select2-container--krajee-bs5.select2-container--open span.select2-selection.select2-selection--single {
    border-color: var(--g-accent) !important;
    box-shadow: inset 0 0 0 1px var(--g-accent), 0 0 0 3px color-mix(in srgb, var(--g-accent) 14%, transparent) !important;
}

/* Filled (a real option is selected): matches the accent the selection text
   is painted in, so the box and its value read as one accent unit. No outer
   ring — the focus/open rules above own the glow. */
.gl-select2 .select2-container--krajee-bs5 span.select2-selection.select2-selection--single:not(:has(.select2-selection__placeholder)),
.gl-select2 select.is-valid + .select2-container--krajee-bs5 span.select2-selection.select2-selection--single,
.gl-select2.has-success .select2-container--krajee-bs5 span.select2-selection.select2-selection--single,
.gl-select2 .has-success .select2-container--krajee-bs5 span.select2-selection.select2-selection--single {
    border-color: var(--g-field-valid) !important;
    background-color: color-mix(in srgb, var(--g-field-valid) 6%, var(--g-surface)) !important;
    box-shadow: inset 0 0 0 1px var(--g-field-valid), 0 0 0 3px color-mix(in srgb, var(--g-field-valid) 10%, transparent) !important;
}

.gl-select2 .select2-container--krajee-bs5.select2-container--focus span.select2-selection.select2-selection--single:not(:has(.select2-selection__placeholder)),
.gl-select2 .select2-container--krajee-bs5.select2-container--open span.select2-selection.select2-selection--single:not(:has(.select2-selection__placeholder)) {
    background-color: var(--g-surface) !important;
    box-shadow: inset 0 0 0 1px var(--g-field-valid), 0 0 0 3px color-mix(in srgb, var(--g-field-valid) 16%, transparent) !important;
}

/* Danger (overrides valid-by-content above) */
.gl-select2 select.is-invalid + .select2-container--krajee-bs5 span.select2-selection.select2-selection--single,
.gl-select2.has-error .select2-container--krajee-bs5 span.select2-selection.select2-selection--single,
.gl-select2 .has-error .select2-container--krajee-bs5 span.select2-selection.select2-selection--single {
    border-color: var(--g-field-danger) !important;
    background-color: color-mix(in srgb, var(--g-field-danger) 6%, var(--g-surface)) !important;
    box-shadow: inset 0 0 0 1px var(--g-field-danger), 0 0 0 3px color-mix(in srgb, var(--g-field-danger) 10%, transparent) !important;
}

.gl-select2 select.is-invalid + .select2-container--krajee-bs5.select2-container--focus span.select2-selection.select2-selection--single,
.gl-select2 select.is-invalid + .select2-container--krajee-bs5.select2-container--open span.select2-selection.select2-selection--single,
.gl-select2.has-error .select2-container--krajee-bs5.select2-container--focus span.select2-selection.select2-selection--single,
.gl-select2.has-error .select2-container--krajee-bs5.select2-container--open span.select2-selection.select2-selection--single,
.gl-select2 .has-error .select2-container--krajee-bs5.select2-container--focus span.select2-selection.select2-selection--single,
.gl-select2 .has-error .select2-container--krajee-bs5.select2-container--open span.select2-selection.select2-selection--single {
    background-color: var(--g-surface) !important;
    box-shadow: inset 0 0 0 1px var(--g-field-danger), 0 0 0 3px color-mix(in srgb, var(--g-field-danger) 16%, transparent) !important;
}

.gl-select2 .select2-container--krajee-bs5.select2-container--disabled span.select2-selection.select2-selection--single {
    border-color: var(--g-border) !important;
    background-color: var(--g-surface-2) !important;
    box-shadow: none !important;
    cursor: not-allowed;
}

/* Leading icon follows the same states (same order). */
.gl-select2__shell:where(:has(.select2-container--focus), :has(.select2-container--open)) .gl-select2__icon {
    color: var(--g-accent-ink);
}

.gl-select2__shell:where(:has(.select2-container):not(:has(.select2-selection__placeholder)), :has(select.is-valid), .has-success *) .gl-select2__icon {
    color: var(--g-field-valid);
}

.gl-select2__shell:where(:has(select.is-invalid), .has-error *) .gl-select2__icon {
    color: var(--g-field-danger);
}
/* ---------- Dropdown (appended to <body>, scoped by dropdownCssClass) ----------
   `!important` overrides Krajee's theme, while the dropdownCssClass keeps the
   rules from leaking into Select2 instances that do not opt into this skin. */
.select2-container.select2-container--krajee-bs5 .select2-dropdown.gl-select2-dropdown {
    overflow: hidden;
    border: 1px solid var(--g-border) !important;
    border-radius: 10px !important;
    background: var(--g-surface) !important;
    box-shadow: 0 14px 32px -18px rgba(15, 23, 42, .2) !important;
}

.select2-container.select2-container--krajee-bs5 .select2-dropdown--below.gl-select2-dropdown { margin-top: 6px !important; }
.select2-container.select2-container--krajee-bs5 .select2-dropdown--above.gl-select2-dropdown { margin-top: -6px !important; }

[data-guest-theme="dark"] .select2-container.select2-container--krajee-bs5 .select2-dropdown.gl-select2-dropdown {
    box-shadow: 0 14px 32px -18px rgba(0, 0, 0, .5) !important;
}

/* Search */
.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-search--dropdown {
    padding: .55rem .55rem .35rem;
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-search--dropdown .select2-search__field {
    height: 36px !important;
    padding: 0 .75rem 0 2.1rem;
    border: 1px solid var(--g-border) !important;
    border-radius: 8px !important;
    background: var(--g-surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M16 16l4 4'/%3E%3C/svg%3E") .7rem center / 15px no-repeat !important;
    box-shadow: inset 0 0 0 1px transparent, 0 0 0 3px transparent !important;
    color: var(--g-text) !important;
    font-size: .82rem;
    outline: 0;
    transition: border-color .18s var(--g-ease), box-shadow .18s var(--g-ease), background-color .18s var(--g-ease);
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-search--dropdown .select2-search__field:focus {
    border-color: var(--g-accent) !important;
    background-color: var(--g-surface) !important;
    box-shadow: inset 0 0 0 1px var(--g-accent), 0 0 0 3px color-mix(in srgb, var(--g-accent) 14%, transparent) !important;
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-search__field::placeholder {
    color: var(--g-text-faint);
}

/* Mobile: the dropdown search box is a real <input>; at .82rem iOS Safari
   auto-zooms the viewport when it gains focus. Lift it to 16px at the mobile
   breakpoint (matching the native .g-control fix) so opening a guest Select2
   on a phone doesn't zoom the page. Desktop keeps the compact size. */
@media (max-width: 767.98px) {
    .select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-search--dropdown .select2-search__field {
        font-size: 16px;
    }
}

/* Results */
.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results > .select2-results__options {
    max-height: 264px;
    padding: .2rem .35rem .4rem;
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option {
    position: relative;
    margin: 1px 0;
    padding: .55rem 2rem .55rem .7rem;
    border-radius: 7px !important;
    background-color: transparent !important;
    color: var(--g-text) !important;
    font-size: .82rem !important;
    font-weight: 400 !important;
    line-height: 1.4;
    text-transform: none;
    user-select: none;
    -webkit-user-select: none;
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option.select2-results__option--highlighted {
    background-color: var(--g-surface-2) !important;
    color: var(--g-text) !important;
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option.select2-results__option--selected {
    background-color: color-mix(in srgb, var(--g-accent) 9%, var(--g-surface)) !important;
    color: var(--g-accent-strong) !important;
    font-weight: 600 !important;
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option.select2-results__option--selected::after {
    position: absolute;
    top: 50%;
    right: .85rem;
    width: 5px;
    height: 9px;
    margin-top: -6px;
    border: solid var(--g-accent);
    border-width: 0 2px 2px 0;
    content: "";
    transform: rotate(45deg);
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option.select2-results__message,
.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option[aria-disabled=true] {
    background-color: transparent !important;
    color: var(--g-text-faint) !important;
    font-weight: 400 !important;
    text-transform: none !important;
}

.select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option.select2-results__message::after {
    display: none;
}

[data-guest-theme="dark"] .select2-container.select2-container--krajee-bs5 .gl-select2-dropdown .select2-results__option.select2-results__option--selected {
    color: #bfdbfe !important;
}
