/* ============================================================================
   Bootstrap 4 compatibility layer for Bootstrap 5
   Re-adds the Bootstrap 4 classes that were removed/renamed in Bootstrap 5
   and are still used by this project's templates. Rule bodies are ported
   from the old customized Bootstrap 4.5.2 build (old-bootstrap.min.css) so
   the visuals match the previous version exactly.
   Load AFTER bootstrap.min.css.
   ============================================================================ */

/* --- Spacing utilities (BS4 physical directions; BS5 uses ms-* / me-* etc.) -- */

.ml-0 { margin-left: 0 !important; }
.ml-1 { margin-left: 0.25rem !important; }
.ml-2 { margin-left: 0.5rem !important; }
.ml-3 { margin-left: 1rem !important; }
.ml-4 { margin-left: 1.5rem !important; }
.ml-5 { margin-left: 3rem !important; }
.ml-auto { margin-left: auto !important; }

.mr-0 { margin-right: 0 !important; }
.mr-1 { margin-right: 0.25rem !important; }
.mr-2 { margin-right: 0.5rem !important; }
.mr-3 { margin-right: 1rem !important; }
.mr-4 { margin-right: 1.5rem !important; }
.mr-5 { margin-right: 3rem !important; }
.mr-auto { margin-right: auto !important; }

.pl-0 { padding-left: 0 !important; }
.pl-1 { padding-left: 0.25rem !important; }
.pl-2 { padding-left: 0.5rem !important; }
.pl-3 { padding-left: 1rem !important; }
.pl-4 { padding-left: 1.5rem !important; }
.pl-5 { padding-left: 3rem !important; }

.pr-0 { padding-right: 0 !important; }
.pr-1 { padding-right: 0.25rem !important; }
.pr-2 { padding-right: 0.5rem !important; }
.pr-3 { padding-right: 1rem !important; }
.pr-4 { padding-right: 1.5rem !important; }
.pr-5 { padding-right: 3rem !important; }

@media (min-width: 576px) {
    .mr-sm-0 { margin-right: 0 !important; }
    .mr-sm-1 { margin-right: 0.25rem !important; }
    .mr-sm-2 { margin-right: 0.5rem !important; }
    .mr-sm-3 { margin-right: 1rem !important; }
    .mr-sm-4 { margin-right: 1.5rem !important; }
    .mr-sm-5 { margin-right: 3rem !important; }
    .mr-sm-auto { margin-right: auto !important; }
    .ml-sm-0 { margin-left: 0 !important; }
    .ml-sm-1 { margin-left: 0.25rem !important; }
    .ml-sm-2 { margin-left: 0.5rem !important; }
    .ml-sm-3 { margin-left: 1rem !important; }
    .ml-sm-4 { margin-left: 1.5rem !important; }
    .ml-sm-5 { margin-left: 3rem !important; }
    .ml-sm-auto { margin-left: auto !important; }
}

/* --- Text alignment / floats (BS5 renamed to *-start / *-end) -------------- */

.text-left { text-align: left !important; }
.text-right { text-align: right !important; }

.float-left { float: left !important; }
.float-right { float: right !important; }
.float-none { float: none !important; }

/* --- Borders (BS5 renamed to border-start / border-end) --------------------- */

