/* ============================================================
   Right-to-left + Persian typography overrides.
   Only active when <html dir="rtl"> (fa, ar, ur).

   RTL pages load the OFFICIAL AdminLTE 4.0.0 RTL build (adminlte/css/adminlte.rtl.min.css,
   chosen in layout/base.html by the same ${dir} as <html dir>). Its bundled Bootstrap already
   mirrors btn-group / input-group / pagination / list-group corners and shared borders, the
   ms-, me-, ps-, pe-, text-start, float-start and start-0 / end-0 utilities, form-select arrows, tick boxes,
   dropdowns, the header lists and the sidebar collapse / off-canvas. This file must NOT patch
   any of those again: a html[dir=rtl] corner, margin or float flip here now double-flips the
   component back to the LTR side (RtlStylesheetTest pins the removed rules, and
   scripts/ui-checks/rtl.js measures the groups in a real browser).
   What stays here is app-specific: the RTL faces and digit rules, directional icon mirroring
   and the hover nudges of app components. App components use CSS logical properties
   (inset-inline-end, border-inline-end, padding-inline-start, text-align:start) instead of a
   dir-scoped patch.
   ============================================================ */

/* Vazirmatn, the Persian/Arabic face, bundled locally — css/vazirmatn.css declares the
   @font-face. It was already named first here, but no @font-face ever backed it, so unless the
   reader happened to have Vazir installed the whole Farsi UI silently fell back to Tahoma.
   Vazirmatn carries Latin as well as Persian, so ear tags and ISO dates stay in it too. */
