/* v27/S7 — ax-lines: بازطراحیِ بنیادیِ «همه‌ی» اینلاین‌های جدولی به «کارت‌ردیف» (RTL، بدونِ
 * اسکرولِ افقی). دامنه: هر اینلاینِ tabular (‎.tabular.inline-related‎) — سراسری، نه opt-in.
 *
 * بینش (v24): اینلاینِ جدولیِ Unfold از قبل روی موبایل «کارتی» است (هر td با ::before برچسب و
 * flex؛ فقط در lg: به table-cell می‌رود). این‌جا همان لِیِ کارتی را در «همه‌ی عرض‌ها» فعال
 * می‌کنیم؛ ماشین‌آلاتِ فرم‌ست (جدول/empty-form/add-row/DELETE) دست‌نخورده می‌ماند. */

/* ۱) بدونِ اسکرولِ افقی */
.tabular.inline-related .formset-wrapper,
.tabular.inline-related .ax-formset-wrapper {
  overflow-x: visible !important;
  box-shadow: none !important;
  border: 0 !important;
}
.tabular.inline-related .simplebar-content-wrapper { overflow: visible !important; }

/* ۲) سرستونِ جدولی پنهان (برچسب‌ها بالای هر فیلد با ::before) */
.tabular.inline-related table.formset > thead { display: none !important; }
.tabular.inline-related table.formset > tfoot .field-tabular::before { display: none !important; }

