.form-control,
.form-control-lg,
.custom-select,
.custom-file-label,
.input-group-text,
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple,
.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-radius: var(--field-radius);
}

.form-control-sm,
.input-group-sm > .form-control,
.input-group-sm > .custom-select,
.input-group-sm > .input-group-prepend > .input-group-text,
.input-group-sm > .input-group-append > .input-group-text {
    border-radius: var(--field-radius-sm);
}

.custom-file-label::after {
    border-radius: 0;
    border-start-start-radius: var(--field-radius);
    border-end-start-radius: var(--field-radius);
}

.input-group-merge .input-group-prepend .input-group-text:first-child,
.input-group-merge .custom-select:not(:first-child),
.input-group-merge .form-control:not(:first-child) {
    border-top-left-radius: var(--field-radius);
    border-bottom-left-radius: var(--field-radius);
}

.input-group-merge .input-group-append .input-group-text:last-child,
.input-group-merge .custom-select:not(:last-child),
.input-group-merge .form-control:not(:last-child) {
    border-top-right-radius: var(--field-radius);
    border-bottom-right-radius: var(--field-radius);
}

/* HSSelect2 renders its selection as `.select2-selection.custom-select` and drops
   select2's own `select2-selection--single`, so every default scoped to that class
   never applies -- including the one that keeps the chosen label on a single line.
   On top of that, style.css:3289 forces `white-space: normal !important` on EVERY
   `.select2-selection__rendered`, which the multi-selects need so their tags wrap.
   A single select inherited it too, so any label wider than its control wrapped to
   two lines and spilled out of a box whose height is fixed -- that is what put
   "All advertisements" half outside its filter on the advertisement list.
   `!important` here only to answer that one.

   `:not(.select2-selection--multiple)` matters: HSSelect2 puts `custom-select` on a
   multi-select's selection too, and there the rendered element is the <ul> of tag
   chips -- those have to keep wrapping.

   `display: block` is the other half. select2 renders the label as an inline span,
   and `overflow` / `text-overflow` do nothing on an inline box, so the text simply
   ran past the 30px the control reserves for its chevron. */
.select2-container--default .select2-selection.custom-select:not(.select2-selection--multiple) .select2-selection__rendered {
    display: block;
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis !important;
}

/* Multi-selects (tax rates, zones, tags…). select2 floats each chip and the type-ahead
   field; the theme then stretched that field wide enough to need a line of its own,
   floated "clear all" into the first row of chips, and centred the custom-select
   chevron on the whole box -- so two choices made a three-line control with a
   chevron halfway down. Flex instead: chips wrap with an even gap, the type-ahead
   takes what is left of the last row, and "clear all" sits beside the chevron.

   `.js-select2-counting` is left alone: it collapses to one row with a "+N" badge
   and style.css lays that out on purpose. The `!important`s answer style.css:14489,
   which paints and pads every `.js-select2-custom` chip with `!important`. */
select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple {
    position: relative;
    display: flex;
    align-items: center;
    height: auto;
    min-height: calc(1.6em + 1.25rem + 2px);
    padding-block: 0.3125rem;
    padding-inline: 0.5rem 4rem;
    cursor: text;
}

select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    width: 100%;
    margin: 0;
    padding: 0;
    list-style: none;
}

select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-selection__choice {
    float: none;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    max-width: 100%;
    margin: 0 !important;
    padding: 0.1875rem 0.375rem 0.1875rem 0.625rem !important;
    border: 1px solid rgba(var(--primary-clr-rgb, 16, 121, 128), 0.18);
    border-radius: 6px;
    background-color: rgba(var(--primary-clr-rgb, 16, 121, 128), 0.08) !important;
    color: var(--title-clr, #334257);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: normal;
}

/* select2 renders the × before the label; `order` moves it to the end, where a
   remove control reads naturally. */
select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
    order: 2;
    position: static;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0 !important;
    border: 0;
    border-radius: 50%;
    background-color: rgba(51, 66, 87, 0.12) !important;
    color: #5b6777 !important;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover {
    background-color: var(--danger-clr, #ff6d6d) !important;
    color: #fff !important;
}

select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-search--inline {
    float: none;
    /* Basis 0 so it only takes the space the chips leave. At rest it may shrink to
       nothing -- any minimum broke the idle field onto a blank row of its own
       whenever the chips filled the line. It claims room only while focused, which
       is when the caret actually needs it. */
    flex: 1 1 0;
    min-width: 0;
}

/* Cancels the row gap before it, which alone was enough to wrap a zero-width field.
   Only after a chip: with nothing chosen there is no gap, and it clipped the placeholder. */
select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-selection__choice + .select2-search--inline {
    margin-inline-start: -0.375rem;
}

select:not(.js-select2-counting) + .select2-container--focus .select2-selection--multiple .select2-search--inline,
select:not(.js-select2-counting) + .select2-container--open .select2-selection--multiple .select2-search--inline {
    min-width: 4rem;
}

select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-search__field {
    width: 100% !important;
    height: 1.625rem;
    min-height: 0;
    margin: 0;
    padding: 0 0.25rem;
    line-height: 1.625rem;
}

select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-selection__clear {
    position: absolute;
    top: 50%;
    inset-inline-end: 2.25rem;
    transform: translateY(-50%);
    float: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    color: #8a94a6;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

select:not(.js-select2-counting) + .select2-container--default .select2-selection--multiple .select2-selection__clear:hover {
    background-color: #f0f2f5;
    color: var(--title-clr, #334257);
}

/* ...and the other half of the same story, for a MULTI-select: its box has to grow with its
   chips instead of holding one row's height.

   `custom.css` already carries this rule, but the vendor panel never loads that file (see the
   stylesheet list in layouts/vendor/app.blade.php), so on every vendor form the box stayed at the
   fixed height `.custom-select` gives it and the tags spilled out underneath -- the tax picker on
   the pharmacy item form with more than one tax chosen, where they covered the field's own label
   (QA Vendor-32).

   Both selectors are needed: HSSelect2 keeps `select2-selection--multiple` but also adds
   `custom-select`, and it is that class Bootstrap pins a height on, so the second selector has to
   outweigh it. The min-height matches a sibling `.form-control` so a field with nothing chosen
   still lines up with Unit, Unit Value and Base Price beside it. */
.select2-container--default .select2-selection--multiple,
.select2-container--default .select2-selection.custom-select.select2-selection--multiple {
    height: auto;
    min-height: 40px;
    padding-bottom: 4px;
}

/* The chips are a <ul>; let it wrap inside the box now that the box can follow it. */
.select2-container--default .select2-selection--multiple .select2-selection__rendered {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    width: 100%;
}

/* Each chip on one line, with its remove button beside the label rather than above it.
   style.css makes that button a 15x15 `display: flex` circle, which is block-level, so in a chip
   that is not itself a flex row it takes a line of its own and the label drops under it. The
   circle is the design and is left alone; the chip around it becomes the flex row.

   `white-space: nowrap` answers style.css forcing `white-space: normal !important` on the
   `__rendered` list -- that is inherited, and a rule set directly on the chip beats inheritance,
   so no `!important` is needed here. Without it a long tax name wraps inside its own chip.

   Four classes deep to match the vendor panel's own `.js-select2-custom + .select2 ...` rule, and
   form-controls.css loads after style.css, so this wins on order rather than on weight. `float`
   goes because the chips are flex items now. */
.select2-container--default .select2-selection--multiple .select2-selection__rendered .select2-selection__choice {
    display: inline-flex;
    align-items: center;
    float: none;
    white-space: nowrap;
}
