/* Billing pages of /next/ (pages/billing.js and pages/billing/*). Only what the shared components in next.css do not already draw: the invoice document
   ("the paper"), the invoice editor's line grid and totals, the timeline, filter bars and a few small helpers. Tokens only; no inline style anywhere
   (the /next/ CSP is style-src 'self'). The paper is always white like real paper (it carries .theme-light), in both themes. */

/* ---------- small helpers (the sub-line, error line, warning word, bar and tag are the shared parts in next.css) ---------- */
.bill-who { display: inline-flex; align-items: center; gap: var(--s-2); min-width: 0; }
.bill-who__name { min-width: 0; overflow-wrap: anywhere; }
.bill-late { color: var(--red); }
.bill-pad { padding: var(--s-2) var(--s-5) var(--s-5); }
.bill-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.bill-filters { display: grid; grid-template-columns: minmax(200px, 1.4fr) minmax(200px, 1.2fr) minmax(150px, .8fr) minmax(150px, .8fr); gap: var(--s-3); align-items: end; }
.bill-filters--1 { grid-template-columns: minmax(200px, 420px); }
.bill-filters--2 { grid-template-columns: minmax(200px, 420px) minmax(160px, 260px); }
.bill-more { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: 52px; padding: var(--s-2) var(--s-5); border-top: 1px solid var(--line-soft); font-size: var(--t-13); }
.bill-narrow { max-width: 680px; display: flex; flex-direction: column; gap: var(--s-4); }
.bill-actions { align-items: center; }
.bill-actions__gap { flex: 1 1 var(--s-4); }
.bill-bigstatus .status { font-size: var(--t-15); }
.bill-grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s-4); }
.bill-kv { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-5); font-size: var(--t-14); color: var(--ink-2); }
.bill-hint { font-size: var(--t-13); color: var(--muted); }
.bill-section-pad { padding: 0 var(--s-5) var(--s-5); }
.bill-num { font-variant-numeric: tabular-nums; text-align: right; }
.field__control--sm { height: var(--h-sm); border-radius: var(--r); font-size: var(--t-14); padding: 0 10px; }
.field__control.is-num { text-align: right; font-variant-numeric: tabular-nums; }
.field__control[aria-invalid="true"] { border-color: var(--red); }

