/* Invoice preview — the stacked dialog and the A4 sheet inside it.
   Colours come from the same variables app.css declares; the sheet deliberately
   does NOT inherit the app's chrome, because it stands in for a printed
   document rather than a screen. */

/* ------------------------------------------------------------ preview shell */

/* Sits above .scrim (z-index 40) and below the popover layer (60) and the
   toasts (80), so a toast fired from the preview still lands on top. */
.scrim--pvw { z-index: 50; background: rgba(0,0,0,.5); padding: 32px 24px; }

.pvw {
  margin: auto; width: min(1000px, 100%); height: 100%;
  background: #eceff1; border-radius: var(--r-lg); box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; overflow: hidden;
}
.pvw__head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 12px 10px 20px;
  background: var(--white); border-bottom: 1px solid var(--line);
}
.pvw__title { font-size: 18px; font-weight: 700; }
.pvw__sub { font-size: 13px; color: var(--ink-3); }
.pvw__headr { display: flex; align-items: center; gap: 8px; }

.pvw__body { flex: 1; overflow: auto; padding: 24px; }
.pvw__banner {
  display: flex; align-items: center; gap: 8px;
  width: 794px; max-width: 100%; margin: 0 auto 16px;
  padding: 10px 14px; border-radius: var(--r-md);
  background: #fdf3f4; border: 1px solid #f0d4d8; color: var(--red); font-size: 14px;
}
/* The builder's own footer now carries two actions. */
.modal__footr { display: flex; align-items: center; gap: 12px; }

/* ------------------------------------------------------------------- sheet */

/* A4 at 96dpi. min-height, not height: the sheet grows with the invoice and the
   print stylesheet lets the browser paginate it. */
.pdfsheet {
  position: relative;
  width: 794px; max-width: 100%; min-height: 1123px; margin: 0 auto;
  background: var(--white); color: #222;
  padding: 56px 56px 48px; box-shadow: 0 10px 30px rgba(0,0,0,.22);
  font-size: 13px; line-height: 1.5;
}
.pdfsheet__wm {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 150px; font-weight: 800; letter-spacing: 12px; color: rgba(0,91,130,.05);
  transform: rotate(-24deg); pointer-events: none; user-select: none;
}
.pdfsheet > *:not(.pdfsheet__wm) { position: relative; }

/* ------------------------------------------------------------ sheet header */

.pdf__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 32px;
  padding-bottom: 20px; border-bottom: 2px solid var(--brand);
}
.pdf__brand { display: flex; gap: 12px; }
.pdf__mark {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; letter-spacing: .5px;
}
.pdf__centre { font-size: 17px; font-weight: 800; color: var(--brand-900); }
.pdf__entity { font-size: 11.5px; color: var(--ink-2); }

.pdf__headr { text-align: right; min-width: 250px; }
.pdf__doctype {
  font-size: 26px; font-weight: 800; letter-spacing: 3px; color: var(--brand-900); line-height: 1.1;
}
.pdf__draft {
  display: inline-block; margin: 6px 0 10px; padding: 2px 8px;
  border: 1px solid #d8c48a; border-radius: 999px;
  background: #fdf8ea; color: #7a5c12; font-size: 11px; font-weight: 700;
}
.pdf__meta { display: flex; justify-content: flex-end; gap: 10px; font-size: 12px; }
.pdf__metak { color: var(--ink-3); }
.pdf__metav { min-width: 96px; text-align: right; font-weight: 700; }

/* ------------------------------------------------------------- bill to row */

.pdf__party { display: flex; gap: 40px; padding: 20px 0 22px; }
.pdf__partyblk { flex: 1; }
.pdf__partyk {
  font-size: 10.5px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px;
}
.pdf__partyname { font-size: 14px; font-weight: 700; }
.pdf__partyline { font-size: 12px; color: var(--ink-2); }

/* ----------------------------------------------------------- items table */

/* CSS grid rather than <table>: the deduction and sub-total rows span columns
   differently, and the sheet needs each row to stay one unbreakable print unit. */
