/* RTL Support */
html[dir="rtl"] body {
    text-align: right;
    direction: rtl;
}

/* Flip Bootstrap/Utility Spacing */
html[dir="rtl"] .ms-1 { margin-right: 0.25rem !important; margin-left: 0 !important; }
html[dir="rtl"] .ms-2 { margin-right: 0.5rem !important; margin-left: 0 !important; }
html[dir="rtl"] .ms-3 { margin-right: 1rem !important; margin-left: 0 !important; }
html[dir="rtl"] .ms-4 { margin-right: 1.5rem !important; margin-left: 0 !important; }
html[dir="rtl"] .ms-5 { margin-right: 3rem !important; margin-left: 0 !important; }
html[dir="rtl"] .ms-auto { margin-right: auto !important; margin-left: 0 !important; }

html[dir="rtl"] .me-1 { margin-left: 0.25rem !important; margin-right: 0 !important; }
html[dir="rtl"] .me-2 { margin-left: 0.5rem !important; margin-right: 0 !important; }
html[dir="rtl"] .me-3 { margin-left: 1rem !important; margin-right: 0 !important; }
html[dir="rtl"] .me-4 { margin-left: 1.5rem !important; margin-right: 0 !important; }
html[dir="rtl"] .me-5 { margin-left: 3rem !important; margin-right: 0 !important; }
html[dir="rtl"] .me-auto { margin-left: auto !important; margin-right: 0 !important; }

html[dir="rtl"] .ps-1 { padding-right: 0.25rem !important; padding-left: 0 !important; }
html[dir="rtl"] .ps-2 { padding-right: 0.5rem !important; padding-left: 0 !important; }
html[dir="rtl"] .ps-3 { padding-right: 1rem !important; padding-left: 0 !important; }
html[dir="rtl"] .ps-4 { padding-right: 1.5rem !important; padding-left: 0 !important; }
html[dir="rtl"] .ps-5 { padding-right: 3rem !important; padding-left: 0 !important; }

html[dir="rtl"] .pe-1 { padding-left: 0.25rem !important; padding-right: 0 !important; }
html[dir="rtl"] .pe-2 { padding-left: 0.5rem !important; padding-right: 0 !important; }
html[dir="rtl"] .pe-3 { padding-left: 1rem !important; padding-right: 0 !important; }
html[dir="rtl"] .pe-4 { padding-left: 1.5rem !important; padding-right: 0 !important; }
html[dir="rtl"] .pe-5 { padding-left: 3rem !important; padding-right: 0 !important; }

/* Text Alignment */
html[dir="rtl"] .text-start { text-align: right !important; }
html[dir="rtl"] .text-end { text-align: left !important; }

/* Positioning */
html[dir="rtl"] .start-0 { right: 0 !important; left: auto !important; }
html[dir="rtl"] .end-0 { left: 0 !important; right: auto !important; }

/* Float */
html[dir="rtl"] .float-start { float: right !important; }
html[dir="rtl"] .float-end { float: left !important; }

/* Icons */
html[dir="rtl"] .fa-arrow-left:before { content: "\f061"; } /* Arrow right */
html[dir="rtl"] .fa-arrow-right:before { content: "\f060"; } /* Arrow left */
html[dir="rtl"] .fa-chevron-left:before { content: "\f054"; } /* Chevron right */
html[dir="rtl"] .fa-chevron-right:before { content: "\f053"; } /* Chevron left */

html[dir="rtl"] .input-group:not(.has-validation) > .form-control:not(:last-child),
html[dir="rtl"] .input-group:not(.has-validation) > .custom-select:not(:last-child),
html[dir="rtl"] .input-group:not(.has-validation) > .custom-file:not(:last-child) .custom-file-label::after {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: 0.25rem;
    border-bottom-right-radius: 0.25rem;
}

