/* Business Manager — blue theme design system.
   Mirrors the React reference app's layout & components (shadcn-style tokens):
   light sidebar (w-60), h-14 sticky topbar with user menu, DataTable with
   expandable line-item rows, status badge color map, summary cards, tabs.
   Responsive: off-canvas drawer < 1024px, grids collapse, tables scroll.
   No external fonts, no CDN: fully offline, shared-hosting friendly. */

:root {
  /* brand — blue */
  --brand-50: #eff6ff;
  --brand-100: #dbeafe;
  --brand-200: #bfdbfe;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --brand-800: #1e40af;
  --brand-950: #172554;
  /* neutrals (React :root tokens) */
  --background: #ffffff;
  --foreground: #1c1d21;
  --muted: #f4f4f5;
  --muted-2: #fafafa;          /* muted/50 table header */
  --muted-foreground: #71717a;
  --border: #e5e7eb;
  --border-soft: #f1f2f4;
  --card: #ffffff;
  --ring: #93b4fd;
  --shadow-sm: 0 1px 2px rgba(28, 29, 33, .05);
  /* status colors (React STATUS_STYLES) */
  --slate-bg: #f1f5f9;  --slate-fg: #334155;  --slate-bd: #e2e8f0;
  --sky-bg: #f0f9ff;    --sky-fg: #0369a1;    --sky-bd: #bae6fd;
  --amber-bg: #fffbeb;  --amber-fg: #b45309;  --amber-bd: #fde68a;
  --green-bg: #ecfdf5;  --green-fg: #047857;  --green-bd: #a7f3d0;
  --red-bg: #fef2f2;    --red-fg: #b91c1c;    --red-bd: #fecaca;
  --zinc-bg: #f4f4f5;   --zinc-fg: #71717a;   --zinc-bd: #e4e4e7;
  --violet-bg: #f5f3ff; --violet-fg: #6d28d9; --violet-bd: #ddd6fe;
  /* semantic */
  --green: #047857;
  --amber: #b45309;
  --red: #b91c1c;
  --info-bg: #f0f9ff;  --info-fg: #0369a1;
  /* share channels (customers/account share dialog) */
  --wa: #059669;
  --tg: #0284c7;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f7f8fa;             /* bg-muted/30 over white */
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-600); text-decoration: none; }
a:hover { color: var(--brand-700); }

.icon { width: 16px; height: 16px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; flex-shrink: 0; }

/* ============================ shell ============================ */
.shell { display: flex; min-height: 100vh; }

/* --- sidebar: light, 240px (React w-60), sticky full height --- */
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--background);
  border-right: 1px solid var(--border);
  color: var(--foreground);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  z-index: 50;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; height: 56px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  background: var(--brand-700); color: #fff; font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.brand-name { font-weight: 700; font-size: 13.5px; line-height: 1.2; }
.brand-sub { font-size: 10px; color: var(--muted-foreground); }

.nav { padding: 14px 8px 20px; flex: 1; overflow-y: auto; }
.nav-group {
  margin: 0 0 4px; padding: 0 8px;
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted-foreground);
}
.nav-section + .nav-section { margin-top: 16px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; margin: 2px 0; min-height: 36px;
  border-radius: 6px; font-size: 13.5px; font-weight: 400;
  color: var(--muted-foreground); transition: background .12s, color .12s;
}
.nav a:hover { background: var(--muted); color: var(--foreground); }
.nav a.active { background: var(--brand-700); color: #fff; font-weight: 500; }
.nav a.active:hover { background: var(--brand-700); color: #fff; }
.nav a .badge-dot {
  margin-left: auto; background: var(--brand-600); color: #fff;
  border-radius: 10px; font-size: 10.5px; padding: 1px 7px; font-weight: 700;
}
.sidebar-footer {
  padding: 12px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--muted-foreground);
  display: flex; align-items: center; gap: 6px;
}
.sidebar-footer .role { color: var(--muted-foreground); }
.sidebar-footer .who { display: none; }   /* name shown in topbar user menu */

/* --- main column --- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 16px;
  background: rgba(255, 255, 255, .95);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar .topbar-title { display: none; }  /* titles live in page headers */
.topbar .spacer { flex: 1; }
.menu-btn {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 0; background: none; cursor: pointer;
  border-radius: 8px; color: var(--foreground);
}
.menu-btn:hover { background: var(--muted); }
.content { padding: 16px 24px 40px; flex: 1; }

/* --- user menu (topbar dropdown) --- */
.user-menu { position: relative; }
.user-menu > button {
  display: flex; align-items: center; gap: 8px;
  border: 0; background: none; cursor: pointer; padding: 4px 8px;
  border-radius: 8px; font: inherit;
}
.user-menu > button:hover { background: var(--muted); }
.avatar {
  width: 28px; height: 28px; border-radius: 9999px;
  background: var(--brand-700); color: #fff;
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.user-name { font-size: 13.5px; font-weight: 500; }
.user-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  width: 224px; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(28,29,33,.12);
  padding: 6px; z-index: 60;
}
.user-dropdown.open { display: block; }
.user-dropdown .ud-head { padding: 8px; }
.user-dropdown .ud-name { font-size: 13.5px; font-weight: 500; }
.user-dropdown .ud-email { font-size: 12px; color: var(--muted-foreground); }
.user-dropdown .ud-sep { height: 1px; background: var(--border-soft); margin: 4px 0; }
.user-dropdown button.ud-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 0; background: none; cursor: pointer; font: inherit;
  padding: 8px; border-radius: 6px; font-size: 13.5px; color: var(--foreground);
}
.user-dropdown button.ud-item:hover { background: var(--muted); }

