/* site.css */
:root {
  /* navy/gold/cream/brand come from themes.css per tenant theme */
  --green:  #1B5E20;
  --red:    #A52A2A;
}

/* Body font/colours, the app shell, cards, tables, buttons, forms and dark mode
   live in erp.css (loaded after themes.css). This file keeps the legacy helpers,
   the mobile safety nets and the print stylesheet. */

/* ── Cards ──────────────────────────────────────── */
.card-header.section-header { padding: .85rem 1.1rem; }

/* ── Buttons ─────────────────────────────────────── */
.btn-gold      { background: var(--gold);  color: var(--navy); border-color: #b8940a; font-weight: 600; }
.btn-gold:hover { background: #b8940a; color: var(--navy); }

/* ── Stat card ───────────────────────────────────── */
.stat-card {
  background: #fff;
  border: 1px solid #ECE7DF;
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(31,24,16,.06);
}
.stat-card .stat-label { font-size: .78rem; color: #5a6480; margin-bottom: .3rem; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--navy); line-height: 1.1; }
.stat-card .stat-sub   { font-size: .75rem; color: #888; margin-top: .2rem; }

/* ── Section divider ─────────────────────────────── */
.section-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1.2rem 0 .7rem;
  color: var(--navy2);
  font-size: .82rem;
  font-weight: 600;
}
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #DEE3EC;
}

/* ── Status badges ───────────────────────────────── */
.badge-sent    { background: #E8F5E9; color: #1B5E20; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-pending { background: #FFF8E1; color: #E65100; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-info    { background: #E3F2FD; color: #0D47A1; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }

/* ── Form improvements ───────────────────────────── */
.form-label { font-size: .83rem; color: #444; font-weight: 500; margin-bottom: .3rem; }

/* ── Dashboard chart container ───────────────────── */
.chart-container {
  position: relative;
  height: 260px;
}

/* ── Page header ─────────────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1.5rem;
}
.page-header h4 { color: var(--navy); margin: 0; font-weight: 600; }

/* ── Toast ───────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.5rem; left: 1.5rem; z-index: 9999; }

/* ── Responsive ──────────────────────────────────── */

/* Tablets */
@media (max-width: 992px) {
  .dropdown-item { font-size: .78rem; padding: .35rem .8rem; }
  .container-fluid { padding-left: 10px; padding-right: 10px; }
  .stat-card { padding: .6rem .5rem; }
  .stat-card .stat-value { font-size: 1.15rem; }
  .stat-card .stat-label { font-size: .72rem; }
  .table { font-size: .8rem; }
  .table th, .table td { padding: .35rem .4rem; }
  .modal-lg, .modal-xl { max-width: 95vw; }
}

/* Mobile phones */
@media (max-width: 576px) {
  body { font-size: .82rem; }
  .page-header { flex-direction: column; align-items: flex-start; gap: .5rem; }
  .page-header h4 { font-size: 1.1rem; }

  /* Stat cards: 2 per row on mobile */
  .stat-card { padding: .5rem .4rem; margin-bottom: .3rem; }
  .stat-card .stat-value { font-size: 1rem; }
  .stat-card .stat-label { font-size: .68rem; }
  /* col-auto wrappers size to content and don't wrap 2-up on their own —
     force their column to 50% so stat cards tile two per row */
  .row > [class*="col"]:has(> .stat-card) { flex: 0 0 50%; max-width: 50%; }

  /* ── Override ALL inline widths on table cells ── */
  .table th[style*="width"],
  .table td[style*="width"],
  .table th[style*="min-width"],
  .table td[style*="min-width"] {
    width: auto !important;
    min-width: 0 !important;
  }

  /* Drop the inline min-width on the TABLE element itself (e.g. report tables
     with style="min-width:900px"). Otherwise, on RTL phones the table opens
     scrolled to the right showing only الكود/الاسم while the amount columns sit
     off-screen behind a sideways scroll. With min-width:0 the table only scrolls
     when its CONTENT genuinely overflows, so few-column reports show in full. */
  table.table[style*="min-width"] { min-width: 0 !important; }

  /* Tables: smaller text, horizontal scroll */
  .table { font-size: .75rem; }
  .table th, .table td { padding: .25rem .35rem; white-space: normal !important; }
  .table-responsive { -webkit-overflow-scrolling: touch; }

  /* ── Override fixed max-width on cards/containers ── */
  .card[style*="max-width"],
  div[style*="max-width"] {
    max-width: 100% !important;
  }

  /* ── Override fixed widths on inputs/selects ── */
  input[style*="width"],
  select[style*="width"],
  .form-control[style*="width"],
  .form-select[style*="width"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* ── Container: less padding on mobile ── */
  .container-fluid { padding-left: 8px !important; padding-right: 8px !important; }

  /* Cards */
  .card { border-radius: 8px; }
  .card-header.section-header { padding: .6rem .8rem; font-size: .82rem; border-radius: 8px 8px 0 0 !important; }

  /* Forms in mobile */
  .form-control-sm, .form-select-sm { font-size: .78rem; padding: .3rem .5rem; }
  .form-label { font-size: .76rem; }

  /* Buttons */
  .btn-sm { font-size: .75rem; padding: .25rem .6rem; }
  .btn-xs { font-size: .68rem; padding: .1rem .3rem; }

  /* Modals: full width on mobile */
  .modal-dialog { margin: .5rem; max-width: calc(100vw - 1rem); }
  .modal-dialog-centered { min-height: calc(100% - 1rem); }
  .modal-body { padding: .8rem; }
  .modal-header { padding: .6rem .8rem; }
  .modal-header .modal-title { font-size: .95rem; }
  .modal-footer { padding: .5rem .8rem; }
  .modal-body .row.g-3 > [class*="col-"] { flex: 0 0 100%; max-width: 100%; }
  .modal-body .row.g-2 > [class*="col-"] { flex: 0 0 50%; max-width: 50%; }

  /* Sidebar: stack below on mobile */
  .col-lg-3, .col-lg-4 { margin-top: 1rem; }

  /* Filter forms: stack and fill width */
  .card-body .row.g-2 > .col-auto { flex: 0 0 50%; max-width: 50%; margin-bottom: .3rem; }
  .row.g-2 > .col-auto .form-control,
  .row.g-2 > .col-auto .form-select,
  .row.g-3 > .col-auto .form-control,
  .row.g-3 > .col-auto .form-select { width: 100% !important; }

  /* Hide less important columns on mobile */
  .d-mobile-none { display: none !important; }

  /* Dropdown menus */
  .dropdown-menu { font-size: .8rem; }

  /* Alert text */
  .alert { font-size: .78rem; padding: .5rem .75rem; }

  /* Badge */
  .badge { font-size: .68rem; }

  /* ── Charts: prevent overflow ── */
  .chart-container { height: 200px; width: 100% !important; }
  canvas[style*="width"],
  canvas[style*="height"] { width: 100% !important; height: auto !important; }
}

/* ── Master data table improvements ─────────────────────── */
.table td, .table th {
  color: #1a1a2e;
}
.table tbody tr td {
  color: #212529;
}
.table-secondary td {
  color: #6c757d !important;
  font-style: italic;
}
.badge-info {
  background: #1565C0 !important;
  color: #ffffff !important;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 600;
}
.badge-type-1 { background: #1B5E20; color: #fff; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-type-2 { background: #E65100; color: #fff; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-type-3 { background: #1565C0; color: #fff; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-kg     { background: #6A1B9A; color: #fff; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-head   { background: #1565C0; color: #fff; padding: 3px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-active   { background: #1B5E20; color: #fff; padding: 3px 8px; border-radius: 4px; font-size: .75rem; }
.badge-inactive { background: #757575; color: #fff; padding: 3px 8px; border-radius: 4px; font-size: .75rem; }

/* ── Master tabs ─────────────────────────────────────────── */
.nav-tabs .nav-link { color: #495057; font-weight: 500; }
.nav-tabs .nav-link.active { color: var(--brand); font-weight: 700; border-bottom: 3px solid var(--brand); }

/* ── Master section header ───────────────────────────────── */
.master-section-title {
  background: var(--navy);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ═══════════════════════════════════════════════════════════
   GLOBAL MOBILE SAFETY NET  (added 2026-05-31)
   The per-breakpoint blocks above already handle the navbar, stat
   cards, modals, charts and inline-width inputs. This block closes
   the two gaps that still break narrow screens:
     1. wide <table>s that were never wrapped in .table-responsive
        (~66 of them) — a long report otherwise scrolls the whole
        page sideways instead of just the table.
     2. toolbars / button groups / fixed-width boxes that overflow.
   Everything here is scoped to ≤992px, so desktop is untouched.
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 992px) {

  /* 1 ── Any .table NOT already inside a .table-responsive wrapper
     becomes its own horizontal-scroll container. width:max-content
     keeps small tables their natural size while letting wide ones
     scroll within max-width:100% instead of pushing the page.
     (:not() with a descendant selector is supported by all current
     mobile browsers — Chrome/Edge 88+, Firefox 84+, Safari 16.4+;
     older engines simply skip the rule, degrading gracefully.) */
  .table:not(.table-responsive .table) {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Smooth momentum scroll for the already-wrapped tables too. */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 2 ── Hard stop on whole-document sideways scroll if a stray
     fixed-width element still slips past everything above. */
  body { overflow-x: hidden; }

  /* 3 ── Toolbars / action bars wrap instead of overflowing. */
  .btn-group,
  .btn-toolbar { flex-wrap: wrap; }

  /* 4 ── Inline flex rows of buttons/filters (page-header actions,
     "d-flex gap-2" toolbars) wrap onto multiple lines. */
  .d-flex.gap-2,
  .page-header .d-flex { flex-wrap: wrap; }

  /* 5 ── Last-resort guard: any element carrying an inline fixed
     width (other than a table cell or the brand) is capped to the
     viewport so it can never force horizontal scroll. */
  [style*="width:"]:not(td):not(th) {
    max-width: 100%;
  }
}

/* Phone-only readability tweaks, layered on top of the ≤576px block */
@media (max-width: 576px) {

  /* Sticky header row so column meaning isn't lost while scrolling
     a long report vertically. */
  .table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
  }

  /* Keep figures on one line so numbers never wrap mid-value. */
  .table td.text-end,
  .table td.text-start.num { white-space: nowrap; }

  /* Comfortable tap target for in-row action buttons. */
  .table td .btn { min-height: 32px; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE ENHANCEMENT PASS 2  (added 2026-05-31)
   Readability + data-entry comfort + navigation + spacing for the
   daily-use phone screens (inventory, accounting reports, dashboard).
   Safe-by-design: no row-background overrides, so the deliberate
   dark totals-row styling in the views is left untouched.
   Scoped to ≤992 / ≤576.
   ═══════════════════════════════════════════════════════════ */

/* ── Table readability ──
   Faint vertical dividers help the eye track columns while a wide
   report scrolls sideways. Additive only — never touches row colour,
   so subtotal / totals rows keep their intended styling. The header
   gets a stronger bottom edge so it reads clearly when sticky. */
@media (max-width: 992px) {
  .table > :not(caption) > * > * { border-inline: 1px solid #ece3d6; }
  .table thead th { box-shadow: inset 0 -2px 0 var(--navy2); }
}

@media (max-width: 576px) {
  /* ── Data entry ──
     16px inputs stop iOS from zooming the page on focus and make
     fields easier to tap; a 40px min-height gives a comfortable
     target. */
  .form-control, .form-select,
  .form-control-sm, .form-select-sm {
    font-size: 16px;
    min-height: 40px;
  }
  textarea.form-control { min-height: 72px; }

  /* Stack form fields one per line. Filter-bar ".col-auto" chips are
     excluded so they keep the existing 2-up layout. */
  form .row > [class*="col-"]:not(.col-auto) {
    flex: 0 0 100%;
    max-width: 100%;
  }

  /* ── Spacing rhythm: tighter, consistent vertical gaps ── */
  .container-fluid.py-3 {
    padding-top: .6rem !important;
    padding-bottom: .6rem !important;
  }
  .card { margin-bottom: .6rem; }
  .card-body { padding: .7rem; }
  .page-header { margin-bottom: .8rem; }

  /* Primary submit buttons span the full width for easy tapping.
     Opt extra buttons in with class="btn-block-mobile". */
  form > .btn-primary,
  .card-body > form > button[type="submit"],
  .btn-block-mobile {
    display: block;
    width: 100%;
  }
}

/* ── Sticky first column (opt-in) ──
   Add class="tbl-stick1" to a .table whose first column is a label
   (account name, item, date) so it stays pinned while the amount
   columns scroll. Wrap such tables in .table-responsive. */
@media (max-width: 992px) {
  .tbl-stick1 > thead > tr > th:first-child,
  .tbl-stick1 > tbody > tr > td:first-child,
  .tbl-stick1 > tfoot > tr > td:first-child {
    position: sticky;
    inset-inline-start: 0;
    background: var(--cream);
    z-index: 1;
    box-shadow: inset -1px 0 0 #d9cdbb;
  }
  .tbl-stick1 > thead > tr > th:first-child {
    background: var(--navy);
    z-index: 3;
  }

  /* Multi-row-header variant: pin only the FIRST header row's first
     cell (for tables whose label column is a rowspan over a two-row
     header, e.g. Warehouse/Movement). Body column uses white so it
     matches plain rows; header/footer use the brand navy. */
  .tbl-stick1m > thead > tr:first-child > th:first-child,
  .tbl-stick1m > tbody > tr > td:first-child,
  .tbl-stick1m > tfoot > tr > td:first-child {
    position: sticky;
    inset-inline-start: 0;
    z-index: 1;
    box-shadow: inset -1px 0 0 #d9cdbb;
  }
  .tbl-stick1m > tbody > tr > td:first-child { background: #fff; }
  .tbl-stick1m > thead > tr:first-child > th:first-child {
    background: var(--navy);
    color: #fff;
    z-index: 3;
  }
  .tbl-stick1m > tfoot > tr > td:first-child {
    background: var(--navy);
    color: #fff;
  }
}

/* ═══ Print Header/Footer ═══ */
.print-header, .print-footer { display: none; }

/* Portrait by default. Wide reports inject a [data-pdf-landscape] marker which
   makes the PDF button request landscape; the renderer (PdfRenderService) drives
   orientation via PdfOptions.Landscape, NOT this @page size, so leave size as A4. */
@page { size: A4; margin: 14mm 12mm; }
@media print {
  body {
    background: #fff !important;
    font-family: "Cambria", "Georgia", "Segoe UI", serif;
    font-size: 9.5pt;
    color: #1a1a1a;
    margin: 0; padding: 0;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .navbar, .erp-sidebar, .erp-topbar, .page-header, .modal, .modal-backdrop,
  .no-print, form[onsubmit], .alert, .nav-tabs,
  .stat-card, .row.g-2.mb-3, .row.g-3.mb-3 { display: none !important; }
  .container-fluid { padding: 0 !important; margin: 0 !important; }
  .btn-group, .btn-xs, .btn-sm, .btn { display: none !important; }
  .card { border: none !important; box-shadow: none !important; margin: 0 !important; }
  .card-header { display: none !important; }

  /* Drilldown links must not print blue/underlined. */
  a { color: inherit !important; text-decoration: none !important; }

  /* ── Tables ── */
  table { font-size: 8.5pt !important; }
  table thead { display: table-header-group; }     /* repeat column headers on every page */
  table tfoot { display: table-footer-group; }     /* repeat the grand-total row on every page */
  table tr { break-inside: avoid; page-break-inside: avoid; } /* never split a row across pages */

  /* ── Sticky helpers must NOT stay sticky on paper ──
     A4 portrait (~794px) matches the max-width:992px query that turns on
     .tbl-stick1 / .tbl-stick1m, so their sticky first column / header stays
     active while printing; combined with display:table-header-group above,
     Chromium then emits blank or broken pages. Force every sticky table cell
     (helper classes, Bootstrap .sticky-top, and inline position:sticky
     headers/columns) back into normal flow. */
  .tbl-stick1 > thead > tr > th, .tbl-stick1 > tbody > tr > td, .tbl-stick1 > tfoot > tr > td,
  .tbl-stick1m > thead > tr > th, .tbl-stick1m > tbody > tr > td, .tbl-stick1m > tfoot > tr > td,
  .sticky-top,
  [style*="position:sticky"], [style*="position: sticky"] { position: static !important; }

  /* ── Wide reports print landscape in the BROWSER too (Ctrl+P), not only via the
     server PDF button ── Wide grids inject a hidden [data-pdf-landscape] marker; use it
     to rotate the page and let the table shrink to the width instead of clipping off
     the left edge. Degrades gracefully (stays portrait) on engines without :has(). */
  @page wideLandscape { size: A4 landscape; margin: 8mm; }
  body:has([data-pdf-landscape]) { page: wideLandscape; }
  body:has([data-pdf-landscape]) .table-responsive { overflow: visible !important; }
  body:has([data-pdf-landscape]) table { min-width: 0 !important; width: 100% !important; font-size: 7.5pt !important; }
  body:has([data-pdf-landscape]) .table td, body:has([data-pdf-landscape]) .table th { padding: 2px 4px !important; }

  .table td, .table th {
    font-variant-numeric: tabular-nums;             /* align figures in columns */
    border-bottom: 1px solid #e2ddd4;               /* light row rules */
  }
  .table thead th {
    background: var(--brand) !important; color: #fff !important;
    border-bottom: 1px solid var(--brand) !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  /* Subtotal / total rows: stronger weight + top rule. */
  .table tfoot td, .table tfoot th,
  .table tr.total-row td, .table tr.subtotal-row td,
  .table tr.rpt-banner td {
    font-weight: 700;
    border-top: 1.5px solid var(--brand);
  }

  /* Badges print as outlined plain text to save toner. */
  .badge {
    background: transparent !important;
    color: #000 !important;
    border: 1px solid #999 !important;
    font-weight: 600;
  }

  /* ── Page-break utilities (modern + legacy aliases) ── */
  .print-avoid-break     { break-inside: avoid; page-break-inside: avoid; }
  .print-keep-with-next  { break-after: avoid; page-break-after: avoid; }
  .print-break-before    { break-before: page; page-break-before: always; }
  .print-break-after     { break-after: page; page-break-after: always; }
  /* Group/section headers must never orphan at a page bottom. */
  tr.rpt-banner, .group-header, .section-header {
    break-inside: avoid; page-break-inside: avoid;
    break-after: avoid;  page-break-after: avoid;
  }

  /* ── Letterhead (bilingual: Arabic right, logo centre, English left) ── */
  .print-header {
    display: block !important;
    text-align: center;
    margin-bottom: 12px;
    border-bottom: 2px solid var(--gold);
    padding-bottom: 8px;
  }
  .print-header .lh-row {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; text-align: start;
  }
  .print-header .lh-ar { flex: 1 1 0; text-align: right; }
  .print-header .lh-en { flex: 1 1 0; text-align: left; direction: ltr; }
  .print-header .lh-logo { flex: 0 0 auto; text-align: center; }
  .print-header .print-logo { height: 58px; width: auto; }
  .print-header .logo-fallback { font-size: 15pt; font-weight: 700; color: var(--brand); }
  .print-header .company-ar { font-size: 15pt; font-weight: 700; color: var(--brand); line-height: 1.2; }
  .print-header .company-en { font-size: 12pt; font-weight: 700; color: var(--brand); line-height: 1.2; letter-spacing: .3px; }
  .print-header .department { font-size: 9.5pt; font-weight: 600; color: var(--gold); margin-top: 1px; }
  .print-header .department-en { font-size: 9pt; font-weight: 600; color: var(--gold); margin-top: 1px; }
  .print-header .lh-addr { font-size: 8pt; color: #666; margin-top: 1px; }
  .print-header .company-contact {
    font-size: 8.5pt; color: #555; margin-top: 6px; padding-top: 4px;
    border-top: 1px solid #EFE7DA;
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px;
  }
  .print-header .company-contact .lh-tin { color: #777; }
  .print-header .report-title { font-size: 13pt; font-weight: 700; color: var(--brand); margin-top: 6px;
    border-top: 1px solid #E3D8C8; padding-top: 5px; display: inline-block; }
  .print-header .report-subtitle { font-size: 9.5pt; color: #555; margin-top: 1px; }
  .print-header .report-date { font-size: 9pt; color: #666; margin-top: 1px; }

  /* ── Signatures / footer ── */
  .print-footer {
    display: block !important;
    margin-top: 16px;
    border-top: 2px solid var(--gold);
    padding-top: 8px;
    break-inside: avoid; page-break-inside: avoid;
    break-before: avoid; page-break-before: avoid;
  }
  .print-footer .sig-row {
    display: flex; flex-wrap: wrap;
    justify-content: space-between; gap: 8px;
    margin-top: 8px;
  }
  .print-footer .sig-box { text-align: center; flex: 1 1 28%; min-width: 120px; }
  .print-footer .sig-label { font-weight: 700; font-size: 10pt; }
  .print-footer .sig-line { border-bottom: 1px solid #333; margin-top: 26px; }
  .print-footer .sig-name { font-size: 9pt; margin-top: 3px; }
  .print-footer .print-date { text-align: center; font-size: 8pt; color: #999; margin-top: 12px; }
}

/* ══════════════════════════════════════════════════════════════
   Mobile "report cards" — opt-in via class="rpt-m" on a report
   <table>. site.js (enhanceReportCards) auto-stamps data-label on
   each <td> from its column header; section-header / total rows are
   tagged .rpt-banner and kept as full-width banners. Desktop is
   untouched — everything here is inside the phone media query.
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 576px) {
  /* Safe even without JS: drop the forced min-width so the table fits. */
  .rpt-m { min-width: 0 !important; }

  /* Card transform activates ONLY after site.js has labelled the cells
     (adds .rpt-on). No JS / no <thead> → table stays a normal fitted table. */
  .rpt-m.rpt-on thead { display: none; }
  .rpt-m.rpt-on, .rpt-m.rpt-on tbody, .rpt-m.rpt-on tfoot,
  .rpt-m.rpt-on tr, .rpt-m.rpt-on td { display: block; width: 100%; }
  /* beat the generic phone rule `.table:not(.table-responsive .table) { width:max-content }` (higher specificity) */
  .rpt-m.rpt-on { width: 100% !important; overflow-x: visible; }

  /* data rows → cards */
  .rpt-m.rpt-on tbody tr:not(.rpt-banner) {
    border: 1px solid var(--line, #e7ddcf); border-radius: 10px;
    margin-bottom: .55rem; padding: .4rem .65rem;
    background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.05);
  }
  .rpt-m.rpt-on tbody tr:not(.rpt-banner) td {
    border: none !important; padding: .22rem 0; min-height: 0 !important;
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 1rem; text-align: start !important; white-space: normal !important;
  }
  .rpt-m.rpt-on tbody tr:not(.rpt-banner) td::before {
    content: attr(data-label); color: var(--muted, #9a8d78); font-weight: 600;
    font-size: .7rem; white-space: nowrap; flex: 0 0 auto;
  }
  /* cells with no header / no value collapse away */
  .rpt-m.rpt-on tbody tr:not(.rpt-banner) td:not([data-label]) { display: none; }
  /* identity line: first labelled cell acts as the card title */
  .rpt-m.rpt-on tbody tr:not(.rpt-banner) td:first-child {
    border-bottom: 1px solid var(--line, #efe7da); margin-bottom: .25rem;
    padding-bottom: .3rem; font-weight: 700;
  }
  .rpt-m.rpt-on tbody tr:not(.rpt-banner) td:first-child::before { color: var(--brand); }

  /* section-header & total rows stay full-width banners */
  .rpt-m.rpt-on .rpt-banner { border-radius: 8px; margin-bottom: .55rem; }
  .rpt-m.rpt-on .rpt-banner > td {
    border: none !important; padding: .35rem .6rem;
    display: inline-block; width: auto;
  }
  /* totals: lay the cells out in a row so "الإجمالي  مدين  دائن" reads across */
  .rpt-m.rpt-on tfoot .rpt-banner, .rpt-m.rpt-on tbody tr.rpt-banner.group-subtotal {
    display: flex; flex-wrap: wrap; align-items: baseline;
    gap: .25rem .9rem; padding: .3rem .4rem; font-weight: 700;
  }
  .rpt-m.rpt-on tfoot .rpt-banner > td:first-child { flex: 1 1 100%; }
  .rpt-m.rpt-on .rpt-banner > td:empty { display: none; }

  /* rpt-m-full: columns hidden on phones (d-none d-md-table-cell) come back inside the card,
     so a phone sees every field of the row, not just the 2-3 that fit across. */
  .rpt-m-full.rpt-on tbody tr:not(.rpt-banner) td.d-none[data-label] { display: flex !important; }
  .rpt-m-full.rpt-on tfoot .rpt-banner > td.d-none { display: none !important; }
  /* a cell with only buttons (no header) sits at the card's end, aligned to the inline-end */
  .rpt-m.rpt-on tbody tr:not(.rpt-banner) td[data-label=""] { justify-content: flex-end; }
}

/* ══════════════════════════════════════════════════════════════
   Editable grids → phone cards. Add class="edit-grid" + data-label
   on each <td>. On phones each row stacks into a card with labelled,
   full-width fields — and columns hidden on desktop via d-none are
   shown here so every field is editable on mobile.
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 576px) {
  .edit-grid { min-width: 0 !important; }
  .edit-grid thead { display: none; }
  .edit-grid, .edit-grid tbody, .edit-grid tr, .edit-grid td { display: block; width: 100%; }
  .edit-grid tbody tr {
    border: 1px solid #e0d6c8; border-radius: 10px;
    padding: .5rem .7rem; margin-bottom: .7rem; background: var(--card);
  }
  .edit-grid td { border: none !important; padding: .25rem 0; white-space: normal !important; }
  .edit-grid td.d-none { display: block !important; }      /* reveal hidden fields in the card */
  .edit-grid td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: .12rem;
    font-weight: 600; color: var(--brand); font-size: .72rem;
  }
  .edit-grid td .form-control, .edit-grid td .form-select { width: 100% !important; }
}

/* Item code chip — shown before item names across inventory/purchase screens */
code.item-code {
  display: inline-block;
  font-family: "Consolas", "Courier New", monospace;
  font-size: .74rem;
  font-weight: 600;
  color: #6B4A2B;
  background: #F3ECE0;
  border: 1px solid #E3D3BC;
  border-radius: 4px;
  padding: 0 .35rem;
  margin-inline-end: .25rem;
  direction: ltr;
  unicode-bidi: isolate;
}
/* dark variant: erp.css (html[data-mode="dark"] code.item-code) — follows the app's
   light/dark toggle instead of the OS setting. */
@media print { code.item-code { background: transparent; border-color: #ccc; color: #000; } }
