/* ========================================
   COMPREHENSIVE RTL SUPPORT FOR ARABIC
   ========================================

   Every selector here is anchored on html[dir="rtl"]. It used to be anchored
   on nothing: the first rule read `body, html[dir="rtl"] { direction: rtl }`,
   so the *unscoped* `body` half applied to whatever document loaded the file.
   base.html only links it under {% if LANGUAGE_CODE == 'ar' %}, which is the
   single reason the English site was not mirrored -- a link tag away from a
   sitewide defect, and nothing in the file said so.

   Anchoring also lets the file be concatenated into a bundle later without
   the bundle having to care.
   ======================================== */

/* Base RTL Layout */
html[dir="rtl"],
html[dir="rtl"] body {
    direction: rtl;
    text-align: right;
}

/* ===== LISTS ===== */
html[dir="rtl"] .main-content ul,
html[dir="rtl"] .main-content ol,
html[dir="rtl"] .guide-container ul,
html[dir="rtl"] .guide-container ol,
html[dir="rtl"] .accordion-body ul,
html[dir="rtl"] .accordion-body ol {
    padding-inline-start: 1.5rem;
    padding-inline-end: 0;
    direction: rtl;
    text-align: start;
}

html[dir="rtl"] .main-content li,
html[dir="rtl"] .guide-container li,
html[dir="rtl"] .accordion-body li {
    text-align: start;
}

/* ===== DASHBOARD LAYOUT ===== */
html[dir="rtl"] .dashboard-container {
    direction: rtl;
}

html[dir="rtl"] .tab-navigation {
    flex-direction: row-reverse;
}

html[dir="rtl"] .tab-navigation a,
html[dir="rtl"] .tab-navigation button {
    flex-direction: row-reverse;
}

html[dir="rtl"] .tab-navigation a i[data-lucide],
html[dir="rtl"] .tab-navigation button i[data-lucide] {
    margin-inline-end: 0.5rem;
    margin-inline-start: 0;
}

/* Market cards */
html[dir="rtl"] .market-card,
html[dir="rtl"] .overview-card {
    direction: rtl;
    text-align: start;
}

html[dir="rtl"] .market-card h3,
html[dir="rtl"] .overview-card h3 {
    text-align: start;
}

/* ===== ICONS - SELECTIVE FLIPPING ===== */
html[dir="rtl"] [data-lucide="chevron-left"],
html[dir="rtl"] [data-lucide="chevron-right"],
html[dir="rtl"] [data-lucide="arrow-left"],
html[dir="rtl"] [data-lucide="arrow-right"] {
    transform: scaleX(-1);
}

html[dir="rtl"] [data-lucide]:not([data-lucide="chevron-left"]):not([data-lucide="chevron-right"]):not([data-lucide="arrow-left"]):not([data-lucide="arrow-right"]) {
    transform: none;
}

/* ===== FORMS & INPUTS ===== */
html[dir="rtl"] input[type="text"],
html[dir="rtl"] input[type="search"],
html[dir="rtl"] input[type="email"],
html[dir="rtl"] textarea,
html[dir="rtl"] select {
    direction: rtl;
    text-align: right;
}

/* ===== MAIN CONTENT AREAS ===== */
html[dir="rtl"] .main-content {
    direction: rtl;
}

html[dir="rtl"] .main-content h1,
html[dir="rtl"] .main-content h2,
html[dir="rtl"] .main-content h3,
html[dir="rtl"] .main-content h4,
html[dir="rtl"] .main-content h5,
html[dir="rtl"] .main-content h6 {
    text-align: start;
}

/* ===== CODE BLOCKS & PRE ===== */
html[dir="rtl"] code {
    direction: ltr;
    text-align: left;
    display: inline-block;
}

html[dir="rtl"] pre {
    direction: ltr;
    text-align: left;
}

/* ===== DASHBOARD TAB NAVIGATION ===== */
html[dir="rtl"] .dashboard-tab-nav,
html[dir="rtl"] .tab-nav-container {
    direction: rtl;
}

