/* RTL baseline. It is inert for the existing LTR locales. */
html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] .okm-header-shell,
html[dir="rtl"] .okm-header-top,
html[dir="rtl"] .okm-header-brand,
html[dir="rtl"] .okm-header-actions,
html[dir="rtl"] .okm-header-tabs .md-tabs__list,
html[dir="rtl"] .okm-public-language__menu,
html[dir="rtl"] .okm-search-result-card,
html[dir="rtl"] .md-content,
html[dir="rtl"] .md-sidebar {
  direction: rtl;
}

html[dir="rtl"] code,
html[dir="rtl"] pre,
html[dir="rtl"] kbd,
html[dir="rtl"] samp,
html[dir="rtl"] .okm-ltr,
html[dir="rtl"] [data-okm-ltr] {
  direction: ltr;
  unicode-bidi: isolate;
}

/*
 * A short Arabic label that contains a Latin product name or abbreviation
 * needs an explicit visual base direction.  Apply this class only to labels
 * that were reviewed as a complete unit; do not apply it globally to Arabic
 * prose.  The surrounding component remains RTL and right-aligned.
 */
html[dir="rtl"] .okm-mixed-ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

html[dir="rtl"] .okm-faq-card .okm-mixed-ltr {
  display: block;
  min-width: 0;
  overflow-wrap: normal;
  text-align: right;
  white-space: normal;
  width: 100%;
}

html[dir="rtl"] .okm-nowrap {
  white-space: nowrap;
}

/*
 * Mixed Arabic/LTR headings use one visual convention everywhere:
 * the isolated Latin token sits on the right, Arabic sits on the left,
 * and the complete label remains aligned to the RTL content edge.
 */
html[dir="rtl"] .md-typeset :is(h1, h2, h3, h4, h5, h6):has(.okm-ltr),
html[dir="rtl"] .md-nav__link:has(.okm-ltr),
html[dir="rtl"] .md-nav__link .md-ellipsis:has(.okm-ltr) {
  direction: ltr !important;
  text-align: right;
  unicode-bidi: isolate;
}

html[dir="rtl"] .md-nav__link .md-ellipsis:has(.okm-ltr) {
  display: block;
  width: 100%;
}

/* MkDocs strips inline bdi markup from generated TOC labels. */
html[dir="rtl"] .md-nav--secondary .okm-toc-mixed-ltr {
  direction: ltr !important;
  display: block;
  text-align: right;
  unicode-bidi: isolate;
  width: 100%;
}

/* Multiple isolated Latin runs need the Arabic sentence as the base. */
html[dir="rtl"] .md-typeset :is(h1, h2, h3, h4, h5, h6):has(.okm-ltr ~ .okm-ltr),
html[dir="rtl"] .md-nav--secondary .okm-toc-mixed-rtl {
  direction: rtl !important;
  text-align: right;
  unicode-bidi: isolate;
}

html[dir="rtl"] .md-nav--secondary .okm-toc-mixed-rtl {
  display: block;
  width: 100%;
}

/* Runtime-generated article-group links contain plain text, not bdi nodes. */
html[dir="rtl"] :is(
  .okm-article-group-nav__links,
  .okm-mobile-article-switch__links
) a[dir="ltr"] {
  text-align: right;
  unicode-bidi: isolate;
}

html[dir="rtl"] :is(
  .md-typeset h1,
  .md-typeset h2,
  .md-typeset h3,
  .md-typeset h4,
  .md-typeset h5,
  .md-typeset h6,
  .md-nav__link
) .okm-ltr {
  white-space: nowrap;
}

html[dir="rtl"] .md-content h1:has(.okm-nowrap) {
  white-space: nowrap;
}

@media screen and (max-width: 600px) {
  html[dir="rtl"] .md-content h1:has(.okm-nowrap) {
    font-size: clamp(0.88rem, 4.5vw, 1.2rem);
  }
}