/* --- mobile drawer --- */
.drawer-overlay {
  display: none; position: fixed; inset: 0; z-index: 45;
  background: rgba(28,29,33,.5);
}
.drawer-overlay.show { display: block; }

/* ==================== page header (React PageHeader) ==================== */
.page-header {
  display: flex; flex-wrap: wrap; align-items: flex-start;
  justify-content: space-between; gap: 12px; margin-bottom: 16px;
}
.page-header h1 {
  margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em;
  line-height: 1.25; overflow-wrap: break-word;
}
@media (min-width: 768px) { .page-header h1 { font-size: 24px; } }
.page-header .ph-sub { margin: 2px 0 0; font-size: 13.5px; color: var(--muted-foreground); overflow-wrap: break-word; }
.page-header .ph-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13.5px; color: var(--muted-foreground);
  background: none; border: 0; cursor: pointer; padding: 4px 8px; margin: 0 0 4px -8px;
  border-radius: 6px; font-family: inherit;
}
.back-link:hover { background: var(--muted); color: var(--foreground); }

/* ==================== filter bar (React FilterBar) ==================== */
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.filter-bar .field-inline { display: flex; align-items: center; gap: 6px; }
.filter-bar label.flabel { font-size: 12.5px; color: var(--muted-foreground); }
/* Inputs default to width:100% for form fields — inside a filter bar they
   must be compact, otherwise every date/select wraps onto its own full-width
   row and pushes the list far down the page. */
.filter-bar .search-box { width: 240px; max-width: 100%; flex: 0 1 auto; }
.filter-bar input[type="date"] { width: 150px; }
.filter-bar input[type="text"] { width: 200px; }
.filter-bar select { width: auto; max-width: 230px; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted-foreground); width: 15px; height: 15px; }
.search-box input { padding-left: 32px; }

