/*
 * RTL overrides for built Arabic (and future RTL) locale pages.
 *
 * Injected by tools/build-locale-pages.mjs into the <head> of any locale
 * with rtl: true. Targets the most visible LTR-only patterns in the source
 * inline CSS so the page reads naturally right-to-left without a full
 * physical→logical CSS rewrite of the source pages.
 *
 * Scoped to [dir="rtl"] only — does not affect LTR builds.
 */

/* ============================================================
 * Base: ensure Arabic font fallback and natural text flow.
 * ============================================================ */
[dir="rtl"] body {
  font-family: 'Cairo', 'Segoe UI', 'Tahoma', system-ui, sans-serif;
  text-align: right;
}

[dir="rtl"] h1,
[dir="rtl"] h2,
[dir="rtl"] h3,
[dir="rtl"] h4,
[dir="rtl"] h5,
[dir="rtl"] h6,
[dir="rtl"] p,
[dir="rtl"] li,
[dir="rtl"] dt,
[dir="rtl"] dd,
[dir="rtl"] blockquote,
[dir="rtl"] label,
[dir="rtl"] th,
[dir="rtl"] td {
  text-align: start;
}

/* Keep visibly centered things centered (heroes, CTAs, stats). */
[dir="rtl"] .hero,
[dir="rtl"] .center,
[dir="rtl"] [class*="hero"],
[dir="rtl"] [class*="center"],
[dir="rtl"] [class*="stat"],
[dir="rtl"] [class*="cta"] {
  text-align: center;
}

/* Form controls follow the writing direction. */
[dir="rtl"] input,
[dir="rtl"] textarea,
[dir="rtl"] select {
  text-align: right;
  direction: rtl;
}

/* But always keep numeric / email / URL / password inputs LTR — they read
 * left-to-right even in RTL languages. */
[dir="rtl"] input[type="email"],
[dir="rtl"] input[type="url"],
[dir="rtl"] input[type="tel"],
[dir="rtl"] input[type="number"],
[dir="rtl"] input[type="password"],
[dir="rtl"] input[inputmode="numeric"] {
  direction: ltr;
  text-align: right;
}

/* ============================================================
 * Flex & grid: rows flow right-to-left automatically. Make sure
 * order stays visually consistent for navbars/footers.
 * ============================================================ */
[dir="rtl"] nav,
[dir="rtl"] header,
[dir="rtl"] footer,
[dir="rtl"] .nav,
[dir="rtl"] .header,
[dir="rtl"] .footer {
  direction: rtl;
}

/* ============================================================
 * Mirror direction-sensitive icons and arrows.
 *
 * Anything with an "arrow", "chevron", or "caret" class — flip
 * horizontally so → becomes ← visually. Skip checkmarks, close,
 * and language flags (🌐) which are direction-neutral.
 * ============================================================ */
[dir="rtl"] [class*="arrow"]:not([class*="up"]):not([class*="down"]),
[dir="rtl"] [class*="chevron"]:not([class*="up"]):not([class*="down"]),
[dir="rtl"] [class*="caret"]:not([class*="up"]):not([class*="down"]),
[dir="rtl"] .icon-back,
[dir="rtl"] .icon-forward,
[dir="rtl"] .icon-next,
[dir="rtl"] .icon-prev {
  transform: scaleX(-1);
}

/* ============================================================
 * Inline-margin / padding utilities: when an author wrote
 * margin-left or margin-right hoping it meant "start" or "end",
 * common patterns are caught here. These cover the most-used
 * spacings (sidebar gaps, nav-item gaps).
 * ============================================================ */

/* Pill / chip / badge gaps */
[dir="rtl"] [class*="badge"],
[dir="rtl"] [class*="chip"],
[dir="rtl"] [class*="pill"],
[dir="rtl"] [class*="tag"] {
  margin-inline-start: 0;
  margin-inline-end: 6px;
}

/* ============================================================
 * Brand "Briefed" mark — keep it Latin and LTR even mid-Arabic.
 * The HTML has <span class="nav-logo-b">B</span>riefed split into
 * two spans; make sure the whole logo reads B-r-i-e-f-e-d in order.
 * ============================================================ */
[dir="rtl"] .nav-logo,
[dir="rtl"] .nav-logo-text,
[dir="rtl"] [class*="logo"] {
  direction: ltr;
  unicode-bidi: isolate;
}

/* Same for any element containing the brand name as text content.
 * <code>, <var>, <kbd> often hold LTR tokens (German terms,
 * code identifiers, file paths) that should not flip. */
[dir="rtl"] code,
[dir="rtl"] var,
[dir="rtl"] kbd,
[dir="rtl"] samp,
[dir="rtl"] .ltr {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
}

/* ============================================================
 * Tables: header alignment and cell direction.
 * ============================================================ */
[dir="rtl"] table {
  direction: rtl;
}
[dir="rtl"] th:first-child,
[dir="rtl"] td:first-child {
  text-align: start;
}

/* ============================================================
 * Lists: bullets / numbering on the correct side.
 * ============================================================ */
[dir="rtl"] ul,
[dir="rtl"] ol {
  padding-inline-start: 24px;
  padding-inline-end: 0;
}

/* ============================================================
 * Common app-shell patterns: sidebar lives on the right in RTL.
 * If the source uses <aside> or a class with "sidebar", swap the
 * border side and box-shadow direction.
 * ============================================================ */
[dir="rtl"] aside,
[dir="rtl"] [class*="sidebar"]:not([class*="content"]) {
  border-left: none;
  border-right: 1px solid var(--border, #ddd9d3);
}

/* ============================================================
 * Form helpers commonly aligned to a side.
 * ============================================================ */
[dir="rtl"] .form-row,
[dir="rtl"] [class*="form-field"],
[dir="rtl"] [class*="input-row"] {
  text-align: start;
}

/* ============================================================
 * Numbers, prices, dates: always LTR runs so "5.99€" reads right.
 * The HTML uses Western digits and Latin currency symbols, so we
 * isolate any short numeric/currency string in inline spans.
 * Authors should wrap these in <bdi>; this is a graceful fallback.
 * ============================================================ */
[dir="rtl"] [class*="price"],
[dir="rtl"] [class*="amount"],
[dir="rtl"] [class*="date"],
[dir="rtl"] [class*="time"],
[dir="rtl"] [class*="number"] {
  unicode-bidi: plaintext;
}

/* ============================================================
 * Modal/drawer slide-in: keep close-X on the start side (= top-right
 * in LTR, top-left in RTL — natural mirror).
 * ============================================================ */
[dir="rtl"] [class*="close"]:not([class*="closer"]) {
  margin-inline-start: auto;
  margin-inline-end: 0;
}

/* ============================================================
 * Footer language switcher — keep language NAMES in their native
 * direction so "English" reads LTR and "العربية" reads RTL.
 * ============================================================ */
[dir="rtl"] footer ul li,
[dir="rtl"] footer ol li {
  unicode-bidi: plaintext;
}
