/* ==========================================================================
   Right-to-left.

   The base stylesheet was written with physical directions (left, right).
   Rewriting all of it to logical properties would touch every rule and risk
   the established layout, so the handful that actually flip are corrected
   here, scoped to [dir="rtl"]. Everything else — flexbox, grid, gap — mirrors
   on its own.
   ========================================================================== */

[dir='rtl'] {
    /* Persian renders better with a font that has proper Arabic-script shaping.
       Tahoma ships on Windows, and the rest are common on other platforms; the
       Latin stack stays as the fallback so mixed strings still look right. */
    --font-body: 'Segoe UI', Tahoma, 'Iranian Sans', 'Vazirmatn', 'Noto Naskh Arabic',
                 system-ui, -apple-system, sans-serif;
    --font-display: 'Segoe UI Variable Display', 'Segoe UI', Tahoma, 'Vazirmatn',
                    system-ui, sans-serif;
}

/* Persian text is visually shorter at the same size; a touch more line height
   keeps the diacritics from crowding. */
[dir='rtl'] body { line-height: 1.7; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

[dir='rtl'] .sidebar {
    border-right: none;
    border-left: 1px solid var(--line);
}

[dir='rtl'] .nav-item.active::before {
    left: auto;
    right: -13px;
    border-radius: 3px 0 0 3px;
}

[dir='rtl'] .nav-badge { margin-left: 0; margin-right: auto; }

/* The drawer slides in from the right on small screens. */
@media (max-width: 980px) {
    [dir='rtl'] .sidebar {
        inset: 0 0 0 auto;
        transform: translateX(100%);
        box-shadow: var(--shadow-lg);
    }
    [dir='rtl'] .sidebar.open { transform: none; }
}

/* ── Accent bars ─────────────────────────────────────────────────────────── */

[dir='rtl'] .stat::before {
    left: auto;
    right: 0;
    border-radius: 3px 0 0 3px;
}

[dir='rtl'] .group {
    border-left: 1px solid var(--line);
    border-right: 3px solid var(--gold);
}
[dir='rtl'] .group.untagged { border-right-color: var(--arcane); }
[dir='rtl'] .group.all-paid { border-right-color: var(--emerald); }

[dir='rtl'] .rp-figure {
    border-left: 1px solid var(--line);
    border-right: 3px solid var(--gold);
}
[dir='rtl'] .rp-figure.rose    { border-right-color: var(--rose); }
[dir='rtl'] .rp-figure.emerald { border-right-color: var(--emerald); }
[dir='rtl'] .rp-figure.teal    { border-right-color: var(--teal); }
[dir='rtl'] .rp-figure.arcane  { border-right-color: var(--arcane); }

/* ── Tables ──────────────────────────────────────────────────────────────── */

[dir='rtl'] table.data th,
[dir='rtl'] table.rp-table th { text-align: right; }

/* Numbers stay left-to-right even inside an RTL row: a price is a number, not
   a word, and 1,110,000 must not be reordered. */
[dir='rtl'] .t-num,
[dir='rtl'] table.data td.t-num,
[dir='rtl'] table.rp-table td.num,
[dir='rtl'] .num,
[dir='rtl'] .mono,
[dir='rtl'] .rp-mono,
[dir='rtl'] .card-num,
[dir='rtl'] .cell-total,
[dir='rtl'] .stat-value,
[dir='rtl'] .page-info,
[dir='rtl'] .audit-when {
    direction: ltr;
    unicode-bidi: embed;
}
[dir='rtl'] .t-num,
[dir='rtl'] table.data td.t-num,
[dir='rtl'] table.rp-table td.num { text-align: left; }

[dir='rtl'] .t-right { text-align: left !important; }
[dir='rtl'] .row-actions { justify-content: flex-start; }

/* Left-aligned cells written inline in the views. */
[dir='rtl'] table.data td[style*='text-align:left'],
[dir='rtl'] table.data th[style*='text-align: left'] { text-align: right !important; }

[dir='rtl'] th.th-sortable .sort-arrow { margin-left: 0; margin-right: 4px; }

/* ── Forms and inputs ────────────────────────────────────────────────────── */

[dir='rtl'] .select {
    padding-right: 12px;
    padding-left: 34px;
    background-position: left 11px center;
}

[dir='rtl'] .filters .search .input { padding-left: 12px; padding-right: 36px; }
[dir='rtl'] .filters .search svg { left: auto; right: 12px; }

/* A card number is digits: keep it left-to-right wherever it is typed. */
[dir='rtl'] input[inputmode='numeric'],
[dir='rtl'] input[type='number'],
[dir='rtl'] input[type='date'] {
    direction: ltr;
    text-align: right;
}

[dir='rtl'] .password-wrap .input { padding-right: 13px; padding-left: 44px; }
[dir='rtl'] .password-toggle { right: auto; left: 5px; }

[dir='rtl'] .switch-track::after { left: auto; right: 2px; }
[dir='rtl'] .switch input:checked + .switch-track::after { transform: translateX(-16px); }

/* ── Misc ────────────────────────────────────────────────────────────────── */

[dir='rtl'] .toast-host { right: auto; left: 18px; }
@media (max-width: 620px) {
    [dir='rtl'] .toast-host { right: 12px; left: 12px; }
}

[dir='rtl'] .modal-foot { justify-content: flex-start; }
[dir='rtl'] .kv dd { text-align: left; }
[dir='rtl'] .bar-value { text-align: left; }

[dir='rtl'] .auth-brand {
    border-right: none;
    border-left: 1px solid var(--line);
}
[dir='rtl'] .auth-brand::after { right: auto; left: -180px; }

[dir='rtl'] .rp-meta { text-align: left; }

/* The printable report has its own table styles in print.css; mirror the same
   two rules here so a PDF saved in Persian reads the right way round. */
[dir='rtl'] table.rp-table th { text-align: right; }
[dir='rtl'] table.rp-table .num { text-align: left; direction: ltr; unicode-bidi: embed; }
[dir='rtl'] .rp-cover, [dir='rtl'] .rp-section h2 { text-align: right; }

/* The language button shows a short code next to the globe. */
.lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 10px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.lang-toggle .lang-code { line-height: 1; }

/* Charts are drawn in SVG with computed coordinates, so they must not be
   mirrored — the axis would read backwards against its own labels. */
[dir='rtl'] .chart,
[dir='rtl'] .chart-wrap { direction: ltr; }
[dir='rtl'] .chart-legend { direction: rtl; }