.pdf__row {
  display: grid;
  grid-template-columns: 1fr 108px 40px 88px 44px 96px;
  gap: 8px; align-items: baseline;
  padding: 8px 0; border-bottom: 1px solid var(--line-soft);
  break-inside: avoid;
}
.pdf__row--head {
  padding: 8px 0; border-bottom: 1px solid #c9d2d6;
  font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--ink-2);
}
.pdf__c--period, .pdf__c--num { text-align: right; }
.pdf__row--head .pdf__c--period { text-align: right; }
.pdf__c--num { font-variant-numeric: tabular-nums; }

.pdf__desc { font-weight: 700; }
.pdf__sub { font-size: 11px; color: var(--ink-3); }

.pdf__row--group {
  grid-template-columns: 1fr; padding: 14px 0 6px; border-bottom: none;
  font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase;
  color: var(--brand-900);
}
.pdf__row--empty {
  grid-template-columns: 1fr; color: var(--ink-3); font-style: italic;
}
.pdf__row--ded { color: var(--green); }
.pdf__row--ded .pdf__c--desc { padding-left: 16px; }
.pdf__dedname { font-size: 12px; }
.pdf__c--minus { font-weight: 700; }
.pdf__row--gded .pdf__c--desc, .pdf__row--ided .pdf__c--desc { padding-left: 0; }
.pdf__row--ided { border-top: 1px solid var(--line-soft); }
.pdf__row--sub {
  border-bottom: none; font-weight: 700; background: #f7f9fa;
}
.pdf__row--sub .pdf__c--desc { padding-left: 8px; }
.pdf__row--sub .pdf__c--num:last-child { padding-right: 8px; }

/* ------------------------------------------------------------ totals block */

.pdf__foot { display: flex; gap: 32px; padding-top: 24px; break-inside: avoid; }
.pdf__remarks { flex: 1; }
.pdf__remarksbody {
  font-size: 12px; color: var(--ink-2); white-space: pre-wrap;
  min-height: 40px; padding-bottom: 12px;
}
.pdf__pay { border-top: 1px solid var(--line); padding-top: 10px; }
.pdf__payline { font-size: 11.5px; color: var(--ink-2); }

.pdf__totals { width: 320px; flex: none; }
.pdf__trow {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0; font-size: 12.5px; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.pdf__trow--ded span:last-child { color: var(--green); }
.pdf__trow--grand {
  margin-top: 6px; padding: 10px 0 0; border-top: 2px solid var(--brand);
  font-size: 15px; font-weight: 800; color: var(--brand-900);
}

.pdf__legal {
  margin-top: 32px; padding-top: 12px; border-top: 1px solid var(--line-soft);
  font-size: 10.5px; color: var(--ink-3); text-align: center;
}

/* ------------------------------------------------------------------ print */

/* Download PDF is the browser's print-to-PDF, so print drops every surface
   except the sheet and lets it flow onto real A4 pages. */
@media print {
  @page { size: A4; margin: 12mm; }

  body { background: var(--white); }
  body.is-modal-open { overflow: visible; }
  #app, #toast-root, .pvw__head, .pvw__banner { display: none !important; }

  .scrim, .scrim--pvw { position: static; inset: auto; padding: 0; background: none; display: block; }
  .pvw { width: auto; height: auto; box-shadow: none; border-radius: 0; background: none; display: block; }
  .pvw__body { overflow: visible; padding: 0; }
  #modal-root > .scrim:not(.scrim--pvw) { display: none !important; }

  .pdfsheet {
    width: auto; max-width: none; min-height: 0; padding: 0;
    box-shadow: none; margin: 0;
  }
  .pdfsheet__wm { display: none; }
  .pdf__row { break-inside: avoid; }
}

/* --------------------------------------------------------------- narrow */

@media (max-width: 900px) {
  .scrim--pvw { padding: 12px; }
  .pvw__body { padding: 12px; }
  .pdfsheet { padding: 28px 24px 32px; }
  .pdf__head { flex-direction: column; gap: 16px; }
  .pdf__headr { text-align: left; }
  .pdf__meta { justify-content: flex-start; }
  .pdf__metav { text-align: left; }
  /* Qty, unit price and the GST rate drop; description, period and amount stay. */
  .pdf__row { grid-template-columns: 1fr 76px 84px; }
  .pdf__row > .pdf__c:nth-child(3),
  .pdf__row > .pdf__c:nth-child(4),
  .pdf__row > .pdf__c:nth-child(5) { display: none; }
  .pdf__foot { flex-direction: column; }
  .pdf__totals { width: 100%; }
}
