/* ---- colour tokens ----------------------------------------------------------------------------
   Light values are the original palette. Dark applies when the person picks Dark (data-theme="dark"
   on <html>, set by the server) or picks System (no attribute) and the device is in dark mode.
   The invoice preview re-declares the light set so it always looks like the paper/PDF it becomes. */
:root, .invoice-doc, .logo-swatch {
  --bg:#fafafa; --surface:#fff; --surface-2:#f3f3f3; --surface-3:#f0f0f0; --input-bg:#fff; --readonly-bg:#f6f6f6;
  --fg:#111; --fg-2:#333; --muted:#666; --line:#ddd; --line-strong:#888;
  --link:#1a55c4; --focus:#1a55c4;
  --accent-soft:#eef4ff; --row-hover:#f5f8ff; --row-picked:#eaf1ff; --highlight:#ffe58a;
  --ok:#0a7d3c; --ok-bg:#eefaf1; --ok-line:#9fd5b0;
  --bad:#c0392b; --bad-bg:#fee; --bad-fg:#800; --bad-soft:#fde8e8; --bad-strong:#b42318; --bad-hint:#8a4b4b; --bad-input:#fff6f6;
  --warn-bg:#fff6d6; --warn-line:#e3c764; --warn-soft:#fff4d6; --warn-fg:#8a5a00;
  --info-line:#a9c3f0;
  --btn-bg:#111; --btn-fg:#fff;
  --shadow:rgba(0,0,0,.12); --shadow-lg:rgba(0,0,0,.25); --backdrop:rgba(0,0,0,.35);
}
:root { color-scheme:light dark; }
.invoice-doc, .logo-swatch { color-scheme:light; color:var(--fg); }
:root[data-theme="light"] { color-scheme:light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#111317; --surface:#1a1d23; --surface-2:#22262d; --surface-3:#262a32; --input-bg:#15181d; --readonly-bg:#1f2329;
    --fg:#e6e8eb; --fg-2:#c9cdd3; --muted:#9aa1ab; --line:#343a43; --line-strong:#5b6370;
    --link:#82adff; --focus:#82adff;
    --accent-soft:#1d2a44; --row-hover:#1f2633; --row-picked:#22314d; --highlight:#6b5a12;
    --ok:#5cc98a; --ok-bg:#16301f; --ok-line:#2f6b45;
    --bad:#ff7b6e; --bad-bg:#3a1d1d; --bad-fg:#ffb4ab; --bad-soft:#3a1d1d; --bad-strong:#ff8f84; --bad-hint:#d9a19b; --bad-input:#2d1a1a;
    --warn-bg:#3a3218; --warn-line:#7a6526; --warn-soft:#3a3218; --warn-fg:#f0c768;
    --info-line:#34507f;
    --btn-bg:#e6e8eb; --btn-fg:#111;
    --shadow:rgba(0,0,0,.5); --shadow-lg:rgba(0,0,0,.6); --backdrop:rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme:dark;
  --bg:#111317; --surface:#1a1d23; --surface-2:#22262d; --surface-3:#262a32; --input-bg:#15181d; --readonly-bg:#1f2329;
  --fg:#e6e8eb; --fg-2:#c9cdd3; --muted:#9aa1ab; --line:#343a43; --line-strong:#5b6370;
  --link:#82adff; --focus:#82adff;
  --accent-soft:#1d2a44; --row-hover:#1f2633; --row-picked:#22314d; --highlight:#6b5a12;
  --ok:#5cc98a; --ok-bg:#16301f; --ok-line:#2f6b45;
  --bad:#ff7b6e; --bad-bg:#3a1d1d; --bad-fg:#ffb4ab; --bad-soft:#3a1d1d; --bad-strong:#ff8f84; --bad-hint:#d9a19b; --bad-input:#2d1a1a;
  --warn-bg:#3a3218; --warn-line:#7a6526; --warn-soft:#3a3218; --warn-fg:#f0c768;
  --info-line:#34507f;
  --btn-bg:#e6e8eb; --btn-fg:#111;
  --shadow:rgba(0,0,0,.5); --shadow-lg:rgba(0,0,0,.6); --backdrop:rgba(0,0,0,.6);
}
* { box-sizing: border-box; }
body { margin:0; font:14px/1.45 system-ui,-apple-system,"Segoe UI",sans-serif; color:var(--fg); background:var(--bg); }
header { background:var(--surface); border-bottom:1px solid var(--line); }
/* same width and gutters as <main>, so nav and content line up */
header .headbar { max-width:1100px; margin:0 auto; padding:0 24px; display:flex; align-items:stretch; gap:24px; min-height:52px; }
header .brand { font-weight:600; font-size:18px; display:flex; align-items:center; }
header nav { display:flex; align-items:stretch; flex-wrap:wrap; }
header nav a { display:flex; align-items:center; margin-right:16px; color:var(--muted); text-decoration:none; border-bottom:2px solid transparent; margin-bottom:-1px; }
header nav a:hover { color:var(--fg); }
header nav a.active { color:var(--fg); font-weight:600; border-bottom-color:var(--fg); }
header .userbox { margin-left:auto; display:flex; align-items:center; gap:12px; }
header .userbox form { margin:0; }
button.linklike { font:inherit; background:none; border:none; padding:0; color:var(--muted); cursor:pointer; text-decoration:underline; }
main { padding:24px; max-width:1100px; margin:0 auto; }
h1,h2 { margin-top:0; }
table { border-collapse:collapse; width:100%; background:var(--surface); }
th,td { border:1px solid var(--line); padding:6px 10px; text-align:left; vertical-align:top; }
th { background:var(--surface-2); }
td.num,th.num,td.amt,th.amt { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; }
.muted,.hint { color:var(--muted); }
.hint { font-size:12px; }
a { color:var(--link); }
.warning { background:var(--bad-bg); border:1px solid var(--bad); color:var(--bad-fg); padding:10px 14px; border-radius:4px; margin-bottom:16px; }
.flash { padding:10px 14px; border-radius:4px; margin-bottom:12px; border:1px solid var(--line); background:var(--surface); }
.flash-success { background:var(--ok-bg); border-color:var(--ok-line); }
.flash-error { background:var(--bad-bg); border-color:var(--bad); color:var(--bad-fg); }
.flash-info { background:var(--accent-soft); border-color:var(--info-line); }
.banner { background:var(--warn-bg); border:1px solid var(--warn-line); padding:10px 14px; border-radius:4px; margin-bottom:14px; }
.card { background:var(--surface); border:1px solid var(--line); border-radius:8px; padding:20px; margin-bottom:18px; }
.card .row { margin-bottom:14px; }
label { display:block; font-weight:600; margin-bottom:4px; }
input,select,textarea { font:inherit; padding:7px 9px; border:1px solid var(--line); border-radius:5px; background:var(--input-bg); color:var(--fg); }
.card input,.card select,.card textarea { width:100%; }
input[readonly] { background:var(--readonly-bg); color:var(--muted); }
button { font:inherit; padding:7px 16px; border:1px solid var(--btn-bg); background:var(--btn-bg); color:var(--btn-fg); cursor:pointer; border-radius:4px; }
button.secondary { background:var(--surface); color:var(--fg); border-color:var(--fg); }
button.small { padding:2px 10px; font-size:12px; }
button.danger { background:var(--surface); color:var(--bad); border-color:var(--bad); }
form.inline { display:inline; margin:0; }
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.grid3 { display:grid; grid-template-columns:repeat(3,1fr); gap:16px; }
.cards { display:grid; grid-template-columns:repeat(3,1fr); gap:16px; }
.cards a.card { text-decoration:none; color:inherit; display:block; }
.cards a.card:hover { border-color:var(--fg); }
@media (max-width:700px) { .grid2,.grid3,.cards { grid-template-columns:1fr; } header .headbar { flex-wrap:wrap; padding:0 12px; } main { padding:12px; } }
.filter { display:flex; gap:12px; align-items:flex-end; flex-wrap:wrap; margin-bottom:14px; }
.filter label { font-weight:400; font-size:12px; color:var(--muted); }
.filter label input { display:block; }
.presets a.preset { margin-right:8px; font-size:12px; }
.pagehead { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:12px; }
.pagehead h1 { margin:0; }
/* statements */
table.stmt td.ind { padding-left:28px; }
table.stmt td.ind2 { padding-left:48px; }
table.stmt tr.sec td { background:var(--surface-2); font-weight:600; }
table.stmt tr.tot td { font-weight:600; border-top:1.5px solid var(--line-strong); }
table.stmt tr.grand td { font-weight:700; background:var(--surface-3); border-top:2px solid var(--fg); }
td.neg,.off { color:var(--bad); }
.ok { color:var(--ok); }
/* typeahead */
.ta { position:relative; }
.ta ul { position:absolute; z-index:20; left:0; right:0; top:100%; background:var(--surface); border:1px solid var(--line); list-style:none; margin:0; padding:0; max-height:220px; overflow:auto; box-shadow:0 4px 10px var(--shadow); }
.ta li { padding:6px 9px; cursor:pointer; display:flex; justify-content:space-between; align-items:baseline; gap:10px; }
.ta li i { font-style:normal; }
.ta li:hover,.ta li.sel { background:var(--accent-soft); }
.ta li span { color:var(--muted); font-size:12px; white-space:nowrap; }
input.bad { border-color:var(--bad); background:var(--bad-input); }
a.plain { color:inherit; text-decoration:none; }
a.plain:hover { text-decoration:underline; color:var(--link); }
.ta li.create { color:var(--link); border-top:1px solid var(--line); font-weight:600; }
/* quick-create account dialog */
dialog.qa { border:1px solid var(--line); border-radius:10px; padding:20px; width:min(560px, calc(100vw - 32px)); box-shadow:0 12px 40px var(--shadow-lg); background:var(--surface); color:var(--fg); }
dialog.qa::backdrop { background:var(--backdrop); }
dialog.qa h2 { margin-bottom:12px; }
dialog.qa .row { margin-bottom:12px; }
dialog.qa input, dialog.qa select { width:100%; }
/* journal form */
table.lines input { width:100%; }
table.lines td { padding:3px 5px; }
table.lines input.num { text-align:right; }
table.lines input[readonly].line-credit { background:var(--surface-2); }
.totals td { font-weight:600; }
/* tables scroll inside their own box instead of widening the page */
.tw { overflow-x:auto; -webkit-overflow-scrolling:touch; margin-bottom:14px; }
.tw > table { margin:0; }
/* export menu */
.actions { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
details.export { position:relative; display:inline-block; }
details.export > summary { list-style:none; cursor:pointer; user-select:none; font:inherit; padding:7px 16px; border:1px solid var(--fg); background:var(--surface); color:var(--fg); border-radius:4px; }
details.export > summary::-webkit-details-marker { display:none; }
details.export > summary::after { content:" ▾"; font-size:11px; }
details.export .menu { position:absolute; left:0; top:calc(100% + 4px); z-index:30; background:var(--surface); border:1px solid var(--line); border-radius:6px; box-shadow:0 6px 18px var(--shadow); min-width:160px; padding:4px 0; }
details.export .menu button { display:block; width:100%; text-align:left; padding:9px 14px; text-decoration:none; color:var(--fg); }
details.export .menu button:hover { background:var(--surface-2); }
details.export .menu button:disabled { color:var(--muted); cursor:progress; }
.pagehead > details.export .menu { left:auto; right:0; } /* sits at the right edge */
/* list views (search · select · click a row to open) */
.listbar { display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:10px; }
.listbar .list-search { flex:1 1 260px; max-width:420px; padding:8px 12px; border-radius:20px; }
.listbar .list-count { white-space:nowrap; }
.listbar .actions { margin-left:auto; }
.listbar details.export .menu { left:auto; right:0; }
table.list tr.rowlink { cursor:pointer; }
table.list tbody tr.rowlink:hover td { background:var(--row-hover); }
table.list tbody tr.rowlink:focus-visible { outline:2px solid var(--focus); outline-offset:-2px; }
table.list tbody tr.picked td { background:var(--row-picked); }
table.list th.sel, table.list td.sel { width:40px; text-align:center; cursor:pointer; padding-left:4px; padding-right:4px; }
table.list .sel input { width:18px; height:18px; cursor:pointer; vertical-align:middle; }
table.list td.accts { color:var(--muted); }
::highlight(list-match) { background:var(--highlight); color:inherit; }
.push-right { margin-left:auto; }
dialog.bulk-dialog { width:min(560px, calc(100vw - 32px)); }
.bulk-list { max-height:40vh; overflow:auto; margin:6px 0 12px; padding-left:20px; }
.bulk-list li { margin:3px 0; }
.bulk-list.blocked li { color:var(--bad); }
.bulk-list.blocked li .hint { color:var(--bad-hint); }
button.danger:not(.small) { padding:7px 16px; }
@media (max-width:700px) {
  .listbar .list-search { max-width:none; flex-basis:100%; }
  .listbar .actions { margin-left:0; }
  .listbar details.export .menu { left:0; right:auto; }
  table.list .sel input { width:22px; height:22px; }
  table.list .hide-sm { display:none; } /* still exported: export reads every cell */
  table.list .show-sm { display:block; margin-top:3px; white-space:normal; }
  table.list th { width:auto !important; } /* desktop column widths don't fit a phone */
  table.list th, table.list td { padding:6px; }
  table.list { font-size:14px; }
  table.list th.sel, table.list td.sel { width:34px; padding:6px 2px; }

  .push-right { margin-left:0; }
}
/* report tabs */
.tabs { display:flex; gap:4px; border-bottom:1px solid var(--line); margin-bottom:14px; overflow-x:auto; }
.tabs a { padding:9px 14px; color:var(--muted); text-decoration:none; border:1px solid transparent; border-bottom:none; border-radius:6px 6px 0 0; white-space:nowrap; margin-bottom:-1px; }
.tabs a:hover { color:var(--fg); }
.tabs a.active { color:var(--fg); font-weight:600; background:var(--surface); border-color:var(--line); border-bottom:1px solid var(--surface); }
.tabpanel[hidden] { display:none; }
/* ---- phones ---- */
@media (max-width:700px) {
  body { font-size:15px; }
  h1 { font-size:22px; } h2 { font-size:17px; }
  /* header: brand + logout on one row, nav as a swipeable strip below */
  header .headbar { gap:0 12px; min-height:0; }
  header .brand { order:1; padding:10px 0; }
  header .userbox { order:2; }
  header nav { order:3; width:100%; flex-wrap:wrap; gap:0 16px; }
  header nav a { padding:8px 0; margin-right:0; white-space:nowrap; }
  .tabs a { flex:1; text-align:center; padding:9px 4px; font-size:14px; }
  /* 16px stops iOS zooming into focused inputs; bigger tap targets */
  input,select,textarea { font-size:16px; }
  button { padding:9px 16px; }
  button.small { padding:5px 12px; font-size:13px; }
  th,td { padding:6px 8px; }
  .card { padding:14px; }
  .pagehead { flex-wrap:wrap; }
  .filter { gap:8px; }
  .filter label input { width:8.5em; }
  .presets { width:100%; }
  .presets a.preset { display:inline-block; padding:4px 0; margin-right:14px; font-size:14px; }
  table.stmt td.ind { padding-left:16px; }
  table.stmt td.ind2 { padding-left:28px; }
  /* journal entry lines: one card per line */
  table.lines, table.lines tbody, table.lines tfoot { display:block; }
  table.lines thead { display:none; }
  table.lines tr.line-row { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px 8px; padding:10px 0; border-bottom:1px solid var(--line);
    grid-template-areas:"rn rn rn rm" "acct acct acct acct" "dr dr cr cr"; }
  table.lines tr.line-row td { display:block; border:none; padding:0; }
  table.lines tr.line-row td:nth-child(1) { grid-area:rn; font-weight:600; font-size:13px; color:var(--muted); align-self:center; }
  table.lines tr.line-row td:nth-child(1)::before { content:"Line "; }
  table.lines tr.line-row td:nth-child(2) { grid-area:acct; }
  table.lines tr.line-row td:nth-child(3) { grid-area:dr; }
  table.lines tr.line-row td:nth-child(4) { grid-area:cr; }
  table.lines tr.line-row td:nth-child(5) { grid-area:rm; text-align:right; }
  table.lines tr.line-row td:nth-child(2)::before { content:"Account"; }
  table.lines tr.line-row td:nth-child(3)::before { content:"Debit"; }
  table.lines tr.line-row td:nth-child(4)::before { content:"Credit"; }
  table.lines tr.line-row td:nth-child(n+2):nth-child(-n+4)::before { display:block; font-size:12px; color:var(--muted); margin-bottom:2px; }
  table.lines tfoot tr { display:flex; gap:12px; border:none; }
  table.lines tfoot td { border:none; padding:8px 0; }
  table.lines tfoot tr.totals td:first-child { flex:1; text-align:left !important; }
  table.lines tfoot tr.totals td:last-child { display:none; }
  table.lines tfoot #tot-dr::before { content:"Dr "; font-weight:400; color:var(--muted); }
  table.lines tfoot #tot-cr::before { content:"Cr "; font-weight:400; color:var(--muted); }
}
.printhead { display:none; }
@media print {
  .no-print,header { display:none !important; }
  body { background:#fff; color:#111; } main { max-width:none; padding:0; }
  .printhead { display:block; margin-bottom:10px; }
  .card { border:none; padding:0; }
  .tw { overflow:visible; }
}
/* change history */
.history > summary { cursor:pointer; list-style:none; display:flex; align-items:baseline; gap:10px; flex-wrap:wrap; }
.history > summary::-webkit-details-marker { display:none; }
.history > summary h2 { margin:0; font-size:17px; }
.history > summary h2::before { content:"▸"; display:inline-block; width:1em; color:var(--muted); transition:transform .15s; }
.history[open] > summary h2::before { transform:rotate(90deg); }
.history[open] > summary { margin-bottom:8px; }
.history-list { list-style:none; margin:0; padding:0; }
.history-list > li { padding:8px 0; border-top:1px solid var(--line); }
.history-list > li:first-child { border-top:none; }
.history-list ul, .change-details { margin:4px 0 0; padding-left:18px; color:var(--fg-2); font-size:13px; }
.change-details li { margin:1px 0; }
label.check { font-weight:400; display:flex; align-items:center; gap:8px; }
label.check input { width:auto; }
table.list td.nowrap { white-space:nowrap; }
/* ---- invoicing ---- */
.badge { display:inline-block; padding:1px 8px; border-radius:10px; font-size:12px; font-weight:600; vertical-align:middle; background:var(--surface-2); color:var(--fg-2); white-space:nowrap; }
.badge-draft { background:var(--surface-2); color:var(--muted); }
.badge-unpaid { background:var(--accent-soft); color:var(--link); }
.badge-overdue { background:var(--bad-soft); color:var(--bad-strong); }
.badge-part-paid { background:var(--warn-soft); color:var(--warn-fg); }
.badge-paid { background:var(--ok-bg); color:var(--ok); }
.badge-cancelled { background:var(--surface-2); color:var(--muted); text-decoration:line-through; }
h1 .badge { font-size:13px; margin-left:6px; }
.stats { display:grid; grid-template-columns:repeat(3, 1fr); gap:12px; margin-bottom:14px; }
.stats > div { background:var(--surface); border:1px solid var(--line); border-radius:8px; padding:12px 14px; display:flex; flex-direction:column; gap:2px; }
.stats b { font-size:20px; font-variant-numeric:tabular-nums; }
.pre { white-space:pre-line; margin:0; }
table.inv-lines td { vertical-align:top; padding:4px; }
table.inv-lines input, table.inv-lines select, table.inv-lines textarea { width:100%; }
table.inv-lines textarea { resize:vertical; min-height:34px; margin-top:4px; font:inherit; }
table.inv-lines .l-amt { padding-top:12px; font-variant-numeric:tabular-nums; white-space:nowrap; }
#invoice-form.is-export .gst-col { display:none; }
.inv-bottom { display:grid; grid-template-columns:1fr 320px; gap:24px; align-items:start; margin:10px 0 16px; }
.inv-bottom textarea { width:100%; }
table.inv-totals { width:100%; background:none; }
table.inv-totals td { border:none; padding:4px 6px; }
table.inv-totals tr.grand td { border-top:2px solid var(--fg); font-weight:700; font-size:16px; }
table.inv-totals tr.hint td { color:var(--muted); font-size:12px; }
.invoice-doc { position:relative; background:#fff; border:1px solid var(--line); border-radius:8px; padding:28px; margin:12px 0 18px; box-shadow:0 2px 10px rgba(0,0,0,.04); }
.invoice-doc a { color:var(--link); }
.invoice-doc.is-cancelled { opacity:.75; }
.inv-head { display:flex; justify-content:space-between; gap:24px; flex-wrap:wrap; padding-bottom:14px; border-bottom:1px solid var(--line); }
.inv-head h2 { margin:6px 0 4px; }
.inv-logo { max-height:50px; max-width:160px; display:block; }
.inv-meta { text-align:right; }
.inv-meta h3 { margin:0 0 8px; letter-spacing:.04em; }
.inv-meta dl { display:grid; grid-template-columns:auto auto; gap:2px 14px; margin:0; font-size:13px; }
.inv-meta dt { color:var(--muted); }
.inv-meta dd { margin:0; font-weight:600; }
.inv-billto { display:flex; flex-direction:column; gap:2px; margin:14px 0; }
.inv-sum { display:grid; grid-template-columns:1fr 300px; gap:24px; margin-top:10px; }
.inv-words { display:flex; flex-direction:column; gap:4px; }
.inv-endorse { border:1px solid var(--line-strong); padding:8px 10px; font-weight:600; font-size:12px; text-transform:uppercase; }
.inv-foot { display:grid; grid-template-columns:1fr 220px; gap:24px; margin-top:16px; font-size:13px; }
.inv-sign { display:flex; flex-direction:column; align-items:flex-end; gap:6px; }
.inv-sign .sigline { width:160px; height:40px; border-bottom:1px solid var(--line-strong); }
.inv-cancelled { position:absolute; top:40%; left:0; right:0; text-align:center; transform:rotate(-12deg); color:var(--bad); font-weight:800; font-size:28px; opacity:.35; pointer-events:none; }
.pay-form { border-top:1px solid var(--line); margin-top:12px; padding-top:12px; }
.cancel-box > summary { cursor:pointer; color:var(--bad); }
.seg { display:flex; gap:18px; flex-wrap:wrap; }
.logo-row { display:flex; align-items:center; gap:14px; flex-wrap:wrap; }
@media (max-width:700px) {
  .stats { grid-template-columns:1fr 1fr; }
  .inv-bottom, .inv-sum, .inv-foot { grid-template-columns:1fr; }
  .invoice-doc { padding:16px; }
  .inv-meta { text-align:left; }
  /* invoice lines as cards */
  table.inv-lines, table.inv-lines tbody { display:block; }
  table.inv-lines thead { display:none; }
  table.inv-lines tr.inv-line { display:grid; grid-template-columns:repeat(4, minmax(0,1fr)); gap:6px; padding:10px 0; border-bottom:1px solid var(--line);
    grid-template-areas:"rn rn rn rm" "desc desc desc desc" "hsn qty unit unit" "rate rate gst amt"; }
  table.inv-lines tr.inv-line td { display:block; border:none; padding:0; }
  table.inv-lines tr.inv-line td:nth-child(1) { grid-area:rn; font-weight:600; color:var(--muted); }
  table.inv-lines tr.inv-line td:nth-child(1)::before { content:"Line "; }
  table.inv-lines tr.inv-line td:nth-child(2) { grid-area:desc; }
  table.inv-lines tr.inv-line td:nth-child(3) { grid-area:hsn; }
  table.inv-lines tr.inv-line td:nth-child(4) { grid-area:qty; }
  table.inv-lines tr.inv-line td:nth-child(5) { grid-area:unit; }
  table.inv-lines tr.inv-line td:nth-child(6) { grid-area:rate; }
  table.inv-lines tr.inv-line td:nth-child(7) { grid-area:gst; }
  table.inv-lines tr.inv-line td:nth-child(8) { grid-area:amt; padding-top:18px; text-align:right; font-weight:600; }
  table.inv-lines tr.inv-line td:nth-child(9) { grid-area:rm; text-align:right; }
  table.inv-lines tr.inv-line td:nth-child(n+3):nth-child(-n+7)::before { display:block; font-size:12px; color:var(--muted); margin-bottom:2px; }
  table.inv-lines tr.inv-line td:nth-child(3)::before { content:"HSN/SAC"; }
  table.inv-lines tr.inv-line td:nth-child(4)::before { content:"Qty"; }
  table.inv-lines tr.inv-line td:nth-child(5)::before { content:"Unit"; }
  table.inv-lines tr.inv-line td:nth-child(6)::before { content:"Rate"; }
  table.inv-lines tr.inv-line td:nth-child(7)::before { content:"GST %"; }
  #invoice-form.is-export tr.inv-line { grid-template-areas:"rn rn rn rm" "desc desc desc desc" "hsn qty unit unit" "rate rate amt amt"; }
}
@media print {
  .invoice-doc { border:none; box-shadow:none; padding:0; }
  .history, .pay-form, .cancel-box, .stats { display:none !important; }
}

.show-sm { display:none; }

/* financial-year switcher */
header .yearbox { margin:0; }
header .yearbox select { padding:4px 8px; border-radius:16px; font-weight:600; background:var(--surface-2); border-color:var(--line); cursor:pointer; }
.explain p { margin:0 0 8px; }
.explain p:last-child { margin:0; }
td.actions-cell { white-space:nowrap; }
td.actions-cell form { margin-right:6px; }
.badge-cancelled-plain { background:var(--surface-2); color:var(--muted); }
@media (max-width:700px) { header .yearbox select { font-size:14px; padding:3px 6px; } td.actions-cell { white-space:normal; } }

/* printing is always light, whatever the screen theme (:not(#_) out-ranks the theme selectors) */
@media print {
  :root:not(#_), :root[data-theme]:not(#_) {
  --bg:#fafafa; --surface:#fff; --surface-2:#f3f3f3; --surface-3:#f0f0f0; --input-bg:#fff; --readonly-bg:#f6f6f6;
  --fg:#111; --fg-2:#333; --muted:#666; --line:#ddd; --line-strong:#888;
  --link:#1a55c4; --focus:#1a55c4;
  --accent-soft:#eef4ff; --row-hover:#f5f8ff; --row-picked:#eaf1ff; --highlight:#ffe58a;
  --ok:#0a7d3c; --ok-bg:#eefaf1; --ok-line:#9fd5b0;
  --bad:#c0392b; --bad-bg:#fee; --bad-fg:#800; --bad-soft:#fde8e8; --bad-strong:#b42318; --bad-hint:#8a4b4b; --bad-input:#fff6f6;
  --warn-bg:#fff6d6; --warn-line:#e3c764; --warn-soft:#fff4d6; --warn-fg:#8a5a00;
  --info-line:#a9c3f0;
  --btn-bg:#111; --btn-fg:#fff;
  --shadow:rgba(0,0,0,.12); --shadow-lg:rgba(0,0,0,.25); --backdrop:rgba(0,0,0,.35);
}
  :root:not(#_) { color-scheme:light; }
}
/* uploaded logos may be transparent: give them a light backing in any theme */
.logo-swatch { display:inline-block; background:#fff; padding:6px; border-radius:6px; border:1px solid var(--line); }
/* ledger opening / closing rows */
table tr.ledger-bd td { background:var(--accent-soft); }
/* ---- top bar: theme button + account menu ---- */
header .themebox { margin:0; }
.iconbtn { display:inline-flex; align-items:center; justify-content:center; width:32px; height:32px; padding:0; border-radius:50%;
  background:var(--surface-2); color:var(--fg); border:1px solid var(--line); }
.iconbtn:hover { border-color:var(--fg); }
.iconbtn span { display:none; line-height:0; }
.iconbtn[data-theme-toggle="system"] span[data-i="system"], .iconbtn[data-theme-toggle="light"] span[data-i="light"],
.iconbtn[data-theme-toggle="dark"] span[data-i="dark"] { display:inline; }
details.usermenu { position:relative; }
details.usermenu > summary { list-style:none; }
details.usermenu > summary::-webkit-details-marker { display:none; }
.avatar { display:inline-flex; align-items:center; justify-content:center; width:32px; height:32px; border-radius:50%; cursor:pointer;
  background:var(--btn-bg); color:var(--btn-fg); font-weight:700; font-size:12px; letter-spacing:.02em; user-select:none; }
details.usermenu[open] > .avatar, .avatar:focus-visible { outline:2px solid var(--focus); outline-offset:2px; }
details.usermenu .menu { position:absolute; right:0; top:calc(100% + 8px); z-index:40; min-width:240px; background:var(--surface);
  border:1px solid var(--line); border-radius:8px; box-shadow:0 8px 24px var(--shadow); padding:6px 0; }
details.usermenu .menu-who { display:flex; flex-direction:column; gap:1px; padding:8px 14px 10px; border-bottom:1px solid var(--line); margin-bottom:4px; word-break:break-all; }
details.usermenu .menu a, details.usermenu .menu-item { display:block; width:100%; text-align:left; padding:8px 14px; color:var(--fg);
  text-decoration:none; background:none; border:none; border-radius:0; font:inherit; cursor:pointer; }
details.usermenu .menu a:hover, details.usermenu .menu-item:hover { background:var(--surface-2); }
details.usermenu form { margin:0; }
.menu-theme { padding:8px 14px; border-top:1px solid var(--line); border-bottom:1px solid var(--line); margin:4px 0; }
.seg-btns { display:flex; margin-top:6px; border:1px solid var(--line); border-radius:6px; overflow:hidden; }
.seg-btns button { flex:1; padding:5px 0; font-size:13px; border:none; border-radius:0; background:var(--surface); color:var(--fg); }
.seg-btns button + button { border-left:1px solid var(--line); }
.seg-btns button.on { background:var(--btn-bg); color:var(--btn-fg); font-weight:600; }
