:root {
  --brand: #1f5c4d;
  --brand-dark: #163f35;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --border: #e5e9e8;
  --text-muted: #6b7a76;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
}

[data-bs-theme="dark"] {
  --brand: #3aa383;
  --brand-dark: #1f5c4d;
  --bg: #14181a;
  --surface: #1c2224;
  --border: #2b3336;
  --text-muted: #99a8a3;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

body {
  background: var(--bg);
  font-family: "Inter", "Segoe UI", Roboto, Arial, sans-serif;
  transition: background-color .15s ease, color .15s ease;
}

.sidebar {
  width: 250px;
  min-height: 100vh;
  background: var(--brand-dark);
  color: #e9f1ee;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  font-size: 1.15rem;
  font-weight: 600;
  padding: 1.1rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  color: #fff;
  display: flex;
  align-items: center;
}
.sidebar-logo {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: .6rem;
  flex-shrink: 0;
}
.sidebar .nav-section {
  text-transform: uppercase;
  font-size: .7rem;
  letter-spacing: .06em;
  color: #9db8ae;
  padding: .9rem 1.2rem .25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.sidebar .nav-section:hover { color: #d7e6e0; }
.sidebar .nav-section .nav-section-chevron {
  transition: transform .15s ease;
  font-size: .65rem;
}
.sidebar .nav-section.collapsed .nav-section-chevron { transform: rotate(-90deg); }
.sidebar .nav-item.nav-collapsible { overflow: hidden; }
.sidebar .nav-link {
  color: #d7e6e0;
  padding: .5rem 1.2rem;
  border-left: 3px solid transparent;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  border-left-color: #7fd8b8;
  font-weight: 600;
}
.sidebar .bi { margin-right: .5rem; width: 1.1rem; display: inline-block; text-align: center; }

.content { flex: 1; min-width: 0; position: relative; }
.page-watermark {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 250px;
  background-repeat: no-repeat;
  background-position: center 45%;
  background-size: min(50vw, 520px);
  opacity: .35;
  pointer-events: none;
  z-index: 0;
}
[data-bs-theme="dark"] .page-watermark { opacity: .42; }
.page-body { position: relative; z-index: 1; }

/* Per-tab accent color — every section of the app gets its own color so pages
   are easy to tell apart at a glance: colored left border + tinted background
   on the page's cards, matching color on the page title. */
.content[data-section="dashboard"]  { --page-accent: #1f5c4d; }
.content[data-section="reports"]    { --page-accent: #6d5b97; }
.content[data-section="inventory"]  { --page-accent: #27ae60; }
.content[data-section="purchasing"] { --page-accent: #eb5757; }
.content[data-section="sales"]      { --page-accent: #2f80ed; }
.content[data-section="finance"]    { --page-accent: #f2994a; }
.content[data-section="fleet"]      { --page-accent: #d35400; }
.content[data-section="payroll"]    { --page-accent: #c9971e; }
.content[data-section="setup"]      { --page-accent: #607d8b; }

.topbar h5 { color: var(--page-accent, inherit); }
.page-body .card:not(.report-card) {
  border-left: 4px solid var(--page-accent, var(--brand));
  position: relative;
  overflow: hidden;
}
.page-body .card:not(.report-card) > .card-header,
.page-body .card:not(.report-card) > .card-body > .card-title {
  color: var(--page-accent, inherit);
}
.page-body .card:not(.report-card)::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: var(--page-accent, transparent);
  opacity: .035;
  pointer-events: none;
}
[data-bs-theme="dark"] .page-body .card:not(.report-card)::after { opacity: .08; }
.topbar {
  background: rgba(255,255,255,.85);
  padding: .8rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
[data-bs-theme="dark"] .topbar { background: rgba(28,34,36,.85); }
.page-body { padding: 1.5rem; }

/* Dashboard stat blocks are translucent too, same as .card, so the
   watermark shows through them consistently across every page/tab. */
.stat-card {
  background: rgba(255,255,255,.65);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  height: 100%;
  position: relative;
  z-index: 1;
}
[data-bs-theme="dark"] .stat-card { background: rgba(28,34,36,.65); }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--brand-dark); }
.stat-card .stat-label { color: var(--text-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }

[data-bs-theme="dark"] .stat-card .stat-value { color: #7fd8b8; }

/* Dashboard stat blocks — same scheme as the Reports-tab blocks: colored left
   border, matching value color, faint color tint across the card. */
.stat-card[class*="sc-"] {
  border-left: 4px solid var(--sc-color, var(--brand));
  position: relative;
  overflow: hidden;
}
.stat-card[class*="sc-"] .stat-value { color: var(--sc-color, var(--brand-dark)); }
.stat-card[class*="sc-"]::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: var(--sc-color, transparent);
  opacity: .05;
  pointer-events: none;
}
[data-bs-theme="dark"] .stat-card[class*="sc-"] .stat-value { color: var(--sc-color, #7fd8b8); }
[data-bs-theme="dark"] .stat-card[class*="sc-"]::after { opacity: .1; }
.sc-sales        { --sc-color: #2f80ed; }
.sc-purchases    { --sc-color: #eb5757; }
.sc-expenses     { --sc-color: #f2994a; }
.sc-receivable   { --sc-color: #c0392b; }
.sc-payable      { --sc-color: #8e44ad; }
.sc-vansales     { --sc-color: #17a2b8; }
.sc-schemeclaims { --sc-color: #bb6bd9; }

/* Cards are intentionally semi-transparent (not fully opaque var(--surface))
   so the page watermark shows through tables/cards too, not just the empty
   margins around them. */
.card { border: none; box-shadow: var(--shadow); border-radius: 10px; background: rgba(255,255,255,.65); position: relative; z-index: 1; }
[data-bs-theme="dark"] .card { background: rgba(28,34,36,.65); }
.card-header { background: transparent; font-weight: 600; border-bottom: 1px solid var(--border); }

.table thead th { font-size: .78rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: .03em; border-bottom-width: 1px; }
.badge-low { background: #f8d7da; color: #842029; }
.badge-over { background: #fff3cd; color: #664d03; }
.badge-ok { background: #d1e7dd; color: #0f5132; }

.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

.alert-tile {
  border-radius: 8px;
  padding: .6rem .9rem;
  margin-bottom: .5rem;
  font-size: .88rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Landing / login pages (no sidebar) */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand-dark) 0%, var(--brand) 100%);
  padding: 1.5rem;
}
.auth-card {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
  padding: 2.2rem;
  width: 100%;
  max-width: 400px;
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--brand-dark);
  margin-bottom: .3rem;
  text-align: center;
}
.auth-logo { width: 64px; height: 64px; border-radius: 50%; }
.auth-logo-full {
  width: 100%;
  max-width: 280px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
[data-bs-theme="dark"] .auth-brand { color: #7fd8b8; }
.landing-hero {
  text-align: center;
  color: #fff;
  max-width: 520px;
}
.landing-logo { width: 96px; height: 96px; border-radius: 50%; }
.landing-logo-full {
  width: 100%;
  max-width: 360px;
  height: auto;
  border-radius: 16px;
  box-shadow: 0 10px 32px rgba(0,0,0,.3);
  margin-bottom: .4rem;
}
.landing-hero h1 { font-weight: 700; margin: .8rem 0 .1rem; }
.landing-subtitle { opacity: .85; font-size: 1.05rem; margin-bottom: .6rem; }
.landing-hero p { opacity: .9; margin-bottom: 1.6rem; }
/* Reports hub — each block tinted a different color so tabs are easy to tell apart at a glance */
.report-card { border-left: 4px solid var(--rc-color, var(--brand)); position: relative; overflow: hidden; }
.report-card .card-title { color: var(--rc-color, inherit); }
.report-card .card-title i { color: var(--rc-color, inherit); }
.report-card::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: var(--rc-color, transparent);
  opacity: .04;
  pointer-events: none;
}
[data-bs-theme="dark"] .report-card::after { opacity: .09; }
.rc-sales        { --rc-color: #2f80ed; }
.rc-purchases    { --rc-color: #eb5757; }
.rc-products     { --rc-color: #27ae60; }
.rc-expenses     { --rc-color: #f2994a; }
.rc-targets      { --rc-color: #9b51e0; }
.rc-stockissues  { --rc-color: #17a2b8; }
.rc-salary       { --rc-color: #d4a017; }
.rc-schemeclaims { --rc-color: #bb6bd9; }
.rc-customers    { --rc-color: #219653; }
.rc-fleet        { --rc-color: #d35400; }
.rc-masters      { --rc-color: #607d8b; }

.theme-toggle-floating {
  position: fixed;
  top: 1rem;
  right: 1rem;
}

/* Reconcile form's Cash / Bank / Total Collected / Expected Amount /
   Discrepancy fields - kept on one single line at every screen size (rather
   than Bootstrap's default column-stacking), since they're one running
   calculation the user reads left-to-right. Each field has a comfortable
   minimum width; if there's not enough room (a phone, or a narrow desktop
   window) the row scrolls horizontally within itself instead of wrapping -
   same pattern as the line-items table above it, not a page-wide scrollbar. */
.money-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: .25rem;
}
.money-field {
  flex: 1 1 160px;
  min-width: 160px;
}

/* ===================== Responsive / mobile ===================== */
.sidebar-close-btn { display: none; }
/* The hamburger toggle itself doesn't rely on Bootstrap's d-lg-none utility
   class (which needs bootstrap.min.css to have actually loaded, e.g. from
   its CDN, to take effect) - defined directly here instead so it reliably
   shows only below the off-canvas breakpoint and never sits there uselessly
   on a full desktop window regardless of what else did or didn't load. */
#sidebarToggle { display: inline-flex; align-items: center; }
@media (min-width: 992px) {
  #sidebarToggle { display: none; }
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1040;
}
.sidebar-backdrop.show { display: block; }

/* Below the lg breakpoint (~992px - phones and most tablets in portrait),
   the sidebar becomes an off-canvas drawer instead of a permanent 250px-wide
   column: it's hidden off-screen and slides in over the page when opened via
   the hamburger button in the topbar, rather than squeezing page content
   into a few inches of width like a fixed-width sidebar would on a phone. */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 84vw;
    max-width: 300px;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-btn { display: inline-block; }
  body.sidebar-open-lock { overflow: hidden; }

  /* The sidebar no longer takes up permanent horizontal space (it's
     position:fixed, out of normal flow), so content already goes full width
     without changes here - only the watermark's hardcoded 250px inset (sized
     for the permanent desktop sidebar) needs correcting, and the page's own
     padding needs to shrink to fit a phone screen. */
  .page-watermark { left: 0; }
  .page-body { padding: 1rem; }
  .topbar { padding: .7rem 1rem; }
  .auth-card { padding: 1.5rem; }
}

@media (max-width: 575.98px) {
  .stat-card .stat-value { font-size: 1.25rem; }
  .page-body { padding: .75rem; }
  .card-body { padding: 1rem; }
}

/* Wide data tables (Sales/Products/Live Sales Monitor, etc.) still need to scroll
   horizontally on a phone once there are more columns than fit - but the row's
   identifying first column (Salesperson/Product/Invoice #...) stays pinned in view
   while the rest scrolls underneath it, so you never lose track of which row you're
   looking at. Only kicks in inside .table-responsive, where the scrolling actually
   happens; a table that already fits doesn't need it and isn't affected. */
@media (max-width: 767.98px) {
  /* :not([colspan]) excludes a totals row's wide label cell (e.g. "Taxable
     Amount" spanning most of an invoice table) - sticking a cell that wide
     would visually cover the actual amount sitting right next to it once
     scrolled, hiding it behind the sticky cell instead of revealing it. A
     plain single-column first cell (a normal data row, or a short "Total"
     label) still gets pinned as before. */
  .table-responsive table.table thead th:first-child,
  .table-responsive table.table tbody td:first-child,
  .table-responsive table.table tfoot td:first-child:not([colspan]),
  .table-responsive table.table tfoot th:first-child:not([colspan]) {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--surface);
    box-shadow: 2px 0 4px rgba(0,0,0,.08);
  }
  /* Tighten up rows so more columns are visible before scrolling is needed at all -
     the Customize Columns option (where a list page offers one) is the other half of
     this: hide columns you don't need day-to-day rather than just shrinking them. */
  .table-responsive table.table { font-size: .82rem; }
  .table-responsive table.table th, .table-responsive table.table td { padding: .45rem .55rem; }
}

/* Fixed-pixel-width fields (many list-page search/filter bars and table
   line-item forms set a comfortable default like style="width:260px") would
   otherwise overflow their row instead of shrinking as a desktop window is
   resized narrower - well before the phone/tablet breakpoint above kicks in.
   max-width caps them at their container's width without removing the
   pixel width as the preferred size on wide screens: CSS applies max-width
   over width whenever they conflict, regardless of the inline style's
   higher specificity, so this works even though it can't "see" the inline
   styles individually. */
input[style*="width"], select[style*="width"] {
  max-width: 100%;
}

/* Toolbar rows (a search/filter form beside a row of action buttons, or a
   plain button/field group) wrap onto a second line instead of clipping or
   forcing a horizontal scrollbar once the window gets too narrow for
   everything to fit on one line. Harmless when there's room - flex-wrap
   only has an effect once content actually doesn't fit. */
.d-flex.justify-content-between,
.d-flex.gap-2 {
  flex-wrap: wrap;
  row-gap: .5rem;
}

/* Resizable table columns (see static/js/column-resize.js): a thin
   draggable handle on the right edge of each sortable <th>, positioned
   with the header itself and drawn only on hover/drag so it doesn't
   clutter every table by default. */
table.table > thead > tr > th {
  position: relative;
}
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
  touch-action: none;
}
.col-resize-handle:hover,
.col-resize-handle.resizing {
  background: rgba(13, 110, 253, 0.35);
}
table.table.col-resize-active {
  table-layout: fixed;
}
table.table.col-resize-active > thead > tr > th,
table.table.col-resize-active > tbody > tr > td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============ Mobile card-view tables (no horizontal scroll) ============
   Opt-in via class="table-cards-mobile" on a <table>, with each <td> given
   data-label="Column Name" matching its <th>. Below the phone breakpoint,
   the table stops behaving like a table (no more scrolling sideways to read
   a row) and each row instead renders as a small stacked card: the header
   row is visually hidden and every cell shows its own column name as a
   label above the value. Desktop/tablet layout (>767px) is untouched - this
   only kicks in once .table-responsive would otherwise force a sideways
   scroll on a phone. First rolled out to the Finance module (Accounts
   Receivable, Expenses, GST, P&L, Scheme Claims); safe to reuse anywhere
   else that lists rows of label/value pairs. */
/* Everything in this section is gated behind body:not(.mobile-ui-off) - a
   single flag (MOBILE_FRIENDLY_UI_ENABLED in app.py) that, if ever flipped to
   False, reverts every page below back to plain tables/buttons instantly,
   with no template changes needed. */
@media (max-width: 767.98px) {
  body:not(.mobile-ui-off) table.table-cards-mobile thead { display: none; }
  body:not(.mobile-ui-off) table.table-cards-mobile,
  body:not(.mobile-ui-off) table.table-cards-mobile tbody,
  body:not(.mobile-ui-off) table.table-cards-mobile tr,
  body:not(.mobile-ui-off) table.table-cards-mobile td {
    display: block;
    width: 100%;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile tbody tr {
    border: 1px solid var(--border);
    border-radius: .5rem;
    margin-bottom: .6rem;
    padding: .5rem .75rem;
    background: var(--surface);
    position: static !important; /* undo the sticky-first-column rule above */
    box-shadow: none !important;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile tbody tr:last-child { margin-bottom: 0; }
  body:not(.mobile-ui-off) table.table-cards-mobile td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    text-align: right;
    padding: .3rem 0;
    border: none !important;
    position: static !important;
    background: transparent !important;
    box-shadow: none !important;
    white-space: normal;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    flex: 0 0 auto;
    margin-right: .5rem;
  }
  /* A cell with no data-label (e.g. an action-button cell, or a colspan
     "no rows" message) - shown plainly, full width, no label row. Switched
     from the base td's display:flex to display:block: a flex row forces its
     children through flexbox sizing (a "width:100%" child's width is only
     treated as a flex-basis, so with several full-width buttons in one cell
     - e.g. Customers' History/Ledger/By Product/Edit - the row shrinks them
     all to fit on one line instead of letting each take the full row and
     wrap below the last, which is what actually produced the cramped
     2-per-row button grid on phones). Plain block children respect
     width:100% and stack normally, one per line, with no flex math involved. */
  body:not(.mobile-ui-off) table.table-cards-mobile td:not([data-label]) {
    display: block;
    text-align: left;
  }
  /* A totals/footer row (tfoot) is a single running summary, not another
     record - keep it as a compact table rather than card-ifying it too. */
  body:not(.mobile-ui-off) table.table-cards-mobile tfoot { display: table; width: 100%; }
  body:not(.mobile-ui-off) table.table-cards-mobile tfoot tr { display: table-row; }
  body:not(.mobile-ui-off) table.table-cards-mobile tfoot td {
    display: table-cell;
    text-align: inherit;
    padding: .45rem .55rem;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile tfoot td::before { content: none; }
}

/* ============ Compact grid cards on phones ============
   Without this, List and Grid look identical on a phone: List already
   stacks every field into one full-width card per row (the block above),
   and Grid's desktop card width (see below) also only fits one column on
   a narrow screen - so both converge on the same "every field, one column"
   layout. This block gives Grid its own, genuinely different phone
   layout: two narrower cards per row showing only the 2-3 fields each
   template marks with data-key-field="primary|secondary|meta" (its title,
   subtitle, and status/amount), with every other field hidden rather than
   shown at a squeezed width. List is untouched - it's still the
   comprehensive, one-row-per-record view.
   Reversible the same way as the rest of this feature: turning off
   LIST_VIEW_TOGGLE_ENABLED (app.py) stops the .view-grid class from ever
   being applied, so none of this ever activates. */
@media (max-width: 767.98px) {
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid tbody {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .5rem;
  }
  /* These next few match the "tbody tr:not(.collapse) td..." shape of the
     unguarded desktop rules further below on purpose - it's what keeps
     these mobile overrides winning on specificity regardless of source
     order, without needing !important anywhere. */
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid tbody tr:not(.collapse) {
    margin-bottom: 0;
    padding: .55rem .65rem;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid tbody tr:not(.collapse) td[data-label]:not([data-key-field]) {
    display: none;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid tbody tr:not(.collapse) td[data-key-field] {
    display: block;
    text-align: left;
    padding: .1rem 0;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid tbody tr:not(.collapse) td[data-key-field]::before {
    content: none;
  }
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid td[data-key-field="primary"] {
    font-weight: 600;
    font-size: .9rem;
    color: var(--brand-dark);
  }
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid td[data-key-field="secondary"] {
    font-size: .78rem;
    color: var(--text-muted, #6c757d);
  }
  body:not(.mobile-ui-off) table.table-cards-mobile.view-grid td[data-key-field="meta"] {
    font-size: .78rem;
    margin-top: .2rem;
  }
}

/* ============ List / Grid view switch (desktop & tablet) ============
   Wired up by static/js/list-view-toggle.js on any table carrying
   data-view-toggle. List view is the plain table, unchanged. Grid view
   reuses the same data-label cells the mobile card view above relies on,
   just arranged as a responsive multi-column card grid instead of a
   single stacked column - and, unlike the mobile rules above, this isn't
   limited to narrow screens: it's the user's own explicit, saved choice,
   so it has to work at any width. */
.list-view-toggle-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: .5rem;
}
.list-view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: .375rem;
  overflow: hidden;
}
.list-view-toggle button {
  display: flex;
  align-items: center;
  border: none;
  background: var(--surface);
  color: var(--brand-dark);
  opacity: .55;
  padding: .3rem .55rem;
  cursor: pointer;
  line-height: 1;
}
.list-view-toggle button + button { border-left: 1px solid var(--border); }
.list-view-toggle button.active { background: var(--brand); color: #fff; opacity: 1; }
.list-view-toggle button:not(.active):hover { opacity: .85; }

table.table-cards-mobile.view-grid thead { display: none; }
table.table-cards-mobile.view-grid tfoot { display: none; }
table.table-cards-mobile.view-grid,
table.table-cards-mobile.view-grid tbody {
  display: block;
  width: 100%;
}
table.table-cards-mobile.view-grid tbody {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .75rem;
}
/* .collapse rows (e.g. an inline "mark received" sub-form) are left out of
   the card grid entirely rather than turned into cards of their own - a
   hidden one should stay hidden, and an expanded one reads fine as a plain
   row, so neither needs the same grid-card treatment. */
table.table-cards-mobile.view-grid tbody tr:not(.collapse) {
  display: block;
  border: 1px solid var(--border);
  border-radius: .5rem;
  padding: .65rem .85rem;
  background: var(--surface);
  position: static !important;
  box-shadow: none !important;
}
table.table-cards-mobile.view-grid tbody tr:not(.collapse) td {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .5rem;
  text-align: right;
  padding: .25rem 0;
  border: none !important;
  position: static !important;
  background: transparent !important;
  box-shadow: none !important;
  white-space: normal;
}
table.table-cards-mobile.view-grid tbody tr:not(.collapse) td[data-label]::before {
  content: attr(data-label);
  font-weight: 600;
  color: var(--text-muted, #6c757d);
  text-align: left;
  flex: 0 0 auto;
  margin-right: .5rem;
}
/* A cell with no data-label (typically the trailing actions column, or a
   colspan "no rows yet" message) - shown as its own full-width block
   beneath the labelled fields rather than squeezed into the label/value row. */
table.table-cards-mobile.view-grid tbody tr:not(.collapse) td:not([data-label]) {
  display: block;
  text-align: left;
  padding-top: .5rem;
  margin-top: .35rem;
  border-top: 1px dashed var(--border) !important;
}

/* ============ Touch targets (app-wide) ============
   Buttons and nav-style tabs get a taller minimum tap height on phones/small
   tablets, per the ~44-48px accessible touch-target guideline - Bootstrap's
   stock .btn-sm/.nav-link are noticeably smaller than that. Originally piloted
   on just the Finance/Sales sections (data-section="finance"/"sales"/"reports"
   on <main>); now applied app-wide since the pilot held up fine everywhere it
   was tried. */
@media (max-width: 767.98px) {
  body:not(.mobile-ui-off) main.content .btn,
  body:not(.mobile-ui-off) main.content .page-body .nav-tabs .nav-link {
    min-height: 44px;
    padding-top: .55rem;
    padding-bottom: .55rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  body:not(.mobile-ui-off) main.content .page-body .nav-tabs .nav-link {
    display: flex;
  }
  /* Buttons packed edge-to-edge in an action cell (Edit / Mark Claimed /
     delete icon, View, etc.) need breathing room between tap targets, not
     just taller ones. */
  body:not(.mobile-ui-off) main.content td .btn + .btn,
  body:not(.mobile-ui-off) main.content td form + .btn,
  body:not(.mobile-ui-off) main.content td form + form {
    margin-top: .35rem;
  }
  body:not(.mobile-ui-off) main.content td .d-inline {
    display: inline-block !important;
    margin: .15rem 0;
  }
}

/* ============ Auto-collapse panels (app-wide) ============
   A page opts a <div class="card">...</div> into "starts collapsed, click
   the header to expand" behaviour just by adding a data-collapsible
   attribute to that outer card div - everything else (wrapping the body in
   a Bootstrap .collapse, adding the chevron, wiring the click handler) is
   done once at runtime by the script in base.html. Used for supplementary/
   drill-down report panels (e.g. "Pending Dues", "Discount/Free-Scheme Line
   Detail", "Day-wise Cost vs Sales" on Stock Issue Schemes & Dues) so the
   page isn't a wall of expanded tables by default - NOT meant for a page's
   one primary table/form, which should stay visible as-is. */
.auto-collapse-header { cursor: pointer; }
.auto-collapse-chevron { transition: transform .2s ease; margin-left: .5rem; }
.auto-collapse-header[aria-expanded="false"] .auto-collapse-chevron { transform: rotate(-90deg); }

/* A table action button (View/Edit/Adjust/...) that should fill the row
   width once a table is in card mode on a phone, but stay as a normal small
   inline button on desktop/tablet - NOT Bootstrap's .w-100, which applies at
   every width and breaks an action cell that has more than one button
   (they'd each claim 100% and collide/overflow on a normal desktop table).
   Selector includes "main.content" (matching the touch-target rule above)
   so its specificity actually wins - a plain "body:not(.mobile-ui-off)
   .mobile-btn-full" selector is LOWER specificity than that rule's
   "body:not(.mobile-ui-off) main.content .btn" and was silently losing to
   its display:inline-flex, leaving every button here sized to its own
   content instead of full-width - that's what caused multiple action
   buttons (e.g. Customers' History/Ledger/By Product/Edit) to wrap into a
   cramped 2-per-row grid on phones instead of stacking one per row. */
@media (max-width: 767.98px) {
  body:not(.mobile-ui-off) main.content .mobile-btn-full {
    display: block;
    width: 100%;
  }
  body:not(.mobile-ui-off) main.content .mobile-btn-full + .mobile-btn-full {
    margin-top: .35rem;
  }
}
