/* =====================================================================
   shared_static/css/locale/direction.css      (replaces locale_styles.css + the generated rtl_containers.css)

   SINGLE SOURCE OF TRUTH:  <html lang="fa" dir="rtl">  /  <html lang="en" dir="ltr">  printed by the server
   (shared/utils/translate/locale_context.py -> templates use {{ lang }} / {{ lang_dir }}).
   Nothing here depends on a container id, on body classes, or on JavaScript: the whole document is RTL or LTR,
   Bootstrap's popper/tooltips/dropdowns read the same attribute, and everything below only fixes what an LTR-only
   Bootstrap 5.3 build gets wrong when <html dir="rtl">.

   RULES FOR NEW CSS
     * write logical properties (margin-inline-start, padding-inline-end, inset-inline-start, border-inline-end,
       text-align: start|end, float: inline-start) - they need NO rule in this file;
     * a physical left/right is only acceptable for things that never mirror (a video timeline, a map);
     * values that must stay left-to-right inside Persian text (e-mail, URL, phone, IBAN/Sheba, codes, English company
       names like "Ar...") get class="ltr-value" or dir="ltr" - never a global direction override.
   ===================================================================== */

/* ---- document defaults -------------------------------------------------- */
html[dir="rtl"] body { text-align: start; }

/* ---- bidi isolation for values that must stay LTR ------------------------- */
.ltr-value, bdi.ltr-value, code, kbd, samp, pre,
input[type="email"], input[type="url"], input[type="tel"],
[data-ltr="true"] {
    direction: ltr;
    unicode-bidi: isolate;
    text-align: start;            /* start of an LTR run = the left edge, even inside an RTL page */
}
input[type="email"], input[type="url"], input[type="tel"] { unicode-bidi: plaintext; }
.rtl-value { direction: rtl; unicode-bidi: isolate; text-align: start; }

/* ---- Bootstrap physical utilities, mirrored for RTL ----------------------- */

html[dir="rtl"] .ms-0 { margin-left: 0 !important; margin-right: 0 !important; }
html[dir="rtl"] .me-0 { margin-left: 0 !important; margin-right: 0 !important; }
html[dir="rtl"] .ps-0 { padding-left: 0 !important; padding-right: 0 !important; }
html[dir="rtl"] .pe-0 { padding-left: 0 !important; padding-right: 0 !important; }
html[dir="rtl"] .ms-1 { margin-left: 0 !important; margin-right: .25rem !important; }
html[dir="rtl"] .me-1 { margin-right: 0 !important; margin-left: .25rem !important; }
html[dir="rtl"] .ps-1 { padding-left: 0 !important; padding-right: .25rem !important; }
html[dir="rtl"] .pe-1 { padding-right: 0 !important; padding-left: .25rem !important; }
html[dir="rtl"] .ms-2 { margin-left: 0 !important; margin-right: .5rem !important; }
html[dir="rtl"] .me-2 { margin-right: 0 !important; margin-left: .5rem !important; }
html[dir="rtl"] .ps-2 { padding-left: 0 !important; padding-right: .5rem !important; }
html[dir="rtl"] .pe-2 { padding-right: 0 !important; padding-left: .5rem !important; }
html[dir="rtl"] .ms-3 { margin-left: 0 !important; margin-right: 1rem !important; }
html[dir="rtl"] .me-3 { margin-right: 0 !important; margin-left: 1rem !important; }
html[dir="rtl"] .ps-3 { padding-left: 0 !important; padding-right: 1rem !important; }
html[dir="rtl"] .pe-3 { padding-right: 0 !important; padding-left: 1rem !important; }
html[dir="rtl"] .ms-4 { margin-left: 0 !important; margin-right: 1.5rem !important; }
html[dir="rtl"] .me-4 { margin-right: 0 !important; margin-left: 1.5rem !important; }
html[dir="rtl"] .ps-4 { padding-left: 0 !important; padding-right: 1.5rem !important; }
html[dir="rtl"] .pe-4 { padding-right: 0 !important; padding-left: 1.5rem !important; }
html[dir="rtl"] .ms-5 { margin-left: 0 !important; margin-right: 3rem !important; }
html[dir="rtl"] .me-5 { margin-right: 0 !important; margin-left: 3rem !important; }
html[dir="rtl"] .ps-5 { padding-left: 0 !important; padding-right: 3rem !important; }
html[dir="rtl"] .pe-5 { padding-right: 0 !important; padding-left: 3rem !important; }
html[dir="rtl"] .ms-auto { margin-left: 0 !important; margin-right: auto !important; }
html[dir="rtl"] .me-auto { margin-right: 0 !important; margin-left: auto !important; }

