/* =====================================================================
   MWS Invoice v2 — design system
   Palette: warm grayscale + single orange accent (#f18833).
   Type:    Fraunces (display) · IBM Plex Sans (UI/body, tabular numerals).
   Ported from shadcn conventions (token system, component anatomy) and
   themed to the Macronimous kit. No frameworks, no build step.
   ===================================================================== */

:root {
  /* --- surfaces & ink (warm neutrals) --- */
  --bg:          #faf9f7;
  --surface:     #ffffff;
  --surface-2:   #f4f2ee;   /* table headers, muted fills */
  --ink:         #222328;   /* headings, strong text */
  --body:        #4a4a48;   /* body copy */
  --muted:       #86847e;   /* secondary text */
  --rule:        #e7e4de;   /* hairline borders */
  --rule-strong: #d7d3cb;

  /* --- accent --- */
  --accent:      #f18833;
  --accent-ink:  #b45f13;   /* orange text on light / hover */
  --accent-wash: #fdf0e3;   /* tinted fill (active nav, badges) */
  --ring:        rgba(241, 136, 51, .30);

  /* --- semantic status tints (restrained) --- */
  --pos:      #2f7d57;  --pos-wash:  #e8f3ec;
  --warn:     #b0741a;  --warn-wash: #fbf1df;
  --neg:      #b23b3b;  --neg-wash:  #f8eaea;
  --info:     #3c5c86;  --info-wash: #e9eef6;
  --seen:     #6a5aa6;  --seen-wash: #eeecf8;  /* client has opened the link */

  /* --- shape --- */
  --radius:    9px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(34, 35, 40, .04), 0 1px 1px rgba(34, 35, 40, .03);
  --shadow-md: 0 4px 16px rgba(34, 35, 40, .06);

  --maxw: 1180px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;   /* reserve scrollbar space so centered pages don't jump right between short/tall views */
  overflow-y: scroll;         /* fallback for engines without scrollbar-gutter */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--body);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "tnum" 1, "cv05" 1;  /* tabular numerals */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  font-family: "Fraunces", Georgia, serif;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 .4em;
  letter-spacing: -0.01em;
}
h1 { font-size: 1.85rem; font-optical-sizing: auto; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

/* numeric cells / money — tabular, slightly tightened */
.num, .money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* =====================================================================
   Masthead + nav
   ===================================================================== */
.masthead {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.masthead-row {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand img { height: 30px; width: auto; display: block; }
.brand-mark {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--ink);
  letter-spacing: -.01em;
}
.brand-sub { color: var(--muted); font-size: .78rem; }

.co-switch { display: flex; gap: .25rem; background: var(--surface-2); padding: .2rem; border-radius: var(--radius-sm); }
.co-tab {
  font-size: .82rem;
  color: var(--body);
  padding: .32rem .7rem;
  border-radius: 4px;
  white-space: nowrap;
}
.co-tab:hover { text-decoration: none; color: var(--ink); }
.co-tab.active { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: var(--shadow); }

.nav {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: .3rem;
}
.nav-item {
  color: var(--body);
  font-size: .9rem;
  font-weight: 500;
  padding: .7rem .8rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.nav-item:hover { color: var(--ink); text-decoration: none; }
.nav-item.active { color: var(--ink); border-bottom-color: var(--accent); }
.nav-spacer { flex: 1; }

/* =====================================================================
   Main container, page head, breadcrumbs
   ===================================================================== */
main { max-width: var(--maxw); margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }

.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: .5rem; display: flex; gap: .4rem; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent-ink); }
.crumbs .sep { color: var(--rule-strong); }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}
.page-head p.lede { color: var(--muted); margin: .1rem 0 0; font-size: .95rem; }
.page-head h1 { margin: 0; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn, .btn-primary, .btn-ghost, .btn-outline, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  font: inherit;
  font-weight: 500;
  font-size: .9rem;
  line-height: 1;
  padding: .58rem .95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); text-decoration: none; color: #fff; }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--rule-strong); }