html[dir="rtl"] .tab-nav-container {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

html[dir="rtl"] .tab-nav-item {
    flex-direction: row-reverse;
    direction: rtl;
}

html[dir="rtl"] .tab-nav-item i[data-lucide] {
    margin-inline-end: 0.5rem;
    margin-inline-start: 0;
}

/* ===== SECTION HEADERS ===== */
html[dir="rtl"] .section-header.enhanced {
    flex-direction: row-reverse;
    direction: rtl;
}

html[dir="rtl"] .section-info {
    text-align: start;
    direction: rtl;
}

html[dir="rtl"] .section-title,
html[dir="rtl"] .section-subtitle {
    text-align: start;
}

html[dir="rtl"] .section-tags {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

html[dir="rtl"] .section-tag {
    flex-direction: row-reverse;
}

html[dir="rtl"] .section-tag i[data-lucide] {
    margin-inline-end: 0.5rem;
    margin-inline-start: 0;
}

/* ===== MARKET SUMMARY CARDS ===== */
html[dir="rtl"] .market-summary-card {
    direction: rtl;
    text-align: start;
}

html[dir="rtl"] .summary-header {
    flex-direction: row-reverse;
}

html[dir="rtl"] .summary-icon {
    order: 3;
    margin-inline-end: 1rem;
    margin-inline-start: 0;
}

html[dir="rtl"] .summary-info {
    order: 1;
    flex: 1;
    text-align: start;
}

html[dir="rtl"] .summary-title,
html[dir="rtl"] .summary-count {
    text-align: start;
}

html[dir="rtl"] .summary-toggle {
    order: 2;
    margin-inline-end: 0;
    margin-inline-start: auto;
}

html[dir="rtl"] .summary-toggle i[data-lucide="chevron-right"],
html[dir="rtl"] .summary-toggle i[data-lucide="chevron-down"] {
    transform: scaleX(-1);
}

html[dir="rtl"] .summary-stats {
    direction: rtl;
    text-align: start;
}

html[dir="rtl"] .summary-stat {
    flex-direction: row-reverse;
    justify-content: space-between;
}

html[dir="rtl"] .stat-label {
    text-align: start;
}

html[dir="rtl"] .stat-value {
    text-align: left;
    direction: ltr;
}

/* ===== OVERVIEW SECTION ===== */
html[dir="rtl"] .overview-section {
    direction: rtl;
}

html[dir="rtl"] .market-summary-grid {
    direction: rtl;
}

/* ===== ANALYSIS CARDS ===== */
html[dir="rtl"] .analysis-cards-grid {
    direction: rtl;
}

html[dir="rtl"] .analysis-card-modern {
    direction: rtl;
    text-align: start;
}

html[dir="rtl"] .card-header {
    flex-direction: row-reverse;
}

html[dir="rtl"] .symbol-info {
    text-align: start;
}

/* ===== BUTTONS IN CARDS ===== */
html[dir="rtl"] .card button,
html[dir="rtl"] .card .btn {
    flex-direction: row-reverse;
}

html[dir="rtl"] .card button i[data-lucide],
html[dir="rtl"] .card .btn i[data-lucide] {
    margin-inline-end: 0.5rem;
    margin-inline-start: 0;
}

/* ===== TAB CONTENT ===== */
html[dir="rtl"] .tab-content {
    direction: rtl;
}

/* ===== MAIN CONTENT CONTAINERS ===== */
html[dir="rtl"] .dashboard-container {
    direction: rtl;
    text-align: start;
}

/* ===== RESPONSIVE RTL ===== */
@media (max-width: 768px) {
    html[dir="rtl"] .section-header.enhanced {
        flex-direction: column;
        align-items: flex-start;
    }

    html[dir="rtl"] .summary-header {
        flex-direction: row-reverse;
    }
}

/* Symbol Detail RTL */
html[dir="rtl"] .symbol-impact-line {
    border-inline-end: none;
    border-inline-start: 3px solid;
}

html[dir="rtl"] .impact-bullish {
    border-inline-end-color: transparent;
    border-inline-start-color: var(--c-up);
}

html[dir="rtl"] .impact-bearish {
    border-inline-end-color: transparent;
    border-inline-start-color: var(--c-down);
}

html[dir="rtl"] .impact-neutral {
    border-inline-end-color: transparent;
    border-inline-start-color: var(--c-line);
}

html[dir="rtl"] .ai-insight-trigger {
    text-align: start;
}

html[dir="rtl"] .back-button:hover {
    transform: translateX(4px);
}

html[dir="rtl"] .news-count {
    margin-inline-end: 0;
    margin-inline-start: 0.5rem;
}

/* ========================================
   PROGRESS, CONFIDENCE AND SENTIMENT BARS
   ========================================

   A percentage-width fill inside an overflow:hidden track already grows from
   the inline start, so under RTL it correctly grows right-to-left with no
   help. Its *gradient* does not: `linear-gradient(90deg, red, green)` is a
   physical direction with no logical form in CSS, so the bar kept painting
   red on the left. The fill then started at the right, in the green, and a
   10%-confidence reading was drawn in the colour of a 90% one -- the one
   place on the page where a wrong direction is not cosmetic but a wrong
   number.

   Flipping to 270deg puts the scale back under the fill. Only the
   multi-stop gradients are listed; the single-colour ones (the digest
   confidence fills) have no direction to get wrong.
   ======================================== */

html[dir="rtl"] .sentiment-bar {
    background-image: linear-gradient(270deg,
        color-mix(in srgb, var(--c-down) 20%, transparent) 0%,
        color-mix(in srgb, var(--c-attention) 20%, transparent) 50%,
        color-mix(in srgb, var(--c-up) 20%, transparent) 100%);
}

html[dir="rtl"] .sentiment-fill {
    background-image: linear-gradient(270deg,
        var(--c-down) 0%, var(--c-attention) 50%, var(--c-up) 100%);
}

html[dir="rtl"] .ai-confidence-fill {
    background-image: linear-gradient(270deg,
        var(--c-down), var(--c-attention), var(--c-up));
}

html[dir="rtl"] .comm-fill-24h {
    background-image: linear-gradient(270deg,
        var(--c-down), var(--c-attention), var(--c-up));
}

/* The accuracy leaderboard's confidence fill is painted from an inline
   `background:` in accuracy_leaderboard.html, a flat colour with no
   direction. Nothing to flip -- listed so the next reader does not go
   looking. */

/* ========================================
   CHARTS STAY LTR
   ========================================

   A price chart is not prose. Its x-axis runs older-to-newer left-to-right in
   every market on earth, TradingView renders it that way regardless of the
   page, and Chart.js reads the computed `direction` of its container and will
   mirror both the axis and the legend if the container inherits rtl. A
   mirrored candlestick chart is not a translation, it is a different claim
   about which way time runs.

   `unicode-bidi: isolate` as well as `direction: ltr`, so a symbol or a
   currency inside a label cannot reorder against the surrounding Arabic.
   ======================================== */

html[dir="rtl"] .chart-loading-fallback,
html[dir="rtl"] .tradingview-widget-container,
html[dir="rtl"] .chart-container,
html[dir="rtl"] [data-chart-ltr] {
    direction: ltr;
    unicode-bidi: isolate;
}

/* ========================================
   MIXED-LANGUAGE CONTENT: LET DIRECTION FOLLOW THE TEXT
   ========================================

   The corpus is English: headlines, publisher names, company names and the
   model's prose all arrive in English and there is no Arabic rendering of
   them (the blocks that do have one already say so in words, and the ones
   that do not now carry a note saying that too). Printing that text inside
   an RTL paragraph is what "half-translated" looks like: the sentence still
   reads left to right because the letters are Latin, but its full stop, its
   brackets and any trailing number jump to the wrong end.

   `unicode-bidi: plaintext` is the CSS form of `dir="auto"`: each paragraph
   takes its direction from its own first strong character. Arabic copy in
   these same slots is unaffected -- it stays RTL -- so this is not a
   mirroring override, it is the rule that lets one slot carry either
   language correctly. Measured before: 57 English runs set RTL on
   /ar/symbol/BTC/, 8 on /ar/reports/daily/, 33 on /ar/news/. All zero after,
   with one exception noted below.

   Selectors name elements, never classes: a class list here would both
   collide with the canvas layer's names and go stale the first time a
   template renamed a block. Every part is spelled out with its own
   `html[dir="rtl"]` prefix because this file's own guard test splits on
   commas.

   Known exception: an `<option>` inside a native `<select>` is drawn by the
   platform, which ignores this property. One provider name on /ar/backtest/
   is affected. ======================================== */
html[dir="rtl"] .main-content p,
html[dir="rtl"] .main-content li,
html[dir="rtl"] .main-content h1,
html[dir="rtl"] .main-content h2,
html[dir="rtl"] .main-content h3,
html[dir="rtl"] .main-content h4,
html[dir="rtl"] .main-content dd,
html[dir="rtl"] .main-content figcaption,
html[dir="rtl"] .main-content blockquote,
html[dir="rtl"] .main-content summary,
html[dir="rtl"] .main-content td,
html[dir="rtl"] .main-content th,
html[dir="rtl"] .main-content a,
html[dir="rtl"] .main-content span {
    unicode-bidi: plaintext;
}

/* Page titles keep the page's direction. A title that is only Latin (a model
   name, a search term) took the LTR paragraph direction from the rule above
   and sat flush-left under an Arabic masthead; the Latin run still reads
   left to right inside the RTL block, which is what a title needs. */
html[dir="rtl"] .main-content h1.am-page-head__title {
    unicode-bidi: isolate;
    text-align: start;
}
/* The same for a breadcrumb crumb: its "‹" separator is a ::before inside
   the item, so a Latin-only crumb (a model name) turned the item LTR and the
   separator landed on the wrong side of it. */
html[dir="rtl"] .main-content .breadcrumb li {
    unicode-bidi: isolate;
}

/* A block that declares its own direction should also range from its own
   start. The blanket above sets `text-align: right` on the body, so an
   English paragraph marked `dir="ltr"` -- the analysis and the publisher's
   excerpt on an Arabic article page -- rendered flush-right and ragged-left:
   the letters in the right order, the paragraph in the wrong place. */
html[dir="rtl"] [dir="ltr"],
html[dir="rtl"] [dir="auto"] {
    text-align: start;
}