html[dir="rtl"] .text-start { text-align: right !important; }
html[dir="rtl"] .text-end   { text-align: left !important; }
html[dir="rtl"] .float-start { float: right !important; }
html[dir="rtl"] .float-end   { float: left !important; }
html[dir="rtl"] .border-start { border-right: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color) !important; border-left: 0 !important; }
html[dir="rtl"] .border-end   { border-left: var(--bs-border-width) var(--bs-border-style) var(--bs-border-color) !important; border-right: 0 !important; }
html[dir="rtl"] .start-0 { right: 0 !important; left: auto !important; }
html[dir="rtl"] .end-0   { left: 0 !important; right: auto !important; }
html[dir="rtl"] .start-50  { right: 50% !important;  left: auto !important; }
html[dir="rtl"] .start-100 { right: 100% !important; left: auto !important; }
html[dir="rtl"] .end-50    { left: 50% !important;   right: auto !important; }
html[dir="rtl"] .end-100   { left: 100% !important;  right: auto !important; }
html[dir="rtl"] .translate-middle   { transform: translate(50%, -50%) !important; }
html[dir="rtl"] .translate-middle-x { transform: translateX(50%) !important; }
html[dir="rtl"] .rounded-start { border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0 !important; }
html[dir="rtl"] .rounded-end   { border-radius: var(--bs-border-radius) 0 0 var(--bs-border-radius) !important; }

/* ---- Bootstrap components ------------------------------------------------- */
html[dir="rtl"] .form-check { padding-left: 0; padding-right: 1.5em; }
html[dir="rtl"] .form-check .form-check-input { float: right; margin-left: 0; margin-right: -1.5em; }
html[dir="rtl"] .form-switch { padding-left: 0; padding-right: 2.5em; }
html[dir="rtl"] .form-switch .form-check-input { margin-right: -2.5em; margin-left: 0; }
html[dir="rtl"] .form-select { padding-left: 2.25rem; padding-right: .75rem; background-position: left .75rem center; }
html[dir="rtl"] .btn-close { margin: calc(-.5 * var(--bs-modal-header-padding-y)) auto calc(-.5 * var(--bs-modal-header-padding-y)) calc(-.5 * var(--bs-modal-header-padding-x)); }
html[dir="rtl"] .alert-dismissible { padding-right: 1rem; padding-left: 3rem; }
html[dir="rtl"] .alert-dismissible .btn-close { right: auto; left: 0; }
html[dir="rtl"] .modal-header .btn-close { margin-right: auto; margin-left: calc(-.5 * var(--bs-modal-header-padding-x)); }
html[dir="rtl"] .dropdown-menu { text-align: right; }
html[dir="rtl"] .dropdown-toggle::after { margin-left: 0; margin-right: .255em; }
/* ---- Breadcrumb --------------------------------------------------------- */

.breadcrumb {
    flex-wrap: wrap;
    row-gap: .25rem;
}

.breadcrumb-item {
    min-width: 0;
    overflow-wrap: anywhere;
}

.breadcrumb-item + .breadcrumb-item {
    padding-left: 0;
    padding-inline-start: var(--bs-breadcrumb-item-padding-x);
}

.breadcrumb-item + .breadcrumb-item::before {
    content: ">" !important;
    display: inline-block;
    float: none;
    direction: ltr;
    unicode-bidi: isolate;
    padding: 0 0.4rem;
    color: #6c757d;
}

html[dir="rtl"] .breadcrumb-item + .breadcrumb-item::before {
    content: "<" !important;
}
html[dir="rtl"] .pagination .page-item:not(:first-child) .page-link { margin-left: 0; margin-right: calc(-1 * var(--bs-border-width)); }
html[dir="rtl"] .list-unstyled, html[dir="rtl"] .list-inline { padding-right: 0; }
html[dir="rtl"] ul, html[dir="rtl"] ol { padding-left: 0;}
html[dir="rtl"] .nav, html[dir="rtl"] .navbar-nav, html[dir="rtl"] .list-group, html[dir="rtl"] .pagination { padding-right: 0; }
html[dir="rtl"] .input-group > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-left: 0; margin-right: calc(-1 * var(--bs-border-width));
}
html[dir="rtl"] .input-group:not(.has-validation) > :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating),
html[dir="rtl"] .input-group:not(.has-validation) > .dropdown-toggle:nth-last-child(n+3) {
    border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
}
html[dir="rtl"] .input-group > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    border-radius: var(--bs-border-radius) 0 0 var(--bs-border-radius);
}
html[dir="rtl"] .form-control.is-invalid, html[dir="rtl"] .form-control.is-valid { padding-right: .75rem; padding-left: calc(1.5em + .75rem); background-position: left calc(.375em + .1875rem) center; }
html[dir="rtl"] .table > :not(caption) > * > :not(th) { text-align: inherit; }

/* ---- table headers: centered by default ------------------------------------------------------------------
   Column headers are centered in EVERY table, in RTL and in LTR alike (center has no direction, so no per-direction rule
   is needed). This is only a default: any class-based rule or utility (.text-start, .text-end, a module's own
   `.x th { text-align: ... }`) still overrides it for a specific table/column. `table th` is deliberately two
   elements wide so it also beats Bootstrap reboot's `th { text-align: inherit }` regardless of stylesheet order. */
table th,
table thead td {
    text-align: center;
}