.btn-outline:hover { border-color: var(--muted); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--body); }
.btn-ghost:hover { background: var(--surface-2); text-decoration: none; }
.btn-sm { padding: .38rem .6rem; font-size: .82rem; }
.btn-danger { background: var(--surface); color: var(--neg); border-color: var(--rule-strong); }
.btn-danger:hover { background: var(--neg-wash); border-color: var(--neg); text-decoration: none; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 1px; border-radius: 3px; }

/* =====================================================================
   Cards + dashboard stat cards
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 1.25rem 1.35rem; }
.card h2, .card h3 { margin-top: 0; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.stat .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 500; }
.stat .value { font-family: "Fraunces", serif; font-size: 1.7rem; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1; }
.stat .sub { font-size: .82rem; color: var(--muted); }
.stat.accent { border-top: 3px solid var(--accent); }
.stat.warn   { border-top: 3px solid var(--warn); }
.stat.pos    { border-top: 3px solid var(--pos); }

/* =====================================================================
   Tables — dense, ledger-like
   ===================================================================== */
.table-wrap { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
table.ledger { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.ledger thead th {
  text-align: left;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
  padding: .7rem .9rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
table.ledger tbody td { padding: .68rem .9rem; border-bottom: 1px solid var(--rule); color: var(--body); vertical-align: middle; }
table.ledger tbody tr:last-child td { border-bottom: none; }
table.ledger tbody tr:hover { background: #fbfaf8; }
table.ledger td.r, table.ledger th.r { text-align: right; }
table.ledger .primary { color: var(--ink); font-weight: 500; }
table.ledger a.rowlink { color: var(--ink); font-weight: 500; }
table.ledger a.rowlink:hover { color: var(--accent-ink); }

/* =====================================================================
   Status badges
   ===================================================================== */
.status {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: capitalize;
  padding: .18rem .5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.status-draft      { background: var(--surface-2); color: var(--muted); }
.status-sent       { background: var(--info-wash); color: var(--info); }
.status-seen       { background: var(--seen-wash); color: var(--seen); }
.status-paid       { background: var(--pos-wash); color: var(--pos); }
.status-issued     { background: var(--pos-wash); color: var(--pos); }
.status-converted  { background: var(--accent-wash); color: var(--accent-ink); }
.status-overdue    { background: var(--neg-wash); color: var(--neg); }
.status-declined   { background: var(--neg-wash); color: var(--neg); }
.status-void       { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.status-written_off{ background: var(--surface-2); color: var(--muted); }

.pill { display: inline-block; font-size: .72rem; font-weight: 600; color: var(--muted); background: var(--surface-2); border-radius: 4px; padding: .1rem .4rem; }

/* =====================================================================
   Forms
   ===================================================================== */
label.field { display: block; margin-bottom: 1rem; }
label.field > span { display: block; font-size: .82rem; font-weight: 500; color: var(--ink); margin-bottom: .3rem; }
input:not([type]),
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
  width: 100%;
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  padding: .5rem .65rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
textarea { min-height: 5rem; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 1rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* =====================================================================
   Flash / alerts, empty states
   ===================================================================== */
.flash {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  background: var(--pos-wash);
  border: 1px solid #cbe4d5;
  color: var(--pos);
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: .9rem;
}
.flash::before {
  content: "✓";
  font-weight: 700;
  line-height: 1.45;
  flex: 0 0 auto;
}
.flash.err { background: var(--neg-wash); border-color: #eccaca; color: var(--neg); font-weight: 500; }
.flash.err::before { content: "⚠"; }

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}
.empty h3 { color: var(--ink); }
.empty p { margin: .3rem 0 1.1rem; }

/* =====================================================================
   Utilities
   ===================================================================== */
.row { display: flex; align-items: center; gap: .6rem; }
.gap-sm { gap: .35rem; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.ink { color: var(--ink); }
.right { margin-left: auto; }
.mt { margin-top: 1.25rem; }
.mb { margin-bottom: 1.25rem; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 1.75rem 0 .8rem; }
.section-title h2 { margin: 0; }

/* =====================================================================
   Toolbar: filter chips + search
   ===================================================================== */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.filters { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip {
  font-size: .82rem; color: var(--body); background: var(--surface);
  border: 1px solid var(--rule); padding: .34rem .72rem; border-radius: 999px;
}
.chip:hover { border-color: var(--muted); color: var(--ink); text-decoration: none; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.search { min-width: 230px; max-width: 320px; }

/* =====================================================================
   Editor: form grid + line-item rows
   ===================================================================== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 1.1rem; }
.form-grid .field.full { grid-column: 1 / -1; }          /* span the whole row */
.form-grid .field.full textarea { min-height: 8.5rem; }  /* roomier multi-line fields */
.readonly-field { padding: .5rem .65rem; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink); font-size: .92rem; }

.doc-dates-strip { color: var(--muted); font-size: .82rem; margin: -0.5rem 0 1rem; }

/* bulk row selection */
table.ledger td.sel, table.ledger th.sel { width: 34px; text-align: center; }
table.ledger input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.bulk-bar { display: flex; align-items: center; gap: .75rem; margin-top: .75rem; }
.bulk-bar .muted { font-size: .85rem; }

/* sortable list headers */
table.ledger thead th a.th-sort { color: var(--muted); text-decoration: none; }
table.ledger thead th a.th-sort:hover { color: var(--ink); }

/* searchable client picker (proforma editor) */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md); max-height: 280px; overflow-y: auto;
}
.combo-item { padding: .5rem .7rem; cursor: pointer; font-size: .92rem; color: var(--ink); }
.combo-item .sub { color: var(--muted); font-size: .8rem; margin-left: .4rem; }
.combo-item:hover, .combo-item.active { background: var(--accent-wash); }
.combo-item.add { color: var(--accent-ink); font-weight: 500; border-top: 1px solid var(--rule); }
.quick-add { border: 1px solid var(--rule-strong); border-radius: var(--radius-sm); background: var(--bg); padding: 1rem; margin-top: .6rem; }
.quick-add h4 { margin: 0 0 .75rem; font-size: .9rem; color: var(--ink); }

/* In-app confirmation dialog (replaces browser confirm()) */
.modal-overlay { position: fixed; inset: 0; background: rgba(34, 35, 40, .45); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal-overlay[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 1.5rem 1.6rem 1.3rem; max-width: 460px; width: 100%; }
.modal p { margin: 0 0 1.25rem; color: var(--ink); font-size: .95rem; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }
#confirm-ok.modal-danger { background: var(--neg); border-color: var(--neg); }
#confirm-ok.modal-danger:hover { background: #9b3232; border-color: #9b3232; }
.set-h { font-size: .95rem; font-weight: 600; color: var(--ink); margin: 1.75rem 0 .9rem; padding-bottom: .4rem; border-bottom: 1px solid var(--rule); }
.set-h:first-child { margin-top: 0; }
.set-h .muted { font-weight: 400; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.5rem; align-items: center; }

.li-head, .li-row { display: grid; grid-template-columns: 1fr 84px 120px 130px 32px; gap: .5rem; align-items: center; }
.li-head {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 600; padding: 0 .1rem .35rem;
}
.li-head .r { text-align: right; }
.li-row { margin-bottom: .5rem; }
.li-amount { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); padding-right: .2rem; white-space: nowrap; }
.li-del {
  border: none; background: transparent; color: var(--muted);
  font-size: 1.25rem; line-height: 1; cursor: pointer; border-radius: 5px; padding: .2rem;
}
.li-del:hover { color: var(--neg); background: var(--neg-wash); }

.totals-preview { margin: 1.1rem 0 0 auto; max-width: 320px; }
.totals-preview .line { display: flex; justify-content: space-between; padding: .26rem 0; font-size: .9rem; color: var(--body); }
.totals-preview .line span:last-child { font-variant-numeric: tabular-nums; color: var(--ink); }
.totals-preview .grand {
  border-top: 1px solid var(--rule); margin-top: .35rem; padding-top: .55rem;
  font-family: "Fraunces", serif; font-size: 1.2rem; color: var(--ink);
}

/* =====================================================================
   Document (proforma / invoice) — screen + print
   ===================================================================== */
.doc-actions {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.doc-actions .right { margin-left: auto; }
.doc-actions form { display: inline; }

.share-bar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  background: var(--accent-wash); border: 1px solid #f3d6b6;
  border-radius: var(--radius-sm); padding: .55rem .8rem; margin-bottom: 1.25rem;
  font-size: .88rem;
}
.share-bar code { background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: .2rem .45rem; color: var(--ink); }

/* Public client-facing share page (share.php) — standalone, no app chrome. */
.share-page { max-width: 760px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }
.share-tools { display: flex; align-items: center; justify-content: flex-end; gap: .75rem; margin-bottom: 1rem; }
.share-tools .share-status { margin-right: auto; }

.doc-sheet {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 760px;
  margin: 0 auto;
  padding: 2.4rem 2.6rem;
  position: relative;
}
.doc-head { display: flex; justify-content: space-between; gap: 2rem; align-items: flex-start; padding-bottom: 1.5rem; border-bottom: 2px solid var(--ink); }
.doc-brand img { height: 30px; width: auto; max-width: 220px; margin-bottom: .7rem; display: block; }
.doc-co { font-family: "Fraunces", serif; font-size: 1.2rem; color: var(--ink); font-weight: 600; }
.doc-co-sub { color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }
.doc-addr { color: var(--body); font-size: .82rem; line-height: 1.5; }
.doc-id { text-align: right; flex-shrink: 0; }
.doc-word { font-family: "Fraunces", serif; font-size: 1.55rem; color: var(--accent-ink); letter-spacing: .02em; }
.doc-number { font-size: 1rem; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; margin-top: .1rem; }

.doc-meta { display: flex; justify-content: space-between; gap: 2rem; margin: 1.5rem 0; }
.doc-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin-bottom: .2rem; }
.doc-party .name { font-family: "Fraunces", serif; font-size: 1.05rem; color: var(--ink); }
.doc-party div { font-size: .87rem; line-height: 1.5; }
.doc-dates { text-align: right; display: grid; gap: .6rem; }
.doc-dates .v { font-size: .92rem; color: var(--ink); font-variant-numeric: tabular-nums; }

table.doc-items { width: 100%; border-collapse: collapse; margin: 1.5rem 0; font-size: .9rem; }
table.doc-items th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--rule-strong); }
table.doc-items th.r, table.doc-items td.r { text-align: right; font-variant-numeric: tabular-nums; }
table.doc-items td { padding: .6rem .6rem; border-bottom: 1px solid var(--rule); color: var(--body); }
table.doc-items td.desc { color: var(--ink); }

.doc-totals { margin-left: auto; width: 300px; }
.doc-totals .line { display: flex; justify-content: space-between; padding: .3rem 0; font-size: .9rem; }
.doc-totals .line span:last-child { font-variant-numeric: tabular-nums; color: var(--ink); }
.doc-totals .grand { border-top: 2px solid var(--ink); margin-top: .4rem; padding-top: .6rem; font-family: "Fraunces", serif; font-size: 1.25rem; color: var(--ink); }

.doc-notes { margin-top: 1.75rem; font-size: .87rem; color: var(--body); white-space: pre-wrap; }
.doc-foot { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--rule); color: var(--muted); font-size: .85rem; }

.doc-stamp {
  position: absolute; top: 2.2rem; right: 2.6rem;
  font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: .2rem .55rem; border-radius: 4px; border: 2px solid currentColor;
}
.doc-stamp.paid { color: var(--pos); }
.doc-stamp.overdue { color: var(--neg); }
.doc-stamp.draft { color: var(--muted); }
.doc-stamp.void, .doc-stamp.declined, .doc-stamp.written_off { color: var(--muted); }

@media print {
  .doc-sheet { max-width: none; margin: 0; border: none; box-shadow: none; padding: 0; border-radius: 0; }
  .share-bar { display: none !important; }
}

/* =====================================================================
   Payment entry / view
   ===================================================================== */
.pay-layout { display: grid; grid-template-columns: 260px 1fr; gap: 1.25rem; align-items: start; }
.pay-summary { position: sticky; top: 1rem; }
.pay-doc { font-family: "Fraunces", serif; font-size: 1.15rem; margin: .1rem 0 .3rem; }
.pay-client { color: var(--body); font-size: .9rem; margin-bottom: .8rem; }
.pay-amount { font-family: "Fraunces", serif; font-size: 1.7rem; color: var(--ink); font-variant-numeric: tabular-nums; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem 1.25rem; }
.kv-strong { font-family: "Fraunces", serif; font-size: 1.15rem; color: var(--ink); font-variant-numeric: tabular-nums; }

.firc-block { border: 1px solid var(--rule); border-radius: var(--radius-sm); margin-top: 1.25rem; background: var(--bg); }
.firc-block > summary {
  cursor: pointer; padding: .7rem .9rem; font-weight: 500; color: var(--ink);
  list-style: none; user-select: none;
}
.firc-block > summary::-webkit-details-marker { display: none; }
.firc-block > summary::before { content: "▸ "; color: var(--muted); }
.firc-block[open] > summary::before { content: "▾ "; }
.firc-block[open] > summary { border-bottom: 1px solid var(--rule); }
.firc-body { padding: 1rem .9rem .3rem; }

@media (max-width: 720px) {
  .pay-layout { grid-template-columns: 1fr; }
  .pay-summary { position: static; }
}

/* =====================================================================
   Login
   ===================================================================== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 360px; }
.login-brand { text-align: center; margin-bottom: .25rem; }
.remember { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--body); margin: .35rem 0 .1rem; }
.remember input { width: auto; }

/* =====================================================================
   Print — keep screen chrome out of saved PDFs. (Full invoice print
   treatment lands with the invoice-redesign chunk.)
   ===================================================================== */
@media print {
  .no-print, .masthead, .nav, .crumbs, .doc-actions, .flash { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
}

/* =====================================================================
   Tax-invoice document (invoice-view.php / print). Ported from the
   approved artifact — its own print language: warm ink on paper, single
   #e86a1c accent, system-sans body with monospace tabular figures. All
   selectors are scoped under .invoice-sheet so nothing here touches the
   app chrome. Body font is per-company via the inline --inv-font var.
   ===================================================================== */
.invoice-sheet {
  --i-ink: #211e1b; --i-soft: #6e665e; --i-faint: #9a9086;
  --i-hair: #eae4dc; --i-hair-strong: #d9d1c6;
  --i-accent: #e86a1c; --i-accent-deep: #b8500e; --i-accent-tint: #fcefe3;
  --i-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;

  max-width: 820px; margin: 0 auto; position: relative; overflow: hidden;
  background: #fff; color: var(--i-ink);
  font-family: var(--inv-font, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
  line-height: 1.5; border: 1px solid var(--i-hair); border-radius: 3px;
  box-shadow: var(--shadow); padding: 56px 56px 44px;
}
.invoice-sheet::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--i-accent), var(--i-accent-deep));
}
/* Screen-only status stamp (never printed — .no-print) */
.invoice-sheet .sheet-stamp {
  position: absolute; top: 150px; left: 56px; transform: rotate(-8deg);
  border: 3px solid var(--i-faint); color: var(--i-faint); border-radius: 8px;
  font-size: 30px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  padding: 3px 16px; opacity: .45; pointer-events: none; z-index: 1;
}
.invoice-sheet .sheet-stamp.stamp-overdue { border-color: #b23b3b; color: #b23b3b; }

/* masthead */
.invoice-sheet .inv-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 32px; }
.invoice-sheet .inv-seller-logo { height: 30px; width: auto; max-width: 220px; display: block; margin-bottom: 18px; }
.invoice-sheet .inv-seller { font-size: 12px; line-height: 1.6; color: var(--i-soft); max-width: 34ch; }
.invoice-sheet .inv-seller .name { color: var(--i-ink); font-weight: 600; font-size: 13px; }
.invoice-sheet .inv-seller a { color: var(--i-accent-deep); text-decoration: none; }

.invoice-sheet .inv-title { text-align: right; flex-shrink: 0; }
.invoice-sheet .inv-title h1 { margin: 0; font-size: 44px; font-weight: 800; letter-spacing: -.03em; line-height: .9; color: var(--i-ink); }
.invoice-sheet .inv-title .num { margin-top: 8px; font-family: var(--i-mono); font-size: 13px; color: var(--i-accent-deep); font-weight: 600; }
.invoice-sheet .balance-card {
  /* display:block (not inline-block): html2canvas drops the label/amount
     text of inline-blocks inside a text-align:right context (PDF export). */
  margin-top: 18px; display: block; width: max-content; min-width: 190px; margin-left: auto;
  text-align: right; background: var(--i-accent-tint);
  border: 1px solid #f3dcc7; border-radius: 6px; padding: 12px 16px 13px;
}
.invoice-sheet .balance-card .lbl { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--i-accent-deep); font-weight: 600; }
.invoice-sheet .balance-card .amt { margin-top: 3px; font-family: var(--i-mono); font-size: 27px; font-weight: 700; color: var(--i-ink); font-variant-numeric: tabular-nums; }
.invoice-sheet .balance-card .amt .cur { font-size: 15px; color: var(--i-soft); font-weight: 600; margin-right: 3px; }

/* parties + meta */
.invoice-sheet .inv-mid { margin-top: 40px; display: grid; grid-template-columns: 1.2fr 1fr; gap: 32px; align-items: start; }
.invoice-sheet .eyebrow { font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--i-accent-deep); font-weight: 600; margin-bottom: 8px; }
.invoice-sheet .bill-to .client { font-size: 15px; font-weight: 700; color: var(--i-ink); }
.invoice-sheet .bill-to address { font-style: normal; font-size: 12.5px; line-height: 1.6; color: var(--i-soft); margin-top: 4px; max-width: 34ch; white-space: pre-wrap; }
.invoice-sheet .inv-meta { border-top: 2px solid var(--i-ink); }
.invoice-sheet .inv-meta .row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--i-hair); font-size: 12.5px; }
.invoice-sheet .inv-meta dt { color: var(--i-soft); margin: 0; }
.invoice-sheet .inv-meta dd { margin: 0; font-family: var(--i-mono); font-variant-numeric: tabular-nums; color: var(--i-ink); font-weight: 500; }
.invoice-sheet .inv-meta dd.term { font-family: inherit; font-weight: 600; }

