/* 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;
}

/* =========================================================================
   Dark mode — Unfold hard-codes light-only colors in a few places. Indigo
   600 on base-900 is ~2.8:1, which makes model links (business names,
   parties, invoices, …) nearly invisible at night. Promote them to the
   lighter primary shades when `.dark` is on <html>.
   ========================================================================= */
.dark a.text-primary-600 { color: rgb(129 140 248); }              /* primary-400 */
.dark a.text-primary-600:hover { color: rgb(165 180 252); }         /* primary-300 */
.dark a.text-primary-600:visited { color: rgb(129 140 248); }

/* The "show all / view" links Unfold ships with a dark variant already keep
   their own class; the above only touches the hard-coded ones. */

/* =========================================================================
   Professional polish — shared card/table affordances used by the
   dashboard templates (hover lift, zebra rows, pill labels).
   ========================================================================= */
.rf-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.rf-card:hover {
  transform: translateY(-2px);
  border-color: rgb(199 210 254);                                  /* primary-200 */
  box-shadow: 0 12px 28px -14px rgb(0 0 0 / 0.22);
}
.dark .rf-card:hover {
  border-color: rgb(67 56 202);                                    /* primary-800 */
  box-shadow: 0 12px 28px -14px rgb(0 0 0 / 0.65);
}

.rf-table tbody tr { transition: background-color 0.15s ease; }
.rf-table tbody tr:nth-child(even) { background: rgb(250 250 250); }
.rf-table tbody tr:hover { background: rgb(238 242 255); }         /* primary-50 */
.dark .rf-table tbody tr:nth-child(even) { background: rgb(255 255 255 / 0.03); }
.dark .rf-table tbody tr:hover { background: rgb(49 46 129 / 0.18); }  /* primary-900/18 */

.rf-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}

/* Keyboard users always get a visible focus ring. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgb(129 140 248);                             /* primary-400 */
  outline-offset: 2px;
}

/* =========================================================================
   Related-object links (add / change / view) beside FK selects. Unfold does
   not load Django's forms.css, so these anchors lose their compact inline
   styling and stretch across the whole field row — the icon sits at the left
   while a ~1000px invisible hit-target swallows clicks. Restore the tiny
   icon button behavior in both themes.
   ========================================================================= */
.related-widget-wrapper {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.related-widget-wrapper-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  opacity: 0.35;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}
.related-widget-wrapper-link:hover,
.related-widget-wrapper-link:focus-visible {
  opacity: 1;
  background-color: rgb(244 244 245);
}
.dark .related-widget-wrapper-link:hover,
.dark .related-widget-wrapper-link:focus-visible {
  background-color: rgb(39 39 42);                                 /* base-800 */
}
.related-widget-wrapper-link img {
  width: 16px;
  height: 16px;
}
.related-widget-wrapper-link:not([href]) {
  pointer-events: none;
  opacity: 0.15;
}
