* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  color: #1e293b;
  background: #f8fafc;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  flex-shrink: 0;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 700; color: #fff; padding: 8px 20px 20px;
}
.sidebar .brand-logo { width: 28px; height: 28px; border-radius: 6px; }
.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: #cbd5e1;
  border-left: 3px solid transparent;
}
.sidebar .nav-link:hover { background: #334155; color: #fff; text-decoration: none; }
.sidebar .nav-link.active { background: rgba(59,130,246,0.15); color: #93c5fd; border-left-color: #3b82f6; }
.sidebar .nav-icon { font-size: 15px; width: 18px; text-align: center; }
.sidebar-spacer { flex: 1; }

.content { flex: 1; padding: 24px 32px; max-width: 1280px; }

h1.page-title { font-size: 22px; font-weight: 700; margin: 0 0 16px; color: #0f172a; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.page-header .page-title { margin-bottom: 0; }
.summary-line { color: #475569; font-size: 13px; margin: 0 0 12px; }
.actions-cell { display: flex; gap: 6px; flex-wrap: nowrap; white-space: nowrap; }

.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  text-align: left;
  font-size: 13px;
}
table.data-table th { background: #f1f5f9; color: #475569; font-weight: 600; }
table.data-table tbody tr:nth-child(even) { background: #fafbfc; }
table.data-table tr:hover { background: #eff6ff; }
table.data-table tfoot .ledger-totals-row td { background: #f1f5f9; border-top: 2px solid #cbd5e1; border-bottom: none; }
table.data-table tbody tr.ledger-opening-row td { background: #f8fafc; font-style: italic; color: #475569; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

form.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.bill-header-grid { display: grid; grid-template-columns: 160px 1fr 260px 160px 120px; gap: 16px; align-items: start; }
.bill-header-grid > div { display: flex; flex-direction: column; }
.bill-header-grid .customer-field { display: flex; flex-direction: row; align-items: center; gap: 6px; }
.bill-header-grid .customer-field select { flex: 1; }

/* Payment-mode + Bank Account select side by side on wide screens (room
   permitting); wraps to its own line automatically when space is tight,
   e.g. inside the narrower Part Payment card or on mobile. Children need an
   explicit width here since the global `select { width: 100% }` rule would
   otherwise make each one claim the full row on its own. */
.payment-mode-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.payment-mode-row > select,
.payment-mode-row > input,
.payment-mode-row > div { width: auto; flex: 1 1 160px; min-width: 140px; }
.last-rate-hint { display: block; font-size: 11px; color: #94a3b8; margin-top: 2px; white-space: nowrap; }
.bill-number-badge { display: inline-block; margin-left: 10px; font-size: 0.7em; font-weight: 600; color: #6366f1; background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 6px; padding: 2px 10px; vertical-align: middle; white-space: nowrap; }
.gst-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-top: 6px; }
.gst-toggle input[type="checkbox"] { display: none; }
.gst-toggle-track { position: relative; width: 40px; height: 22px; background: #cbd5e1; border-radius: 11px; transition: background .2s; flex-shrink: 0; }
.gst-toggle input:checked ~ .gst-toggle-track { background: #6366f1; }
.gst-toggle-thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: left .2s; }
.gst-toggle input:checked ~ .gst-toggle-track .gst-toggle-thumb { left: 21px; }
.gst-toggle-label { font-size: 12px; color: #475569; font-weight: 600; white-space: nowrap; }

label { display: block; font-size: 12px; color: #475569; margin: 10px 0 4px; font-weight: 600; }
input, select, textarea {
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
textarea { resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn:hover { text-decoration: none; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: #dcfce7; color: #15803d; }
.btn-success:hover { background: #bbf7d0; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.badge { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; padding: 2px 10px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.mode-suffix { display: none; }
.status-line { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.badge-paid { background: #dcfce7; color: #15803d; }
.badge-pending { background: #fef3c7; color: #b45309; }
.status-icon { width: 11px; height: 11px; vertical-align: -1px; }

.flash-stack { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; font-size: 13px; }
.flash-success { background: #dcfce7; color: #15803d; }
.flash-error { background: #fee2e2; color: #b91c1c; }

/* Items page: table on left, form panel on right */
.items-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 20px;
  align-items: start;
}
.items-sidebar { position: sticky; top: 20px; }
.items-form-card .form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
.items-form-card .form-group label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
}
.items-form-card .form-group input,
.items-form-card .form-group select {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
}
.items-form-card .form-actions { margin-top: 4px; display: flex; flex-direction: column; }

/* Items filter bar */
.items-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: nowrap;
}
.items-filter-search {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
}
.items-filter-search .filter-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  pointer-events: none;
}
.items-filter-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px 7px 30px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.items-filter-search input:focus { border-color: #6366f1; }
.items-filter-bar select {
  flex: 0 0 160px;
  padding: 7px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}
.item-count-badge {
  flex: 0 0 auto;
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
}

/* Sortable column headers */
.sortable-table thead th[data-col] { user-select: none; }
.sortable-table thead th[data-col]:hover { background: #162e50; }
.sort-icon { font-size: 10px; opacity: 0.4; margin-left: 4px; }

/* Customer ledger */
.ledger-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.ledger-info-fields {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: center;
}
.ledger-info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ledger-info-label { color: #64748b; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.ledger-balance {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  margin-top: 4px;
}
.ledger-balance-label { font-size: 12px; font-weight: 600; }
.ledger-balance-amount { font-size: 18px; font-weight: 700; }
.ledger-balance-due    { background: #fee2e2; color: #b91c1c; }
.ledger-balance-credit { background: #dcfce7; color: #15803d; }
.ledger-balance-clear  { background: #f1f5f9; color: #475569; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin: 18px 0 22px; }
.stat-card {
  background: #fff; border: 1px solid #e2e8f0; border-left: 4px solid #cbd5e1;
  border-radius: 8px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  color: inherit; text-decoration: none; cursor: pointer;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(15,23,42,0.08); text-decoration: none; }
.stat-card .stat-icon {
  font-size: 22px; width: 44px; height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; background: #f1f5f9;
}
.stat-card .label { font-size: 12px; color: #64748b; }
.stat-card .value { font-size: 20px; font-weight: 700; color: #0f172a; margin-top: 2px; }
.stat-card .value-sub { font-size: 12px; font-weight: 600; color: #64748b; }

.stat-card.accent-blue   { border-left-color: #3b82f6; }
.stat-card.accent-green  { border-left-color: #16a34a; }
.stat-card.accent-amber  { border-left-color: #f59e0b; }
.stat-card.accent-red    { border-left-color: #ef4444; }
.stat-card.accent-purple { border-left-color: #8b5cf6; }
.stat-card.accent-teal   { border-left-color: #0d9488; }
.stat-card.accent-blue .stat-icon   { background: #dbeafe; }
.stat-card.accent-green .stat-icon  { background: #dcfce7; }
.stat-card.accent-amber .stat-icon  { background: #fef3c7; color: #b45309; }
.stat-card.accent-red .stat-icon    { background: #fee2e2; }
.stat-card.accent-purple .stat-icon { background: #ede9fe; }
.stat-card.accent-teal .stat-icon   { background: #ccfbf1; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-bottom: 18px; }
.chart-grid .card { margin-bottom: 0; }
.card h3 { margin: 0 0 14px; font-size: 14px; font-weight: 700; color: #0f172a; }
.empty-note { color: #94a3b8; font-size: 13px; }

.login-screen {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 60%, #1e293b 100%);
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 36px 38px;
  width: min(340px, 92vw);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.login-card .login-logo { width: 56px; height: 56px; border-radius: 12px; margin-bottom: 10px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: #0f172a; }
.login-card .login-subtitle { margin: 0 0 18px; font-size: 12px; color: #64748b; }
.login-card label { text-align: left; }
.login-card .btn-block { margin-top: 18px; }
.login-card .login-footnote { margin-top: 16px; font-size: 11px; color: #94a3b8; }
.login-card .flash { text-align: left; }

.items-table input { padding: 5px 8px; font-size: 12px; }
.items-table th, .items-table td { padding: 6px; }
.totals-box { width: 280px; margin: 0 0 18px auto; border: 1px solid #e2e8f0; border-radius: 6px; padding: 12px 16px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.totals-box .grand { font-weight: 700; font-size: 15px; border-top: 2px solid #e2e8f0; padding-top: 8px; color: #16a34a; }

.txn-credit { color: #16a34a; font-weight: 700; }
.txn-debit { color: #dc2626; font-weight: 700; }
.txn-amber { color: #d97706; font-weight: 700; }
.summary-bar { display: flex; gap: 24px; flex-wrap: wrap; background: #f1f5f9; font-size: 13px; align-items: center; }

.modal-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(15,23,42,0.45);
  align-items: center; justify-content: center; z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal-box { background: #fff; border-radius: 10px; padding: 22px; width: min(360px, 92vw); }

.pdf-modal-box {
  background: #fff; border-radius: 10px; padding: 16px;
  width: min(720px, 94vw); height: min(880px, 92vh);
  display: flex; flex-direction: column; gap: 10px;
}
.pdf-modal-header { display: flex; align-items: center; justify-content: space-between; }
.pdf-modal-header h3 { margin: 0; font-size: 16px; }
.pdf-modal-frame { flex: 1; border: 1px solid #e2e8f0; border-radius: 6px; width: 100%; }

.history-modal-box {
  width: min(640px, 94vw); max-height: 88vh;
  display: flex; flex-direction: column; gap: 10px; overflow: hidden;
}
.history-modal-box .history-table-wrap { overflow: auto; max-height: 50vh; }

/* ── Mobile top bar & hamburger ─────────────────────────────────────────── */
.topbar {
  display: none;
  align-items: center;
  background: #1e293b;
  padding: 10px 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 45;
}
.topbar-title { color: #fff; font-weight: 700; font-size: 16px; flex: 1; }
.mobile-add-wrap { display: none; }

.btn-wa {
  background: #25d366;
  color: #fff;
  border: none;
}
.btn-wa:hover { background: #1ebe5d; color: #fff; }

.wa-inline-link {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 6px;
  color: #25d366;
}
.wa-inline-link:hover { color: #1ebe5d; }

.fin-period-select {
  width: auto;
  padding: 6px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  color: #1d4ed8;
  background: #eff6ff;
  cursor: pointer;
  font-weight: 600;
}

.hamburger {
  background: none; border: none; cursor: pointer;
  color: #cbd5e1; font-size: 22px; line-height: 1; padding: 2px 4px;
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 40;
}
.sidebar-overlay.open { display: block; }

/* ── Responsive breakpoints ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar { display: flex; }

  .sidebar {
    position: fixed; left: -240px; top: 0;
    height: 100vh; width: 220px;
    z-index: 50; transition: left .22s ease;
    overflow-y: auto;
  }
  .sidebar.open { left: 0; }

  .app-shell { flex-direction: column; }
  .content { padding: 14px 12px; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .toolbar { flex-wrap: wrap; }
  .totals-box { width: 100%; }

  .bill-header-grid { grid-template-columns: 1fr 1fr; gap: 10px; }

  .items-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .items-layout { grid-template-columns: 1fr; }
  .items-sidebar { position: static; }

  /* Search + filter dropdowns + count badge: wrap instead of forcing
     everything onto one unshrinkable row (the desktop layout gives the
     search box flex:1 and each select a fixed 160px basis, which has no
     room to breathe under ~400px). */
  .items-filter-bar { flex-wrap: wrap; }
  .items-filter-search { flex: 1 1 100%; }
  .items-filter-bar select { flex: 1 1 auto; }

  form.inline-form { flex-direction: column; align-items: stretch; }
  form.inline-form > div { width: 100%; }
  form.filter-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  form.filter-form > div:last-child { grid-column: 1 / -1; }

  /* ── Table → Card ───────────────────────────────────────────────────── */
  table.data-table { border: none; }
  table.data-table thead { display: none; }
  table.data-table, table.data-table tbody { display: block; }

  table.data-table tbody tr {
    display: block;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 4px 12px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }
  table.data-table tbody tr:hover { background: #f8fafc; }

  table.data-table tbody td {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    padding: 7px 0;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
    font-size: 13px;
    gap: 8px;
  }
  table.data-table tbody td:last-child { border-bottom: none; }

  table.data-table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex-shrink: 0;
    min-width: 72px;
  }
  table.data-table tbody td[data-label=""] { display: none; }

  /* Flexbox gotcha: form elements default to min-width:auto (their
     intrinsic content size) as flex items, not 0 -- so an <input>/<select>
     ignores flex-shrink and forces the row to overflow instead of
     shrinking to fit, even though a fixed `width` was set inline for the
     desktop table layout. min-width:0 lets them actually shrink here. */
  table.data-table tbody td input,
  table.data-table tbody td select {
    min-width: 0;
    flex: 1 1 auto;
  }

  table.data-table tbody td.actions-cell {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    padding-top: 10px;
  }
  table.data-table tbody td.actions-cell::before { display: none; }

  table.data-table tbody td[colspan] {
    justify-content: center;
    color: #94a3b8;
  }
  table.data-table tbody td[colspan]::before { display: none; }

  /* Billing item rows: the Item cell holds two stacked inputs (category +
     name), which doesn't fit the generic label-left/single-input-right
     layout every other cell uses -- give it its own column so the label
     sits above full-width inputs instead of squeezing them into whatever
     space is left after the label. */
  table.items-table tbody td[data-label="Item"] {
    flex-direction: column;
    align-items: stretch;
  }
  table.items-table tbody td[data-label="Item"] input { width: 100%; }

  /* Other Charges row (title + amount + %/₹ + remove): plain flex div,
     not a table, so it needs its own wrap -- the fixed 200+100+70px
     widths otherwise overflow any phone-width screen. */
  .oc-row { flex-wrap: wrap; }
  .oc-row .oc-title { flex: 1 1 100%; width: auto !important; }
  .oc-row .oc-value { flex: 1 1 auto; width: auto !important; }
}

@media (max-width: 480px) {
  .bill-header-grid { grid-template-columns: 1fr; }
  .modal-box { width: calc(100vw - 32px); }
}

/* Icon-only actions, opt-in per table via .icon-only on the cell -- applies
   at every width (unlike the mobile-only rule above) and relies on each
   button's title attribute to supply the label instead. */
.actions-cell.icon-only .btn-label { display: none; }

/* ── Bill list card redesign (mobile) ───────────────────────────────────── */
@media (max-width: 768px) {
  table.bill-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    padding: 0;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  }

  table.bill-table tbody td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    flex: 0 0 50%;
    padding: 9px 13px;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
    gap: 2px;
  }
  table.bill-table tbody td::before {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
    min-width: 0;
    line-height: 1;
  }

  /* ── Header: Bill # | Date | Total (3 columns, dark) ── */
  table.bill-table tbody td[data-label="Bill #"],
  table.bill-table tbody td[data-label="Date"],
  table.bill-table tbody td[data-label="Total"] {
    flex: 0 0 33.33%;
    background: #1e293b;
    color: #f1f5f9;
    font-size: 14px;
    font-weight: 700;
    border-bottom: none;
    border-right: 1px solid #334155;
  }
  table.bill-table tbody td[data-label="Bill #"]::before,
  table.bill-table tbody td[data-label="Date"]::before,
  table.bill-table tbody td[data-label="Total"]::before { color: #64748b; }

  table.bill-table tbody td[data-label="Bill #"] { order: 1; }
  table.bill-table tbody td[data-label="Date"]   { order: 2; }
  table.bill-table tbody td[data-label="Total"] {
    order: 3;
    align-items: flex-end;
    color: #4ade80;
    border-right: none;
  }

  /* ── Customer — full width ── */
  table.bill-table tbody td[data-label="Customer"] {
    order: 4;
    flex: 0 0 100%;
    font-size: 14px;
    font-weight: 600;
    color: #0f172a;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
  }
  table.bill-table tbody td[data-label="Customer"]::before { color: #64748b; }

  /* ── Status | Items ── */
  table.bill-table tbody td[data-label="Status"] {
    order: 5;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  table.bill-table tbody td[data-label="Items"] {
    order: 6;
    align-items: flex-end;
    border-left: 1px solid #f1f5f9;
  }

  /* Mode column hidden on mobile — info moves into Status cell */
  table.bill-table tbody td[data-label="Mode"] { display: none; }
  table.bill-table .mode-suffix {
    display: inline;
    font-size: 12px;
    color: #64748b;
    font-weight: 600;
  }

  /* ── Actions — full width ── */
  table.bill-table tbody td.actions-cell {
    order: 8;
    flex: 0 0 100%;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    border-bottom: none;
    padding: 10px 13px;
  }
  table.bill-table tbody td.actions-cell::before { display: none; }
  table.data-table tbody td.actions-cell .btn-label { display: none; }

  /* Ledger transaction cards */
  table.ledger-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    padding: 0;
  }
  table.ledger-table tbody td {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex: 0 0 100%;
    padding: 9px 13px;
    font-size: 13px;
    border-bottom: 1px solid #f1f5f9;
    gap: 8px;
  }
  table.ledger-table tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #94a3b8;
    flex-shrink: 0;
  }

  /* Dark header — Date (left) + running Balance (right), forced to top via order */
  table.ledger-table tbody td[data-label="Date"]    { order: 1; flex: 0 0 50%; background: #1e293b; color: #f1f5f9; padding: 10px 13px; font-weight: 700; font-size: 14px; border-bottom: none; }
  table.ledger-table tbody td[data-label="Balance"] { order: 2; flex: 0 0 50%; background: #1e293b; color: #4ade80;  padding: 10px 13px; font-weight: 700; font-size: 14px; border-bottom: none; }
  table.ledger-table tbody td[data-label="Date"]::before,
  table.ledger-table tbody td[data-label="Balance"]::before { color: #94a3b8; }

  table.ledger-table tbody td[data-label="B"]         { order: 3; }
  table.ledger-table tbody td[data-label="Narration"] { order: 4; }
  table.ledger-table tbody td[data-label="Debit"]     { order: 5; }
  table.ledger-table tbody td[data-label="Credit"]    { order: 6; }

  table.ledger-table tbody td.actions-cell {
    order: 99;
    flex: 0 0 100%;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 8px 13px;
    background: #f8fafc;
    border-bottom: none;
  }
  table.ledger-table tbody td.actions-cell::before { display: none; }

  /* Mobile Add Transaction toggle */
  .mobile-add-wrap { display: block; margin-bottom: 12px; }
  .mobile-add-btn  { width: 100%; }
  .mobile-txn-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.3s ease;
    opacity: 0;
    margin-top: 0;
  }
  .mobile-txn-panel.open {
    max-height: 900px;
    opacity: 1;
    margin-top: 10px;
  }
  /* The sidebar Add/Edit form is only hidden on mobile for pages that
     supply the .mobile-add-wrap toggle+panel above the table as a
     replacement (currently just the Customer ledger) -- otherwise the
     form would just vanish with no way to add/edit anything from a
     phone. Every other .items-layout page keeps its sidebar, just moved
     above the table (order) so it's visible without scrolling past a
     potentially long list first. */
  .items-layout.has-mobile-toggle .items-sidebar { display: none; }
  .items-layout:not(.has-mobile-toggle) .items-sidebar { order: -1; }
}
