/*
 * takwinx-direction.css — per-content text direction for the LMS portal.
 *
 * Feature: 005-per-content-direction (T009)
 * Contract: specs/005-per-content-direction/contracts/direction-resolution.md
 *
 * Injected into apps/lms/lms/www/_lms.html at image build time. There is no
 * supported extension point: the SPA shell is a standalone document that extends
 * no Frappe base template, so `web_include_css` never reaches it (spike Q2).
 *
 * WHAT THIS FILE DOES AND DOES NOT DO
 * -----------------------------------
 * It supplies direction-neutral layout only. The actual `dir` value is set by
 * takwinx-direction.js from the course's declared `custom_language`, because
 * auto-detection is NOT sufficient here — the existing Arabic course contains
 * table cells beginning with numerals ("42 هكتار", "309 متر") which detect as
 * LTR while their surroundings are RTL.
 *
 * It must NOT touch the app shell. Navigation, menus and buttons continue to
 * follow the learner's own language, which is the pilot's result and is
 * protected by US2.
 */

/* Content roots the script marks. `start` resolves against each element's own
   direction, so one declaration serves both — hardcoding left/right would mean
   writing every rule twice and getting one of them wrong later. */
[data-takwinx-dir] {
    text-align: start;
}

/* EditorJS blocks inherit direction from the marked root. These selectors exist
   to undo alignment the editor hardcodes, not to set direction themselves. */
[data-takwinx-dir] .ce-block,
[data-takwinx-dir] .ce-paragraph,
[data-takwinx-dir] .ce-header,
[data-takwinx-dir] .cdx-block,
[data-takwinx-dir] .cdx-nested-list__item-content,
[data-takwinx-dir] .tc-cell {
    text-align: start;
}

/* Lists and tables need their own nudge: browsers place markers and the first
   column by the *inherited* direction, which is what we are overriding. */
[data-takwinx-dir] ul,
[data-takwinx-dir] ol,
[data-takwinx-dir] .cdx-nested-list {
    padding-inline-start: 1.5em;
    padding-inline-end: 0;
}

[data-takwinx-dir] .tc-table,
[data-takwinx-dir] table {
    text-align: start;
}

/* Unknown course language → per-block detection. This is the documented FR-006
   fallback and applies ONLY when the script could not determine a language;
   it is never the primary mechanism (FR-005). */
[data-takwinx-dir="auto"] .ce-block,
[data-takwinx-dir="auto"] .ce-paragraph,
[data-takwinx-dir="auto"] .ce-header,
[data-takwinx-dir="auto"] .cdx-block,
[data-takwinx-dir="auto"] .cdx-nested-list__item-content,
[data-takwinx-dir="auto"] .tc-cell {
    unicode-bidi: plaintext;
}

/* Media must not be mirrored — direction applies to text flow, not to video
   frames or images, and an RTL container should not flip an embedded player. */
[data-takwinx-dir] iframe,
[data-takwinx-dir] video,
[data-takwinx-dir] img {
    direction: ltr;
}