html[dir="rtl"] {
    --font-rtl: "Vazirmatn", "Vazir", "Tahoma",
                -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* Arabic gets Cairo (css/vazirmatn.css declares it); Vazirmatn stays the fallback so a glyph
   Cairo lacks still renders in the same family of shapes rather than in Tahoma. */
html[lang="ar"] {
    --font-rtl: "Cairo", "Vazirmatn", "Vazir", "Tahoma",
                -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

html[dir="rtl"],
html[dir="rtl"] body {
    font-family: var(--font-rtl);
    letter-spacing: 0;
}

/* Numerals must sit in the same face as the words around them. Persian digits (۰-۹) are
   emitted app-wide by fa-digits.js, and any element that keeps the system UI font renders them
   in a different design and a different width — visible the moment a table column mixes a
   label and a figure. Bootstrap's reboot already inherits the face onto form controls; this is
   belt-and-braces for the widgets that set a family of their own. */
html[dir="rtl"] button,
html[dir="rtl"] input,
html[dir="rtl"] select,
html[dir="rtl"] textarea,
html[dir="rtl"] optgroup,
html[dir="rtl"] .btn,
html[dir="rtl"] .form-control,
html[dir="rtl"] .form-select,
html[dir="rtl"] .badge,
html[dir="rtl"] .tooltip,
html[dir="rtl"] .popover,
html[dir="rtl"] .toast,
html[dir="rtl"] .modal,
html[dir="rtl"] table,
html[dir="rtl"] .table {
    font-family: var(--font-rtl);
}

/* Hover nudges toward the reading direction (theme.css moves them +2px in LTR). */
html[dir="rtl"] .sidebar-menu .nav-link:hover { transform: translateX(-2px); }
html[dir="rtl"] .quick-link:hover { transform: translateX(-2px); }

/* Directional icons must mirror in RTL: a "next"/forward chevron or arrow should point LEFT, and a
   "back" one should point RIGHT. Flipping every directional glyph with scaleX(-1) does exactly that
   (right→left, left→right) and covers cards/nav/pagination automatically — new components included. */
html[dir="rtl"] .bi-chevron-right,
html[dir="rtl"] .bi-chevron-left,
html[dir="rtl"] .bi-chevron-double-right,
html[dir="rtl"] .bi-chevron-double-left,
html[dir="rtl"] .bi-arrow-right,
html[dir="rtl"] .bi-arrow-left,
html[dir="rtl"] .bi-arrow-right-short,
html[dir="rtl"] .bi-arrow-left-short,
html[dir="rtl"] .bi-arrow-return-right,
html[dir="rtl"] .bi-arrow-return-left,
html[dir="rtl"] .bi-arrow-bar-right,
html[dir="rtl"] .bi-arrow-bar-left,
html[dir="rtl"] .bi-caret-right-fill,
html[dir="rtl"] .bi-caret-left-fill,
html[dir="rtl"] .bi-caret-right,
html[dir="rtl"] .bi-caret-left {
    display: inline-block;
    transform: scaleX(-1);
}

/* ------------------------------------------------------------------
   Persian numerals are never set in tabular figures, and never tracked.

   Vazirmatn's tabular digits are a quarter wider than its proportional ones — measured, 105.4px
   against 83.2px for ۱۲۳۴۵۶۷۸۹۰ at 16px — so the fixed advance that steadies a Latin dashboard
   makes a Persian one look spelled out one digit at a time. That was the reported fault on
   /dashboard, where .dash-figure asks for tabular figures. Column alignment is worth less than a
   figure that reads as a single number.

   Positive letter-spacing is the other half: tracking is a Latin device, and it pulls apart the
   joins that make Persian and Arabic legible, spacing out the digits with them.

   The named selectors are not redundant with the universal one. app.css and theme.css load AFTER
   this file, so a bare "html[dir=rtl] body *" (0,1,2) loses the tie to any single-class rule
   there; the dir-scoped class selectors win outright. The universal rule is the net that catches
   whatever gets added next.
   ------------------------------------------------------------------ */
html[dir="rtl"] .stat-value,
html[dir="rtl"] .dash-figure,
html[dir="rtl"] .stat-card .stat-value,
html[dir="rtl"] body * {
    font-variant-numeric: normal;
}

html[dir="rtl"] .dash-figure,
html[dir="rtl"] body * {
    letter-spacing: normal;
}

/* Amount column emphasis */
.amount-cell { font-weight: 600; white-space: nowrap; }

/* Header end-side controls: even spacing in both directions (the RTL build's .ms-auto already puts
   the group at the far end of the bar). */
.app-header .navbar-nav.ms-auto { gap: 0.35rem; }
.app-header .navbar-nav.ms-auto .theme-toggle { position: relative; z-index: 1; }

/* ---------- Custom Jalali date picker ---------- */
.jdp-pop {
    background: var(--bg-elevated);
    border: 1px solid var(--surface-border-strong);
    border-radius: 14px;
    padding: 0.6rem;
    width: 264px;
    box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.65);
    z-index: 2000;
}
.jdp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    gap: 0.3rem;
}
.jdp-head select.form-select {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.3rem 0.5rem;
    padding-inline-end: 2rem;      /* clear of the select arrow at the end side */
    border-radius: 8px;
    font-size: 0.85rem;
}
.jdp-head .jdp-month { flex: 1 1 58%; }
.jdp-head .jdp-year { flex: 1 1 42%; }
.jdp-title { font-weight: 600; color: var(--text-primary); font-size: 0.95rem; }
.jdp-nav {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    color: var(--text-secondary);
    border-radius: 8px;
    width: 30px; height: 30px;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
}
.jdp-nav:hover { color: var(--text-primary); background: var(--surface-strong); }
.jdp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.jdp-wd { text-align: center; font-size: 0.7rem; color: var(--text-muted); padding: 0.25rem 0; }
.jdp-day {
    background: transparent;
    border: 0;
    color: var(--text-primary);
    border-radius: 8px;
    height: 32px;
    cursor: pointer;
    font-size: 0.85rem;
    font-variant-numeric: normal;
}
.jdp-day:hover { background: var(--surface-strong); }
.jdp-empty { visibility: hidden; pointer-events: none; }
.jdp-sel { background: var(--gradient-primary); color: #fff; }
.jdp-today { border: 1px solid var(--surface-border-strong); }

/* The shared CSS refresh loads later; these dir-scoped rules preserve joined
   RTL text and proportional digits in labels, headings and dashboard figures. */
html[dir="rtl"] .brand-text,
html[dir="rtl"] .app-content-header h3,
html[dir="rtl"] .card h2.h4,
html[dir="rtl"] .nav-header,
html[dir="rtl"] .table > thead th {
    letter-spacing: normal;
    font-variant-numeric: normal;
}