/* ---------- the invoice document ---------- */
.doc { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s-5); align-items: start; }
.doc__paper { min-width: 0; container-type: inline-size; }
.doc__side { min-width: 0; }
.paper { position: relative; max-width: 860px; margin: 0 auto; padding: 48px 52px 32px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-pop); font-size: var(--t-14); line-height: 1.5; overflow: hidden; }
.paper--void > :not(.paper__stamp) { opacity: .62; }
.paper__stamp { position: absolute; top: 44px; right: 40px; padding: 6px 18px; border: 3px solid var(--green); border-radius: var(--r); color: var(--green); font-size: 26px; font-weight: 700; letter-spacing: .04em; transform: rotate(-8deg); pointer-events: none; }
.paper__stamp--void { border-color: var(--red); color: var(--red); }
.paper__head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-5); padding-bottom: var(--s-5); border-bottom: 1px solid var(--line); }
.paper__brand { display: flex; align-items: center; gap: var(--s-3); }
.paper__logo { display: grid; place-items: center; width: 52px; height: 52px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line); overflow: hidden; flex: none; }
.paper__logo img { width: 80%; height: 80%; object-fit: contain; }
.paper__brandtext { display: flex; flex-direction: column; }
.paper__brandtext b { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.paper__brandtext span { font-size: var(--t-13); color: var(--muted); }
.paper__co { font-size: var(--t-13); color: var(--ink-2); text-align: right; line-height: 1.55; }
.paper__titlerow { display: flex; align-items: baseline; gap: var(--s-3); margin-top: var(--s-6); }
.paper__title { font-size: 30px; font-weight: 600; letter-spacing: -.015em; }
.paper__state { font-size: var(--t-14); color: var(--muted); font-weight: 500; }
.paper__parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); margin-top: var(--s-5); font-size: var(--t-14); }
.paper__h { margin: 0 0 4px; font-size: var(--t-12); font-weight: 600; color: var(--muted); }
.paper__meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--s-3); margin: var(--s-5) 0 0; padding: var(--s-3) var(--s-4); background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r); }
.paper__meta dt { font-size: var(--t-12); color: var(--muted); }
.paper__meta dd { margin: 2px 0 0; font-size: var(--t-14); }
.paper__lines { width: 100%; margin-top: var(--s-5); border-collapse: collapse; font-size: var(--t-14); }
.paper__lines th { padding: 8px 10px; border-bottom: 2px solid var(--ink); font-size: var(--t-12); font-weight: 600; color: var(--ink-2); text-align: left; white-space: nowrap; }
.paper__lines td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.paper__lines .is-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.paper__desc { font-weight: 500; overflow-wrap: anywhere; }
.paper__sub { display: block; margin-top: 2px; font-size: var(--t-13); font-weight: 400; color: var(--muted); }
.paper__unit { color: var(--muted); font-size: var(--t-12); }
.paper__review { color: var(--amber); font-weight: 500; }
.paper__lines td.paper__none { color: var(--muted); text-align: center; padding: var(--s-6); }
.paper__sum { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: var(--s-6); margin-top: var(--s-4); }
.paper__notes { font-size: var(--t-13); color: var(--ink-2); white-space: pre-line; padding-top: 6px; }
.paper__totals { margin: 0; }
.paper__totals > div { display: flex; justify-content: space-between; gap: var(--s-4); padding: 6px 0; font-variant-numeric: tabular-nums; }
.paper__totals dt { display: flex; flex-direction: column; color: var(--ink-2); }
.paper__totals dt small { font-size: var(--t-12); color: var(--muted); }
.paper__totals dd { margin: 0; white-space: nowrap; }
.paper__quiet dt, .paper__quiet dd { color: var(--muted); }
.paper__totals > .paper__big { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; font-size: var(--t-17); font-weight: 600; }
.paper__big dt { color: var(--ink); }
.paper__pay { margin-top: var(--s-5); padding: var(--s-3) var(--s-4); border-radius: var(--r); background: var(--info-bg); border: 1px solid var(--info-line); font-size: var(--t-13); overflow-wrap: anywhere; }
.paper__foot { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-5); margin-top: var(--s-6); padding-top: var(--s-4); border-top: 1px solid var(--line); font-size: var(--t-13); color: var(--ink-2); }
.paper__fine { display: flex; justify-content: space-between; gap: var(--s-3); margin-top: var(--s-5); font-size: var(--t-12); color: var(--muted); }
@container (max-width: 620px) {
  .paper { padding: 24px 20px 20px; }
  .paper__co { text-align: left; }
  .paper__stamp { top: 20px; right: 16px; font-size: 20px; }
  .paper__parties, .paper__foot, .paper__sum { grid-template-columns: minmax(0, 1fr); }
  .paper__lines thead { display: none; }
  .paper__lines tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px var(--s-3); padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
  .paper__lines td { border: 0; padding: 0; }
  .paper__lines td.paper__desc { grid-column: 1 / -1; }
  .paper__lines td[data-l]::before { content: attr(data-l); display: block; font-size: var(--t-12); color: var(--muted); font-weight: 400; }
  .paper__lines td.paper__desc::before { display: none; }
  .paper__lines .is-num { text-align: left; }
}

/* ---------- the timeline of a posted invoice ---------- */
.tl { list-style: none; margin: 0; padding: 0; }
.tl__item { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr); column-gap: var(--s-3); padding: 0 0 var(--s-4); color: var(--muted); }
.tl__item:last-child { padding-bottom: 0; }
.tl__item::before { content: ""; position: absolute; left: 6px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.tl__item:last-child::before { display: none; }
.tl__dot { grid-row: 1 / span 2; width: 14px; height: 14px; margin-top: 4px; border-radius: 50%; border: 2px solid var(--control); background: var(--surface); }
.tl__item.is-on .tl__dot { border-color: var(--green); background: var(--green); }
.tl__word { font-weight: 600; color: var(--ink-2); }
.tl__item.is-on .tl__word { color: var(--ink); }
.tl__note { font-size: var(--t-13); overflow-wrap: anywhere; }
.paylink { margin: 0; padding: var(--s-2) var(--s-3); background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r); font-size: var(--t-12); overflow-wrap: anywhere; }