/* ==================== cards / grids ==================== */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-title .icon { color: var(--brand-700); }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.span-2 { grid-column: span 2 / span 2; }
@media (max-width: 1280px) { .grid-3 { grid-template-columns: minmax(0, 1fr); } .grid-3 > .span-2 { grid-column: auto; } }
@media (max-width: 1000px) { .grid-4, .grid-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span-2 { grid-column: auto; } }
@media (max-width: 820px)  { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
/* grid children must be shrinkable so wide .table-wrap tables scroll inside
   the card instead of stretching the page (mobile horizontal-overflow fix) */
.grid > *, .grid-2 > *, .grid-3 > *, .grid-4 > *, .grid-6 > * { min-width: 0; }

/* --- summary card (React SummaryCard) --- */
.sum-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (min-width: 768px) { .sum-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.sum-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-sm); padding: 16px;
  display: flex; align-items: flex-start; gap: 12px; min-width: 0;
}
.sum-card .sc-icon { border-radius: 8px; padding: 8px; flex-shrink: 0; background: var(--muted); color: var(--muted-foreground); }
.sum-card .sc-body { min-width: 0; flex: 1; }
.sum-card .sc-label { font-size: 12px; font-weight: 500; color: var(--muted-foreground); text-transform: uppercase; letter-spacing: .03em; }
.sum-card .sc-value { font-size: 17px; font-weight: 700; line-height: 1.25; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 1280px) { .sum-card .sc-value { font-size: 18px; } }
.sum-card .sc-sub { font-size: 12px; color: var(--muted-foreground); margin-top: 2px; }
.sum-card.tone-success .sc-value { color: var(--green-fg); }
.sum-card.tone-warning .sc-value { color: var(--amber-fg); }
.sum-card.tone-danger  .sc-value { color: var(--red-fg); }
.sum-card.tone-info    .sc-value { color: var(--info-fg); }
.sum-card.tone-success .sc-icon { background: #d1fae5; color: var(--green-fg); }
.sum-card.tone-warning .sc-icon { background: #fef3c7; color: var(--amber-fg); }
.sum-card.tone-danger  .sc-icon { background: #fee2e2; color: var(--red-fg); }
/* KPI cards are anchors deep-linking to the matching list; cards without an
   href (permission withheld) keep the plain look, clickable ones get affordance. */
a.sum-card { color: inherit; }
a.sum-card[href] { transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
a.sum-card[href]:hover { border-color: var(--brand-600); box-shadow: var(--shadow-sm), 0 0 0 3px rgba(59, 110, 241, .10); transform: translateY(-1px); }
.sum-card.tone-info    .sc-icon { background: #e0f2fe; color: var(--info-fg); }

/* ==================== buttons ==================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand-600); color: #fff; border: 1px solid var(--brand-600);
  height: 36px; padding: 0 14px; border-radius: 8px; font-weight: 500; font-size: 13.5px;
  cursor: pointer; text-decoration: none; line-height: 1; white-space: nowrap;
}
.btn:hover { background: var(--brand-700); color: #fff; border-color: var(--brand-700); }
.btn.secondary { background: #fff; color: var(--foreground); border-color: var(--border); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { background: var(--muted); color: var(--foreground); border-color: var(--border); }
.btn.ghost { background: none; color: var(--muted-foreground); border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--muted); color: var(--foreground); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red-bd); }
.btn.danger:hover { background: var(--red-bg); color: var(--red); border-color: var(--red-bd); }
.btn.small { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.icon-btn { width: 32px; height: 32px; padding: 0; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.w-100 { width: 100%; }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; border-radius: 6px; }

/* ==================== forms ==================== */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; font-weight: 500; color: var(--foreground); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], select, textarea {
  width: 100%; height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; color: var(--foreground); background: #fff; box-shadow: var(--shadow-sm);
}
textarea { height: auto; min-height: 74px; padding: 8px 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-100); border-color: var(--brand-500); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.inline-check { display: flex; align-items: center; gap: 7px; margin-bottom: 12px; font-size: 13.5px; }
.inline-check input { width: auto; height: auto; }
.help-text { font-size: 12px; color: var(--muted-foreground); margin-top: 3px; }

/* ==================== tables (React DataTable) ==================== */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--border);
  border-radius: 10px; background: #fff;
}
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted-foreground);
  background: var(--muted-2);
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafafa; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.ctr, table.data th.ctr { text-align: center; }
table.data .cell-main { font-weight: 500; }
table.data .cell-sub { font-size: 12px; color: var(--muted-foreground); overflow-wrap: break-word; }
table.data .actions { display: flex; gap: 6px; justify-content: flex-end; }
table.data tfoot td { font-weight: 700; background: var(--muted-2); border-top: 1px solid var(--border); }
.empty-state { padding: 44px 16px; text-align: center; color: var(--muted-foreground); }
.empty-state .icon { width: 30px; height: 30px; opacity: .4; margin-bottom: 8px; }
.empty-state p { margin: 0; }

/* --- expandable line-item rows --- */
tr.expand-btn { cursor: pointer; }
tr.expand-btn .chev { display: inline-flex; transition: transform .15s; color: var(--muted-foreground); }
tr.expand-btn .chev .icon { width: 15px; height: 15px; }
tr.expand-btn.open .chev { transform: rotate(180deg); }
tr.expand-btn.open td { background: #fafafa; }
tr.expand-row > td { display: none; }
tr.expand-row.show > td { display: table-cell; background: #f7f8fa; padding: 0; border-bottom: 1px solid var(--border); }
tr.expand-row > td > .expand-inner { padding: 14px 16px; }
.expand-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted-foreground); margin-bottom: 6px;
}
.mini-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.mini-table th {
  background: #f9fafb; padding: 6px 12px; text-align: left; font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em; font-weight: 600; color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
}
.mini-table td { padding: 6px 12px; border-top: 1px solid var(--border-soft); }
.mini-table td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted-foreground); }
.mini-table td.tot { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.mini-table tr:first-child th { border-top: 0; }
@media (max-width: 640px) { .mini-table th:nth-child(3), .mini-table td:nth-child(3) { } }

/* ==================== badges (React STATUS_STYLES) ==================== */
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 6px; font-size: 12px; font-weight: 500;
  letter-spacing: .01em; white-space: nowrap;
  border: 1px solid transparent;
}
.badge.PAID, .badge.RECEIVED, .badge.DELIVERED, .badge.ACTIVE, .badge.APPLIED, .badge.RECEIVED_OK, .badge.OK {
  background: var(--green-bg); color: var(--green-fg); border-color: var(--green-bd);
}
.badge.ISSUED, .badge.CONFIRMED, .badge.ORDERED, .badge.APPROVED {
  background: var(--sky-bg); color: var(--sky-fg); border-color: var(--sky-bd);
}
.badge.PARTIALLY_PAID, .badge.PARTIALLY_RECEIVED, .badge.PARTIALLY_DELIVERED, .badge.PENDING {
  background: var(--amber-bg); color: var(--amber-fg); border-color: var(--amber-bd);
}
.badge.OVERDUE, .badge.REVERSED, .badge.REJECTED {
  background: var(--red-bg); color: var(--red-fg); border-color: var(--red-bd);
}
.badge.DRAFT, .badge.INACTIVE { background: var(--slate-bg); color: var(--slate-fg); border-color: var(--slate-bd); }
.badge.CANCELLED { background: var(--zinc-bg); color: var(--zinc-fg); border-color: var(--zinc-bd); }
.badge.CONVERTED { background: var(--violet-bg); color: var(--violet-fg); border-color: var(--violet-bd); }
.badge.neutral { background: var(--muted); color: var(--muted-foreground); border-color: var(--border); }
.badge.LOW, .badge.brand { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-200); }
.badge.red { background: var(--red-bg); color: var(--red-fg); border-color: var(--red-bd); }

