/* Site Builder Builder — Invoices
   The books page: the CRM's summary strip and glass table (crm.css) carry the
   list; this file adds the status pills, the filter chips, the tax report and
   the editor — form on the left in glass cards, the invoice itself on the
   right as a white sheet on the stage, the one thing on screen that is not
   glass. Same tokens and press contract as app.css; nothing snaps. Status
   colour follows the house rule: paid is the ok green, overdue is warn amber,
   red stays reserved for delete. The sheet's own styles live in
   invoice-doc.js, shared with the server's PDF. */

.inv-main { padding: 38px 28px 90px; max-width: 1240px; width: 100%; margin: 0 auto; }
.inv-main .sub { margin-bottom: 22px; max-width: 64ch; }
.inv-stat-overdue.is-hot b { color: var(--warn); }
.inv-stat-overdue.is-hot { border-color: rgba(154, 106, 18, .3); }
.inv-tools .crm-search { flex: 1 1 240px; }
.inv-spacer { flex: 1; }
.inv-pane { animation: crm-view-in .3s var(--ease-out) both; }
.inv-empty { margin-top: 10px; max-width: 60ch; }
.inv-pane-note { margin: 0 0 10px; font-size: 12.5px; color: var(--ink); }
.inv-pane > .crm-table-wrap + .inv-pane-note { margin: 12px 0 0; }
.inv-muted { color: var(--muted); }

/* ---- status pills ---- */
.inv-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  font: 700 10.5px var(--sans); letter-spacing: .08em; text-transform: uppercase;
  background: rgba(255, 255, 255, .6); color: var(--muted); border: 1px solid var(--line);
  transition: background .2s var(--ease-out), color .2s var(--ease-out), border-color .2s var(--ease-out);
}
.inv-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.inv-pill.sent { color: var(--accent-deep); background: var(--accent-soft); border-color: rgba(123, 30, 46, .3); }
.inv-pill.partial { color: var(--accent-deep); background: linear-gradient(90deg, rgba(14, 138, 95, .12), var(--accent-soft)); border-color: rgba(123, 30, 46, .3); }
.inv-pill.overdue { color: #6E4A0C; background: rgba(154, 106, 18, .14); border-color: rgba(154, 106, 18, .4); }
.inv-pill.paid { color: #0A6B49; background: rgba(14, 138, 95, .12); border-color: rgba(14, 138, 95, .38); }
.inv-pill.void { color: var(--muted); background: rgba(26, 26, 26, .06); text-decoration: line-through; }
.inv-pill.draft::before { background: transparent; border: 1.5px solid currentColor; width: 4px; height: 4px; }

/* ---- filter chips (and the editor's terms) ---- */
.inv-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.inv-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  font: 600 12.5px var(--sans); color: var(--ink);
  background: rgba(255, 255, 255, .5); border: 1px solid var(--line-soft);
  transition: transform .32s var(--ease-spring), box-shadow .32s var(--ease-out), background .16s var(--ease-out), border-color .16s var(--ease-out), color .16s var(--ease-out);
}
.inv-chip span { font: 500 11px var(--mono); color: var(--muted); }
.inv-chip:hover { background: #FFFFFF; border-color: rgba(123, 30, 46, .4); transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.inv-chip:active { transform: translateY(1px) scale(.96); box-shadow: var(--shadow-rest); transition-duration: .06s; }
.inv-chip.is-on { background: var(--accent-soft); border-color: rgba(123, 30, 46, .5); color: var(--accent-deep); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), 0 0 14px rgba(123, 30, 46, .12); }
.inv-chip.is-on span { color: var(--accent-deep); }

/* ---- the list ---- */
.inv-table { min-width: 760px; }
.inv-col-num { white-space: nowrap; color: var(--ink); }
.inv-row td { white-space: nowrap; }
.inv-row td:nth-child(2) { max-width: 0; width: 32%; }
.inv-row.void td { color: var(--muted); }
.inv-due-cell.overdue { color: var(--warn); font-weight: 700; }
.inv-due-cell.paid { color: var(--ok); }
.inv-table td.num { font-variant-numeric: tabular-nums; }
.inv-row:focus-visible { outline: none; }
.inv-row:focus-visible td { background: var(--accent-soft); }

/* ---- taxes ---- */
.inv-tax-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.inv-inline { display: inline-flex; align-items: center; gap: 8px; }
.inv-inline select { width: auto; padding: 6px 30px 6px 12px; border-radius: 999px; }
.inv-tax-note { margin: 0; font-size: 12.5px; color: var(--ink); flex: 1 1 260px; }
.inv-tax-table td { font-variant-numeric: tabular-nums; }
.inv-tax-table tbody tr td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.inv-tax-table tbody tr.is-now td { background: rgba(245, 197, 24, .12); }
.inv-tax-table tbody tr.is-now td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.inv-tax-table .inv-total-row td { border-bottom: 0; border-top: 1.5px solid var(--ink); font-weight: 800; background: rgba(255, 255, 255, .5); }
.inv-link {
  background: none; border: 0; padding: 0; font: inherit; color: var(--accent-deep); font-weight: 700; cursor: pointer;
  text-decoration: underline; text-decoration-color: rgba(123, 30, 46, .35); text-underline-offset: 2px;
  transition: text-decoration-color .16s var(--ease-out);
}
.inv-link:hover { text-decoration-color: currentColor; }

/* ---- the editor ---- */
.inv-editor { flex: 1; display: flex; flex-direction: column; min-height: 0; animation: inv-ed-in .34s var(--ease-out) both; }
@keyframes inv-ed-in { from { opacity: 0; transform: translateY(8px); } }
.inv-ed-bar {
  position: sticky; top: var(--inv-head, 59px); z-index: 6; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 28px; border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .72); backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4);
}
.inv-ed-title { display: flex; align-items: center; gap: 10px; min-width: 0; margin-left: 6px; }
.inv-ed-title b { font: 800 18px var(--display); letter-spacing: -.01em; white-space: nowrap; }
.inv-ed-saved { font-size: 12px; color: var(--muted); white-space: nowrap; transition: color .2s var(--ease-out); }
.inv-ed-saved.ok { color: var(--ok); }
.inv-ed-saved.bad { color: var(--danger-ink); }