/* ---- third-party widgets -------------------------------------------------- */
html[dir="rtl"] .select2-container[dir="rtl"] .select2-selection--single .select2-selection__rendered { padding-right: 8px; padding-left: 20px; text-align: right; }
html[dir="rtl"] .select2-container--default .select2-selection--single .select2-selection__arrow { right: auto; left: 1px; }
html[dir="rtl"] .select2-results__option { text-align: right; }
html[dir="rtl"] .swal2-popup { direction: rtl; }
html[dir="rtl"] .swal2-actions { flex-direction: row-reverse; }
html[dir="rtl"] .flatpickr-calendar, html[dir="rtl"] .datepicker-plot-area { direction: rtl; }
/* maps never mirror (tiles, markers, controls keep their geography) */
.leaflet-container, .leaflet-container * { direction: ltr; }
.leaflet-container .leaflet-popup-content { direction: inherit; }

/* ---- dropdown menus: logical anchoring --------------------------------------------------------------------
   Inside .navbar, Bootstrap 5.3.3 never runs Popper (Dropdown._detectNavbar -> data-bs-popper="static"): menus are placed by
   CSS alone and the LTR build anchors them with a physical "left: 0" - in RTL that sends the menu of an element at the right
   edge off-screen. Anchor to the inline START instead: identical to Bootstrap in LTR, mirrored in RTL.
   dropend/dropstart are logical here (end = the side text flows toward). Collisions with the viewport are corrected by
   js/utils/dropdownViewportGuard.js, which adds .dropdown-menu-flipped or shifts the menu. */
.dropdown-menu[data-bs-popper]     { inset-inline-start: 0; inset-inline-end: auto; }
.dropdown-menu-end[data-bs-popper] { inset-inline-start: auto; inset-inline-end: 0; }
.dropend > .dropdown-menu[data-bs-popper]   { inset-inline-start: 100%; inset-inline-end: auto; margin-inline-start: var(--bs-dropdown-spacer); margin-inline-end: 0; }
.dropstart > .dropdown-menu[data-bs-popper] { inset-inline-start: auto; inset-inline-end: 100%; margin-inline-start: 0; margin-inline-end: var(--bs-dropdown-spacer); }
.dropdown-menu-flipped[data-bs-popper]      { inset-inline-start: auto; inset-inline-end: 0; }
.dropend > .dropdown-menu-flipped[data-bs-popper]   { inset-inline-start: auto; inset-inline-end: 100%; margin-inline-start: 0; margin-inline-end: var(--bs-dropdown-spacer); }
.dropstart > .dropdown-menu-flipped[data-bs-popper] { inset-inline-start: 100%; inset-inline-end: auto; margin-inline-start: var(--bs-dropdown-spacer); margin-inline-end: 0; }
html[dir="rtl"] .dropend .dropdown-toggle::after   { border-left: 0; border-right: .3em solid; }
html[dir="rtl"] .dropstart .dropdown-toggle::before { border-right: 0; border-left: .3em solid; }

/* A glyph whose meaning is directional (a chevron, an arrow) mirrors; a settings/user/logo icon never does. */
html[dir="rtl"] .rtl-mirror { display: inline-block; transform: scaleX(-1); }

/* ---- Font Awesome direction arrows flip with the text -------------------------------------------- */
/* Directional Font Awesome glyphs (chevrons, carets, arrows) point along the reading direction; opt-in helper: .fa-flip-rtl.
   Exception: the wizard Back/Next row never mirrors (see the next section). */
html[dir="rtl"] .fa-flip-rtl,
html[dir="rtl"] .fa-arrow-left,  html[dir="rtl"] .fa-arrow-right,
html[dir="rtl"] .fa-chevron-left, html[dir="rtl"] .fa-chevron-right,
html[dir="rtl"] .fa-angle-left,  html[dir="rtl"] .fa-angle-right,
html[dir="rtl"] .fa-angle-double-left, html[dir="rtl"] .fa-angle-double-right,
html[dir="rtl"] .fa-caret-left,  html[dir="rtl"] .fa-caret-right,
html[dir="rtl"] .fa-long-arrow-left, html[dir="rtl"] .fa-long-arrow-right { transform: scaleX(-1); }

/* ---- Wizard Back/Next row: identical in Persian and English -----------------------------------------------
   Every wizard ends with  <div class="d-flex justify-content-evenly"> #nextButton | #backButton </div>.
   Only the LABELS are translated (_("Next") / _("Back")); the row is a fixed control and never mirrors:
   button order (Next left, Back right), icon-before/after-text order, arrow direction and icon gap all stay as written
   in the markup. Same idea as .pf-toggle in bilan_project.html: the component pins its own direction, the page stays RTL.
   Keyed on the shared button ids so every existing wizard is covered without touching its template.
   The selectors are one id wider than the generic rules above, so they win without !important where those have none,
   and the .ms-1/.me-1 restores use !important only because the mirrored utilities above do. */
div:has(> #nextButton, > #backButton) { direction: ltr; }
html[dir="rtl"] div:has(> #nextButton, > #backButton) [class*="fa-"] { transform: none; }
html[dir="rtl"] div:has(> #nextButton, > #backButton) .ms-1 { margin-right: 0 !important; margin-left: .25rem !important; }
html[dir="rtl"] div:has(> #nextButton, > #backButton) .me-1 { margin-left: 0 !important; margin-right: .25rem !important; }