html[dir="rtl"] .okm-public-language__menu {
  left: 0;
  right: auto;
}

html[dir="rtl"] .okm-header-tabs .md-tabs__item--active .okm-header-tabs__text::after {
  left: auto;
  right: 0;
}

html[dir="rtl"] .md-typeset table:not([dir="ltr"]) {
  direction: rtl;
}

html[dir="rtl"] .md-nav__title,
html[dir="rtl"] .md-nav__link .md-ellipsis {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

html[dir="rtl"] .okm-download-app-card-v2 {
  height: auto !important;
  min-height: 156px !important;
  overflow: visible !important;
}

/* Forward navigation points left in RTL while retaining its position after the label. */
html[dir="rtl"] .okm-app-category-all::after {
  transform: scaleX(-1);
}

html[dir="rtl"] .okm-app-category-all:hover::after {
  transform: translateX(-2px) scaleX(-1);
}

/* Forward navigation points left in RTL search results and FAQ article rows. */
html[dir="rtl"] .okm-search-result-card__action-icon,
html[dir="rtl"] .okm-faq-card .okm-app-category-links a::after {
  transform: scaleX(-1);
}

html[dir="rtl"] .okm-faq-card .okm-app-category-links a:hover::after {
  transform: translateX(-2px) scaleX(-1);
}

/* Flip page navigation, but keep the non-directional download glyph unchanged. */
html[dir="rtl"] .okm-download-primary-link:not(.okm-download-primary-link--download)::after {
  transform: scaleX(-1) !important;
}

/* Contact-card actions keep their left-side RTL position and point forward (left). */
html[dir="rtl"] .md-main:has(.okm-support-page) .okm-support-card em::after {
  transform: rotate(225deg);
}

/* Keep the short Arabic app-path label on one line and leave the UI path flexible. */
html[dir="rtl"] .okm-app-category-entry {
  grid-template-columns: max-content minmax(0, 1fr);
}

html[dir="rtl"] .okm-app-category-entry > span:first-child {
  white-space: nowrap;
}

/* Keep English UI paths visually anchored to the RTL flow while preserving LTR order. */
html[dir="rtl"] .okm-app-category-entry > b[dir="ltr"] {
  justify-content: flex-end;
  text-align: right;
  unicode-bidi: isolate;
}

/*
 * On narrow RTL pages the header tab row is wider than its viewport. Keep
 * that extra width inside the tab scroller instead of centering the row and
 * exposing its negative inline edge to the document.
 */
@media screen and (max-width: 640px) {
  html[dir="rtl"],
  html[dir="rtl"] body {
    max-width: 100%;
    overflow-x: clip;
  }

  html[dir="rtl"]
    .okm-public-header.okm-header--two-row
    .okm-header-tabs,
  html[dir="rtl"]
    .okm-public-header.okm-header--two-row
    .okm-header-tabs[hidden] {
    contain: inline-size paint;
    direction: ltr;
    justify-content: flex-start !important;
    max-width: 100%;
    min-width: 0;
    overflow-x: clip !important;
    overflow-y: hidden !important;
  }

  html[dir="rtl"]
    .okm-public-header.okm-header--two-row
    .okm-header-tabs
    .md-tabs__list {
    direction: ltr;
    flex: 0 1 100% !important;
    flex-direction: row-reverse;
    justify-content: flex-start !important;
    margin: 0 !important;
    max-width: 100%;
    min-width: 0 !important;
    overflow-x: auto;
    overflow-y: hidden;
    width: 100% !important;
  }

  html[dir="rtl"] .okm-header-tabs .md-tabs__item,
  html[dir="rtl"] .okm-header-tabs .md-tabs__link,
  html[dir="rtl"] .okm-header-tabs__text {
    direction: rtl;
  }
}

@media screen and (min-width: 761px) {
  html[dir="rtl"] .okm-app-category-entry > b {
    font-size: 0.54rem;
    padding-inline: 0.3rem;
    white-space: nowrap;
  }
}