/* line items */
.invoice-sheet table.inv-lines { margin-top: 34px; width: 100%; border-collapse: collapse; }
.invoice-sheet .inv-lines thead th {
  background: var(--i-ink); color: #f6f1ea; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
  font-weight: 600; text-align: left; padding: 11px 14px;
}
.invoice-sheet .inv-lines thead th:first-child { border-radius: 4px 0 0 4px; width: 34px; text-align: center; }
.invoice-sheet .inv-lines thead th:last-child { border-radius: 0 4px 4px 0; }
.invoice-sheet .inv-lines th.r, .invoice-sheet .inv-lines td.r { text-align: right; }
.invoice-sheet .inv-lines th.hsn, .invoice-sheet .inv-lines td.hsn { text-align: right; width: 120px; }
.invoice-sheet .inv-lines tbody td { padding: 15px 14px; border-bottom: 1px solid var(--i-hair); font-size: 13px; vertical-align: top; }
.invoice-sheet .inv-lines td.idx { text-align: center; color: var(--i-soft); font-family: var(--i-mono); }
.invoice-sheet .inv-lines td.desc .d-main { font-weight: 600; color: var(--i-ink); }
.invoice-sheet .inv-lines td.desc .d-sub { color: var(--i-faint); font-size: 11.5px; margin-top: 2px; }
.invoice-sheet .inv-lines td.mono { font-family: var(--i-mono); font-variant-numeric: tabular-nums; color: var(--i-ink); }

