/* ==========================================================================
   rtl.css — what changes when the lab reads right to left
   --------------------------------------------------------------------------
   Linked from the <head> of every page, and every rule in it is scoped to
   html[dir="rtl"], so on an English page it declares nothing at all. It was
   injected by lang.js at first, only when Arabic was on, which is cheaper
   and was wrong: an injected stylesheet can arrive after the first paint,
   and tests/uat-rtl.js caught five pages showing a frame of Latin tracking
   pulling Arabic words apart at the joins before this file landed. A
   stylesheet in the markup cannot lose that race. An English reader pays
   one small file that does nothing; an Arabic reader never sees a wrong
   frame. That is the trade and it is not close.

   THIS FILE IS THE SMALL HALF OF THE WORK. The large half was done in the
   stylesheets themselves, by replacing the properties that name a physical
   side with the ones that name a logical one:

       margin-left      ->  margin-inline-start
       padding-left     ->  padding-inline-start
       border-left      ->  border-inline-start
       text-align:left  ->  text-align:start
       left:0           ->  inset-inline-start:0

   Those render identically in English, byte for byte on screen, and they
   answer dir on their own. So they are not in here. What is in here is only
   the things a logical property cannot say.

   WHY THE LETTER-SPACING RULE CARRIES !important, and it is the only place
   in this lab that does. Arabic is a joined script. Tracking pulls the
   letters of a word apart at the joins, and the result is not "airy", it is
   misspelled-looking, the way s p a c e d Latin is merely airy but spaced
   Devanagari is broken. This lab declares letter-spacing in about a hundred
   and thirty places, most of them inside a <style> block on a page, which
   means they come after every stylesheet and win on order. There is no
   selector I can write that beats all of them and stays readable. So this
   is an assertion rather than an override: in Arabic, tracking is off,
   whatever any page says. tests/uat-rtl.js walks every element on an Arabic
   page and fails if a computed letter-spacing is anything but normal, so
   the claim is checked and not just written down.

   text-transform goes with it. Arabic has no case, so uppercase does
   nothing to Arabic glyphs, but this lab writes English terms in brackets
   inside Arabic sentences, and a bracketed (ITIL) inside an uppercased
   kicker comes out shouting in a sentence that is not shouting.

   NUMBERS ARE NOT TOUCHED, here or anywhere. 615 laptops, 93.5 percent,
   700 XP. The register, Intune, Jira and every export an intern has to
   match a number against are Western digits, and the Unicode bidi
   algorithm already sets a Western number left to right inside an Arabic
   line without being asked. Arabic-Indic digits are in the font subset
   because the font has them, not because this lab uses them.
   ========================================================================== */

/* ---- typography -----------------------------------------------------------
   Arabic sits taller than Latin at the same font-size: the ascenders on
   alef and lam and the descenders on jeem and ain use vertical room that a
   line-height tuned for Latin does not leave. 1.15 of the Latin leading was
   measured on the week 4 pages, not guessed, and is small enough that a
   card built for four English lines still holds four Arabic ones. */
html[dir="rtl"]{
  line-height:1.75;
  /* rlig is the Arabic required ligature set: lam-alef is not decoration,
     a word is spelled wrong without it. calt drives the contextual forms.
     Both are on by default in every engine tested, and both are named here
     so that a future font-feature-settings elsewhere cannot turn them off
     by replacing the whole property. */
  font-feature-settings:"rlig" 1,"calt" 1;
}
html[dir="rtl"] *{
  letter-spacing:normal !important;
  word-spacing:normal !important;
  text-transform:none !important;
}
/* Restored for the one case where tracking is not typographic: a run of
   Latin that has been isolated on purpose, such as a product name set on
   its own line. Nothing uses it yet; it is here so that the assertion above
   has a documented way out rather than an undocumented one. */
html[dir="rtl"] .lat{
  letter-spacing:inherit !important;
  direction:ltr;
  unicode-bidi:isolate;
}

/* ---- the things a logical property cannot say -----------------------------
   Every rule below flips something that is genuinely physical: a transform,
   a transform-origin, or a glyph that points. */

/* The growing underline and the hover nudge are already answered by the
   :dir(rtl) rules in motion.css, which were written when the interaction
   language was built. They are not repeated here. */

/* fx.css fills a progress bar by scaling it from its origin. The origin is
   physical, so in Arabic the bar would fill from the right-hand end of a
   track that starts on the right, which is to say it would empty. */
html[dir="rtl"] .fx-fill{transform-origin:100% 50%}

/* brand.css marks a plain list with a triangle that points into the text.
   In Arabic the text is on the other side, so the triangle has to turn
   around; a mirrored layout with an arrow still pointing away from its own
   sentence is the single clearest tell that a page was translated and not
   laid out. */
html[dir="rtl"] ul.clean li:before{content:"\25C2"}

/* Shake is symmetric, so it needs nothing, and that is worth saying once so
   nobody adds a flip for it later: a sequence that goes left, right, left,
   right reads the same from either end. */

/* ---- form controls --------------------------------------------------------
   A number input, a time, and anything holding a bare figure stays left to
   right even on an Arabic page, for the same reason the numbers do. */
html[dir="rtl"] input[type="number"],
html[dir="rtl"] input[type="tel"],
html[dir="rtl"] input[type="url"],
html[dir="rtl"] input[type="email"],
html[dir="rtl"] code,
html[dir="rtl"] pre,
html[dir="rtl"] kbd,
html[dir="rtl"] samp{
  direction:ltr;
  text-align:start;
  unicode-bidi:isolate;
}

/* ---- tables ---------------------------------------------------------------
   A table mirrors as a whole under dir, which is correct: the first column
   belongs on the right. What does not mirror is a cell holding a figure,
   which should stay a column of digits that line up. */
html[dir="rtl"] table.t td.num,
html[dir="rtl"] table.t th.num{direction:ltr;text-align:start}

/* ---- runs that are not Arabic ---------------------------------------------
   This is the rule that a bilingual page lives or dies on, and it is worth
   saying at length because it is invisible until it is wrong.

   Unicode's bidi algorithm decides the order of a line from the characters
   themselves. Digits are neutral about direction and the punctuation between
   them is more neutral still, so "0 / 24" inside an Arabic paragraph is read
   as two separate numbers with a slash between them, and the paragraph's own
   right-to-left order puts the 24 first. The page then says 24 / 0. Nothing
   is broken, no rule is wrong, and the number is backwards.

   The fix is not to disable bidi, which would wreck the Arabic around it. It
   is to tell the browser that this small run is its own island with its own
   direction: isolate stops the run from being reordered against its
   neighbours, and direction:ltr sets the order inside it. That is exactly
   what the <bdi> element is for, and .num is the same thing for a span that
   is already there.

   USE IT FOR: a fraction, a score, a version, a serial, a file name, a
   command, a rank or product name in Latin, a time on a clock. Anything an
   intern has to read character by character and match against a system.

   DO NOT use it for a whole sentence. A sentence of English inside an Arabic
   page is a translation that has not been written yet, and hiding that it
   reads oddly hides that it is missing. */
html[dir="rtl"] .num,
html[dir="rtl"] bdi{direction:ltr;unicode-bidi:isolate}
/* direction:ltr also decides where a BLOCK's line sits, and it would park a
   figure against the left edge of a card whose label is against the right
   one. The order inside the run is what had to change; where the run sits is
   still the page's business, so it is put back explicitly. An inline .num
   ignores this, which is why one rule serves both. */
html[dir="rtl"] .num{text-align:right}