.border-left { border-left: 1px solid #dee2e6 !important; }
.border-right { border-right: 1px solid #dee2e6 !important; }
.border-left-0 { border-left: 0 !important; }
.border-right-0 { border-right: 0 !important; }

/* --- Rounded (BS5 renamed rounded-sm/lg to rounded-1/3) --------------------- */

.rounded-sm { border-radius: 0.2rem !important; }
.rounded-lg { border-radius: 0.3rem !important; }

/* --- Screen readers (BS5 renamed to visually-hidden) ------------------------ */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only-focusable:active,
.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* --- Forms: form-group / form-row (removed in BS5) -------------------------- */

.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    margin-right: -5px;
    margin-left: -5px;
}

.form-row>.col,
.form-row>[class*="col-"] {
    padding-right: 8px;
    padding-left: 8px;
}

/* --- Custom controls (checkbox / radio / switch) — full BS4 port ------------ */

.custom-control {
    position: relative;
    z-index: 1;
    display: block;
    min-height: 1.5rem;
    padding-left: 1.5rem;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.custom-control-inline {
    display: -ms-inline-flexbox;
    display: inline-flex;
    margin-right: 1rem;
}

.custom-control-input {
    position: absolute;
    left: 0;
    z-index: -1;
    width: 1rem;
    height: 1.25rem;
    opacity: 0;
}

.custom-control-input:checked~.custom-control-label::before {
    color: #fff;
    border-color: var(--app-theme-color);
    background-color: var(--app-theme-color);
}

.custom-control-input:focus~.custom-control-label::before {
    box-shadow: 0 0 0 0.2rem rgb(103 58 183 / 36%);
}

.custom-control-input:focus:not(:checked)~.custom-control-label::before {
    border-color: var(--app-theme-color);
}

.custom-control-input:not(:disabled):active~.custom-control-label::before {
    color: #fff;
    background-color: var(--app-theme-color);
    border-color: var(--app-theme-color);
}

.custom-control-input[disabled]~.custom-control-label,
.custom-control-input:disabled~.custom-control-label {
    color: #5a7684;
}

.custom-control-input[disabled]~.custom-control-label::before,
.custom-control-input:disabled~.custom-control-label::before {
    background-color: #e9ecef;
}

.custom-control-label {
    position: relative;
    margin-bottom: 0;
    vertical-align: top;
}

.custom-control-label::before {
    position: absolute;
    top: 0.25rem;
    left: -1.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    pointer-events: none;
    content: "";
    background-color: #fff;
    border: #adb5bd solid 1px;
}

.custom-control-label::after {
    position: absolute;
    top: 0.25rem;
    left: -1.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    content: "";
    background: no-repeat 50% / 50% 50%;
}

.custom-checkbox .custom-control-label::before {
    border-radius: 0.25rem;
}

.custom-checkbox .custom-control-input:checked~.custom-control-label::after {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/%3e%3c/svg%3e");
}

.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before {
    border-color: var(--app-theme-color);
    background-color: var(--app-theme-color);
}

.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::after {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3e%3cpath stroke='%23fff' d='M0 2h4'/%3e%3c/svg%3e");
}

.custom-checkbox .custom-control-input:disabled:checked~.custom-control-label::before,
.custom-checkbox .custom-control-input:disabled:indeterminate~.custom-control-label::before {
    background-color: rgba(72, 43, 217, 0.5);
}

.custom-radio .custom-control-label::before {
    border-radius: 50%;
}

.custom-radio .custom-control-input:checked~.custom-control-label::after {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
}

.custom-radio .custom-control-input:disabled:checked~.custom-control-label::before {
    background-color: rgba(72, 43, 217, 0.5);
}

.custom-switch {
    padding-left: 2.25rem;
}

.custom-switch .custom-control-label::before {
    left: -2.25rem;
    width: 1.75rem;
    pointer-events: all;
    border-radius: 0.5rem;
}

.custom-switch .custom-control-label::after {
    top: calc(0.25rem + 2px);
    left: calc(-2.25rem + 2px);
    width: calc(1rem - 4px);
    height: calc(1rem - 4px);
    background-color: #adb5bd;
    border-radius: 0.5rem;
    transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
    .custom-switch .custom-control-label::after {
        transition: none;
    }
}

.custom-switch .custom-control-input:checked~.custom-control-label::after {
    background-color: #fff;
    -webkit-transform: translateX(0.75rem);
    transform: translateX(0.75rem);
}

.custom-switch .custom-control-input:disabled:checked~.custom-control-label::before {
    background-color: rgba(72, 43, 217, 0.5);
}

/* --- Custom select (removed in BS5, replaced by .form-select) --------------- */

.custom-select {
    display: inline-block;
    width: 100%;
    height: calc(1.5em + 0.75rem + 2px);
    padding: 0.375rem 1.75rem 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    vertical-align: middle;
    background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='%23343a40' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") no-repeat right 0.75rem center/8px 10px;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.custom-select:focus {
    border-color: var(--app-theme-color);
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(72, 43, 217, 0.25);
}

.custom-select[multiple],
.custom-select[size]:not([size="1"]) {
    height: auto;
    padding-right: 0.75rem;
    background-image: none;
}

.custom-select:disabled {
    color: #5a7684;
    background-color: #e9ecef;
}

.custom-select::-ms-expand {
    display: none;
}

.custom-select-sm {
    height: calc(1.5em + 0.5rem + 2px);
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
    padding-left: 0.5rem;
    font-size: 0.875rem;
}

.custom-select-lg {
    height: calc(1.5em + 1rem + 2px);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    padding-left: 1rem;
    font-size: 1.25rem;
}

/* --- Custom file input (removed in BS5) ------------------------------------- */

.custom-file {
    position: relative;
    display: inline-block;
    width: 100%;
    height: calc(1.5em + 0.75rem + 2px);
    margin-bottom: 0;
}

.custom-file-input {
    position: relative;
    z-index: 2;
    width: 100%;
    height: calc(1.5em + 0.75rem + 2px);
    margin: 0;
    opacity: 0;
}

.custom-file-input:focus~.custom-file-label {
    border-color: var(--app-theme-color);
    box-shadow: 0 0 0 0.2rem rgba(72, 43, 217, 0.25);
}

.custom-file-input[disabled]~.custom-file-label,
.custom-file-input:disabled~.custom-file-label {
    background-color: #e9ecef;
}

.custom-file-input:lang(en)~.custom-file-label::after {
    content: "Browse";
}

.custom-file-input~.custom-file-label[data-browse]::after {
    content: attr(data-browse);
}

.custom-file-label {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    z-index: 1;
    height: calc(1.5em + 0.75rem + 2px);
    padding: 0.375rem 0.75rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
}

.custom-file-label::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: block;
    height: calc(1.5em + 0.75rem);
    padding: 0.375rem 0.75rem;
    line-height: 1.5;
    color: #495057;
    content: "Browse";
    background-color: #e9ecef;
    border-left: inherit;
    border-radius: 0 0.25rem 0.25rem 0;
}

/* --- Input group prepend/append (removed in BS5) ----------------------------- */

.input-group-prepend,
.input-group-append {
    display: -ms-flexbox;
    display: flex;
}

.input-group-prepend .btn,
.input-group-append .btn {
    position: relative;
    z-index: 2;
}

.input-group-prepend .btn:focus,
.input-group-append .btn:focus {
    z-index: 3;
}

.input-group-prepend .btn+.btn,
.input-group-prepend .btn+.input-group-text,
.input-group-prepend .input-group-text+.input-group-text,
.input-group-prepend .input-group-text+.btn,
.input-group-append .btn+.btn,
.input-group-append .btn+.input-group-text,
.input-group-append .input-group-text+.input-group-text,
.input-group-append .input-group-text+.btn {
    margin-left: -1px;
}

.input-group-prepend {
    margin-right: -1px;
}

.input-group-append {
    margin-left: -1px;
}

/* Border-radius fixes so wrapped input-group-text/.btn join the input cleanly */
.input-group-prepend>.btn,
.input-group-prepend>.input-group-text,
.input-group-append:not(:last-child)>.btn,
.input-group-append:not(:last-child)>.input-group-text {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-append>.btn,
.input-group-append>.input-group-text,
.input-group-prepend:not(:first-child)>.btn,
.input-group-prepend:not(:first-child)>.input-group-text {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.input-group>.form-control:not(:last-child),
.input-group>.custom-select:not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

/* The old build had the left-corner squaring rule commented out, so inputs
   kept their rounded left corners even inside .input-group. Bootstrap 5
   squares every non-first child, so restore the rounded corners. */
.input-group>.form-control,
.input-group>.form-select,
.input-group>.custom-select {
    border-top-left-radius: 6px !important;
    border-bottom-left-radius: 6px !important;
}

/* ...except inputs joined to an .input-group-prepend addon: keep the classic
   squared join so icon and input touch cleanly (standalone and has-search
   inputs stay rounded). */
.input-group>.input-group-prepend+.form-control,
.input-group>.input-group-prepend+.form-select,
.input-group>.input-group-prepend+.custom-select {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

/* Search bars with the floating feedback icon: the search button is visually
   detached (ml-3), so the input is rounded on all sides as in the old UI. */
.has-search.input-group>.form-control {
    border-radius: 6px !important;
}

/* The old build had the focus z-index rule commented out, so the focused
   input never covered the .form-control-feedback search icon (z-index 2).
   Bootstrap 5 raises focused controls to z-index 5 — reset it. */
.input-group>.form-control:focus,
.input-group>.form-select:focus,
.input-group>.custom-select:focus {
    z-index: 0;
}

/* Bootstrap 4 only squared the corners of form controls inside .input-group;
   Bootstrap 5 squares EVERY direct child, including buttons. Restore the
   fully rounded corners buttons had in the old build (e.g. search buttons). */
.input-group>button,
.input-group>.btn,
.input-group>input[type="button"],
.input-group>input[type="submit"] {
    border-radius: 3px !important;
}

.input-group>[class*="-btn"],
.input-group>a[class*="btn"] {
    border-radius: 0.25rem !important;
}

/* --- Close button (BS5 uses .btn-close with an SVG icon) --------------------- */

.close {
    float: right;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    color: #000;
    text-shadow: 0 1px 0 #fff;
    opacity: .5;
}

.close:hover {
    color: #000;
    text-decoration: none;
}

.close:not(:disabled):not(.disabled):hover,
.close:not(:disabled):not(.disabled):focus {
    opacity: .75;
}

button.close {
    padding: 0;
    background-color: transparent;
    border: 0;
}

a.close.disabled {
    pointer-events: none;
}

.modal-header .close {
    padding: 1rem 1rem;
    margin: -1rem -1rem -1rem auto;
}

/* --- Media object (removed in BS5) ------------------------------------------- */

.media {
    display: -ms-flexbox;
    display: flex;
    -ms-flex-align: start;
    align-items: flex-start;
}

.media-body {
    -ms-flex: 1;
    flex: 1;
}

/* --- No gutters (BS5 uses .g-0) ---------------------------------------------- */

.no-gutters {
    margin-right: 0;
    margin-left: 0;
}

.no-gutters>.col,
.no-gutters>[class*="col-"] {
    padding-right: 0;
    padding-left: 0;
}

/* Bootstrap 4 only applied widths/padding to .col-* children of .row; any
   other direct child simply shrink-wrapped to its content. Bootstrap 5
   forces width:100% on EVERY direct child (.row > *), which pushes inline
   items placed directly inside .row (e.g. separator icons between two
   inputs) onto their own line. Restore the Bootstrap 4 behavior. */
.row> :not([class*="col-"]):not(.col) {
    flex-shrink: 1;
    width: auto;
    padding-right: 0;
    padding-left: 0;
}

/* --- Block button (removed in BS5) ------------------------------------------- */

.btn-block {
    display: block;
    width: 100%;
}

.btn-block+.btn-block {
    margin-top: 0.5rem;
}

/* --- Dropdown menu right alignment (BS5 uses dropdown-menu-end) -------------- */

.dropdown-menu-right {
    right: 0;
    left: auto;
}

/* --- Badges (BS5 uses bg-* utilities; BS4 had badge-* color classes) --------- */

.badge {
    padding: 0.25em 0.4em;
    font-size: 75%;
    font-weight: 700;
    line-height: 1;
    border-radius: 0.25rem;
}

.badge-pill {
    padding-right: 0.6em;
    padding-left: 0.6em;
    border-radius: 10rem;
}

.badge-primary {
    color: #fff;
    background-color: var(--app-theme-color);
}

a.badge-primary:hover,
a.badge-primary:focus {
    color: #fff;
    background-color: var(--app-theme-color);
}

.badge-secondary {
    color: #fff;
    background-color: #5a7684;
}

a.badge-secondary:hover,
a.badge-secondary:focus {
    color: #fff;
    background-color: #5a7684;
}

.badge-success {
    color: #fff;
    background-color: #32ab13;
}

a.badge-success:hover,
a.badge-success:focus {
    color: #fff;
    background-color: #2c9610;
}

.badge-info {
    color: #fff;
    background-color: #198fed;
}

a.badge-info:hover,
a.badge-info:focus {
    color: #fff;
    background-color: #127fd6;
}

.badge-warning {
    color: #212529;
    background-color: #ffc107;
}

a.badge-warning:hover,
a.badge-warning:focus {
    color: #212529;
    background-color: #e0a800;
}

.badge-danger {
    color: #fff;
    background-color: #f02769;
}

a.badge-danger:hover,
a.badge-danger:focus {
    color: #fff;
    background-color: #f02769;
}

.badge-light {
    color: #212529;
    background-color: #f8f9fa;
}

a.badge-light:hover,
a.badge-light:focus {
    color: #212529;
    background-color: #dae0e5;
}

.badge-dark {
    color: #fff;
    background-color: #343a40;
}

a.badge-dark:hover,
a.badge-dark:focus {
    color: #fff;
    background-color: #1d2124;
}

/* --- Card deck (removed in BS5) ---------------------------------------------- */

.card-deck .card {
    margin-bottom: 15px;
}

@media (min-width: 576px) {
    .card-deck {
        display: -ms-flexbox;
        display: flex;
        -ms-flex-flow: row wrap;
        flex-flow: row wrap;
        margin-right: -15px;
        margin-left: -15px;
    }

    .card-deck .card {
        -ms-flex: 1 0 0%;
        flex: 1 0 0%;
        margin-right: 15px;
        margin-bottom: 0;
        margin-left: 15px;
    }
}