html[dir="rtl"] .input-group > .input-group-append > .btn,
html[dir="rtl"] .input-group > .input-group-append > .input-group-text,
html[dir="rtl"] .input-group > .input-group-prepend:not(:first-child) > .btn,
html[dir="rtl"] .input-group > .input-group-prepend:not(:first-child) > .input-group-text,
html[dir="rtl"] .input-group > .input-group-prepend:first-child > .btn:not(:first-child),
html[dir="rtl"] .input-group > .input-group-prepend:first-child > .input-group-text:not(:first-child) {
    /* border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: 0.25rem;
    border-bottom-left-radius: 0.25rem; */
}

/* Modal Close Button */
html[dir="rtl"] .modal-header .btn-close {
    margin-left: 0;
    margin-right: auto;
}

/* Offcanvas */
html[dir="rtl"] .offcanvas-start {
    right: 0;
    left: auto;
    border-right: 0;
    border-left: 1px solid rgba(0,0,0,.2);
    transform: translateX(100%);
}

html[dir="rtl"] .offcanvas-end {
    left: 0;
    right: auto;
    border-left: 0;
    border-right: 1px solid rgba(0,0,0,.2);
    transform: translateX(-100%);
}

html[dir="rtl"] .offcanvas.show {
    transform: none;
}

/* Custom Classes from style.css that might need flipping */
html[dir="rtl"] .item-title-row .item-media {
    margin-right: 0 !important;
    margin-left: 15px !important;
}

html[dir="rtl"] .dz-stepper .input-group-prepend {
    order: 2;
}
html[dir="rtl"] .dz-stepper .input-group-append {
    order: 0;
}
html[dir="rtl"] .dz-stepper .form-control {
    order: 1;
}

/* Lists */

html[dir="rtl"] .list-unstyled {
    padding-right: 0;
}

/* Form Checks */
html[dir="rtl"] .form-check {
    padding-right: 1.5em;
    padding-left: 0;
}

html[dir="rtl"] .form-check .form-check-input {
    float: right;
    margin-right: -1.5em;
    margin-left: 0;
}

/* Input Groups with Append/Prepend */
html[dir="rtl"] .input-group .input-group-text {
    border-radius: 0.25rem; /* Reset */
}

/* --- Form Check & Radios --- */
.form-check {
    padding-left: 0;
    padding-right: 1.5em; /* Swapped from padding-left */
}

.form-check .form-check-input {
    float: right; /* Swapped from left */
    margin-right: -1.5em; /* Swapped from margin-left */
    margin-left: 0;
}

/* Reverse the "Reverse" logic for RTL context */
.form-check-reverse {
    padding-left: 1.5em; /* Swapped from padding-right */
    padding-right: 0;
    text-align: left; /* Swapped from right */
}

.form-check-reverse .form-check-input {
    float: left; /* Swapped from right */
    margin-left: -1.5em; /* Swapped from margin-right */
    margin-right: 0;
}

/* --- Switches --- */
.form-switch {
    padding-left: 0;
    padding-right: 2.5em; /* Swapped from padding-left */
}

.form-switch .form-check-input {
    margin-right: -2.5em; /* Swapped from margin-left */
    margin-left: 0;
    background-position: right center; /* Swapped from left center */
}

.form-switch .form-check-input:checked {
    background-position: left center; /* Swapped from right center */
}

.form-switch.form-check-reverse {
    padding-left: 2.5em; /* Swapped from padding-right */
    padding-right: 0;
}

.form-switch.form-check-reverse .form-check-input {
    margin-left: -2.5em; /* Swapped from margin-right */
    margin-right: 0;
}

/* --- Inline Forms --- */
.form-check-inline {
    margin-right: 0;
    margin-left: 1rem; /* Swapped from margin-right */
}

/* --- Floating Labels --- */
.form-floating::before:not(.form-control:disabled) {
    left: auto;
    right: var(--bs-border-width); /* Swapped from left */
}

.form-floating > label {
    left: auto;
    right: 0; /* Swapped from left */
    transform-origin: 100% 0; /* Swapped from 0 0 */
}

