/* ==========================================================================
   PHASE 2 — RTL FOUNDATION
   Direction-aware primitives. Nothing here uses physical left/right unless
   it is explicitly a mirroring rule.
   ========================================================================== */

@layer base {
  /* ---------- Document direction ---------- */
  [dir="rtl"] {
    direction: rtl;
  }

  [dir="rtl"] body {
    text-align: start;
  }

  /* ---------- Form controls follow the document direction ---------- */
  input,
  textarea,
  select {
    text-align: start;
    direction: inherit;
  }

  input[type="tel"],
  input[type="email"],
  input[type="url"],
  input[type="number"] {
    direction: ltr;
    text-align: end;
    unicode-bidi: isolate;
  }

  /* ---------- Bidi isolation for mixed Persian/Latin/number runs ---------- */
  .ltr-inline,
  .num,
  code,
  kbd,
  samp {
    direction: ltr;
    unicode-bidi: isolate;
  }

  .ltr-inline {
    display: inline-block;
  }

  /* ---------- Icon contract ----------
     .icon            → neutral glyph, never flipped
     .icon--directional → arrows, chevrons, undo/redo, indentation: flipped in RTL
     .icon--fixed     → opt out even inside a directional context (logos, play)
     Icons are drawn in a 24×24 box with 1.5 stroke, currentColor only.        */
  .icon {
    inline-size: 1.5rem;
    block-size: 1.5rem;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.25em;
  }

  .icon--sm {
    inline-size: 1.125rem;
    block-size: 1.125rem;
  }

  .icon--lg {
    inline-size: 2rem;
    block-size: 2rem;
  }

  [dir="rtl"] .icon--directional {
    transform: scaleX(-1);
  }

  [dir="rtl"] .icon--directional.icon--fixed,
  .icon--fixed {
    transform: none;
  }

  /* ---------- Physical-property guard ----------
     Any legacy physical utility is neutralised in RTL so a stray `ml-*`
     can never break the layout. Logical utilities (ms-*, me-*, ps-*, pe-*)
     are the supported path. */
  [dir="rtl"] .force-flip {
    transform: scaleX(-1);
  }
}

@layer utilities {
  /* Text that must stay left-to-right inside RTL copy: file names, formulas */
  .dir-ltr {
    direction: ltr;
    unicode-bidi: isolate;
    text-align: start;
  }

  /* Numbers that should render as a stable block (prices, counters) */
  .dir-num {
    font-variant-numeric: tabular-nums;
    unicode-bidi: isolate;
  }

  .text-start {
    text-align: start;
  }

  .text-end {
    text-align: end;
  }
}