/* ==================== flash ==================== */
.flash { margin-bottom: 16px; }
.flash .msg { padding: 10px 14px; border-radius: 9px; font-weight: 500; font-size: 13.5px; display: flex; justify-content: space-between; gap: 12px; cursor: pointer; }
.flash .ok { background: var(--green-bg); color: var(--green-fg); border: 1px solid var(--green-bd); }
.flash .err { background: var(--red-bg); color: var(--red-fg); border: 1px solid var(--red-bd); }
.flash .warn { background: var(--amber-bg); color: var(--amber-fg); border: 1px solid var(--amber-bd); }

/* ==================== pagination (React Pagination) ==================== */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 0 0; font-size: 13.5px; color: var(--muted-foreground); }
.pager .links { display: flex; align-items: center; gap: 4px; }
.pager .links a, .pager .links span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
  color: var(--foreground); font-size: 12.5px;
}
.pager .links a:hover { background: var(--muted); color: var(--foreground); }
.pager .links span.current { background: var(--brand-600); border-color: var(--brand-600); color: #fff; font-weight: 600; }
.pager .links span.disabled { opacity: .45; }
.pager b { color: var(--foreground); }

/* ==================== tabs (dashboard recent activity) ==================== */
.tabs-list {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--muted); border-radius: 10px;
  max-width: 100%; overflow-x: auto; margin-bottom: 12px;
}
.tabs-list button {
  border: 0; background: none; cursor: pointer; font: inherit;
  font-size: 13px; font-weight: 500; color: var(--muted-foreground);
  padding: 6px 12px; border-radius: 7px; white-space: nowrap;
}
.tabs-list button.active { background: #fff; color: var(--foreground); box-shadow: var(--shadow-sm); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ==================== charts (SVG, server-rendered) ==================== */
.chart-card .chart-box { height: 256px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted-foreground); justify-content: center; padding-top: 6px; }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
svg.chart text { font-size: 10.5px; fill: var(--muted-foreground); font-family: inherit; }
.exp-bar-row { margin-bottom: 8px; }
.exp-bar-row .exp-labels { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.exp-bar-row .exp-labels .amt { font-variant-numeric: tabular-nums; color: var(--muted-foreground); }
.exp-bar-row .exp-track { height: 6px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.exp-bar-row .exp-fill { height: 100%; border-radius: 999px; background: var(--brand-500); }

/* --- dashboard list rows (debtors / alerts) --- */
.row-list { display: flex; flex-direction: column; gap: 8px; }
.debtor-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px;
  background: #fff; cursor: pointer; font: inherit; text-align: left;
  transition: border-color .12s;
}
.debtor-row:hover { border-color: var(--brand-500); }
.debtor-row .rank {
  width: 24px; height: 24px; border-radius: 999px; background: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--foreground); flex-shrink: 0;
}
.debtor-row .d-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.debtor-row .d-body { flex: 1; min-width: 0; }
.debtor-row .d-code { font-size: 12px; color: var(--muted-foreground); }
.debtor-row .d-right { text-align: right; flex-shrink: 0; margin-left: auto; }
.debtor-row .d-out { font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.debtor-row .d-over { font-size: 12px; color: var(--red-fg); font-variant-numeric: tabular-nums; }
.alert-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid #fee2e2; background: rgba(254, 242, 242, .4);
  border-radius: 10px; padding: 8px 12px;
}
.alert-row .a-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-row .a-sub { font-size: 12px; color: var(--muted-foreground); }
.alert-row .a-sub .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 11.5px; }
.alert-row .a-right { text-align: right; flex-shrink: 0; margin-left: auto; }
.alert-row .a-qty { font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--red-fg); }
.alert-row .a-level { font-size: 12px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.alert-row .a-reorder { font-size: 12px; font-weight: 500; color: var(--brand-800); font-variant-numeric: tabular-nums; }

/* ==================== line item editor ==================== */
.lines-box { border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; background: #fff; }
.lines-table { width: 100%; border-collapse: collapse; min-width: 860px; font-size: 13px; }
.lines-table th {
  background: var(--muted-2); padding: 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; font-weight: 600; color: var(--muted-foreground); text-align: left;
  border-bottom: 1px solid var(--border);
}
.lines-table td { padding: 6px 8px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.lines-table input, .lines-table select { padding: 0 8px; font-size: 13px; height: 34px; }
.lines-table .col-desc input { min-width: 220px; }
.lines-table .narrow { width: 70px; }
.lines-table .line-total { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; padding-top: 12px; }
.lines-table .row-del { color: var(--red); border: 0; background: none; cursor: pointer; font-size: 15px; padding-top: 9px; }
.lines-totals {
  display: flex; gap: 26px; justify-content: flex-end; padding: 12px 14px;
  background: var(--muted-2); border-top: 1px solid var(--border); flex-wrap: wrap;
}
.lines-totals .tot { font-size: 13px; color: var(--muted-foreground); }
.lines-totals .tot strong { display: block; color: var(--foreground); font-size: 15px; font-variant-numeric: tabular-nums; }

/* allocation helper */
.alloc-hint { font-size: 12.5px; color: var(--muted-foreground); margin-top: 4px; }
.alloc-sum { font-weight: 700; color: var(--brand-700); }

/* ==================== auth (React LoginScreen) ==================== */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #172554, #0f172a 55%, #020617);
  padding: 20px;
}
.auth-card {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(2, 6, 23, .45); width: 448px; max-width: 100%;
  padding: 24px;
}
.auth-card .brand { border: 0; padding: 0 0 16px; justify-content: center; height: auto; }
.auth-card .brand-mark { width: 48px; height: 48px; border-radius: 12px; margin: 0 auto 10px; font-size: 20px; }
.auth-card .brand > div { text-align: center; }
.auth-card h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; text-align: center; letter-spacing: -.01em; }
.auth-card .sub { color: var(--muted-foreground); text-align: center; font-size: 13.5px; margin: 0 0 20px; }
.auth-card .btn { height: 40px; }
.auth-hint {
  margin-top: 16px; background: var(--muted); border: 1px solid var(--border);
  padding: 12px; border-radius: 10px; font-size: 12.5px; color: var(--muted-foreground);
}
.auth-hint strong { color: var(--foreground); font-weight: 500; }
.auth-hint code { background: #fff; border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }

/* ==================== misc ==================== */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters label.field { margin-bottom: 0; min-width: 150px; }
.muted { color: var(--muted-foreground); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.right { text-align: right; }
.w-100 { width: 100%; }
.mb-0 { margin-bottom: 0; }
.mt-8 { margin-top: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted-foreground); }
.kv dd { margin: 0; font-weight: 500; }
@media (max-width: 640px) { .kv { grid-template-columns: 1fr; gap: 0; } .kv dt { margin-top: 8px; } }
.tag-openings {
  display: inline-block; background: var(--brand-50); border: 1px solid var(--brand-200);
  color: var(--brand-700); border-radius: 8px; padding: 2px 8px; font-size: 11.5px; font-weight: 600;
}
.money-pos { color: var(--green-fg); font-variant-numeric: tabular-nums; }
.money-neg { color: var(--red-fg); font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ==================== modal (React-style dialogs for quick forms) ==================== */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 70;
  background: rgba(28, 29, 33, .55);
  align-items: flex-start; justify-content: center; padding: 40px 16px;
  overflow-y: auto;
}
.modal-overlay.show { display: flex; }
.modal-card {
  background: #fff; border-radius: 14px; box-shadow: 0 24px 70px rgba(2, 6, 23, .35);
  width: 520px; max-width: 100%; padding: 20px; position: relative;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-head .modal-sub { font-size: 12.5px; color: var(--muted-foreground); margin: 2px 0 0; }
.modal-close {
  border: 0; background: none; cursor: pointer; color: var(--muted-foreground);
  width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--muted); color: var(--foreground); }

/* ==================== responsive: drawer < 1024px ==================== */
@media (max-width: 1023px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100vh;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 50px rgba(2, 6, 23, .18); }
  .content { padding: 16px 12px 32px; }
}
@media (max-width: 640px) {
  .user-name { display: none; }
  .topbar { padding: 0 8px; }
  .page-header h1 { font-size: 20px; }
  .filters label.field { min-width: 130px; }
}

/* print: PDF pages manage their own styles */
@media print {
  .sidebar, .topbar, .flash, .pager, .btn { display: none !important; }
  body { background: #fff; }
}

/* ==================== shared utilities (replaces per-view inline styles) === */
.ml-auto { margin-left: auto; }
.mt-4 { margin-top: 4px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mb-10 { margin-bottom: 10px; }
.mb-16 { margin-bottom: 16px; }
.flush { padding: 0; }            /* card/table wrapper without body padding */
.stack { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #fff; }
.panel.muted { background: var(--muted-2); }
.scroll-box { max-height: 190px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.actions-end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.form-actions {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-soft);
}
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hide-sm { display: inline; }
@media (max-width: 640px) { .hide-sm { display: none; } }
.text-good { color: var(--green-fg); }
.text-bad { color: var(--red-fg); }
.text-warn { color: var(--amber); display: inline-flex; }
.row-warn { background: rgba(254, 242, 242, .5); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.w-430 { max-width: 430px; }
.w-672 { max-width: 672px; }
.w-760 { max-width: 760px; }
.amt-pos { color: var(--green); font-weight: 600; font-variant-numeric: tabular-nums; }
.amt-neg { color: var(--red); font-weight: 600; font-variant-numeric: tabular-nums; }

/* fixed-width filter/select inputs (filter bars) */
.w-130 { width: 130px; max-width: 100%; }
.w-150 { width: 150px; max-width: 100%; }
.w-160 { width: 160px; max-width: 100%; }
.w-190 { width: 190px; max-width: 100%; }
.w-210 { width: 210px; max-width: 100%; }
.w-240 { width: 240px; max-width: 100%; }
.w-280 { width: 280px; max-width: 100%; }
.w-380 { max-width: 380px; }

/* ==================== report summary chips ==================== */
.sum-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.sum-chip { background: var(--muted); border-radius: 6px; padding: 6px 12px; font-size: 13.5px; color: var(--muted-foreground); }
.sum-chip b { color: var(--foreground); font-weight: 600; }

/* ==================== dashboard helpers ==================== */
.dash-row { margin-bottom: 16px; }                 /* grid rows on the dashboard */
.dash-card { margin-bottom: 0; }                    /* cards inside dash-row grids */
.chart-empty { padding: 40px 0; text-align: center; }
.dash-exp-total { font-size: 24px; font-weight: 700; }
.dash-trend-note { padding: 16px 0; text-align: center; }
.legend .dot.sales { background: #1d4ed8; }
.legend .dot.purchases { background: #d97706; }
.icon-alarm-good { color: var(--green-fg); }
.icon-alarm-bad { color: #dc2626; }

/* customer/supplier account: pick rows (invoice/workspace selection) */
.pick-list { border: 1px solid var(--border); border-radius: 8px; max-height: 280px; overflow-y: auto; }
.pick-row {
  display: flex; gap: 8px; align-items: center;
  padding: 7px 10px; border-bottom: 1px solid var(--border);
  font-size: 13px; cursor: pointer;
}
.pick-row:last-child { border-bottom: 0; }
.pick-row:hover { background: var(--muted-2); }
.sticky-panel { position: sticky; top: 64px; align-self: start; }
.alloc-in { max-width: 110px; }

/* document show pages: right-aligned totals panel */
.totals-panel { max-width: 320px; margin-left: auto; }
.totals-panel .tp-row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }

/* ==================== error pages ==================== */
.error-card { text-align: center; }
.error-card .brand { justify-content: center; }
.error-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* ==================== inline toggle forms (account pages) ==================== */
.toggle-form { display: none; }
.toggle-form.show-inline { display: block; }

/* share statement dialog buttons */
.btn.share-wa { background: var(--wa); border-color: var(--wa); }
.btn.share-wa:hover { background: #047857; border-color: #047857; }
.btn.share-tg { color: #0369a1; border-color: #bae6fd; }
.btn.share-tg:hover { background: #f0f9ff; color: #0369a1; border-color: #bae6fd; }
.w-430 { max-width: 430px; }

/* ==================== reports index (report picker cards) ==================== */
.report-card {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; box-shadow: var(--shadow-sm); color: var(--foreground);
  transition: border-color .12s, box-shadow .12s;
}
.report-card:hover { border-color: var(--brand-500); box-shadow: 0 4px 14px rgba(29, 78, 216, .10); color: var(--foreground); }
.rc-icon {
  width: 32px; height: 32px; border-radius: 8px; margin-bottom: 4px;
  background: var(--brand-50); color: var(--brand-700);
  display: flex; align-items: center; justify-content: center;
}
.rc-name { font-weight: 600; font-size: 13.5px; }
.rc-desc { font-size: 12.5px; color: var(--muted-foreground); flex: 1; }
.rc-open { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 500; color: var(--brand-700); margin-top: 6px; }

/* Reports toolbar — search box + group tab chips (client-side filter) */
.report-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
/* Denser card grid: 3 columns down to 1100px (the generic .grid-3 collapses at 1280px). */
.report-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .report-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px)  { .report-grid { grid-template-columns: minmax(0, 1fr); } }
.report-search {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 230px; max-width: 360px;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: #fff;
  color: var(--muted-foreground);
}
.report-search input { border: 0; outline: 0; flex: 1; font-size: 13.5px; background: transparent; color: var(--foreground); }
.report-search input::placeholder { color: var(--muted-foreground); }
.report-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.report-tab {
  border: 1px solid var(--border); background: #fff; color: var(--muted-foreground);
  border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: border-color .12s, background .12s, color .12s;
}
.report-tab:hover { color: var(--brand-700); border-color: var(--brand-200); }
.report-tab.active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.rt-count {
  font-size: 11px; font-weight: 700; background: var(--muted); color: var(--muted-foreground);
  border-radius: 999px; padding: 1px 7px;
}
.report-tab.active .rt-count { background: rgba(255, 255, 255, .22); color: #fff; }

/* Fulfilment badges (Order Fulfillment report) */
.badge.OPEN { background: var(--slate-bg); color: var(--slate-fg); border-color: var(--slate-bd); }
.badge.PARTIAL { background: var(--amber-bg); color: var(--amber-fg); border-color: var(--amber-bd); }
.badge.COMPLETE { background: var(--green-bg); color: var(--green-fg); border-color: var(--green-bd); }
.badge.SALES { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-200); }
.badge.PURCHASE { background: var(--violet-bg); color: var(--violet-fg); border-color: var(--violet-bd); }

/* ==================== users & roles (RBAC matrix) ==================== */
.rbac-mod td {
  background: var(--muted); border-bottom: 1px solid var(--border-soft);
  padding: 5px 12px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--brand-800);
}
.ok-mark { color: var(--green); }
.inline-form { display: inline-flex; align-items: center; gap: 8px; }