/* Adjust label transform for floating state */
.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label,
.form-floating > .form-control-plaintext ~ label,
.form-floating > .form-select ~ label {
    /* translateX(0.15rem) becomes -0.15rem for RTL */
    transform: scale(0.85) translateY(-0.5rem) translateX(-0.15rem);
}

.form-floating > .form-control:-webkit-autofill ~ label {
    transform: scale(0.85) translateY(-0.5rem) translateX(-0.15rem);
}

/* --- Input Groups --- */
.input-group-lg > .form-select,
.input-group-sm > .form-select {
  padding-left: 3rem; /* Swapped from padding-right */
  padding-right: 0.75rem;
}

/* Rounded corners for items in the middle or end of the group */
.input-group:not(.has-validation) > :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating),
.input-group:not(.has-validation) > .dropdown-toggle:nth-last-child(n + 3),
.input-group:not(.has-validation) > .form-floating:not(:last-child) > .form-control,
.input-group:not(.has-validation) > .form-floating:not(:last-child) > .form-select {
  border-top-left-radius: 0; /* Swapped from right */
  border-bottom-left-radius: 0; /* Swapped from right */
  border-top-right-radius: 0.375rem;
  border-bottom-right-radius: 0.375rem;
}

.input-group.has-validation > :nth-last-child(n + 3):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating),
.input-group.has-validation > .dropdown-toggle:nth-last-child(n + 4),
.input-group.has-validation > .form-floating:nth-last-child(n + 3) > .form-control,
.input-group.has-validation > .form-floating:nth-last-child(n + 3) > .form-select {
  border-top-left-radius: 0; /* Swapped from right */
  border-bottom-left-radius: 0; /* Swapped from right */
}

/* Handling the "not first-child" items (now on the left side in RTL) */
.input-group > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
  margin-right: calc(var(--bs-border-width) * -1); /* Swapped from margin-left */
  margin-left: 0;
  border-top-right-radius: 0; /* Swapped from left */
  border-bottom-right-radius: 0; /* Swapped from left */
}

.input-group > .form-floating:not(:first-child) > .form-control,
.input-group > .form-floating:not(:first-child) > .form-select {
  border-top-right-radius: 0; /* Swapped from left */
  border-bottom-right-radius: 0; /* Swapped from left */
}

/* --- Validation States (Success & Danger) --- */

/* Control icons (Checkmark / Exclamation) */
.was-validated .form-control:valid, .form-control.is-valid,
.was-validated .form-control:invalid, .form-control.is-invalid {
  padding-left: calc(1.6em + 0.75rem); /* Swapped from padding-right */
  padding-right: 0.75rem;
  background-position: left calc(0.4em + 0.1875rem) center; /* Swapped from right */
}

.was-validated textarea.form-control:valid, textarea.form-control.is-valid,
.was-validated textarea.form-control:invalid, textarea.form-control.is-invalid {
  padding-left: calc(1.6em + 0.75rem); /* Swapped from padding-right */
  background-position: top calc(0.4em + 0.1875rem) left calc(0.4em + 0.1875rem); /* Swapped from right */
}

/* Select Box Validation */
.was-validated .form-select:valid:not([multiple]):not([size]),
.was-validated .form-select:valid:not([multiple])[size="1"],
.form-select.is-valid:not([multiple]):not([size]),
.form-select.is-valid:not([multiple])[size="1"],
.was-validated .form-select:invalid:not([multiple]):not([size]),
.was-validated .form-select:invalid:not([multiple])[size="1"],
.form-select.is-invalid:not([multiple]):not([size]),
.form-select.is-invalid:not([multiple])[size="1"] {
  padding-left: 4.125rem; /* Swapped from padding-right */
  padding-right: 0.75rem;
  /* Swapped background positions for both the arrow and the validation icon */
  background-position: left 0.75rem center, center left 2.25rem;
}

/* Inline Checkbox Feedback */
.form-check-inline .form-check-input ~ .valid-feedback,
.form-check-inline .form-check-input ~ .invalid-feedback {
  margin-right: .5em; /* Swapped from margin-left */
  margin-left: 0;
}