/* ۳) هر ردیف (tbody.form-group) = یک کارت */
.tabular.inline-related table.formset > tbody.form-group {
  display: block !important;
  border: 1px solid var(--ax-sidebar-border, #E5E7EC);
  border-radius: 12px;
  margin: 8px 0;
  padding: 10px 42px 10px 12px;   /* جای شماره‌ی ردیف در سمتِ راست (RTL) */
  background: #fff;
  position: relative;
}
.tabular.inline-related table.formset > tbody.form-group:nth-of-type(2n) {
  background: color-mix(in srgb, var(--ax-gold, #C9A14A) 5%, #fff);
}
html.dark .tabular.inline-related table.formset > tbody.form-group,
.dark .tabular.inline-related table.formset > tbody.form-group { background: #1b1f26; border-color: #2a2e37; }
/* hotfix v27 — فقط فرمِ خالیِ __prefix__ (empty-form) مخفی می‌شود. کلاسِ template را مخفی نکن:
 * در Unfold هر فرمِ unbound (ردیف‌های extra و «کلونِ» ساخته‌شده با دکمه‌ی افزودن) کلاسِ template
 * دارد و app.js هنگامِ کلون فقط empty-form را برمی‌دارد؛ مخفی‌کردنِ template یعنی «ردیفِ تازه
 * نامرئی درج می‌شود» (باگِ add-row). */
.tabular.inline-related table.formset > tbody.empty-form { display: none !important; }

/* v31/P5.S10 — مقیاسِ z یکپارچه (مستند): محتوا(۰) < آیکنِ ردیف(۱۰) < منوی بازشو/Select2(۱۰۰۰)
 * < دیالوگ(۱۱۰۰) < توست(۱۲۰۰). هیچ z-indexِ خام — همیشه var. */
:root {
  --ax-z-content: 0; --ax-z-rowicons: 10; --ax-z-dropdown: 1000;
  --ax-z-dialog: 1100; --ax-z-toast: 1200;
}
.select2-dropdown { z-index: var(--ax-z-dropdown) !important; }

/* v31/P5.S10 — شماره/ابزارِ ردیف: دیگر absolute نیست؛ «ستونِ رزروِ» ثابت در آغازِ کارت
 * (عضوِ واقعیِ گرید = td.delete وقتی هست) — روی هیچ عنصرِ تعاملی نمی‌افتد. */
.tabular.inline-related .ax-rownum {
  position: static;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--ax-gold, #C9A14A); color: #15171C;
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  z-index: var(--ax-z-rowicons);
}
.tabular.inline-related tr.form-row > td.delete {
  order: -1; flex: 0 0 48px !important; min-width: 48px !important;
  display: flex !important; flex-direction: column; gap: 6px;
  align-items: center; justify-content: center; align-self: stretch;
  border-inline-end: 1px dashed rgba(201, 161, 74, .45) !important;
}
.tabular.inline-related tr.form-row > td.delete input[type="checkbox"] {
  width: 20px; height: 20px;                                   /* هدفِ لمسیِ ≥40 با پدینگِ سلول */
}

/* ۴) ردیفِ فیلدها → گریدِ واکنش‌گرا (برچسب بالای فیلد؛ در موبایل تک‌ستون) */
.tabular.inline-related tr.form-row {
  display: flex !important; flex-wrap: wrap; gap: 6px 12px; align-items: flex-end;
}

/* ۵) هر سلولِ فیلد → ستونی (برچسب بالای فیلد) */
.tabular.inline-related td.field-tabular {
  display: flex !important; flex-direction: column; align-items: stretch;
  border: 0 !important; min-height: 0 !important;
  padding: 2px 0 !important; margin: 0 !important;
  flex: 1 1 150px; min-width: 120px;
}
.tabular.inline-related td.field-tabular::before {
  display: block !important;
  margin: 0 0 2px !important; padding: 0 !important; text-align: start !important;
  font-size: 11px !important; font-weight: 600 !important;
  color: var(--ax-sidebar-header, #6b7280) !important;
}
.tabular.inline-related td.field-tabular input,
.tabular.inline-related td.field-tabular select,
.tabular.inline-related td.field-tabular textarea,
.tabular.inline-related td.field-tabular .select2-container { width: 100% !important; min-width: 0 !important; }

/* ۶) «مبلغِ سطر» چیپِ طلایی */
.tabular.inline-related td.field-line_total_display,
.tabular.inline-related td[class*="field-"][class*="total"] { flex: 0 0 auto; align-items: flex-start; }
.tabular.inline-related td.field-line_total_display p,
.tabular.inline-related td.field-line_total_display .readonly {
  background: color-mix(in srgb, var(--ax-gold, #C9A14A) 20%, #fff);
  color: #7a5c12; font-weight: 700; border-radius: 999px; padding: 4px 14px;
  white-space: nowrap; display: inline-block;
}

/* ۷) ستونِ حذف */
.tabular.inline-related td.delete, .tabular.inline-related td.field-tabular.delete {
  flex: 0 0 auto; align-self: center;
}

/* ۸) دکمه‌ی «افزودنِ ردیف» خط‌چین و تمام‌عرض */
.tabular.inline-related .add-row td, .tabular.inline-related tfoot tr:last-child td { display: block !important; }
.tabular.inline-related a.add-row {
  display: block; text-align: center;
  border: 1.5px dashed var(--ax-gold, #C9A14A); border-radius: 10px;
  padding: 10px; color: #7a5c12; font-weight: 700; background: transparent;
}

/* ۹) نوارِ سرِ پنل (تعداد ردیف) */
.tabular.inline-related .ax-lines-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 2px 8px; font-size: 13px; color: var(--ax-sidebar-header, #6b7280);
}
.tabular.inline-related .ax-lines-head b { color: var(--ax-gold, #C9A14A); }

/* ۱۰) چیپِ معادله‌ی مبلغِ سطر: مقدار × قیمت واحد − تخفیف = مبلغِ سطر (JS live) */
.ax-eq-chip {
  flex: 1 1 100%; order: 99; margin-top: 4px;
  background: color-mix(in srgb, var(--ax-gold, #C9A14A) 12%, #fff);
  border: 1px solid color-mix(in srgb, var(--ax-gold, #C9A14A) 35%, #fff);
  border-radius: 10px; padding: 4px 12px; font-size: 12px; color: #7a5c12;
  direction: rtl; display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.ax-eq-chip b { color: #5a4409; }
html.dark .ax-eq-chip, .dark .ax-eq-chip { background: #2a2410; border-color: #4a3f18; color: #d9c38a; }

/* ۱۱) نوارِ ابزارِ ردیف (ذخیره/تکثیر/حذف/مشاهده) — افقی، یکدست */
.tabular.inline-related .ax-row-toolbar {
  display: flex; gap: 6px; align-items: center; flex: 0 0 auto; align-self: center; order: 100;
}
.tabular.inline-related .ax-row-toolbar button,
.tabular.inline-related .ax-row-toolbar a {
  border: 1px solid var(--ax-sidebar-border, #E5E7EC); background: #fff; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 6px 8px; border-radius: 8px; text-decoration: none;
  color: var(--ax-sidebar-header, #6b7280); display: inline-flex; align-items: center;
}
.tabular.inline-related .ax-row-toolbar button:hover,
.tabular.inline-related .ax-row-toolbar a:hover { border-color: var(--ax-gold, #C9A14A); color: #7a5c12; }
.tabular.inline-related .ax-row-toolbar .ax-save.ax-dirty { border-color: var(--ax-gold, #C9A14A); color: #7a5c12; font-weight: 700; }
html.dark .tabular.inline-related .ax-row-toolbar button,
.dark .tabular.inline-related .ax-row-toolbar a { background: #1b1f26; border-color: #2a2e37; }

/* ۱۲) خطاهای اعتبارسنجیِ هر ردیف */
.tabular.inline-related td.field-tabular.errors input,
.tabular.inline-related td.field-tabular.errors select { border-color: #c0392b !important; }

/* ۱۳) v28/S9 — آیکن‌های کنارِ FK (افزودن/ویرایش/حذف/مشاهده): نوارِ «افقیِ» فشرده، هم روی
 * کارت‌ها و هم فرم‌های عادی. رپرِ استوکِ جنگو (لینک‌های آیکنی) پیش‌تر زیرِ فلکس-ستونِ کارت
 * عمودی تلنبار می‌شد؛ رپرِ خودِ Unfold (دکمه‌ی ⋯) هم row می‌ماند. */
.related-widget-wrapper {
  display: flex !important; flex-direction: row !important; align-items: center;
  gap: 5px; flex-wrap: nowrap; min-width: 0;
}
.related-widget-wrapper > select,
.related-widget-wrapper > .select2,
.related-widget-wrapper .select2-container { flex: 1 1 auto; min-width: 0; }
a.related-widget-wrapper-link {
  display: inline-flex; align-items: center; justify-content: center;
  /* v32/P1.S1 — هدفِ لمسیِ ≥40×40 (با padding، نه جابه‌جاییِ absolute)؛ گلیف همان 15px. */
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 10px;
  color: #9AA1AC; text-decoration: none;
}
a.related-widget-wrapper-link:hover { color: #20293A; background: rgba(154,161,172,.12); }
a.related-widget-wrapper-link img,
a.related-widget-wrapper-link svg { width: 15px; height: 15px; filter: grayscale(1) opacity(.75); }
a.related-widget-wrapper-link:hover img,
a.related-widget-wrapper-link:hover svg { filter: none; }
a.related-widget-wrapper-link .material-symbols-outlined { font-size: 16px; }
/* عرضِ خیلی کم (کارتِ باریک): لینک‌ها جمع می‌شوند و «⋯» بازشان می‌کند (ax_lines.js). */
.ax-rel-collapsed a.related-widget-wrapper-link { display: none; }
.ax-rel-collapsed.ax-rel-open a.related-widget-wrapper-link { display: inline-flex; }
.ax-rel-toggle {
  flex: 0 0 auto; border: 1px solid var(--ax-sidebar-border, #E5E7EC); background: #fff;
  border-radius: 6px; width: 22px; height: 22px; line-height: 1; cursor: pointer;
  color: #9AA1AC; font-size: 14px; display: none; width: 40px; height: 40px; }
.ax-rel-collapsed .ax-rel-toggle { display: inline-flex; align-items: center; justify-content: center; }

/* ۱۴) v29/S7 — آیکن‌های FK «چسبیده به فیلدِ خودشان» (نه شناور وسطِ فاصله‌ی ستون‌ها):
 * رپر = یک واحدِ ردیفیِ کامل [ورودی][نوارِ آیکن]؛ ورودی fluid، آیکن‌ها بلافاصله بعدش. */
.related-widget-wrapper {
  justify-content: flex-start !important;
  align-self: stretch;              /* خنثی‌سازیِ items-centerِ رپرِ بیرونیِ Unfold */
  width: 100%;
}
.related-widget-wrapper > select:first-child,
.related-widget-wrapper > .select2:first-child,
.related-widget-wrapper > .select2-container:first-child,
.related-widget-wrapper > input:first-child { flex: 1 1 auto; min-width: 0; }
.related-widget-wrapper > select + a.related-widget-wrapper-link,
.related-widget-wrapper > .select2 + a.related-widget-wrapper-link,
.related-widget-wrapper > .select2-container + a.related-widget-wrapper-link,
.related-widget-wrapper > input + a.related-widget-wrapper-link { margin-inline-start: 6px; }
a.related-widget-wrapper-link { position: static !important; }   /* هرگز absolute */

/* ۱۵) v29/S7 — ورودیِ فایلِ فارسی (AxClearableFileInput) */
.ax-file { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; max-width: 100%; }
.ax-file input[type="file"] {
  position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;                       /* مخفی ولی قابلِ‌فوکوس */
}
.ax-file .ax-file-btn {
  background: #C9A14A; color: #fff; border-radius: 8px; padding: 5px 14px;
  font-size: 12.5px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.ax-file .ax-file-btn:hover { background: #B8923E; }
.ax-file .ax-file-name {
  color: #6b7280; font-size: 12px; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ax-file .ax-file-current {
  border: 1px dashed #C9A14A; color: #7a5c12; border-radius: 8px; padding: 3px 10px;
  font-size: 12px; text-decoration: none; white-space: nowrap;
}
.ax-file .ax-file-clear { color: #b91c1c; font-size: 12px; display: inline-flex;
                          align-items: center; gap: 4px; cursor: pointer; }
html.dark .ax-file .ax-file-name, .dark .ax-file .ax-file-name { color: #9AA1AC; }

/* ۱۶) v30/S2 — سامانه‌ی اندازه‌ی فیلد بر اساسِ «نوع» (ریشه‌ایِ مشکلِ فیلدهای ریز و ردیف‌های
 * به‌هم‌ریخته). درونِ کارت‌ها (td.field-tabular با flex) و فرم‌های عادی، عرضِ هر فیلد از نوعش
 * می‌آید: رابطه‌ای/متنی پهن، عددی/تاریخ متوسط، چک‌باکس فشرده، textarea/فایل تمام‌ردیف. */

/* — کارت‌های اینلاین — */
.tabular.inline-related td.field-tabular:has(select),
.tabular.inline-related td.field-tabular:has(.select2-container),
.tabular.inline-related td.field-tabular:has(.related-widget-wrapper) {
  flex: 2 1 260px; min-width: 240px;                    /* fw-rel: رابطه‌ای/انتخابی پهن */
}
.tabular.inline-related td.field-tabular:has(input[type="text"]:not([name$="quantity"]):not([name$="price"]):not([name$="amount"]):not([name*="date"])):not(:has(select)):not(:has(.select2-container)) {
  flex: 2 1 220px; min-width: 200px;                    /* fw-text: متنی پهن (شرح…) */
}
.tabular.inline-related td.field-tabular:has(input[name$="quantity"]),
.tabular.inline-related td.field-tabular:has(input[name$="price"]),
.tabular.inline-related td.field-tabular:has(input[name$="amount"]),
.tabular.inline-related td.field-tabular:has(input[name*="date"]) {
  flex: 1 1 170px; min-width: 150px;                    /* fw-num/money/date: متوسطِ راحت */
}
.tabular.inline-related td.field-tabular:has(input[type="checkbox"]):not(:has(select)):not(:has(input[type="text"])) {
  flex: 0 0 auto; min-width: 84px; justify-content: flex-end;   /* fw-flag: فشرده و تراز */
}
.tabular.inline-related td.field-tabular:has(textarea),
.tabular.inline-related td.field-tabular:has(.ax-file) {
  flex: 1 1 100%; min-width: 100%;                      /* fw-full: تمام‌ردیف */
}

/* — بلندا و تایپوگرافی: نام‌های بلندِ کالا/طرف خوانا — */
.tabular.inline-related td.field-tabular input:not([type="checkbox"]),
.tabular.inline-related td.field-tabular select,
.tabular.inline-related td.field-tabular .select2-container .select2-selection--single {
  min-height: 40px !important; font-size: 0.95rem;
}
.tabular.inline-related .select2-container .select2-selection__rendered { line-height: 38px !important; }
.tabular.inline-related .select2-container .select2-selection__arrow { height: 38px !important; }
.tabular.inline-related td.field-tabular .ax-file .ax-file-btn { padding: 9px 14px; }  /* هم‌قدِ ورودی‌ها */

/* — فرم‌های عادی (فیلدست‌ها): سلکت/رابطه‌ای هرگز ریز نشود — */
.field-line:has(.select2-container) .select2-container,
.field-line:has(select) select { min-width: 260px; max-width: 100%; }
.field-line .select2-container .select2-selection--single { min-height: 40px !important; }
.field-line .select2-container .select2-selection__rendered { line-height: 38px !important; }
.field-line input[type="text"] { min-height: 40px; font-size: 0.95rem; }
.field-line:has(input[type="checkbox"]) { align-items: center; }

/* — منوی بازشوی Select2 دستِ‌کم به پهنای فیلدش (گزینه‌ها بریده نشوند) — */
.select2-dropdown { min-width: 260px !important; }

/* v31/P2.S3 — گونه‌ی قفل تا انتخابِ کالا */
.ax-variant-locked::before { content: "اول کالا را انتخاب کنید"; color: #b45309; font-size: 12px; }

/* ۱۷) v35/P4.S7 — پایانِ سرریزِ آیکن روی سلولِ همسایه (شرح): رپر هرگز از سلولش بیرون
 * نمی‌زند؛ حالتِ باز، آیکن‌ها را «داخلِ همان سلول» می‌شکند (wrap)، نه به پهلو. */
.tabular.inline-related td.field-tabular { overflow: clip; }
.tabular.inline-related td.field-tabular .related-widget-wrapper { min-width: 0; max-width: 100%; }
.tabular.inline-related .related-widget-wrapper.ax-rel-collapsed.ax-rel-open { flex-wrap: wrap; }

/* ۱۸) v37/P1.S1 — ایزوله‌سازیِ لایه‌ی کارت از ویجت‌های استانداردِ جنگو/Unfold.
 * خانواده‌ی «هر روز یک چیز می‌شکند»: کارتِ سراسری روی اینلاین‌ها، ویجت‌های عرض‌خواه را له می‌کرد.
 * سلولِ حاویِ SelectFilter (filter_horizontal) = تمام‌ردیف، بدونِ clip، دوجعبه‌ی پهن. */
.tabular.inline-related td.field-tabular:has(.selector) {
  flex: 1 1 100% !important; min-width: 100% !important; overflow: visible !important;
}
.tabular.inline-related td.field-tabular .selector {
  display: flex !important; gap: 12px; width: 100%; align-items: stretch;
}
.tabular.inline-related td.field-tabular .selector select {
  min-height: 180px !important; min-width: 200px !important; height: auto !important;
}
.tabular.inline-related td.field-tabular .selector .selector-available,
.tabular.inline-related td.field-tabular .selector .selector-chosen { flex: 1 1 45%; }
/* فرم‌های عادی: جعبه‌های دوقلو هرگز زیرِ قاعده‌ی min-widthِ سلکتِ عمومی له/کش نشوند */
.field-line .selector select { min-width: 200px; min-height: 180px; }
/* عمومی: هر سلولِ کارت که ویجتِ پیچیده‌ی عرض‌خواه دارد (map/datetime shortcuts/…) clip نشود */
.tabular.inline-related td.field-tabular:has(.datetimeshortcuts) { overflow: visible !important; }
