/* ===== print.css : the printed page IS the product =====
   The .sheet element is a faithful A4 or US Letter page, styled the same
   on screen (scaled preview) and on paper. Printing goes through the
   browser's own print dialog; "Save as PDF" there is the PDF engine.
   The sheet is always ink-on-white regardless of app theme. */

.sheet {
  --paper-ink: #17201b;
  --paper-soft: #5a655f;
  --paper-line: #d7dcd6;
  --paper-accent: #4338CA;
  --paper-tick: #818CF8;
  background: #ffffff;
  color: var(--paper-ink);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 10pt;
  line-height: 1.45;
  width: 210mm;
  min-height: 296mm;
  padding: 15mm 16mm 12mm;
  display: flex;
  flex-direction: column;
}
.sheet--letter {
  width: 8.5in;
  min-height: 10.95in;
}

/* ---------- Header: brand left, document identity right ---------- */
.sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 8mm;
  align-items: flex-start;
  padding-bottom: 6mm;
  border-bottom: 2px solid var(--paper-ink);
}
.sheet-brand { display: flex; gap: 5mm; align-items: flex-start; min-width: 0; }
.sheet-logo {
  max-height: 22mm;
  max-width: 40mm;
  object-fit: contain;
  display: block;
}
.sheet-bizname {
  font-family: "Bricolage", system-ui, sans-serif;
  font-weight: 700;
  font-size: 15pt;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.sheet-bizmeta {
  margin-top: 1.5mm;
  color: var(--paper-soft);
  font-size: 8.5pt;
  white-space: pre-line;
}
.sheet-doc { text-align: right; flex-shrink: 0; }
.sheet-doctype {
  font-family: "Bricolage", system-ui, sans-serif;
  font-weight: 700;
  font-size: 21pt;
  letter-spacing: 0.06em;
  line-height: 1;
}
.sheet--estimate .sheet-doctype { color: var(--paper-soft); }
.sheet--invoice .sheet-doctype { color: var(--paper-accent); }
.sheet-meta {
  margin-top: 3mm;
  margin-left: auto;
  border-collapse: collapse;
  font-size: 9pt;
}
.sheet-meta th {
  text-align: right;
  font-weight: 400;
  color: var(--paper-soft);
  padding: 0.5mm 2.5mm 0.5mm 0;
}
.sheet-meta td {
  text-align: right;
  font-weight: 600;
  padding: 0.5mm 0;
  font-variant-numeric: tabular-nums;
}

/* ---------- Parties ---------- */
.sheet-parties {
  display: flex;
  justify-content: space-between;
  gap: 8mm;
  padding: 5mm 0 6mm;
}
.sheet-label {
  font-size: 7.5pt;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--paper-soft);
  margin-bottom: 1.5mm;
}
.sheet-billto .who { font-weight: 700; font-size: 11pt; }
.sheet-billto .addr { white-space: pre-line; color: var(--paper-ink); font-size: 9.5pt; }
.sheet-estnote {
  align-self: flex-end;
  max-width: 62mm;
  font-size: 8.5pt;
  color: var(--paper-soft);
  text-align: right;
}

/* ---------- Line items: the ledger ---------- */
.sheet-lines {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.5pt;
}
.sheet-lines thead th {
  font-size: 7.5pt;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--paper-soft);
  text-align: right;
  padding: 2mm 0 1.5mm 3mm;
  border-bottom: 1.5px solid var(--paper-ink);
}
.sheet-lines thead th.col-num { text-align: left; padding-left: 0; width: 7mm; }
.sheet-lines thead th.col-desc { text-align: left; padding-left: 0; }
.sheet-lines tbody td {
  padding: 2.2mm 0 2.2mm 3mm;
  border-bottom: 1px solid var(--paper-line);
  vertical-align: top;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sheet-lines tbody td.col-num {
  text-align: left;
  padding-left: 0;
  color: var(--paper-soft);
  font-size: 8.5pt;
  font-variant-numeric: tabular-nums;
}
.sheet-lines tbody td.col-desc {
  text-align: left;
  padding-left: 0;
  white-space: normal;
}
.sheet-lines .line-unit { color: var(--paper-soft); font-size: 8.5pt; }
.sheet-lines .exempt-mark { color: var(--paper-soft); }

/* ---------- Totals ---------- */
.sheet-totalrow {
  display: flex;
  justify-content: flex-end;
  padding-top: 4mm;
}
.sheet-totals {
  width: 74mm;
  font-size: 10pt;
  font-variant-numeric: tabular-nums;
}
.sheet-totals .trow {
  display: flex;
  justify-content: space-between;
  gap: 6mm;
  padding: 1mm 0;
}
.sheet-totals .trow .tkey { color: var(--paper-soft); }
.sheet-totals .trow.grand {
  font-family: "Bricolage", system-ui, sans-serif;
  font-weight: 700;
  font-size: 13.5pt;
  border-top: 1.5px solid var(--paper-ink);
  margin-top: 2mm;
  padding-top: 2.5mm;
}
.sheet-totals .trow.grand .tkey { color: var(--paper-ink); }
.sheet-totals .trow.grand .tval {
  position: relative;
}
.sheet-totals .trow.grand .tval::after {
  /* the amber tick under the number that matters */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1.6mm;
  height: 1.2mm;
  background: var(--paper-tick);
  border-radius: 1mm;
}
.sheet-exemptnote {
  text-align: right;
  font-size: 8pt;
  color: var(--paper-soft);
  margin-top: 3mm;
}

/* ---------- Notes, payment, terms ---------- */
.sheet-blocks { margin-top: 7mm; display: grid; gap: 5mm; }
.sheet-block .sheet-label { margin-bottom: 1mm; }
.sheet-block .body {
  white-space: pre-line;
  font-size: 9.5pt;
}
.sheet-pay .body {
  border-left: 2px solid var(--paper-accent);
  padding-left: 3.5mm;
}

/* ---------- Footer of the page ---------- */
.sheet-foot {
  margin-top: auto;
  padding-top: 6mm;
}
.sheet-terms {
  font-size: 8pt;
  color: var(--paper-soft);
  white-space: pre-line;
  border-top: 1px solid var(--paper-line);
  padding-top: 2.5mm;
}
.sheet-madewith {
  margin-top: 2.5mm;
  font-size: 7pt;
  color: #5f6763;
  text-align: right;
}

/* ---------- Screen-only print root stays hidden ---------- */
#print-root { display: none; }

/* ---------- Print: only the sheet exists ----------
   The body gets .printing-doc while a document is staged in #print-root
   (set on the Print buttons and on beforeprint when a document is open).
   Without it, printing behaves like printing any normal webpage, so
   Cmd+P on the documents list never yields a blank page. */
@media print {
  body.printing-doc > *:not(#print-root) { display: none !important; }
  body.printing-doc #print-root { display: block !important; }
  body { background: #ffffff !important; margin: 0; }
  .sheet {
    width: auto !important;
    min-height: auto !important;
    box-shadow: none !important;
    margin: 0 !important;
  }
  /* Let the amber tick and accent rules survive ink-saver defaults */
  .sheet * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .sheet-lines tbody tr { break-inside: avoid; }
  .sheet-blocks, .sheet-totalrow { break-inside: avoid; }
}