/* ---------- the invoice editor ---------- */
.ed { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--s-5); align-items: start; }
.ed__main { min-width: 0; }
.ed__side { position: sticky; top: calc(var(--top-h) + var(--s-4)); min-width: 0; }
.ed-fields { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.ed-saved { font-size: var(--t-13); color: var(--muted); }
.ed-tools { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s-3); padding: 0 var(--s-5) var(--s-4); }
.ed-tools > .field { flex: 1 1 280px; }
.ed-lines { container-type: inline-size; border-top: 1px solid var(--line-soft); }
.ed-lines__head, .ed-line { display: grid; grid-template-columns: minmax(0, 1fr) 92px 120px 112px 150px 40px; gap: var(--s-3); align-items: start; padding: 0 var(--s-5); }
.ed-lines__head { padding-top: var(--s-2); padding-bottom: var(--s-2); font-size: var(--t-13); color: var(--muted); border-bottom: 1px solid var(--line-soft); }
.ed-lines__head span:nth-child(2), .ed-lines__head span:nth-child(3), .ed-lines__head span:nth-child(4) { text-align: right; }
.ed-line { padding-top: var(--s-3); padding-bottom: var(--s-3); border-bottom: 1px solid var(--line-soft); }
.ed-line:last-child { border-bottom: 0; }
.ed-line.is-bad { background: var(--red-bg); }
.ed-line__desc { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ed-line__desc .badge { align-self: flex-start; }
.ed-line__detail { font-size: var(--t-13); color: var(--ink-2); }
.ed-line__lbl { display: none; font-size: var(--t-12); color: var(--muted); }
.ed-line__amt { min-height: var(--h-sm); display: flex; flex-direction: column; align-items: flex-end; justify-content: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.ed-line__tax { min-height: var(--h-sm); display: flex; flex-direction: column; justify-content: center; font-size: var(--t-13); }
.ed-line__x { display: flex; justify-content: flex-end; }
.ed-line__err { grid-column: 1 / -1; margin: 0; font-size: var(--t-13); color: var(--red); font-weight: 500; }
.ed-line__err:empty { display: none; }
.ed-empty { padding: var(--s-6) var(--s-5); color: var(--muted); text-align: center; }
@container (max-width: 899px) {
  .ed-lines__head { display: none; }
  .ed-line { grid-template-columns: repeat(4, minmax(0, 1fr)) 40px; row-gap: var(--s-2); }
  .ed-line__desc { grid-column: 1 / 5; }
  .ed-line__x { grid-column: 5; grid-row: 1; }
  .ed-line__lbl { display: block; margin-bottom: 4px; }
  .ed-line__amt { align-items: flex-start; justify-content: flex-start; }
  .ed-line__tax { justify-content: flex-end; }
}
@container (max-width: 520px) {
  .ed-line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px; padding-left: var(--s-4); padding-right: var(--s-4); }
  .ed-line__desc { grid-column: 1 / 3; }
  .ed-line__x { grid-column: 3; }
  .ed-line__qty { grid-column: 1; } .ed-line__price { grid-column: 2; }
  .ed-line__amt { grid-column: 1; } .ed-line__tax { grid-column: 2 / 4; }
}
.ed-fix { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.ed-fix__row { display: flex; flex-direction: column; gap: var(--s-2); padding: var(--s-3); background: var(--surface); border: 1px solid var(--amber-line); border-radius: var(--r-md); }
.ed-postbtns { justify-content: flex-end; }
.ed-postbtns .btn { flex: 1 1 auto; }

/* ---------- totals (the editor's side) ---------- */
.totals { margin: 0; font-variant-numeric: tabular-nums; }
.totals > div { display: flex; justify-content: space-between; gap: var(--s-3); padding: 6px 0; font-size: var(--t-14); }
.totals dt { display: flex; flex-direction: column; color: var(--ink-2); min-width: 0; }
.totals dt small { font-size: var(--t-12); color: var(--muted); }
.totals dd { margin: 0; white-space: nowrap; }
.totals__quiet dt, .totals__quiet dd { color: var(--muted); }
.totals > .totals__big { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); font-size: var(--t-17); font-weight: 600; }
.totals__big dt { color: var(--ink); }

/* ---------- drawers: record payment, Pax8 lines, credit memo ---------- */
.rp-mode { display: flex; flex-direction: column; gap: 6px; }
.rp-lines, .px-list, .cm-lines { display: flex; flex-direction: column; border: 1px solid var(--line-soft); border-radius: var(--r-md); overflow: hidden; }
.rp-line, .px-sub, .cm-line { display: grid; grid-template-columns: minmax(0, 1fr) 140px; gap: var(--s-3); align-items: center; padding: var(--s-2) var(--s-3); border-top: 1px solid var(--line-soft); }
.rp-line:first-child, .px-sub:first-child, .cm-line:first-child { border-top: 0; }
.rp-line .field__label, .cm-line .field__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rp-line .field__control, .cm-line .field__control { height: var(--h-sm); text-align: right; }
.rp-line__text { display: flex; flex-direction: column; min-width: 0; }
.px-sub { grid-template-columns: minmax(0, 1fr) 220px; }
.px-list > .check { padding: var(--s-2) var(--s-3); border-top: 1px solid var(--line-soft); }
.px-list > .check:first-child { border-top: 0; }

/* ---------- lists and steps used by several Billing pages ---------- */
.bill-steps { display: flex; flex-wrap: wrap; gap: var(--s-2); list-style: none; margin: 0; padding: 0; }
.bill-steps li { display: flex; align-items: center; gap: var(--s-2); height: var(--h-sm); padding: 0 var(--s-3); border-radius: 18px; background: var(--sunk); color: var(--ink-2); font-size: var(--t-14); }
.bill-steps li[aria-current="step"] { background: var(--selected); color: var(--selected-ink); font-weight: 600; }
.bill-steps li.is-done { color: var(--green); }
.bill-steps .badge { min-width: 22px; }
.bill-drop { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 96px; padding: var(--s-4); border: 2px dashed var(--control); border-radius: var(--r-md); background: var(--surface-2); color: var(--ink-2); text-align: center; cursor: pointer; }
.bill-drop:hover, .bill-drop.is-over { border-color: var(--accent); background: var(--hover); }
.bill-drop:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.bill-drop input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.bill-prog { width: 100%; height: 10px; }
.bill-prog__track { fill: var(--sunk); }
.bill-prog__fill { fill: var(--accent-fill); }
.ws { display: flex; flex-direction: column; }
.ws__f { display: grid; grid-template-columns: 44px 72px minmax(0, 1.4fr) minmax(180px, 1fr) 140px; gap: var(--s-3); align-items: center; padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line-soft); container-type: inline-size; }
.ws__f:first-child { border-top: 0; }
.ws__f.is-done { background: var(--green-bg); }
.ws__line { font-family: var(--mono); font-size: var(--t-13); color: var(--muted); }
.ws__label { min-width: 0; font-size: var(--t-14); }
.ws__label small { display: block; color: var(--muted); font-size: var(--t-12); }
.ws__value { display: flex; align-items: center; gap: var(--s-2); justify-content: flex-end; font-variant-numeric: tabular-nums; font-weight: 600; }
.ws__value .field__control { height: var(--h-sm); max-width: 150px; text-align: right; }
.ws__how { grid-column: 3 / -1; font-size: var(--t-13); color: var(--ink-2); }
.ws__how summary { cursor: pointer; color: var(--accent); min-height: 32px; display: flex; align-items: center; }
.ws__how ul { margin: 6px 0 0; padding-left: var(--s-4); }
.ws__f .check { padding: 0; min-height: 0; }
@media (max-width: 899px) {
  .ws__f { grid-template-columns: 40px minmax(0, 1fr); row-gap: 6px; padding: var(--s-3) var(--s-4); }
  .ws__line { grid-column: 2; }
  .ws__label, .ws__value, .ws__state, .ws__how { grid-column: 2; }
  .ws__value { justify-content: flex-start; }
}

