/* Right to left (Arabic, Persian, Hebrew, Urdu): the cheap mirror.

   <html dir="rtl">, set by the server and on language switch
   (locales/registry.json "rtl"), is what mirrors the screen: the browser
   itself puts rows, columns, sidebar and icons-next-to-labels on the other
   side and aligns text right. This file only adds what one attribute cannot
   say: arrows point the reading way, and some things never turn. */

/* 0. Menus, tooltips and popovers that JavaScript places with an inline
   style.left (or style.right): the stylesheet's logical edge would pin the
   other side too and stretch them. The inline side wins, as in English. */
[dir="rtl"] :is([style^="left:"], [style*=" left:"], [style*=";left:"]):not([style^="right:"], [style*=" right:"], [style*=";right:"]) {
    right: auto !important;
}
[dir="rtl"] :is([style^="right:"], [style*=" right:"], [style*=";right:"]):not([style^="left:"], [style*=" left:"], [style*=";left:"]) {
    left: auto !important;
}

/* 1. Directional icons point the reading way: back, next, chevrons, reply,
   send. `scale` adds to any `transform` an icon already has. Logos, media,
   charts and the network previews never mirror. */
[dir="rtl"] :is(
    .fa-chevron-left, .fa-chevron-right, .fa-arrow-left, .fa-arrow-right,
    .fa-caret-left, .fa-caret-right, .fa-angle-left, .fa-angle-right,
    .fa-paper-plane, .fa-share, .fa-reply,
    svg:has(> :is(
        path[d^="M9 18l6-6-6-6"], path[d^="m9 18 6-6-6-6"], path[d^="M9 6l6 6-6 6"], path[d^="M9 6L15 12L9 18"],
        path[d^="M15 18l-6-6 6-6"], path[d^="m15 18-6-6 6-6"], path[d^="M15 6L9 12L15 18"], path[d^="M15 6l-6 6 6 6"],
        path[d^="m12 5 7 7-7 7"], path[d^="M12 5l7 7-7 7"], path[d^="m12 19-7-7 7-7"], path[d^="M12 19l-7-7 7-7"],
        path[d^="M9 5l-7 7 7 7"], polyline[points^="9 17 4 12 9 7"],
        path[d^="M21 3L14 21L10 14L3 10L21 3Z"]
    ))
):not(.post-preview-stage *) {
    scale: -1 1;
}

/* 2. Network previews show the post as the network would, in the post's own
   language: their frame stays as drawn. */
[dir="rtl"] .post-preview-stage {
    direction: ltr;
}

/* 3. What people write reads in its own direction, whatever the app's
   language: an English caption, name or message inside the Arabic app, an
   Arabic one inside the English app. */
textarea,
[contenteditable="true"],
[contenteditable=""],
input:is([type="text"], [type="search"], :not([type])),
.post-preview-stage :is([class*="caption"], [class*="comment"], [class*="body"]) {
    unicode-bidi: plaintext;
}
/* Shown, not typed (captions in lists, bios, messages, names, handles): the
   words keep their own order ("@geomotion_en" keeps its @ in front) but the
   line stays aligned with the page, so an English bio in the Arabic app does
   not jump to the other edge. :where() adds no weight: a component's own
   text-align (a centred name) still wins. */
:where(
    [class*="caption"]:not(label, button, [langKey]), .mydrop-approval-text, .caption-suggestion,
    .conversation-message-body, .inbox-exec-snippet, .list-row-subtitle, .error-panel-row p,
    .editor-addon-chip-value,
    [translate="no"]:not([langKey]), .username, [class*="username"], [class*="profile-name"], [class*="handle"],
    .portal-row-text strong, .mydrop-report-profile-identity strong,
    .inbox-thread-preview-text, .inbox-thread-headline strong
) {
    unicode-bidi: plaintext;
    text-align: -webkit-match-parent;
    text-align: match-parent;
}
[dir="rtl"] input:is([type="email"], [type="url"], [type="tel"], [type="password"], [type="number"]) {
    direction: ltr;
}

/* 4. Figures that stand alone ("+3" more posts, "↗ +9.3%") keep their sign
   on the left, as Arabic readers expect. In a sentence the script wraps the
   figure in Unicode isolates instead (mydropReport.js _isolateNumber). */
[dir="rtl"] :is(
    .mr-change, .day-more-count, .editor-tab-more, .workspace-sheet-more, .post-profiles-more,
    .error-panel-row-more, .home-next-action-avatars-more, .inbox-composer-avatars-more,
    .home-journey-traveller-more, .mydrop-approval-profiles-more
) {
    direction: ltr;
    unicode-bidi: isolate;
}