.inv-ed-body {
  display: grid; grid-template-columns: minmax(400px, 560px) minmax(0, 1fr); gap: 22px;
  padding: 22px 28px 60px; max-width: 1640px; width: 100%; margin: 0 auto; align-items: start;
}
.inv-ed-form { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.inv-card {
  background: var(--glass); border: 1px solid var(--line); border-radius: 18px; padding: 16px 18px;
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: var(--shadow-rest), inset 0 1px 0 rgba(255, 255, 255, .7);
  display: flex; flex-direction: column; gap: 11px;
}
.inv-card-head { display: flex; align-items: center; gap: 10px; min-height: 28px; }
.inv-card-head select { width: auto; max-width: 60%; margin-left: auto; padding: 5px 30px 5px 12px; border-radius: 999px; font-size: 12.5px; }
.inv-card textarea { resize: vertical; }
.inv-hint { margin: 0; font-size: 12px; color: var(--muted); }

.inv-terms { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inv-terms-lab { font: 700 10.5px var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-right: 4px; }
.inv-terms .inv-chip { padding: 4px 11px; font-size: 12px; }

/* line items: the description on its own row, then qty × rate, tax = amount */
.inv-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.inv-item {
  display: flex; flex-direction: column; gap: 6px; padding: 10px 0;
  border-bottom: 1px solid var(--line-soft); animation: crm-row-in .28s var(--ease-out) both;
}
.inv-item:first-child { padding-top: 0; }
.inv-item textarea { resize: none; min-height: 38px; overflow: hidden; line-height: 1.4; padding: 8px 12px; }
.inv-item-nums { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inv-item-nums input, .inv-item-nums select { padding: 7px 9px; font-size: 13px; }
.inv-item-nums input[type=number] { font-family: var(--mono); font-size: 12.5px; text-align: right; -moz-appearance: textfield; }
.inv-item-nums input[type=number]::-webkit-inner-spin-button, .inv-item-nums input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.inv-qty { width: 64px; flex: none; }
.inv-rate { width: 120px; flex: none; }
.inv-rate input { padding-left: 22px; }
.inv-item-nums select { width: auto; flex: 1 1 100px; min-width: 96px; }
.inv-op { font: 500 13px var(--mono); color: var(--muted); }
.inv-amt { min-width: 92px; text-align: right; font-size: 12.5px; font-weight: 500; color: var(--ink); white-space: nowrap; }
.inv-item-del { padding: 6px; }
.inv-item-del svg { width: 13px; height: 13px; }
.inv-add-line { align-self: flex-start; padding: 6px 13px; font-size: 12.5px; }

.inv-totals { margin: 4px 0 0; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.inv-totals div { display: grid; grid-template-columns: 150px 120px; gap: 10px; font-size: 13px; }
.inv-totals dt { color: var(--muted); text-align: right; }
.inv-totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.inv-totals .total dt, .inv-totals .total dd { color: var(--ink); font-weight: 700; }
.inv-totals .due { margin-top: 4px; padding: 6px 10px; border-radius: 10px; background: var(--accent-soft); }
.inv-totals .due dt, .inv-totals .due dd { color: var(--accent-deep); font-weight: 800; }

.inv-pays { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.inv-pay {
  display: flex; align-items: center; gap: 12px; padding: 7px 6px 7px 12px; border-radius: 12px;
  background: rgba(14, 138, 95, .07); border: 1px solid rgba(14, 138, 95, .2);
  animation: crm-row-in .28s var(--ease-out) both;
}
.inv-pay-amt { font: 700 13px var(--mono); color: #0A6B49; white-space: nowrap; }
.inv-pay-what { flex: 1; min-width: 0; font-size: 12.5px; color: var(--ink); }
.inv-pay-what i { display: block; font-style: normal; color: var(--muted); font-size: 12px; }
.inv-pay .btn svg { width: 13px; height: 13px; }
.inv-pays-empty { padding: 8px 0 2px; text-align: left; }

.inv-ed-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 2px; }

/* the sheet: real size, zoomed to its column, on the stage */
.inv-ed-paper {
  position: sticky; top: calc(var(--inv-head, 59px) + var(--inv-bar, 59px) + 14px); min-width: 0; padding: 20px; border-radius: 20px;
  background: rgba(26, 26, 26, .1); box-shadow: inset 0 2px 10px rgba(26, 26, 26, .12);
  max-height: calc(100vh - var(--inv-head, 59px) - var(--inv-bar, 59px) - 28px); overflow: auto;
}
.inv-paper {
  width: 8.5in; margin: 0 auto; background: #FFFFFF; border-radius: 4px;
  box-shadow: 0 30px 80px rgba(26, 26, 26, .3), 0 4px 14px rgba(26, 26, 26, .14);
}
.inv-print-frame { position: fixed; right: 0; bottom: 0; width: 0; height: 0; border: 0; visibility: hidden; }

/* ---- modals ---- */
.inv-modal .crm-form { margin-bottom: 2px; }
.inv-form-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.inv-biz-modal { max-width: 640px; display: flex; flex-direction: column; max-height: 92vh; max-height: 92dvh; }
.inv-biz-scroll { overflow: auto; min-height: 0; margin: 0 -6px; padding: 2px 6px; }
.inv-biz-sec { margin: 18px 0 8px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.inv-taxes { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.inv-tax { display: grid; grid-template-columns: minmax(0, 1fr) 130px 32px; gap: 8px; align-items: center; }
.inv-tax .btn svg { width: 13px; height: 13px; }
.inv-rate-in i { left: auto; right: 12px; }
.inv-rate-in input { padding-left: 12px; padding-right: 28px; text-align: right; }

@media (max-width: 1180px) {
  .inv-ed-body { grid-template-columns: minmax(0, 1fr); max-width: 860px; }
  .inv-ed-paper { position: static; max-height: none; }
}
@media (max-width: 1000px) {
  .inv-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .inv-main { padding: 26px 16px 80px; }
  .inv-ed-bar { padding: 10px 16px; position: static; }
  .inv-ed-body { padding: 16px 16px 50px; }
  .inv-form-3 { grid-template-columns: 1fr 1fr; }
  .inv-totals div { grid-template-columns: 1fr 110px; }
}
@media (prefers-reduced-motion: reduce) {
  .inv-editor, .inv-pane, .inv-item, .inv-pay { animation: none; }
}
