/* RialFactor admin — RTL & Persian polish on top of Unfold/Tailwind. */

:root { --rf-font: "Vazirmatn", "IRANSans", "Segoe UI", Tahoma, sans-serif; }

body, .unfold, input, select, textarea, button, table, .text-font-default-light {
  font-family: var(--rf-font);
}

/* Never let the Persian font leak onto Material Symbols icon glyphs — the icon
   font is ligature-based, so an overridden family renders the ligature *name*
   as literal text (e.g. "unfold_more"). Force the icon family unconditionally. */
.material-symbols-outlined,
.material-symbols-rounded,
.material-symbols-sharp,
span[class*="material-symbols"] {
  font-family: "Material Symbols Outlined", "Material Symbols Rounded", "Material Symbols Sharp" !important;
  font-variant-numeric: normal !important;
  direction: ltr !important;
  unicode-bidi: normal !important;
}

/* Right-align the shell for Persian. */
html[dir="rtl"] #content, html[dir="rtl"] .unfold main { direction: rtl; }

/* Numeric columns read better tabular + LTR. */
.font-mono, .tabular-nums { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; }

/* Soften card shadows to match the dashboard SVG charts. */
.rounded-default { border-radius: 10px; }

/* Keep long Persian labels from overflowing sidebar. */
.unfold aside a span { overflow: hidden; text-overflow: ellipsis; }

/* =========================================================================
   RTL layout — Unfold is authored LTR with physical `fixed`/`border-r`/`right-*`
   utilities that don't respond to `dir="rtl"`. Pin the sidebar to the RIGHT and
   mirror its chrome.
   ========================================================================= */
html[dir="rtl"] #nav-sidebar {
  right: 0 !important;
  left: auto !important;
  border-right: 0 !important;
  border-left: 1px solid rgb(228 228 231);       /* base-200 */
}
html[dir="rtl"] .dark #nav-sidebar,
.dark html[dir="rtl"] #nav-sidebar,
html[dir="rtl"].dark #nav-sidebar {
  border-left-color: rgb(39 39 42);              /* base-800 */
}

/* Move the drag-to-resize handle to the inner (left) edge in RTL. */
html[dir="rtl"] #nav-sidebar .right-\[-3px\] {
  right: auto !important;
  left: -3px !important;
  cursor: col-resize;
}

/* Sub-menu / collapsible chevrons and paddings read from the right. */
html[dir="rtl"] #nav-sidebar .pl-3 { padding-left: 0; padding-right: 0.75rem; }

/* =========================================================================
   Mobile (< 1280px / below Tailwind `xl`): the sidebar wrapper is `position:
   fixed` and toggled by `sidebarOpen`. Turn it into a right-anchored slide-in
   drawer with a dimmed backdrop, and let the content take the full width.
   ========================================================================= */
@media (max-width: 1279px) {
  html[dir="rtl"] #page > .relative.z-60 .fixed {
    right: 0 !important;
    left: auto !important;
    top: 0;
    bottom: 0;
    z-index: 70;
  }
  html[dir="rtl"] #nav-sidebar {
    box-shadow: -12px 0 32px -12px rgba(0, 0, 0, 0.35);
    max-width: 88vw;
  }

  /* Content should never be squeezed by the (overlay) sidebar on phones. */
  html[dir="rtl"] #main { width: 100% !important; min-width: 0 !important; }

  /* Comfortable tap targets and spacing on small screens. */
  #content { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
  .unfold table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* On phones, let the header hamburger + title wrap cleanly. */
@media (max-width: 640px) {
  #content, .container { padding-left: 0.5rem; padding-right: 0.5rem; }
  h1 { font-size: 1rem; }
  .grid { gap: 0.75rem; }
}

/* Flip a few common physical utilities Unfold uses in forms/toolbars so the
   RTL rhythm stays consistent (borders, rounded corners, spacing). */
/* =========================================================================
   Form-field trailing icons (select chevron, date/number pickers) are pinned
   with physical `right-0 mr-[12px]`. In RTL they belong on the leading (left)
   edge so they don't sit on top of the right-aligned text.
   ========================================================================= */
html[dir="rtl"] span.material-symbols-outlined.right-0 {
  right: auto !important;
  left: 0 !important;
  margin-right: 0 !important;
  margin-left: 12px !important;
}
/* Give inputs room for the now-left icon and clear the right padding. */
html[dir="rtl"] select,
html[dir="rtl"] .unfold select {
  padding-left: 2.25rem;
  padding-right: 0.75rem;
}

/* =========================================================================
   Sticky "N selected" action bar. Unfold pins it `right-0` and drives its
   `left` from `sidebarWidth` (its sidebar-on-the-left assumption). In RTL the
   sidebar is on the right, so mirror it: left:0, right:=sidebar width. A tiny
   JS shim (admin-charts.js) keeps --rf-sb-w synced to the live sidebar width.
   ========================================================================= */
html[dir="rtl"] .fixed.z-50.group-has-\[input\.action-select\:checked\]\:flex,
html[dir="rtl"] div.fixed.bottom-0.right-0.z-50 {
  left: 0 !important;
  right: var(--rf-sb-w, 0px) !important;
  direction: rtl;
}
/* The counter inside the bar uses responsive `sm:ml-auto` (not plain ml-auto),
   which pushes it the wrong way in RTL — mirror every auto-margin variant. */
html[dir="rtl"] .ml-auto,
html[dir="rtl"] .sm\:ml-auto,
html[dir="rtl"] .lg\:ml-auto {
  margin-left: 0 !important;
  margin-right: auto !important;
}
html[dir="rtl"] .mr-auto,
html[dir="rtl"] .sm\:mr-auto,
html[dir="rtl"] .lg\:mr-auto {
  margin-right: 0 !important;
  margin-left: auto !important;
}

/* Breadcrumb / header chevrons point the correct way in RTL. */
html[dir="rtl"] nav [class*="chevron_right"],
html[dir="rtl"] .material-symbols-outlined.rotate-0 { transform: scaleX(-1); }

/* =========================================================================
   Changelist tables — Unfold right-aligns the header row (logical props) but
   leaves the data cells physically left-aligned, so numbers/text drift away
   from their headers. Align every cell to the RTL leading (right) edge.
   ========================================================================= */
html[dir="rtl"] #result_list th,
html[dir="rtl"] #result_list td,
html[dir="rtl"] #changelist table th,
html[dir="rtl"] #changelist table td {
  text-align: right !important;
}
/* Keep the row-select checkbox + boolean/action icon columns centered. */
html[dir="rtl"] #result_list th.action-checkbox-column,
html[dir="rtl"] #result_list td.action-checkbox,
html[dir="rtl"] #result_list .field-boolean,
html[dir="rtl"] #result_list th:has(input[type="checkbox"]),
html[dir="rtl"] #result_list td:has(input[type="checkbox"]) {
  text-align: center !important;
}
/* Numeric money cells stay right-aligned with LTR digits (grouping intact). */
html[dir="rtl"] #result_list td .font-mono,
html[dir="rtl"] #result_list td .tabular-nums {
  display: inline-block;
  direction: ltr;
  text-align: right;
}
