/* ==========================================================================
   Karina (fa) — invoice sheet (فاکتور چاپی)
   Used three ways: inside the full-screen invoice view, on paper (print) and
   inside the PDF image (karina-pdf.js embeds this file). It therefore uses
   fixed ink-on-paper colours and no theme variables, and never depends on
   style.css. A4 width at 96 dpi is 794px.
   ========================================================================== */
.sheet {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  max-width: 794px;
  margin: 0 auto;
  padding: 34px 38px 28px;
  background: #fff;
  color: #17171b;
  font: 400 12.5px/1.75 "YekanBakh", Tahoma, "Segoe UI", sans-serif;
  direction: rtl;
  text-align: right;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 16px 40px -24px rgba(0, 0, 0, .35);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.sheet *, .sheet *::before, .sheet *::after { box-sizing: border-box; }
.sheet h1, .sheet h2, .sheet p, .sheet dl, .sheet dd { margin: 0; }
.sheet b { font-weight: 700; }
.sheet small { font-size: 11px; color: #5c5a55; }
.sheet--export { box-shadow: none; border-radius: 0; }

.sheet__head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; padding-bottom: 14px; border-bottom: 2px solid #17171b; }
.sheet__brand b { display: block; font-size: 15px; font-weight: 800; }
.sheet__brand small { display: block; }
.sheet__logo { display: block; max-width: 150px; height: 46px; margin-bottom: 6px; object-fit: contain; object-position: right center; }
.sheet__title { text-align: center; }
.sheet__title h1 { font-size: 22px; font-weight: 800; line-height: 1.4; }
.sheet__title p { font-size: 13px; }
.sheet__title p b { font-size: 16px; }
.sheet__meta { display: grid; gap: 2px; justify-self: end; font-size: 12px; }
.sheet__meta div { display: flex; justify-content: space-between; gap: 14px; }
.sheet__meta dt { color: #5c5a55; }
.sheet__meta dd { font-weight: 600; }

.sheet__order { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-top: 12px; padding: 8px 12px; border: 1px solid #d8d4c8; border-radius: 6px; background: #faf8f2; font-size: 13px; }
.sheet__order b { font-size: 14px; }
.sheet__order--online { border-color: #c58d10; background: #fdf3d6; }

.sheet__parties { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; margin-top: 14px; }
.sheet__box { padding: 10px 12px; border: 1px solid #d8d4c8; border-radius: 6px; }
.sheet__box h2 { margin-bottom: 4px; font-size: 11.5px; font-weight: 600; color: #5c5a55; }
.sheet__name { font-size: 15px; font-weight: 700; }
.sheet__box dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 14px; margin-top: 4px; }
.sheet__box dl .wide { grid-column: 1 / -1; }
.sheet__box dt { font-size: 11px; color: #5c5a55; }
.sheet__box dd { font-weight: 600; }
.sheet .sheet__note { margin-top: 6px; font-size: 10.5px; color: #5c5a55; }

.sheet table { width: 100%; margin-top: 14px; border-collapse: collapse; font-size: 11.5px; }
.sheet th { padding: 6px 5px; background: #17171b; color: #fff; font-weight: 600; text-align: center; white-space: nowrap; }
.sheet td { padding: 6px 5px; border-bottom: 1px solid #e3dfd4; text-align: center; vertical-align: top; font-variant-numeric: tabular-nums; }
.sheet .t { text-align: right; }
.sheet td.t small { display: block; }
.sheet td.b { font-weight: 700; }
.sheet td.code { white-space: nowrap; }
.sheet tbody tr:nth-child(even) td { background: #faf8f2; }
.sheet .sheet__unit { margin-top: 4px; font-size: 10.5px; color: #5c5a55; }

.sheet__totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.sheet__totals dl { padding: 8px 12px; border: 1px solid #d8d4c8; border-radius: 6px; }
.sheet__totals dl div { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.sheet__totals dt { color: #3d3b37; }
.sheet__totals dd { font-weight: 600; font-variant-numeric: tabular-nums; }

/* the gallery's profit (settings formula): on screen, on paper and in the PDF */
.sheet th.sheet__internal { background: #3d3b37; }
.sheet td.sheet__internal { background: #f6f1e2; font-weight: 600; }
.sheet .sheet__loss { color: #b9392f; }
.sheet__totals .sheet__profit { margin-top: 2px; padding-top: 4px; border-top: 1px dashed #bdb8aa; }
.sheet__totals .sheet__profit dt, .sheet__totals .sheet__profit dd { font-weight: 800; color: #17171b; }
.sheet__sum .em { margin-top: 2px; padding-top: 4px; border-top: 1px dashed #bdb8aa; font-size: 13.5px; }
.sheet__sum .em dt, .sheet__sum .em dd { font-weight: 800; color: #17171b; }

.sheet__payments th { background: #3d3b37; }
.sheet .sheet__desc { margin-top: 12px; padding: 8px 12px; border-radius: 6px; background: #faf8f2; }

.sheet__foot { margin-top: 18px; padding-top: 10px; border-top: 1px solid #d8d4c8; font-size: 10.5px; color: #5c5a55; }
.sheet__signs { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 22px; }
.sheet__signs span { padding-top: 32px; border-top: 1px dotted #8e8a80; text-align: center; color: #3d3b37; }

/* a voided invoice keeps its figures but says so across the page */
.sheet__void { margin: -10px -14px 14px; padding: 8px 14px; border-radius: 6px; background: #fbe3df; color: #b9392f; font-weight: 800; text-align: center; }
.sheet--void::after {
  content: "باطل شده";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 110px; font-weight: 800; color: rgba(185, 57, 47, .09);
  transform: rotate(-24deg);
  pointer-events: none;
}

/* person statement (صورت‌حساب شخص): same frame, a long ledger table that may run over several pages */
.sheet--statement { page: statement; }
.sheet__box .st-sum { display: block; margin-top: 2px; }
.st-sum div { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 10px; padding: 2px 0; }
.st-sum--gold div { grid-template-columns: minmax(0, 1fr) 110px 84px; }
.st-sum dt { font-size: 11.5px; color: #3d3b37; }
.st-sum dd { text-align: left; font-variant-numeric: tabular-nums; }
.st-sum .st-sum__head dd { font-size: 10.5px; font-weight: 600; color: #5c5a55; }
.st-sum .em { margin-top: 2px; padding-top: 4px; border-top: 1px dashed #bdb8aa; }
.st-sum .em dt, .st-sum .em dd { font-weight: 800; color: #17171b; }
.sheet--statement i { margin-inline-start: 3px; font-style: normal; font-size: 9.5px; font-weight: 600; color: #5c5a55; }

.sheet .st-verdict { margin-top: 12px; padding: 8px 12px; border: 1px solid #c58d10; border-radius: 6px; background: #fdf3d6; font-size: 13px; }
.st-verdict b { font-size: 14px; }

.sheet .st-table { font-size: 10.5px; }
.sheet .st-table th { padding: 5px 4px; }
.sheet .st-table thead tr:first-child th { border-inline-start: 1px solid #3d3b37; }
.sheet .st-table thead tr:first-child th:first-child { border-inline-start: 0; }
.sheet .st-table thead th.grp { border-bottom: 1px solid #5c5a55; }
.sheet .st-table thead tr + tr th { background: #3d3b37; font-weight: 500; }
.sheet .st-table td { padding: 5px 4px; white-space: nowrap; }
.sheet .st-table td.t { white-space: normal; }
.sheet .st-table td.t small { display: inline; margin-inline-start: 6px; font-size: 9.5px; color: #7a776f; }
.sheet .st-table td:nth-child(n+4), .sheet .st-table tr.st-total td:not(.t) { padding-left: 6px; text-align: left; }
.sheet .st-table:not(.st-table--rial) td.sep { border-inline-end: 1px solid #cfcabd; }
.sheet .st-table tbody tr.st-open td { background: #f1eee5; font-weight: 600; }
.sheet .st-table tbody tr.st-total td { padding: 7px 4px; border-top: 2px solid #17171b; border-bottom: 2px solid #17171b; background: #fdf3d6; font-weight: 800; }
.sheet .st-table tbody tr.is-reversal td { color: #7a776f; font-style: italic; }
.sheet .st-table .st-empty { padding: 16px; color: #5c5a55; }

@page statement {
  @bottom-center { content: "صفحه " counter(page, persian) " از " counter(pages, persian); font: 9px Tahoma, sans-serif; color: #5c5a55; }
}

/* reports (گزارش‌ها) printed in the same frame; wide ones on landscape pages */
.sheet--report { page: report; }
.sheet--report.sheet--wide { page: report-wide; max-width: 1123px; }
.sheet--report .sheet__head { grid-template-columns: auto minmax(0, 1fr) auto; }
.sheet--report .sheet__brand, .sheet--report .sheet__meta dt, .sheet--report .sheet__meta dd { white-space: nowrap; }
.sheet--report .sheet__title p { font-size: 12px; color: #3d3b37; }
/* the source line sits in the page margin, so it never pushes a lone footer onto an extra page */
@page report {
  size: A4 portrait;
  @bottom-center { content: "صفحه " counter(page, persian) " از " counter(pages, persian); font: 9px Tahoma, sans-serif; color: #5c5a55; }
  @bottom-right { content: "تهیه‌شده از اسناد ثبت‌شده‌ی حسابداری در سیستم کارینا"; font: 8px Tahoma, sans-serif; color: #8e8a80; }
}
@page report-wide {
  size: A4 landscape;
  @bottom-center { content: "صفحه " counter(page, persian) " از " counter(pages, persian); font: 9px Tahoma, sans-serif; color: #5c5a55; }
  @bottom-right { content: "تهیه‌شده از اسناد ثبت‌شده‌ی حسابداری در سیستم کارینا"; font: 8px Tahoma, sans-serif; color: #8e8a80; }
}

@media (max-width: 720px) {
  .sheet { padding: 20px 16px; }
  .sheet__head, .sheet__parties, .sheet__totals { grid-template-columns: minmax(0, 1fr); }
  .sheet__meta { justify-self: stretch; }
  .sheet table { display: block; overflow-x: auto; }
}

@media print {
  /* 2px inside the printable area so the outer boxes keep their borders */
  .sheet { max-width: none; padding: 0 2px; box-shadow: none; border-radius: 0; }
  .sheet table, .sheet__totals, .sheet__parties { break-inside: avoid; }
  .sheet tr { break-inside: avoid; }
  .sheet .st-table { break-inside: auto; }
  .sheet--statement .sheet__foot { break-inside: avoid; }
}