/* totals + amount in words */
.invoice-sheet .inv-foot { margin-top: 26px; display: grid; grid-template-columns: 1fr 300px; gap: 32px; align-items: start; }
.invoice-sheet .in-words { font-size: 12.5px; color: var(--i-soft); align-self: end; }
.invoice-sheet .in-words .lbl { display: block; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; margin-bottom: 4px; }
.invoice-sheet .in-words .val { font-style: italic; font-size: 14px; color: var(--i-ink); }
.invoice-sheet .inv-totals { font-size: 13px; }
.invoice-sheet .inv-totals .line { display: flex; justify-content: space-between; gap: 20px; padding: 8px 0; border-bottom: 1px solid var(--i-hair); }
.invoice-sheet .inv-totals .line span:first-child { color: var(--i-soft); }
.invoice-sheet .inv-totals .line .v { font-family: var(--i-mono); font-variant-numeric: tabular-nums; color: var(--i-ink); font-weight: 500; }
.invoice-sheet .inv-totals .line.grand { border-bottom: none; margin-top: 4px; padding: 13px 16px; background: var(--i-ink); border-radius: 6px; align-items: baseline; }
.invoice-sheet .inv-totals .line.grand span:first-child { color: #d9cfc2; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; font-size: 11px; }
.invoice-sheet .inv-totals .line.grand .v { color: #fff; font-weight: 700; font-size: 19px; }
.invoice-sheet .inv-totals .line.grand .v .cur { font-size: 12px; color: #c9beb0; margin-right: 2px; }

/* notes + terms */
.invoice-sheet .inv-notes { margin-top: 44px; display: grid; grid-template-columns: 1fr 1fr; gap: 36px; }
.invoice-sheet .inv-notes h3 { margin: 0 0 8px; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--i-accent-deep); font-weight: 600; }
.invoice-sheet .inv-notes p { margin: 0; font-size: 12px; line-height: 1.65; color: var(--i-soft); white-space: pre-wrap; }
.invoice-sheet .inv-notes .thanks { font-size: 13px; color: var(--i-ink); font-weight: 600; }

/* compliance footer (data-driven from registration_details) */
.invoice-sheet .compliance { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--i-hair-strong); }
/* Content-flowing strip: each cell is as wide as its value, so email/URLs
   stay on one line and short codes stay compact; wraps to the next row. */
.invoice-sheet .compliance .grid { display: flex; flex-wrap: wrap; gap: 14px 30px; }
.invoice-sheet .compliance .cell { min-width: 0; }
.invoice-sheet .compliance .cell .k { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: var(--i-soft); }
.invoice-sheet .compliance .cell .val { margin-top: 3px; font-family: var(--i-mono); font-size: 11px; color: var(--i-ink); white-space: nowrap; }

@media (max-width: 660px) {
  .invoice-sheet { padding: 36px 24px 32px; }
  .invoice-sheet .inv-top, .invoice-sheet .inv-mid, .invoice-sheet .inv-foot, .invoice-sheet .inv-notes { display: block; }
  .invoice-sheet .inv-top { display: flex; flex-direction: column; }
  .invoice-sheet .inv-title { text-align: left; }
  .invoice-sheet .inv-mid > * + *, .invoice-sheet .inv-foot > * + *, .invoice-sheet .inv-notes > * + * { margin-top: 28px; }
  .invoice-sheet .inv-title h1 { font-size: 38px; }
}

/* Clean A4 export: margin:0 suppresses the browser's injected URL/date
   header; the 12mm page frame becomes sheet padding. One page, no chrome.
   print-color-adjust keeps the ink Balance-Due bar, table header and
   accent rule from being washed out by the browser's ink-saver. */
@media print {
  @page { size: A4; margin: 0; }
  .invoice-sheet {
    max-width: none; margin: 0; border: none; box-shadow: none; border-radius: 0;
    padding: 12mm; font-size: 12px;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .invoice-sheet::before { position: absolute; }
}

/* ---- pager (25/page on every list) ---- */
.pager { display:flex; align-items:center; justify-content:space-between; gap:1rem;
         margin:.65rem 0 1.25rem; font-size:.85rem; }
.pager-ctl { display:flex; align-items:center; gap:.6rem; }
.pager-off { opacity:.35; pointer-events:none; }
.table-wrap .pager { position: sticky; left: 0; }  /* stays put when the table scrolls sideways */

/* Masthead logo is a link to the dashboard — keep it looking like the brand, not a link. */
a.brand { text-decoration: none; color: inherit; cursor: pointer; }
a.brand:hover { opacity: .85; }

/* Clients list: keep the three row actions on one line; let long names wrap instead. */
.actions-cell { white-space: nowrap; }
.client-cell { max-width: 420px; }
