/* The A4 document sheet: invoices, quotations, receipts, credit notes.
   Layout mirrors the OfficeLab Portal's pdfkit output (A4, 50pt margins,
   slate palette), extended with GST rows, discounts and template variants.
   Printing this sheet IS the PDF — no PDF library on the request path. */

.sheet {
  --sheet-accent: #0ea5e9;
  --s-dark: #0f172a;
  --s-muted: #64748b;
  --s-line: #e2e8f0;
  --s-line-light: #f1f5f9;

  width: 210mm;
  min-height: 297mm;
  background: #ffffff;
  color: var(--s-dark);
  padding: 50pt;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px -12px rgb(2 6 23 / 0.28);
  border-radius: 4px;
  font-family: Inter, Helvetica, Arial, sans-serif;
  font-size: 10pt;
  line-height: 1.35;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.sheet.font-system { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
.sheet.font-serif { font-family: "Iowan Old Style", Georgia, "Times New Roman", serif; }

.sheet .s-muted { color: var(--s-muted); }
.sheet p { margin: 0 0 2pt; }

/* ── Header ────────────────────────────────────────────────── */

.s-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20pt; }
.s-header h1 { margin: 0; font-size: 28pt; font-weight: 700; letter-spacing: -0.02em; }
.s-logo { max-width: 140pt; max-height: 70pt; object-fit: contain; object-position: right top; }
.s-issuer-name-lg { font-size: 14pt; font-weight: 700; text-align: right; max-width: 200pt; }
.s-draft-tag {
  display: inline-block; margin-top: 4pt;
  border: 1pt solid var(--s-muted); color: var(--s-muted);
  border-radius: 4pt; padding: 1pt 6pt;
  font-size: 8pt; font-weight: 700; letter-spacing: 0.08em;
}

/* ── Meta & parties ────────────────────────────────────────── */

.s-meta { margin-top: 22pt; font-size: 10pt; }
.s-meta .m-row { display: flex; gap: 8pt; margin-bottom: 4pt; }
.s-meta .m-label { width: 110pt; font-weight: 700; flex-shrink: 0; }

.s-parties { display: flex; gap: 30pt; margin-top: 18pt; }
.s-parties > div { flex: 1; min-width: 0; }
.s-parties h3 { margin: 0 0 5pt; font-size: 11pt; font-weight: 700; }
.s-parties p { font-size: 10pt; }

.s-headline {
  margin-top: 22pt; font-size: 16pt; font-weight: 700;
  display: flex; align-items: baseline; gap: 4pt; flex-wrap: wrap;
}
.s-validline { margin-top: 22pt; font-size: 10pt; color: var(--s-muted); }

/* ── Items ─────────────────────────────────────────────────── */

.s-items { width: 100%; border-collapse: collapse; margin-top: 18pt; }
.s-items th {
  font-size: 9pt; font-weight: 400; color: var(--s-muted); text-align: left;
  padding: 0 0 6pt 0; border-bottom: 1pt solid var(--s-line);
}
.s-items th.r, .s-items td.r { text-align: right; }
.s-items th:not(:first-child), .s-items td:not(:first-child) { padding-left: 8pt; }
.s-items td {
  padding: 8pt 0; border-bottom: 0.5pt solid var(--s-line-light);
  vertical-align: top; font-size: 10pt;
}
.s-items td.desc { width: 46%; padding-right: 10pt; }
.s-items .i-name { display: block; }
.s-items .i-desc { display: block; font-size: 9pt; color: var(--s-muted); margin-top: 1pt; white-space: pre-line; }
.s-items td .amount { white-space: nowrap; }

/* ── Totals ────────────────────────────────────────────────── */

.s-totals-wrap { position: relative; margin-top: 10pt; }
.s-totals { margin-left: auto; width: 215pt; }
.s-totals .t-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4pt 0; font-size: 10pt; color: var(--s-muted);
  border-bottom: 0.5pt solid var(--s-line-light);
}
.s-totals .t-row span:last-child, .s-totals .t-row .amount { color: var(--s-dark); }
.s-totals .t-row.t-grand {
  font-size: 12pt; font-weight: 700; color: var(--s-dark);
  border-bottom: none; padding-top: 6pt;
}
.s-totals .t-row.t-adv { border-bottom: none; }
.s-totals .t-row.t-adv-recv, .s-totals .t-row.t-adv-recv .amount { color: #047857; }
.s-totals .t-row.t-balance, .s-totals .t-row.t-balance .amount { color: var(--s-dark); font-weight: 700; }
.s-totals .t-disc, .s-totals .t-disc .amount { color: #b45309; }

.s-stamp {
  position: absolute; left: 100pt; top: -4pt;
  width: 132pt; height: 46pt;
  border: 3pt solid #10b981; border-radius: 8pt; color: #10b981;
  display: grid; place-items: center;
  font-size: 30pt; font-weight: 800; letter-spacing: 0.02em;
  transform: rotate(-14deg); opacity: 0.55;
}
.s-stamp-accepted { border-color: var(--sheet-accent); color: var(--sheet-accent); font-size: 20pt; }

/* ── Notes, payment details, signing ───────────────────────── */

.s-fx { margin-top: 10pt; font-size: 9pt; }
.s-notes { margin-top: 24pt; }
.s-notes h4, .s-pay h4 { margin: 0 0 5pt; font-size: 10pt; font-weight: 700; color: var(--s-dark); }
.s-notes p { font-size: 10pt; color: var(--s-muted); white-space: pre-line; }
.s-pay { margin-top: 24pt; }
.s-pay p { font-size: 10pt; color: var(--s-muted); }
.s-pay .acct { color: var(--s-dark); font-weight: 700; }

.s-sign-row { margin-top: 30pt; display: flex; justify-content: flex-end; }
.s-sign { position: relative; width: 180pt; text-align: center; }
.s-stamp-img { position: absolute; right: 0; bottom: 10pt; max-width: 80pt; max-height: 80pt; opacity: 0.85; }
.s-sign-img { max-width: 140pt; max-height: 46pt; object-fit: contain; }
.s-sign-line {
  border-top: 0.5pt solid var(--s-muted); margin-top: 2pt; padding-top: 4pt;
  font-size: 9pt; color: var(--s-muted);
}

.s-footer { margin-top: auto; padding-top: 26pt; text-align: center; color: var(--s-muted); }
.s-footer .f1 { font-size: 9pt; margin: 0 0 3pt; }
.s-footer .f2 { font-size: 8pt; margin: 0; }

/* Rufiyaa glyph — a real inline SVG so it survives printing. */
.s-rf {
  display: inline-block; height: 0.62em; width: auto;
  aspect-ratio: 276.85 / 175.6;
  vertical-align: baseline; margin-right: 0.16em;
}

/* ── Template variants ─────────────────────────────────────── */

/* Minimal: no rules, lighter weights, more air. */
.sheet.tpl-minimal .s-header h1 { font-weight: 400; letter-spacing: 0; }
.sheet.tpl-minimal .s-items th { border-bottom-color: var(--s-line-light); }
.sheet.tpl-minimal .s-items td { border-bottom: none; padding: 6pt 0; }
.sheet.tpl-minimal .s-totals .t-row { border-bottom: none; }
.sheet.tpl-minimal .s-meta .m-label { font-weight: 400; color: var(--s-muted); }

/* Bold: an accent band across the header. */
.sheet.tpl-bold { padding-top: 0; }
.sheet.tpl-bold .s-header {
  background: var(--sheet-accent);
  color: #fff;
  margin: 0 -50pt 0;
  padding: 26pt 50pt 22pt;
  align-items: center;
}
.sheet.tpl-bold .s-header h1 { color: #fff; }
.sheet.tpl-bold .s-issuer-name-lg { color: #fff; }
.sheet.tpl-bold .s-draft-tag { border-color: #fff; color: #fff; }
.sheet.tpl-bold .s-meta { margin-top: 20pt; }
.sheet.tpl-bold .s-items th { color: var(--sheet-accent); font-weight: 700; border-bottom-color: var(--sheet-accent); }
.sheet.tpl-bold .s-totals .t-row.t-grand { color: var(--sheet-accent); }
.sheet.tpl-bold .s-totals .t-row.t-grand .amount { color: var(--sheet-accent); }

/* ── Print ─────────────────────────────────────────────────── */

@media print {
  .sheet {
    box-shadow: none;
    border-radius: 0;
    width: auto;
    min-height: 0;
    padding: 42pt 50pt;
  }
  .sheet.tpl-bold .s-header { margin: -42pt -50pt 0; }
  /* Keep a row and the totals block from splitting across pages. */
  .s-items tr { page-break-inside: avoid; }
  .s-totals-wrap, .s-pay, .s-sign-row { page-break-inside: avoid; }
  .s-items thead { display: table-header-group; }
}

/* ── Print pagination ──────────────────────────────────────────
   Screen shows one continuous sheet; print breaks it across pages. */

.s-runfoot { display: none; }

@media print {
  /* A fixed element repeats on every printed page in Chromium and WebKit,
     which is how the standing footer survives a page break. */
  .s-runfoot {
    display: flex;
    justify-content: space-between;
    gap: 20pt;
    position: fixed;
    left: 50pt;
    right: 50pt;
    bottom: 0;
    padding-top: 5pt;
    border-top: 0.5pt solid var(--s-line);
    font-size: 7.5pt;
    color: var(--s-muted);
    background: #fff;
  }


  /* Keep rows, totals and the signing block whole across a break. */
  .s-items tr, .s-totals, .s-sign-row, .s-pay, .s-notes { break-inside: avoid; }
  .s-items thead { display: table-header-group; }
  .s-items tfoot { display: table-footer-group; }
  .s-header, .s-meta, .s-parties { break-inside: avoid; }

  /* The closing lines belong at the end of the last page, never orphaned. */
  .s-footer { break-inside: avoid; break-before: avoid; }
}
