/* invoices module styles — tokens from app.css only, never raw hex.
   The printable sheet sits on the shared white .print-page, so its greys are mixed from
   currentColor and its accent is the brand red fill (var(--red)), which reads on paper. */

/* ───────── list: stats, aging, filters ───────── */
.inv-stats { margin-bottom: 16px; }
.inv-aging { margin-bottom: 18px; }
.inv-strong { font-weight: 700; }
.inv-num { font-weight: 600; white-space: nowrap; }
.inv-proj { display: inline-block; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

.aging-bar { display: flex; gap: 2px; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-3); }
.aging-seg { flex-basis: 0; min-width: 6px; }
.age-current { background: var(--green); }
.age-1 { background: var(--amber); }
.age-2 { background: color-mix(in srgb, var(--amber) 45%, var(--red)); }
.age-3 { background: var(--red); }
.age-4 { background: color-mix(in srgb, var(--red) 62%, black); }
.aging-legend { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.aging-key { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.aging-key-label { display: flex; align-items: center; gap: 6px; font: 500 10.5px/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); white-space: nowrap; }
.aging-swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.aging-key-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.aging-key-sub { font-size: 12px; color: var(--muted); }

.inv-seg-scroll { max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.inv-seg-scroll::-webkit-scrollbar { display: none; }
.inv-client-filter { flex: 0 1 230px; min-width: 170px; }

/* ───────── builder ───────── */
.inv-builder { display: flex; flex-direction: column; gap: 20px; }
.inv-kind-row { gap: 12px; }
.inv-usage { margin-top: 6px; }
.inv-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
.inv-link-btn { align-self: flex-start; background: none; border: 0; padding: 0; margin-top: 2px; color: var(--red-ink); font: 600 12px/1.3 var(--font); cursor: pointer; text-align: left; }
.inv-link-btn:hover { text-decoration: underline; }
.inv-foot-total { color: var(--text); font-size: 14px; }

.li-editor { display: flex; flex-direction: column; gap: 8px; }
.li-head, .li-row { display: grid; grid-template-columns: minmax(0, 1fr) 78px 132px 104px 94px; gap: 8px; align-items: start; }
.li-head { font: 500 10.5px/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); padding: 0 11px; }
.li-row { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.li-row:focus-within { border-color: var(--border-strong); }
.li-desc { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.li-details { min-height: 36px; font-size: 13px; }
.li-qty, .li-unit { min-width: 0; }
.li-amt { height: 36px; display: flex; align-items: center; justify-content: flex-end; font-weight: 700; white-space: nowrap; }
.li-actions { display: flex; gap: 2px; justify-content: flex-end; align-items: center; height: 36px; }
.li-mlabel { display: none; }
.li-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 2px; }
.li-card-select { flex: 0 1 380px; width: auto; min-width: 220px; }

.inv-builder-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.inv-totals-panel { position: sticky; top: 0; display: flex; flex-direction: column; gap: 9px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.inv-trow { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 28px; }
.inv-trow > label, .inv-trow > span:first-child { color: var(--text-2); font-size: 13px; }
.inv-tinput { width: 132px; flex: none; }
.inv-total { border-top: 1px solid var(--border-strong); padding-top: 10px; margin-top: 2px; }
.inv-total > span { font-weight: 800; font-size: 17px; color: var(--text) !important; }
.inv-deposit-note { font-size: 12.5px; line-height: 1.5; color: var(--text-2); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; }

/* ───────── payment modal ───────── */
.inv-pay-context { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.inv-pay-quick { margin-top: 4px; }

/* ───────── detail ───────── */
.inv-banner { margin-bottom: 14px; }
.inv-banner.note { background: var(--surface-2); border-color: var(--border); }
.inv-banner.note .icon { color: var(--muted); }
.inv-banner.amber { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 45%, transparent); }
.inv-banner.amber .icon { color: var(--amber-ink); }
.table.inv-lines tfoot td { font-weight: 500; border-top: 0; padding-top: 5px; padding-bottom: 5px; color: var(--text-2); }
.table.inv-lines tfoot tr:first-child td { border-top: 1px solid var(--border-strong); padding-top: 11px; }
.table.inv-lines tfoot tr:last-child td { padding-bottom: 12px; }
.table.inv-lines tfoot .inv-grand td { font-weight: 800; font-size: 15px; color: var(--text); }
.table.inv-lines tfoot .inv-grand td.text-red { color: var(--red-ink); }
.table.inv-lines tbody tr:hover td { background: transparent; }
.inv-details, .inv-text { white-space: pre-line; overflow-wrap: anywhere; }
.inv-text { margin-top: 4px; color: var(--text-2); }
.inv-sched { display: flex; flex-direction: column; }
.inv-sched-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 96px; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.inv-sched-row:last-child { border-bottom: 0; }
.inv-sched-row > :nth-child(2) { font-weight: 700; }
.inv-sched-row > :last-child { justify-self: end; }
.inv-progress { margin-bottom: 10px; }
.inv-billto-screen { font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.inv-contact { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

@media (max-width: 760px) {
  .aging-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inv-client-filter { flex: 1 1 100%; }
  .li-head { display: none; }
  .li-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .li-desc { grid-column: 1 / -1; }
  .li-qty, .li-unit, .li-amt { display: flex; flex-direction: column; }
  .li-amt { height: auto; align-items: flex-start; justify-content: flex-start; }
  .li-actions { height: auto; justify-content: flex-end; align-self: end; }
  .li-mlabel { display: block; font: 500 10.5px/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 5px; }
  .li-amt .mono { line-height: 36px; }
  .li-card-select { flex: 1 1 100%; min-width: 0; }
  .inv-builder-bottom { grid-template-columns: minmax(0, 1fr); }
  .inv-totals-panel { position: static; }
  .inv-sched-row { grid-template-columns: minmax(0, 1fr) auto; }
  .inv-sched-row > :last-child { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 420px) {
  .inv-dates { grid-template-columns: minmax(0, 1fr); }
  .inv-tinput { width: 118px; }
}

/* ───────── printable invoice ───────── */
.invoice-print { min-height: 100vh; }
.invoice-print .print-page { padding: 32px 16px 56px; }
.inv-print-msg { padding: 40px 16px; }
.inv-sheet {
  position: relative; max-width: 820px; margin: 0 auto; padding: 44px 48px 36px;
  border: 1px solid color-mix(in srgb, currentColor 12%, transparent); border-radius: 6px;
  box-shadow: 0 10px 34px color-mix(in srgb, currentColor 10%, transparent);
  font-size: 13px; line-height: 1.5; -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.inv-dim { color: color-mix(in srgb, currentColor 64%, transparent); }
.inv-pre { white-space: pre-line; overflow-wrap: anywhere; }

.inv-stamp {
  position: absolute; top: 132px; right: 48px; transform: rotate(-8deg);
  border: 3px solid currentColor; border-radius: 6px; padding: 5px 14px;
  font: 800 22px/1 var(--font); letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.8; pointer-events: none;
}
.inv-stamp.paid { color: color-mix(in srgb, var(--green) 72%, black); }
.inv-stamp.void { color: var(--red); }
.inv-stamp.draft { color: color-mix(in srgb, currentColor 40%, transparent); }

.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 20px; border-bottom: 3px solid var(--red); }
.inv-brand { display: flex; gap: 16px; align-items: flex-start; min-width: 0; }
.inv-logo { width: 78px; height: auto; flex: none; }
.inv-company { font-size: 12px; line-height: 1.5; }
.inv-company > div:not(.inv-company-name) { color: color-mix(in srgb, currentColor 70%, transparent); }
.inv-company-name { font-weight: 800; font-size: 15px; text-transform: uppercase; letter-spacing: 0.04em; font-variation-settings: 'wdth' 112; }
.inv-doc { text-align: right; flex: none; }
.inv-doc-kind { font-weight: 800; font-size: 32px; line-height: 1; letter-spacing: 0.12em; text-transform: uppercase; color: var(--red); font-variation-settings: 'wdth' 118; }
.inv-doc-number { font-family: var(--mono); font-size: 13px; margin-top: 10px; font-weight: 600; }

.inv-parties { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; margin: 26px 0 22px; }
.inv-label { font: 600 10.5px/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.1em; color: color-mix(in srgb, currentColor 58%, transparent); margin-bottom: 6px; }
.inv-billto { white-space: pre-line; font-weight: 600; font-size: 13.5px; overflow-wrap: anywhere; }
.inv-facts { margin: 0; display: grid; grid-template-columns: auto auto; gap: 5px 20px; align-content: start; }
.inv-facts > div { display: contents; }
.inv-facts dt { font: 600 10.5px/1.8 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: color-mix(in srgb, currentColor 58%, transparent); }
.inv-facts dd { margin: 0; text-align: right; font-weight: 600; }

.inv-items { width: 100%; border-collapse: collapse; }
.inv-items th { text-align: left; font: 600 10.5px/1.2 var(--mono); text-transform: uppercase; letter-spacing: 0.08em; color: color-mix(in srgb, currentColor 62%, transparent); padding: 8px; border-bottom: 1.5px solid currentColor; }
.inv-items td { padding: 11px 8px; border-bottom: 1px solid color-mix(in srgb, currentColor 13%, transparent); vertical-align: top; }
.inv-items .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inv-items th:first-child, .inv-items td:first-child { padding-left: 0; }
.inv-items th:last-child, .inv-items td:last-child { padding-right: 0; }
.inv-item-desc { font-weight: 600; }
.inv-item-details { white-space: pre-line; font-size: 12px; margin-top: 3px; color: color-mix(in srgb, currentColor 64%, transparent); }

.inv-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 32px; margin-top: 22px; align-items: start; }
.inv-block + .inv-block { margin-top: 16px; }
.inv-link { font-family: var(--mono); font-size: 12px; font-weight: 600; word-break: break-all; }
.inv-totals { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.inv-totals td { padding: 5px 0; }
.inv-totals td:last-child { text-align: right; white-space: nowrap; }
.inv-totals .inv-grand td { border-top: 1.5px solid currentColor; padding-top: 9px; font-weight: 800; font-size: 15px; }
.inv-totals .inv-balance td { padding: 10px; font-weight: 800; font-size: 16px; background: color-mix(in srgb, var(--red) 9%, transparent); }
.inv-totals .inv-balance td:first-child { border-radius: 6px 0 0 6px; }
.inv-totals .inv-balance td:last-child { border-radius: 0 6px 6px 0; color: var(--red); }
.inv-notes { margin-top: 24px; }
.inv-foot { margin-top: 34px; padding-top: 18px; border-top: 1px solid color-mix(in srgb, currentColor 14%, transparent); text-align: center; font-size: 12px; }
.inv-thanks { font-weight: 800; font-size: 16px; letter-spacing: 0.05em; text-transform: uppercase; font-variation-settings: 'wdth' 112; margin-bottom: 2px; }
.inv-footer-text { margin-top: 10px; color: color-mix(in srgb, currentColor 64%, transparent); }
.inv-tagline { margin-top: 10px; font: 600 10.5px/1.2 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--red); }

@media (max-width: 640px) {
  .invoice-print .print-page { padding: 12px 8px 40px; }
  .inv-sheet { padding: 22px 16px; font-size: 12.5px; }
  .inv-head { flex-direction: column; gap: 14px; }
  .inv-doc { text-align: left; }
  .inv-doc-kind { font-size: 26px; }
  .inv-parties, .inv-bottom { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .inv-facts dd { text-align: left; }
  .inv-stamp { top: 18px; right: 16px; font-size: 15px; }
  .inv-items th, .inv-items td { padding-left: 4px; padding-right: 4px; }
}

@media print {
  .invoice-print { min-height: 0; }
  .invoice-print .print-page { padding: 0; min-height: 0; }
  .inv-sheet { max-width: none; padding: 0; border: 0; border-radius: 0; box-shadow: none; }
  .inv-items thead { display: table-header-group; }
  .inv-items tr, .inv-bottom, .inv-notes, .inv-foot { break-inside: avoid; page-break-inside: avoid; }
  .inv-stamp { top: 110px; right: 0; }
}
