:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6eb;
  --text: #16181d;
  --text-2: #4d5360;
  --muted: #7a8190;
  --primary: #1f4b99;
  --primary-hover: #183d7e;
  --primary-soft: #e8eef9;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #067647;
  --success-soft: #e7f6ee;
  --warning: #93600b;
  --warning-soft: #fff5e0;
  --info-soft: #e8f1fd;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
  --sidebar: 236px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111317;
    --surface: #1a1c21;
    --surface-2: #22252b;
    --border: #2e323a;
    --text: #eceef2;
    --text-2: #bfc4ce;
    --muted: #8d94a3;
    --primary: #5b8ef0;
    --primary-hover: #7aa4f3;
    --primary-soft: #1f2a40;
    --danger: #f97066;
    --danger-soft: #3a1f1d;
    --success: #47cd89;
    --success-soft: #16301f;
    --warning: #fdb022;
    --warning-soft: #3a2c12;
    --info-soft: #1c2a3d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2a2d34;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317; --surface: #1a1c21; --surface-2: #22252b; --border: #2e323a; --text: #eceef2; --text-2: #bfc4ce;
  --muted: #8d94a3; --primary: #5b8ef0; --primary-hover: #7aa4f3; --primary-soft: #1f2a40; --danger: #f97066;
  --danger-soft: #3a1f1d; --success: #47cd89; --success-soft: #16301f; --warning: #fdb022; --warning-soft: #3a2c12;
  --info-soft: #1c2a3d; --series-1: #3987e5; --series-2: #d95926; --grid: #2a2d34; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; line-height: 1.3; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 14px; margin: 20px 0 8px; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.upper { text-transform: uppercase; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-link { border-color: transparent; background: none; color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row form { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.linklike { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.icon-btn { background: none; border: 0; cursor: pointer; padding: 6px; color: var(--text-2); border-radius: 6px; font-size: 18px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ---------- forms */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; color: var(--text-2); }
