/* Printable sheets: proposal, invoice, receipt and year summary (SPEC 2.4, 6.9).
   Builds on Makeup Studio's .sheet-wrap / .sheet / .sheet-head / .sheet-tools in styles.css and its
   @media print block; everything here is prefixed doc- so nothing in the app changes.
   Phone rules are screen-only: in print the page is about 700px wide, which would trip a max-width query. */

/* ---------- page and tools (screen) ---------- */
.doc-page { min-height: 100%; background: var(--page); }
.doc-wrap { max-width: 880px; }
.doc-tools { position: sticky; top: 0; z-index: 5; align-items: center; flex-wrap: wrap; padding: 10px 0; margin: -10px 0 14px; background: color-mix(in srgb, var(--page) 90%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.doc-tools-right { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.doc-hints { margin: 0 0 14px; padding: 10px 14px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--warning) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent); color: var(--ink-2); font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.doc-missing h2 { margin-bottom: 6px; }

/* ---------- the paper ---------- */
.sheet.doc { position: relative; padding: 44px 48px 36px; font-size: 13.5px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }
.doc .num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.doc .nowrap { white-space: nowrap; }
.doc h3 { margin: 26px 0 8px; }
.doc-label { font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 3px; }
.doc-strong { font-weight: 650; }
.doc-soft { color: var(--muted); font-size: 12.5px; }
.doc-text { white-space: pre-line; color: var(--ink-2); }
.doc-intro { margin-bottom: 4px; font-size: 14px; }
.doc-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.doc-critical { color: var(--critical-ink); font-weight: 600; }

/* header: business on the left, document on the right */
.doc-head { margin-bottom: 22px; padding-bottom: 18px; }
.doc-from { min-width: 0; }
.doc-brand { display: flex; align-items: center; gap: 12px; }
.doc-brand h1 { font-size: 22px; line-height: 1.2; }
.doc-mark { flex: none; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent, #fff); font: 700 14px/1 var(--font-display); letter-spacing: 0.02em; }
.doc-contact { margin-top: 8px; color: var(--ink-2); font-size: 12.5px; line-height: 1.55; }
.doc-address { white-space: pre-line; }
.doc-id { text-align: right; flex: none; max-width: 52%; }
.doc-type { font: 700 11.5px/1 var(--font); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent-ink); }
.doc-number { font: 650 22px/1.25 var(--font-display); letter-spacing: -0.01em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.doc-meta { display: grid; grid-template-columns: auto auto; justify-content: end; gap: 2px 14px; margin: 10px 0 0; font-size: 12.5px; }
.doc-meta dt { color: var(--muted); }
.doc-meta dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* bill to / project */
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.doc-subject { margin-top: 10px; color: var(--ink-2); }
.doc-title { font: 650 20px/1.25 var(--font-display); letter-spacing: -0.01em; margin: 4px 0 10px; }

/* line items */
.doc-lines { width: 100%; border-collapse: collapse; }
.doc-lines th { text-align: left; font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); padding: 0 0 8px; border-bottom: 1.5px solid var(--ink); }
.doc-lines th.num { text-align: right; }
.doc-lines td { padding: 10px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
.doc-lines th + th, .doc-lines td + td { padding-left: 16px; }
/* Tables never break inside a word (that collapses their columns); long text outside tables still wraps anywhere. */
.doc-lines { overflow-wrap: break-word; }
/* A total under a table, outside it, so phones can hide columns without upsetting a colspan. */
.doc-table-total { display: flex; justify-content: space-between; gap: 16px; border-top: 1.5px solid var(--ink); margin-top: -1px; padding: 8px 0 0; font-weight: 650; }
.doc-line-label { font-weight: 550; }
.doc-line-detail { color: var(--ink-2); font-size: 12.5px; white-space: pre-line; margin-top: 1px; }
.doc-line-qty { display: none; color: var(--muted); font-size: 12px; margin-top: 2px; }
.doc-compact td { padding: 7px 0; }
.doc-share { color: var(--muted); width: 48px; }
.doc-col-check { width: 28px; }
.doc-box { display: inline-grid; place-items: center; width: 16px; height: 16px; border: 1.5px solid var(--border-strong); border-radius: 4px; font-size: 11px; font-weight: 700; line-height: 1; color: var(--on-accent, #fff); vertical-align: -3px; }
.doc-box.on { background: var(--accent); border-color: var(--accent); }
.doc-addons > .doc-soft { margin: -4px 0 6px; }

/* stamp + payments on the left, totals on the right */
.doc-summary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 300px); gap: 24px; align-items: start; margin-top: 14px; }
.doc-summary-left { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; min-width: 0; }
.doc-totals { margin: 0; display: flex; flex-direction: column; }
.doc-total-row { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; }
.doc-total-row dt { color: var(--ink-2); }
.doc-total-row dd { margin: 0; }
.doc-total-row.is-total { border-top: 1.5px solid var(--ink); margin-top: 4px; padding-top: 8px; font-weight: 700; font-size: 15px; }
.doc-total-row.is-total dt { color: var(--ink); }
.doc-total-row.is-paid dd { color: var(--good-ink); }
.doc-total-row.is-due { margin-top: 6px; padding: 9px 12px; border-radius: 9px; background: var(--accent-wash); font-weight: 700; font-size: 15px; }
.doc-total-row.is-due dt { color: var(--ink); }
.doc-payments { width: 100%; max-width: 340px; }
.doc-mini { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.doc-mini td { padding: 3px 0; border-bottom: 1px dashed var(--grid); }
.doc-mini td + td { padding-left: 12px; }

/* the rubber stamp */
.doc-stamp { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 16px 6px; border: 2.5px solid currentColor; border-radius: 10px; transform: rotate(-6deg); color: var(--muted); opacity: 0.9; }
.doc-stamp-label { font: 800 21px/1 var(--font-display); letter-spacing: 0.16em; text-transform: uppercase; }
.doc-stamp-sub { font-size: 10.5px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }
.doc-stamp-good { color: var(--good-ink); }
.doc-stamp-critical { color: var(--critical-ink); }
.doc-stamp-accent { color: var(--accent-ink); }

/* what to pay and by when */
.doc-due-box { margin-top: 20px; padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); background: var(--accent-wash); font-size: 14px; }
.doc-due-box strong { font-weight: 700; }
.doc-muted-box { border-color: var(--border-strong); background: var(--surface-2); color: var(--ink-2); }
.doc-good-box { border-color: color-mix(in srgb, var(--good) 35%, transparent); background: color-mix(in srgb, var(--good) 10%, var(--surface)); color: var(--good-ink); font-weight: 600; }
.doc-pay-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.doc-pay-list li { padding-left: 14px; position: relative; }
.doc-pay-list li::before { content: ""; position: absolute; left: 0; top: 0.62em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.doc-pay-note { margin-top: 8px; color: var(--ink-2); white-space: pre-line; }
.doc-safety { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.doc-safety .icon { width: 13px; height: 13px; }

/* receipt */
.doc-received { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border-radius: var(--radius); background: var(--surface-2); margin-bottom: 6px; }
.doc .doc-received-amount { font: 700 30px/1.15 var(--font-display); letter-spacing: -0.02em; text-align: left; margin: 2px 0 4px; }

/* proposal */
.doc-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.doc-step-title { font-weight: 600; }
.doc-steps + .doc-soft { margin-top: 8px; }
.doc-table-total + .doc-soft { margin-top: 8px; }
.doc-acceptance { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-top: 26px; padding: 4px 20px 16px; border: 1px solid var(--border-strong); border-radius: var(--radius); }
.doc-acceptance h3 { margin-top: 14px; }

/* year summary */
.doc-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.doc-kpi { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface-2); min-width: 0; }
.doc .doc-kpi-value { font: 700 22px/1.2 var(--font-display); text-align: left; margin: 2px 0; }
.doc-bars { display: flex; flex-direction: column; gap: 5px; }
.doc-bar-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 104px; align-items: center; gap: 12px; font-size: 12.5px; }
.doc-bar-label { color: var(--ink-2); }
.doc-bar-track { height: 12px; border-radius: 3px; background: var(--series-track); overflow: hidden; }
.doc-bar-fill { display: block; height: 100%; border-radius: 3px; background: var(--series-1); }
.doc-bar-fill.is-zero { display: none; }
.doc-bar-row.is-future .doc-bar-label, .doc-bar-row.is-future .doc-bar-value { color: var(--muted); }
.doc-bar-row.is-total { border-top: 1.5px solid var(--ink); padding-top: 6px; margin-top: 3px; font-weight: 700; font-size: 13.5px; }
.doc-bar-row.is-total .doc-bar-label { color: var(--ink); }
.doc-two { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }

/* footer line */
.doc-foot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 32px; padding-top: 12px; border-top: 1px solid var(--grid); font-size: 11.5px; color: var(--muted); }

/* ---------- phones and narrow windows (screen only) ---------- */
@media screen and (max-width: 720px) {
  .doc-wrap { padding: 12px 16px 48px; }
  .sheet.doc { padding: 24px 18px 22px; border-radius: var(--radius); }
  .doc-tools .btn { height: 34px; padding: 0 11px; }
  .doc-head { flex-direction: column; gap: 14px; }
  .doc-id { text-align: left; max-width: none; }
  .doc-meta { justify-content: start; }
  .doc-meta dd { text-align: left; }
  .doc-parties, .doc-two, .doc-summary { grid-template-columns: 1fr; gap: 16px; }
  .doc-col-qty { display: none; }
  .doc-line-qty { display: block; }
  .doc-kpis { grid-template-columns: 1fr; }
  .doc-bar-row { grid-template-columns: 34px minmax(0, 1fr) 92px; gap: 8px; }
  .doc-received { flex-direction: column; align-items: flex-start; }
  .doc-acceptance { flex-direction: column; align-items: flex-start; }
}

/* ---------- paper ---------- */
@page {
  margin: 14mm 14mm 16mm;
  @bottom-right { content: "Page " counter(page) " of " counter(pages); font: 8pt system-ui, sans-serif; color: #6a7080; }
}
@media print {
  /* Black on white whatever the theme; the accent stays. */
  :root, :root[data-theme] { color-scheme: light; }
  html, body, #root { height: auto !important; background: #fff !important; }
  .doc-page {
    min-height: 0;
    background: #fff;
    --page: #fff; --surface: #fff; --surface-2: #f3f4f7; --surface-3: #e5e8f0;
    --ink: #111318; --ink-2: #3b404d; --muted: #646a7a; --grid: #dcdfe7;
    --border: rgba(17, 19, 24, 0.12); --border-strong: rgba(17, 19, 24, 0.22);
    --accent-ink: var(--accent); --accent-wash: color-mix(in srgb, var(--accent) 9%, #fff);
    --series-1: var(--accent); --series-track: color-mix(in srgb, var(--accent) 14%, #fff);
    --good-ink: #0b7a0b; --critical-ink: #b42b2b; --on-accent: #fff;
  }
  /* The footer line repeats the header; on paper the page counter in @page takes its place. */
  .doc-tools, .doc-hints, .doc-foot, .toasts, .fab { display: none !important; }
  .doc-wrap { padding: 0; max-width: none; margin: 0; }
  .sheet.doc { border: 0; border-radius: 0; box-shadow: none; padding: 0; font-size: 10pt; }
  /* A little tighter than the screen, so a typical invoice fits on one page. */
  .doc-head { padding-bottom: 14px; margin-bottom: 16px; }
  .doc-parties { margin-bottom: 16px; }
  .doc h3 { margin: 18px 0 6px; }
  .doc-lines td { padding: 7px 0; }
  .doc-due-box { margin-top: 14px; padding: 10px 14px; }
  .doc-received { padding: 14px 18px; }
  .doc a { color: inherit; text-decoration: none; }
  .doc h3 { break-after: avoid; page-break-after: avoid; }
  .doc-head, .doc-parties, .doc-lines tr, .doc-keep, .doc-total-row, .doc-bar-row { break-inside: avoid; page-break-inside: avoid; }
  .doc-lines thead { display: table-header-group; }
  .doc-table-total { break-before: avoid; page-break-before: avoid; }
  .doc-keep-heading > h3 + * { break-before: avoid; }
  .doc-mark, .doc-box.on, .doc-stamp, .doc-bar-track, .doc-bar-fill, .doc-due-box, .doc-total-row.is-due, .doc-received, .doc-kpi {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .doc-stamp { opacity: 1; }
}