/* ---------- buttons that look like text or like a list row ---------- */
.bill-linkbtn { display: inline-flex; align-items: center; min-height: var(--h-sm); padding: 0; border: 0; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.bill-linkbtn:hover { color: var(--accent); }
button.bill-rowbtn { width: 100%; border-left: 0; border-right: 0; border-bottom: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.bill-stepbtn { display: inline-flex; align-items: center; gap: var(--s-2); height: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }

/* ---------- the agreement editor's lines ---------- */
.ag-lines { display: flex; flex-direction: column; gap: var(--s-3); }
.ag-line { display: flex; flex-direction: column; gap: var(--s-3); padding: var(--s-4); border: 1px solid var(--line-soft); border-radius: var(--r-md); background: var(--surface-2); }
.ag-line__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }

/* ---------- the ST-100 worksheet: the value field's own label is the row's label ---------- */
.ws__value .field { flex: 1 1 auto; }
.ws__value .field__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ws__how summary { list-style: none; }
.ws__how summary::-webkit-details-marker { display: none; }
.ws__how summary::before { content: ""; width: 8px; height: 8px; margin-right: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .12s var(--ease); }
.ws__how[open] summary::before { transform: rotate(45deg); }

/* ---------- page widths ---------- */
@media (max-width: 1099px) {
  .doc, .ed { grid-template-columns: minmax(0, 1fr); }
  .ed__side { position: static; }
}
@media (max-width: 719px) {
  .bill-filters, .bill-filters--1, .bill-filters--2 { grid-template-columns: minmax(0, 1fr); }
  .bill-more { padding: var(--s-2) var(--s-4); }
  .rp-line, .cm-line, .px-sub { grid-template-columns: minmax(0, 1fr); }
  .bill-actions .btn { flex: 1 1 auto; }
}

/* ---------- print: an invoice prints as its document only ---------- */
@media print {
  .bill .ph, .bill .tabs, .bill-actions, .doc__side, .bill > .banner { display: none !important; }
  .doc { display: block; }
  .paper { box-shadow: none; border: 0; max-width: none; padding: 0; }
  .ws-print .ws__how summary { display: none; }
}

/* ---------- compact rows: a status and an amount on the right of a simple list row ---------- */
.bill-trail { display: inline-flex; align-items: center; gap: var(--s-3); white-space: nowrap; }
.bill-trail .bill-amt { min-width: 88px; text-align: right; }
.ed__side .facts, .doc__side .facts { grid-template-columns: 92px minmax(0, 1fr); }

/* ---------- setup pages: the catalog, tax setup, online payments, Pax8 (pages/billing/items.js, tax.js, paysettings.js, pax8.js) ---------- */
.bill-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
.bill-list__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-4); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line-soft); min-width: 0; }
.bill-list__row:first-child { border-top: 0; }
.bill-list__row > span:first-child { min-width: 0; flex: 1 1 260px; overflow-wrap: anywhere; }
.sheet__body .bill-list__row { padding-left: 0; padding-right: 0; }
.ps-copy { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); padding: var(--s-2) var(--s-3); background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r); min-width: 0; }
.ps-copy .mono { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; font-size: var(--t-13); }
.ps-fee { margin: 0; padding: 0; border: 0; min-width: 0; }
.ps-fee legend { padding: 0; margin-bottom: var(--s-2); font-size: var(--t-14); font-weight: 600; }
.bill-pre { margin: 0; padding: var(--s-3); max-height: 260px; overflow: auto; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r); font-size: var(--t-12); white-space: pre-wrap; overflow-wrap: anywhere; }
.bill-steps-list { margin: 0; padding-left: var(--s-5); display: flex; flex-direction: column; gap: var(--s-2); font-size: var(--t-14); }