label.inline { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
label.inline input { width: auto; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.req { color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; font-weight: 500; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.form-grid.single { grid-template-columns: 1fr; }
.narrow-grid { max-width: 760px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.small-input { width: 110px; padding: 5px 8px; }

/* ---------- alerts & badges */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--text); }
.alert-warning { background: var(--warning-soft); color: var(--text); border-color: var(--warning); }
.alert.reveal code { font-size: 15px; user-select: all; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .02em; vertical-align: middle; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-paid, .badge-active, .badge-valid { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-overdue { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-partial, .badge-unpaid { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-void, .badge-inactive { text-decoration: line-through; }
.tag { font-size: 12px; color: var(--success); font-weight: 600; }

/* ---------- admin shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--border);
  position: fixed; top: 0; bottom: 0; left: 0; display: flex; flex-direction: column; z-index: 20; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: var(--text); text-decoration: none !important; }
.brand-center { justify-content: center; padding: 0 0 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; }
.brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.2; }
.brand-text small { font-weight: 400; color: var(--muted); font-size: 12px; }
.sidebar nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; text-decoration: none; }
.sidebar nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar nav a:hover { background: var(--surface-2); }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav-section { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sidebar-foot { padding: 14px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); }
.main { flex: 1; margin-left: var(--sidebar); min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.topbar [data-toggle] { display: none; }
.global-search { flex: 1; max-width: 460px; }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-menu form { margin: 0; }
.user-name { display: flex; flex-direction: column; line-height: 1.2; text-align: right; font-weight: 600; margin-right: 6px; }
.user-name small { color: var(--muted); font-weight: 400; }
.content { padding: 24px; max-width: 1400px; }

/* ---------- page parts */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions form { margin: 0; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 480px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card.flush .card-head { padding: 14px 16px 0; }
.card-head a { font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-2-wide { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; }
.stats-small .stat-value { font-size: 16px; }
.stat-hero .stat-value { font-size: 28px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { flex: 1 1 240px; width: auto; }
.filters select { width: auto; }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 12px; color: var(--text-2); }
.totals-bar { display: flex; gap: 22px; flex-wrap: wrap; margin: 0 0 10px; color: var(--text-2); }
.details { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.notes { margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 8px; white-space: normal; font-size: 13px; }
.login-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
details summary { cursor: pointer; color: var(--primary); font-weight: 500; margin: 10px 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.empty { text-align: center; color: var(--muted); padding: 22px !important; }

/* ---------- tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }
.table-hover tbody tr[data-href] { cursor: pointer; }
.table-hover tbody tr:hover td { background: var(--surface-2); }
.table-compact th, .table-compact td { padding: 6px 8px; }
.row-void td { color: var(--muted); }
.row-void td:not(:first-child) { text-decoration: line-through; }
.muted-row td { color: var(--muted); font-style: italic; }
.total-row td { font-weight: 700; }
.wrap-cell { max-width: 380px; }
.card.flush { overflow-x: auto; }
.table-scroll { overflow-x: auto; }
.items-table td { padding: 6px; }
.items-table .w-qty { width: 90px; }
.items-table .w-price { width: 140px; }
.items-table .w-x { width: 40px; }
.items-table .line-total { padding-top: 14px; }
.invoice-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; margin-top: 18px; align-items: start; }
.totals { width: 100%; border-collapse: collapse; }
.totals td { padding: 6px 0; }
.totals td.num input { text-align: right; margin-left: auto; display: block; }
.totals .grand td { font-size: 18px; font-weight: 700; border-top: 2px solid var(--border); padding-top: 10px; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0 20px; flex-wrap: wrap; }
.aging-bar-cell { width: 40%; }
.aging-bar { height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.aging-bar span { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }

/* ---------- chart */
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.chart-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.sw-1, .bar-1 { background: var(--series-1); }
.sw-2, .bar-2 { background: var(--series-2); }
.chart-plot { position: relative; height: 220px; margin: 0 0 26px 40px; }
.chart-grid { position: absolute; inset: 0; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid); }
.gridline span { position: absolute; left: -40px; width: 34px; text-align: right; top: -8px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 4px; }
.bar-group { flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; position: relative; outline: none; border-radius: 4px; }
.bar-group.hover, .bar-group:focus-visible { background: var(--surface-2); }
.bar { width: 38%; max-width: 16px; border-radius: 4px 4px 0 0; min-height: 0; }
.bar-label { position: absolute; bottom: -22px; font-size: 11px; color: var(--muted); }
.chart-tip { position: absolute; z-index: 50; background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 6px; font-size: 12px; white-space: pre; pointer-events: none; display: none; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.chart-table summary { font-size: 12px; }

/* ---------- document preview (invoice / receipt on screen) */
.doc-preview { padding: 32px; }
.doc { position: relative; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 24px; }
.doc-brand { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.doc-from { color: var(--text-2); font-size: 13px; }
.doc-title h2 { font-size: 22px; letter-spacing: .08em; color: var(--primary); margin: 0 0 8px; text-align: right; }
.doc-meta td { padding: 2px 0 2px 16px; font-size: 13px; }
.doc-meta td:first-child { color: var(--muted); padding-left: 0; }
.doc-to { margin-bottom: 18px; font-size: 13px; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.doc-subject { margin-bottom: 14px; }
.doc-items { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-items th { text-align: left; font-size: 12px; color: var(--muted); border-bottom: 2px solid var(--border); padding: 8px 6px; }
.doc-items th.num { text-align: right; }
.doc-items td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-items .w-no { width: 34px; }
.doc-totals { margin-left: auto; min-width: 280px; border-collapse: collapse; }
.doc-totals td { padding: 5px 6px; }
.doc-totals .grand td { font-weight: 700; font-size: 16px; border-top: 2px solid var(--border); }
.doc-totals .due td { font-weight: 700; color: var(--primary); }
.doc-words { margin: 14px 0; font-size: 13px; }
.doc-section { margin-top: 18px; font-size: 13px; }
.doc-small { border-collapse: collapse; font-size: 13px; }
.doc-small td, .doc-small th { padding: 3px 14px 3px 0; text-align: left; }
.doc-foot { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; text-align: center; }
.receipt-amount { background: var(--surface-2); border-radius: 10px; padding: 16px; margin: 10px 0 18px; }
.receipt-amount .big { font-size: 28px; font-weight: 700; color: var(--primary); }
.stamp { position: absolute; top: 215px; right: 30px; transform: rotate(-14deg); border: 3px solid; border-radius: 8px; padding: 4px 14px; font-size: 22px; font-weight: 800; letter-spacing: .12em; opacity: .55; pointer-events: none; }
.stamp-paid { color: var(--success); }
.stamp-void { color: var(--danger); }
.signature { display: flex; gap: 40px; margin-top: 40px; font-size: 12px; color: var(--muted); }
.signature > div { flex: 1; }
.signature .line { display: block; border-bottom: 1px solid var(--text-2); height: 30px; margin-bottom: 4px; }

/* ---------- auth */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 30px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.error-code { font-size: 54px; font-weight: 800; color: var(--primary); }

/* ---------- portal */
.wrap { max-width: 1180px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.portal-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.portal-header .wrap { display: flex; align-items: center; gap: 18px; min-height: 64px; flex-wrap: wrap; }
.portal-header .brand { padding: 10px 0; }
.portal-nav { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
.portal-nav > a { padding: 8px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.portal-nav > a.active { background: var(--primary-soft); color: var(--primary); }
.portal-user { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: 13px; }
.portal-user form { margin: 0; }
.portal-menu-btn { display: none; margin-left: auto; }
body.portal .content { padding-top: 24px; padding-bottom: 24px; }
.portal-footer { color: var(--muted); font-size: 12px; padding-top: 10px; padding-bottom: 30px; }

/* ---------- responsive */
@media (max-width: 1100px) {
  .grid-2, .grid-2-wide { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .topbar [data-toggle] { display: inline-flex; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; }
  .global-search { order: 3; flex-basis: 100%; max-width: none; }
  .user-name { display: none; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .invoice-bottom { grid-template-columns: minmax(0, 1fr); }
  .portal-menu-btn { display: inline-flex; }
  .portal-nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding-bottom: 12px; }
  .portal-nav.open { display: flex; }
  .portal-user { margin-left: 0; padding: 8px 12px; flex-wrap: wrap; }
  .doc-preview { padding: 16px; }
  .doc-title h2 { text-align: left; }
  .stat-value { font-size: 19px; }
  .filters label.inline { flex: 1 1 140px; }
  .filters label.inline input { width: 100%; }
}

/* dates & document numbers never wrap */
.statement td:nth-child(-n+2), .table td.nowrap { white-space: nowrap; }

/* ---------- refinements */
/* full width */
.content { max-width: none; }
/* client portal: centred, max 1200px (header bar background stays full width) */
.portal .wrap { max-width: 1200px; margin-left: auto; margin-right: auto; padding-left: 24px; padding-right: 24px; }
/* label text + required star / hint stay on one line */
label > .lbl { display: block; }
label > .lbl .req, label > .lbl .hint { display: inline; }
/* no underline on menus, buttons, chips, brand */
.sidebar nav a:hover, .portal-nav a:hover, .btn:hover, .chip:hover, .brand:hover, .card-head a:hover, .crumbs a:hover { text-decoration: none; }
.portal-nav > a:hover { background: var(--surface-2); color: var(--text); }
.portal-nav > a.active:hover { background: var(--primary-soft); color: var(--primary); }
.card-head a:hover, .crumbs a:hover { color: var(--primary-hover); }
/* period chips: selected one highlighted */
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
/* client portal header */
.portal-user { gap: 8px; }
.portal-user__name { font-weight: 600; color: var(--text-2); margin-right: 4px; }
/* auth pages */
.auth-title { font-size: 18px; margin: 0 0 6px; text-align: center; }
.auth-card .stack a { font-weight: 500; }
/* receipt signature shows name + date on the line */
.signature .line { display: flex; align-items: flex-end; padding-bottom: 4px; color: var(--text); font-weight: 600; }

/* ---------- responsive: phones & tablets */
@media (max-width: 860px) {
  .portal .wrap { padding-left: 16px; padding-right: 16px; }
  .page-head { align-items: flex-start; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .filters > * { flex: 1 1 100%; }
  .filters select, .filters .btn { width: 100%; }
  .chips { width: 100%; }
  .details { grid-template-columns: 110px minmax(0, 1fr); }
  .doc-head { flex-direction: column; gap: 14px; }
  .doc-meta td { padding-left: 10px; }
  .doc-totals { min-width: 0; width: 100%; }
  .doc-items { font-size: 13px; }
  .doc-items th, .doc-items td { padding: 6px 4px; }
  .stamp { position: static; display: inline-block; margin: 14px 0 0; transform: rotate(-4deg); font-size: 16px; }
  .signature { gap: 18px; }
  .user-menu .btn { padding: 4px 8px; }
  .table th, .table td { padding: 8px 10px; }
  .wrap-cell { min-width: 180px; }
  .invoice-bottom .totals { max-width: none; }
  .chart-plot { margin-left: 34px; }
  .bar { width: 40%; }
  .login-row .btn-row form { width: 100%; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-hero { grid-column: 1 / -1; }
  .stat-value { font-size: 16px; }
  .stat-label { font-size: 10px; }
  .stat-hero .stat-value { font-size: 24px; }
  h1 { font-size: 20px; }
  .items-table { min-width: 560px; }
  .bar-label { font-size: 9px; }
  .auth-card { padding: 22px; }
}

/* hidden mobile menu must not cast a shadow on the page edge */
@media (max-width: 860px) {
  .sidebar { box-shadow: none; }
  .sidebar.open { box-shadow: 0 0 30px rgba(0,0,0,.25); }
}

/* phones: tables become stacked cards (labels come from the column headers, see app.js) */
@media (max-width: 640px) {
  .card.flush { overflow: visible; }
  table.stackable, table.stackable tbody, table.stackable tfoot, table.stackable tr, table.stackable td { display: block; width: 100%; }
  table.stackable thead { display: none; }
  table.stackable tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  table.stackable tbody tr:last-child { border-bottom: 0; }
  table.stackable td { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 4px 0; border: 0; text-align: right; white-space: normal; }
  table.stackable td.num { white-space: normal; }
  table.stackable td::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; text-align: left; padding-top: 2px; }
  table.stackable td:not([data-label])::before, table.stackable td[data-label=""]::before { content: none; }
  table.stackable td:not([data-label]), table.stackable td[data-label=""] { justify-content: flex-end; }
  table.stackable td > .cell-v { display: block; min-width: 0; text-align: right; overflow-wrap: anywhere; }
  table.stackable td > .cell-v .badge { margin-left: 4px; }
  table.stackable td.is-empty { display: none; }
  table.stackable td.empty { justify-content: center; text-align: center; }
  table.stackable td.empty::before { content: none; }
  table.stackable tfoot tr { background: var(--surface-2); }
  table.stackable .wrap-cell { max-width: none; min-width: 0; }
  table.stackable tbody tr:hover td { background: transparent; }
  .table-hover tbody tr[data-href]:active { background: var(--surface-2); }
}
