/* مِداد — الوثيقة المطبوعة (A4). الورقة بيضاء دائمًا في الوضعين، فألوانها ثابتة هنا. */
:root { --doc-paper: #ffffff; --doc-ink: #16202c; --doc-muted: #5b6876; --doc-line: #d5dde7; --doc-soft: #f4f6f9; }

.sheet { --acc: #071a33; --acc2: #c6a15b;
  width: 210mm; min-height: 297mm; background: var(--doc-paper); color: var(--doc-ink); position: relative; box-sizing: border-box;
  padding: 12mm 16mm 10mm; display: flex; flex-direction: column; direction: rtl; text-align: right;
  font-family: "IBM Plex Sans Arabic", Tahoma, sans-serif; font-size: 12pt; line-height: 1.85;
  -webkit-print-color-adjust: exact; print-color-adjust: exact; overflow: hidden; }
.sheet * { box-sizing: border-box; }
.sheet h1, .sheet h2, .sheet h3 { font-family: "Noto Kufi Arabic", "IBM Plex Sans Arabic", sans-serif; margin: 0; line-height: 1.4; }
.sheet p { margin: 0 0 .55em; }
.sheet .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.sheet .num { font-variant-numeric: tabular-nums; }

/* الترويسة: كلاسيكية */
.dh { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6mm; padding-bottom: 4mm; border-bottom: 2px solid var(--acc); position: relative; }
.dh::after { content: ""; position: absolute; inset-inline: 0; bottom: -5px; height: 1px; background: var(--acc2); }
.dh .ar { text-align: right; }
.dh .en { text-align: left; direction: ltr; font-family: "IBM Plex Sans Arabic", Arial, sans-serif; }
.dh .nm { font-family: "Noto Kufi Arabic", sans-serif; font-weight: 800; font-size: 14.5pt; color: var(--acc); line-height: 1.45; }
.dh .en .nm { font-size: 12.5pt; }
.dh .sb { font-size: 9pt; color: var(--doc-muted); line-height: 1.6; }
.dh .lg { display: grid; place-items: center; }
.dh .lg img { height: 24mm; width: auto; max-width: 44mm; object-fit: contain; display: block; }
/* ترويسة: شريط */
.dh.band { background: var(--acc); color: #fff; border: 0; margin: -12mm -16mm 0; padding: 7mm 16mm; }
.dh.band::after { bottom: 0; height: 3px; }
.dh.band .nm { color: #fff; }
.dh.band .sb { color: rgba(255, 255, 255, .78); }
.dh.band .lg img { background: #fff; border-radius: 3mm; padding: 2mm; }
/* ترويسة: وسط */
.dh.center { grid-template-columns: 1fr; text-align: center; justify-items: center; gap: 2mm; }
.dh.center .ar, .dh.center .en { text-align: center; }
.dh.center .en { display: none; }

/* ورق مطبوع مسبقًا: نترك مكان الترويسة والتذييل فارغًا */
.sheet.pre .dh, .sheet.pre .df { visibility: hidden; }

/* بيانات الخطاب */
.dm { display: flex; justify-content: flex-end; margin: 6mm 0 4mm; }
.dm table { border-collapse: collapse; font-size: 10.5pt; }
.dm td { padding: 1px 0 1px 3mm; }
.dm td:first-child { color: var(--doc-muted); }
.dm td:last-child { font-weight: 600; }
.dt { text-align: center; margin: 5mm 0 4mm; }
.dt h1 { font-size: 17pt; color: var(--acc); display: inline-block; padding: 0 6mm 1.5mm; border-bottom: 2px solid var(--acc2); }
.dt .en { display: block; font-size: 10pt; color: var(--doc-muted); direction: ltr; letter-spacing: .04em; }
.dsub { font-weight: 700; margin: 2mm 0 4mm; }
.dsub span { color: var(--acc); }
.db { text-align: justify; }
.db table { border-collapse: collapse; width: 100%; margin: 2mm 0 4mm; font-size: 11pt; }
.db td, .db th { border: 1px solid var(--doc-line); padding: 1.5mm 2.5mm; }
.db th { background: var(--doc-soft); }
.db ul, .db ol { margin: 0 0 .6em; padding-inline-start: 7mm; }

/* التوقيع والختم */
.ds { display: flex; justify-content: flex-end; margin: 6mm 0 6mm; padding-inline-end: 8mm; }
.ds .sg { text-align: center; min-width: 62mm; position: relative; padding-bottom: 2mm; }
.ds .cl { margin-bottom: 1mm; }
.ds .tt { font-weight: 700; color: var(--acc); }
.ds .sig { height: 20mm; display: grid; place-items: center; }
.ds .sig img { max-height: 19mm; max-width: 52mm; object-fit: contain; }
.ds .nm { font-weight: 700; }
.ds .stamp { position: absolute; width: 34mm; height: 34mm; object-fit: contain; inset-inline-start: -30mm; top: 0; opacity: .88; transform: rotate(-9deg); mix-blend-mode: multiply; }
.dverify { position: absolute; inset-inline-start: 16mm; bottom: 24mm; display: flex; align-items: center; gap: 2mm; font-size: 7.5pt; color: var(--doc-muted); }
.dverify svg { width: 18mm; height: 18mm; }

/* التذييل */
.df { margin-top: auto; border-top: 1px solid var(--acc2); padding-top: 2.5mm; display: flex; flex-wrap: wrap; justify-content: center; gap: 1mm 6mm; font-size: 8.5pt; color: var(--doc-muted); }
.df b { color: var(--acc); font-weight: 600; }
.dpg { position: absolute; bottom: 4mm; inset-inline-start: 16mm; font-size: 7.5pt; color: #9aa6b3; }

/* الفاتورة */
.iv-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border: 1px solid var(--doc-line); border-radius: 2mm; margin-bottom: 4mm; font-size: 10pt; overflow: hidden; }
.iv-meta div { padding: 2mm 3mm; border-inline-start: 1px solid var(--doc-line); }
.iv-meta div:first-child { border-inline-start: 0; }
.iv-meta span { display: block; color: var(--doc-muted); font-size: 8.5pt; }
.iv-meta b { font-variant-numeric: tabular-nums; }
.iv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 4mm; margin-bottom: 4mm; }
.iv-party { border: 1px solid var(--doc-line); border-radius: 2mm; padding: 2.5mm 3.5mm; font-size: 10pt; line-height: 1.7; }
.iv-party h3 { font-size: 10.5pt; color: var(--acc); border-bottom: 1px solid var(--doc-line); padding-bottom: 1mm; margin-bottom: 1.5mm; }
.iv-party div { display: flex; gap: 2mm; }
.iv-party div span { color: var(--doc-muted); min-width: 24mm; }
.iv-items { width: 100%; border-collapse: collapse; font-size: 10pt; }
.iv-items th { background: var(--acc); color: #fff; font-weight: 600; padding: 2mm 2mm; font-size: 9pt; text-align: center; }
.iv-items td { border-bottom: 1px solid var(--doc-line); padding: 2mm; text-align: center; font-variant-numeric: tabular-nums; }
.iv-items td.d { text-align: right; }
.iv-items tbody tr:nth-child(even) td { background: var(--doc-soft); }
.iv-bottom { display: grid; grid-template-columns: minmax(0, 1fr) 78mm; gap: 6mm; margin-top: 4mm; align-items: start; }
.iv-tot { border: 1px solid var(--doc-line); border-radius: 2mm; overflow: hidden; font-size: 10.5pt; }
.iv-tot div { display: flex; justify-content: space-between; padding: 1.6mm 3mm; border-bottom: 1px solid var(--doc-line); font-variant-numeric: tabular-nums; }
.iv-tot div:last-child { border-bottom: 0; background: var(--acc); color: #fff; font-weight: 700; font-size: 11.5pt; }
.iv-words { margin-top: 2mm; font-size: 9.5pt; background: var(--doc-soft); border-radius: 2mm; padding: 2mm 3mm; }
.iv-qr { display: flex; gap: 3mm; align-items: center; font-size: 8.5pt; color: var(--doc-muted); }
.iv-qr svg { width: 30mm; height: 30mm; flex: none; }
.iv-notes { font-size: 10pt; margin-top: 3mm; }

/* الحقل الناقص يظهر على الشاشة فقط */
.doc mark.miss { background: #fde4e1; color: #a12a1d; border-radius: 3px; padding: 0 3px; }

/* ───── الطباعة ───── */
#print-root { display: none; }
@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff !important; height: auto; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root .sheet { box-shadow: none; margin: 0; break-after: page; page-break-after: always; overflow: visible; }
  #print-root .sheet:last-child { break-after: auto; page-break-after: auto; }
  .doc mark.miss { background: none; color: inherit; }
}

/* الفاتورة أكثف حتى تبقى في صفحة واحدة */
.sheet.inv .dt { margin: 3mm 0 3mm; }
.sheet.inv .ds { margin: 2mm 0 3mm; }
.sheet.inv .ds .sig { height: 14mm; }
.sheet.inv .ds .stamp { width: 28mm; height: 28mm; }
@media print { #print-root .sheet { min-height: 296mm; } }
