/* =====================================================================
   نظام إدارة الخطابات - القنصلية | تنسيق المحرر والطباعة (A4)
   ===================================================================== */
/* خطوط محلية (تعمل offline بالكامل) — بديلة عن Google Fonts */
@import url('../fonts/letter-fonts.css');

@page { size: A4; margin: 0 !important; }

@font-face { font-family: 'Sakkal Majalla'; src: local('Sakkal Majalla'), local('Traditional Arabic'); }
@font-face { font-family: 'Andalus'; src: local('Andalus'), local('Arabic Typesetting'); }
@font-face { font-family: 'Century'; src: local('Century'), local('Century Schoolbook'); }

/* ---------- صفحة A4 ---------- */
.letter-format-a4 {
  /* قيم افتراضية قابلة للضبط عبر شريط التحكم (JS يضبطها كخصائص مضمّنة) */
  --body-font-size: 19pt;
  --body-line-height: 1.8;
  --para-gap: 4mm;
  --meta-line-gap: 1.5mm;
  --meta-bottom: 8mm;
  --title-gap-top: 6mm;
  --title-gap-bottom: 8mm;
  --sign-gap-top: 8mm;
  --page-padding-y: 12mm;
  --meta-font-size: 17pt;
  --title-font-size: 22pt;
  --barcode-size: 24mm;

  font-family: 'Sakkal Majalla', 'Traditional Arabic', 'Amiri', serif;
  width: 210mm;
  min-height: 297mm;
  padding: var(--page-padding-y) 16mm;
  margin: 0 auto;
  box-sizing: border-box;
  position: relative;
  direction: rtl;
  text-align: right;
  color: #000;
  background: #fff;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* ---------- الترويسة (بدون إطار، مطابقة لترويسة السفارة) ---------- */
.letter-format-a4 .header-container { margin-bottom: 10mm; }
.letter-format-a4 .letterhead {
  width: 100%;
  border-collapse: collapse;
  border: none;
  direction: rtl;
}
.letter-format-a4 .letterhead td {
  vertical-align: middle;
  padding: 0;
  border: none;
}
.letter-format-a4 .arabic-section { width: 38%; text-align: right; }
.letter-format-a4 .logo-section { width: 24%; text-align: center; }
.letter-format-a4 .english-section { width: 38%; text-align: left; }
.letter-format-a4 .head-logo { width: 26mm; height: auto; display: block; margin: 0 auto; }

.letter-format-a4 .head-ar {
  font-family: 'Sakkal Majalla', 'Traditional Arabic', 'Amiri', serif;
  line-height: 1.4;
  color: #000;
  font-weight: bold;
}
.letter-format-a4 .head-ar .ln1 { font-size: 20pt; }
.letter-format-a4 .head-ar .ln2 { font-size: 18pt; margin-top: 2px; }

.letter-format-a4 .head-en {
  font-family: 'Times New Roman', 'Century', serif;
  line-height: 1.3;
  color: #000;
  font-weight: bold;
}
.letter-format-a4 .head-en .ln1 { font-size: 11.5pt; white-space: nowrap; }
.letter-format-a4 .head-en .ln2 { font-size: 11.5pt; white-space: nowrap; }
.letter-format-a4 .head-en .ln3 { font-size: 11.5pt; margin-top: 2px; }

/* ---------- الترويسة: ثلاث صناديق (معتمدة من letterhead-boxed-a4.html / مرجع) ----------
   هامش علوي أصغر من الترويسة العادية حتى تبدأ الصناديق أقرب لأعلى الورقة. */
.letter-format-a4.letterhead-style-boxed {
  padding-top: 5mm;
}
.letter-format-a4 .letterhead.letterhead--boxed {
  width: 100%;
  border-collapse: collapse;
  border: 0.5pt solid #000;
  direction: rtl;
  table-layout: fixed;
}
.letter-format-a4 .letterhead.letterhead--boxed td {
  border: none;
  border-left: 0.5pt solid #000;
  padding: 5px 8px;
  height: 32mm;
  vertical-align: middle;
}
.letter-format-a4 .letterhead.letterhead--boxed .english-section {
  border-left: none;
}
.letter-format-a4 .letterhead.letterhead--boxed .arabic-section,
.letter-format-a4 .letterhead.letterhead--boxed .english-section {
  width: 40%;
  text-align: center;
}
.letter-format-a4 .letterhead.letterhead--boxed .logo-section {
  width: 20%;
  text-align: center;
  padding: 5px;
}
.letter-format-a4 .letterhead.letterhead--boxed .head-logo {
  width: 22mm;
  height: auto;
  display: block;
  margin: 0 auto;
}
.letter-format-a4 .letterhead.letterhead--boxed .head-ar,
.letter-format-a4 .letterhead.letterhead--boxed .head-en {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 22mm;
  width: 100%;
}
.letter-format-a4 .letterhead.letterhead--boxed .head-ar {
  font-family: 'Andalus', 'Arabic Typesetting', 'Amiri', 'Sakkal Majalla', serif;
  line-height: 1.3;
  font-weight: normal;
  color: #000;
}
.letter-format-a4 .letterhead.letterhead--boxed .head-ar .ln1 { font-size: 20pt; }
.letter-format-a4 .letterhead.letterhead--boxed .head-ar .ln2 { font-size: 20pt; margin-top: 2px; }
.letter-format-a4 .letterhead.letterhead--boxed .head-en {
  font-family: 'Century', 'Century Schoolbook', 'Times New Roman', serif;
  line-height: 1.25;
  font-weight: bold;
  color: #000;
}
.letter-format-a4 .letterhead.letterhead--boxed .head-en .ln1 {
  font-size: 10.5pt;
  white-space: nowrap;
  max-width: 100%;
}
.letter-format-a4 .letterhead.letterhead--boxed .head-en .ln2 {
  font-size: 12pt;
  margin-top: 4px;
  white-space: nowrap;
}

/* ---------- المحتوى ---------- */
.letter-format-a4 .document-content { padding-bottom: 40mm; }
/* احتواء التوقيع الطافي (float) داخل المحتوى كي يُقاس ارتفاعه بدقة في الاحتواء
   التلقائي — يمنع طفح التوقيع فوق الفوتر ويجعل الضغط/التصغير يعمل بشكل صحيح */
.letter-format-a4 .document-content::after {
  content: '';
  display: block;
  clear: both;
}

.letter-format-a4 .letter-meta {
  text-align: right;
  margin-bottom: var(--meta-bottom);
  font-size: var(--meta-font-size);
  font-weight: bold;
  line-height: 1.15;
  font-family: 'Sakkal Majalla', 'Traditional Arabic', 'Amiri', serif;
}
.letter-format-a4 .letter-meta .meta-line {
  display: table;
  border-bottom: 1.5pt solid #000;
  padding-bottom: 1px;
  margin-bottom: var(--meta-line-gap);
  line-height: 1.15;
}
.letter-format-a4 .letter-meta .meta-label { letter-spacing: 2px; }
.letter-format-a4 .letter-meta .meta-value { unicode-bidi: isolate; }

/* شارة معاينة/رسمي — للشاشة فقط، لا تُطبع على الورقة */
.letter-format-a4 .seq-status-badge {
  display: inline-block;
  margin-inline-start: 0.45rem;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.72em;
  font-weight: 700;
  vertical-align: middle;
  letter-spacing: 0;
}
.letter-format-a4 .seq-status-badge.seq-preview {
  background: rgba(219, 162, 39, 0.22);
  color: #9a6b00;
}
.letter-format-a4 .seq-status-badge.seq-official {
  background: rgba(39, 174, 96, 0.18);
  color: #1a7a45;
}
@media print {
  .letter-format-a4 .seq-status-badge { display: none !important; }
}
/* تاريخ عربي: اليوم يميناً ثم الشهر فالسنة ثم م يساراً */
.letter-format-a4 .meta-date,
.letter-format-a4 .field-slot-date {
  direction: rtl;
  unicode-bidi: isolate;
}
.letter-format-a4 .date-ar {
  direction: rtl;
  unicode-bidi: isolate;
}
.letter-format-a4 .date-ymd {
  direction: ltr;
  unicode-bidi: embed;
}
.letter-format-a4 .date-mim {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  vertical-align: baseline;
}

.letter-format-a4 .doc-title-container { text-align: center; margin: var(--title-gap-top) 0 var(--title-gap-bottom); line-height: 1.2; }
.letter-format-a4 .doc-title {
  font-size: var(--title-font-size);
  font-weight: bold;
  display: inline-block;
  padding-bottom: 4px;
  border-bottom: 2pt solid #000;
  line-height: 1.2;
  font-family: 'Sakkal Majalla', 'Traditional Arabic', 'Amiri', serif;
  text-wrap: balance;
}

.letter-format-a4 .body-content {
  font-size: var(--body-font-size);
  line-height: var(--body-line-height);
  text-align: justify;
  font-family: 'Sakkal Majalla', 'Traditional Arabic', 'Amiri', serif;
}
.letter-format-a4 .body-content p {
  margin: 0 0 var(--para-gap) 0;
  /* معالجة الأسطر اليتيمة وتوازن اللف (متصفحات حديثة) */
  text-wrap: pretty;
  orphans: 2;
  widows: 2;
}
/* ---------- القوائم: تعداد نقطي / ترقيم / متعددة المستويات ---------- */
.letter-format-a4 .body-content ul,
.letter-format-a4 .body-content ol {
  margin: 0 0 var(--para-gap) 0;
  padding-right: 2.2em;
  padding-left: 0;
  list-style-position: outside;
}
.letter-format-a4 .body-content li {
  margin-bottom: calc(var(--para-gap) * 0.4);
  text-align: justify;
}
/* قوائم متداخلة: بلا هامش سفلي إضافي بين المستويات */
.letter-format-a4 .body-content li > ul,
.letter-format-a4 .body-content li > ol {
  margin-bottom: 0;
  margin-top: calc(var(--para-gap) * 0.4);
}
/* ترقيم بأرقام عربية، وأنماط مختلفة لكل مستوى */
.letter-format-a4 .body-content ol { list-style-type: arabic-indic; }
.letter-format-a4 .body-content ol ol { list-style-type: lower-alpha; }
.letter-format-a4 .body-content ol ol ol { list-style-type: lower-roman; }
/* تعداد نقطي بأشكال مختلفة لكل مستوى */
.letter-format-a4 .body-content ul { list-style-type: disc; }
.letter-format-a4 .body-content ul ul { list-style-type: circle; }
.letter-format-a4 .body-content ul ul ul { list-style-type: square; }

/* ---------- الجداول داخل متن الخطاب ----------
   ذكية ومرنة (كنظام عدم ممانعة الزواج): table-layout:fixed يحافظ على تناسق
   الأعمدة، بينما لا تُحدَّد أي ارتفاعات — فالصف يكبر تلقائياً كلما زاد
   النص ويلتف بدلاً من أن يفيض أو يُقصّ. الحدود بلون أسود صريح مع
   print-color-adjust كي تُطبع فعلياً (بعض المتصفحات تُسقط الحدود الفاتحة). */
.letter-format-a4 .body-content table.letter-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin: 0 0 var(--para-gap) 0;
  font-size: inherit;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .body-content .letter-table th,
.letter-format-a4 .body-content .letter-table td {
  border: 1pt solid #000;
  padding: 1.5mm 2.5mm;
  vertical-align: top;
  text-align: right;
  box-sizing: border-box;
  line-height: 1.4;
  height: auto;
  white-space: normal;
  word-break: normal;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.letter-format-a4 .body-content .letter-table th {
  font-weight: bold;
  text-align: center;
  background: #f2f2f2;
}
/* احترازي: منع قطع صف في منتصفه إن تجاوز جدول طويل الصفحة سهواً */
.letter-format-a4 .body-content .letter-table tr { break-inside: avoid; page-break-inside: avoid; }

/* ---------- جداول صفوف/أعمدة (قيد عائلي، مرافقون، إلخ) ----------
   للجداول ذات الصفوف المتعددة والأعمدة الثابتة — ليست حقول Flex.
   الحدود متراصة، والخلايا الفارغة قابلة للتعبئة في المحرر. */
.letter-format-a4 .body-content .data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin: 0 0 var(--para-gap) 0;
  font-size: calc(var(--body-font-size) * 0.92);
  direction: rtl;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .body-content .data-table th,
.letter-format-a4 .body-content .data-table td {
  border: 1pt solid #000;
  padding: 2mm 2.2mm;
  text-align: center;
  vertical-align: middle;
  box-sizing: border-box;
  line-height: 1.35;
  height: auto;
  min-height: 8mm;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.letter-format-a4 .body-content .data-table th {
  font-weight: 700;
  background: #f0f0f0;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .body-content .data-table td {
  font-weight: bold;
}
.letter-format-a4 .body-content .data-table .col-num {
  width: 10%;
}
.letter-format-a4 .body-content .data-table .col-name {
  width: 28%;
}
.letter-format-a4 .body-content .data-table .ltr {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: 'Times New Roman', 'Courier New', monospace;
  letter-spacing: 0.3px;
}
.letter-format-a4 .body-content .data-table tr {
  break-inside: avoid;
  page-break-inside: avoid;
}

.letter-format-a4 .body-content .table-caption {
  font-weight: 700;
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 1.5mm 0;
  /* خط متصل بـ border — لا ينقطع أبداً عند الحروف النازلة، ولاصق بالنص كالوورد
     (line-height منخفض يمنع تمدد صندوق inline-block ويُبعد الخط عن النص) */
  text-decoration: none !important;
  border-bottom: 0.07em solid #000;
  padding-bottom: 0.04em;
  line-height: 1.15;
}

/* ---------- جداول بيانات ذكية ومرنة (إزاحة عرضية + حدود طولية مستقيمة) ----------
   - الحقول تُلفّ بحد أقصى 3 في الصف (أو 2 لـ .pair).
   - عمود التسمية داخل كل حقل ثابت 34mm عبر grid حتى تصطف الحدود الطولية.
   ملاحظة: لا تستخدم class="field" — يتعارض مع .field في style.css. */
.letter-format-a4 .body-content .info-block {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  align-content: flex-start;
  width: 100%;
  margin: 0 0 var(--para-gap) 0;
  font-size: calc(var(--body-font-size) * 0.78);
  direction: rtl;
  border-top: 1pt solid #000;
  border-inline-start: 1pt solid #000;
  box-sizing: border-box;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .body-content .info-block .section-head {
  flex: 1 1 100%;
  width: 100%;
  box-sizing: border-box;
  background: #e8e8e8;
  text-align: center;
  font-weight: bold;
  font-size: 1.05em;
  letter-spacing: 1px;
  padding: 2mm;
  border-bottom: 1pt solid #000;
  border-inline-end: 1pt solid #000;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .body-content .info-block .ib-field {
  /* شبكة داخلية: تسمية ثابتة + قيمة — يضمن خطّاً طولياً موحّداً */
  display: grid !important;
  grid-template-columns: 34mm minmax(0, 1fr);
  align-items: stretch;
  gap: 0 !important;
  flex: 1 1 33.333%;
  min-width: 33.333%;
  max-width: 100%;
  box-sizing: border-box;
  border-bottom: 1pt solid #000;
  border-inline-end: 1pt solid #000;
  break-inside: avoid;
  page-break-inside: avoid;
}
.letter-format-a4 .body-content .info-block .ib-field.full {
  flex: 1 1 100%;
  width: 100%;
  min-width: 100%;
  max-width: 100%;
  grid-template-columns: 34mm minmax(0, 1fr);
}
/* حقل يشارك صفاً مع بيان واحد فقط كحد أقصى */
.letter-format-a4 .body-content .info-block .ib-field.pair {
  flex: 1 1 50%;
  min-width: 50%;
  max-width: 100%;
}
.letter-format-a4 .body-content .info-block .ib-lbl {
  width: 100%;
  min-width: 0;
  max-width: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  background: #f5f5f5;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.3;
  padding: 1.8mm 1.5mm;
  box-sizing: border-box;
  border-inline-end: 1pt solid #000;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .body-content .info-block .ib-val {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  text-align: center;
  line-height: 1.3;
  padding: 1.8mm 2.5mm;
  box-sizing: border-box;
  white-space: normal;
  word-break: normal;
  overflow-wrap: anywhere;
}
.letter-format-a4 .body-content .info-block .ib-val.full {
  justify-content: flex-start;
  text-align: right;
  padding-right: 3mm;
  padding-left: 3mm;
}
.letter-format-a4 .body-content .info-block .ib-val.ltr {
  direction: ltr;
  unicode-bidi: isolate;
  justify-content: center;
  font-family: 'Times New Roman', 'Courier New', monospace;
  letter-spacing: 0.3px;
  white-space: normal;
  overflow-wrap: anywhere;
}
.letter-format-a4 .body-content .closing-center {
  text-align: center;
  font-weight: bold;
}

/* ---------- التوكيل الفردي / الجماعي — أبعاد أساسية متوازنة قبل الاحتواء ---------- */
.letter-format-a4:has(.poa-individual) .document-content,
.letter-format-a4:has(.poa-joint) .document-content,
.letter-format-a4:has(.affidavit) .document-content {
  padding-bottom: 32mm;
}
.letter-format-a4 .body-content .poa-individual,
.letter-format-a4 .body-content .poa-joint,
.letter-format-a4 .body-content .affidavit {
  line-height: inherit;
}
.letter-format-a4 .body-content .poa-individual > p,
.letter-format-a4 .body-content .poa-joint > p,
.letter-format-a4 .body-content .affidavit > p {
  margin: 0 0 var(--para-gap, 2.5mm) 0;
  text-align: right;
}
/* كتلة الهوية: مقروءة مع خانات فارغة (لا تلتصق الخطوط) */
.letter-format-a4 .body-content .poa-id-block {
  line-height: 1.35;
  margin: 0 0 calc(var(--para-gap, 2.5mm) * 1.2) 0;
}
.letter-format-a4 .body-content .poa-id-block > p {
  margin: 0 0 0.7mm 0 !important;
  line-height: 1.35;
  text-align: right;
}
.letter-format-a4 .body-content .poa-id-block > p:last-child {
  margin-bottom: 0 !important;
}
.letter-format-a4 .body-content .poa-id-line {
  margin-right: 8mm;
}
.letter-format-a4 .body-content .poa-content {
  margin-top: calc(var(--para-gap, 2.5mm) * 0.6) !important;
  margin-bottom: calc(var(--para-gap, 2.5mm) * 1.4) !important;
  text-align: justify;
  line-height: inherit;
}
.letter-format-a4 .body-content .poa-content > p {
  margin: 0 0 var(--para-gap, 2.5mm) 0;
  text-align: justify;
  line-height: inherit;
}
.letter-format-a4 .body-content .poa-content > p:last-child {
  margin-bottom: 0;
}
.letter-format-a4 .body-content .poa-section-label {
  margin-top: calc(var(--para-gap, 2.5mm) * 1.4) !important;
  margin-bottom: 1.2mm !important;
}
.letter-format-a4 .body-content .poa-sign-row {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8mm;
  margin-bottom: calc(var(--para-gap, 2.5mm) * 1.2) !important;
}
.letter-format-a4 .body-content .poa-sign-line {
  white-space: nowrap;
  flex: 0 0 auto;
}
.letter-format-a4 .body-content .poa-principal {
  flex: 0 1 auto;
}
/* الشهود: سطر واحد — المعلومات ثم التوقيع بمسافة قصيرة */
.letter-format-a4 .body-content .poa-witness {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: baseline;
  gap: 5mm;
  margin-bottom: 2mm !important;
  line-height: 1.35;
  font-weight: bold;
  font-size: 0.94em;
}
.letter-format-a4 .body-content .poa-witness-info {
  flex: 0 1 auto;
  min-width: 0;
}
.letter-format-a4 .body-content .poa-attest {
  margin-top: calc(var(--para-gap, 2.5mm) * 1.6) !important;
  margin-bottom: 0 !important;
  text-align: justify;
  font-weight: normal;
  line-height: 1.45;
  font-size: 0.97em;
}

/* ---------- الإقرار المشفوع باليمين ---------- */
.letter-format-a4 .body-content .aff-intro {
  text-align: justify !important;
  line-height: inherit;
  margin-bottom: calc(var(--para-gap, 2.5mm) * 1.4) !important;
}
.letter-format-a4 .body-content .aff-content {
  font-weight: inherit;
}
.letter-format-a4 .body-content .aff-sign-row {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8mm;
  margin-bottom: calc(var(--para-gap, 2.5mm) * 1.2) !important;
}
.letter-format-a4 .body-content .aff-declarant {
  flex: 0 1 auto;
}

/* جدول الموكلين في التوكيل الجماعي — صفوف مضمومة كالورقة الورقية */
.letter-format-a4 .body-content .poa-principals-table {
  margin-top: 1mm;
  margin-bottom: calc(var(--para-gap, 2.5mm) * 1.2);
  font-size: calc(var(--body-font-size) * 0.88);
}
.letter-format-a4 .body-content .poa-principals-table th,
.letter-format-a4 .body-content .poa-principals-table td {
  padding: 0.7mm 1.5mm !important;
  line-height: 1.25 !important;
  min-height: 0;
  font-size: inherit;
  font-weight: bold;
}
.letter-format-a4 .body-content .poa-principals-table th {
  padding: 0.9mm 1.5mm !important;
  font-weight: 700;
}
.letter-format-a4 .body-content .poa-principals-table .poa-sign-cell {
  min-height: 0;
  padding-top: 0.7mm !important;
  padding-bottom: 0.7mm !important;
}
.letter-format-a4 .body-content .data-table,
.letter-format-a4 .body-content .letter-table,
.letter-format-a4 .body-content .poa-principals-table {
  table-layout: fixed;
}

/* تظليل يدوي من شريط الجدول — يُطبع فعلياً */
.letter-format-a4 .body-content table.tbl-shaded td,
.letter-format-a4 .body-content table.tbl-shaded th,
.letter-format-a4 .body-content table tr.tbl-row-shaded > td,
.letter-format-a4 .body-content table tr.tbl-row-shaded > th,
.letter-format-a4 .body-content table td.tbl-cell-shaded,
.letter-format-a4 .body-content table th.tbl-cell-shaded {
  background: #e8e8e8 !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* ---------- أشكال هندسية عائمة (مثل Word) — رسم عبر SVG للطباعة ---------- */
.letter-format-a4 .letter-shape {
  position: absolute !important;
  z-index: 20;
  box-sizing: border-box !important;
  margin: 0 !important;
  padding: 0 !important;
  border: none !important;
  line-height: 0 !important;
  font-size: 0 !important;
  user-select: none;
  -webkit-user-select: none;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto;
  overflow: visible !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .letter-shape .letter-shape-fill {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
  line-height: 0 !important;
  visibility: visible !important;
  opacity: 1 !important;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
/* أشكال قديمة بدون SVG: حدود CSS */
.letter-format-a4 .letter-shape .letter-shape-fill:not(.letter-shape-fill--svg) {
  border: 1.2pt solid #000;
  background: rgba(255, 255, 255, 0.01);
  box-shadow: inset 0 0 0 1.2pt #000;
}
.letter-format-a4 .letter-shape--round .letter-shape-fill:not(.letter-shape-fill--svg) {
  border-radius: 3mm;
}
.letter-format-a4 .letter-shape--ellipse .letter-shape-fill:not(.letter-shape-fill--svg) {
  border-radius: 50%;
}
.letter-format-a4 .letter-shape--line .letter-shape-fill:not(.letter-shape-fill--svg) {
  height: 0 !important;
  top: 50% !important;
  bottom: auto !important;
  border: none !important;
  border-top: 1.5pt solid #000 !important;
  background: none !important;
  box-shadow: none !important;
}
/* أشكال SVG (الافتراضي الجديد) */
.letter-format-a4 .letter-shape .letter-shape-fill--svg {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
}
.letter-format-a4 .letter-shape .letter-shape-fill svg {
  display: block !important;
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
}
.letter-format-a4 .letter-shape--line {
  min-height: 2mm !important;
  padding: 0;
  border: none;
  background: transparent;
}
.letter-format-a4 .letter-shape-handles {
  display: none !important;
}

@media print {
  .letter-format-a4 {
    overflow: visible !important;
  }
  .letter-format-a4 .letter-shape,
  .letter-format-a4 .letter-shape .letter-shape-fill,
  .letter-format-a4 .letter-shape .letter-shape-fill svg {
    visibility: visible !important;
    opacity: 1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .letter-format-a4 .letter-shape-handles {
    display: none !important;
  }
}

.letter-format-a4 .body-content b,
.letter-format-a4 .body-content strong { font-weight: bold; }
.letter-format-a4 .body-content i,
.letter-format-a4 .body-content em { font-style: italic; }

/* ---------- تسطير متصل في كل الخطابات (معاينة + طباعة) ----------
   text-decoration الافتراضي يتقطع عند الحروف النازلة العربية.
   نستخدم border-bottom على u / .letter-u ليكون الخط متصلاً كالوورد.
   محددات style دقيقة فقط (لا [style*="underline"] العام الذي كان يمنع الإلغاء). */
.letter-format-a4 {
  text-decoration-skip-ink: none;
  -webkit-text-decoration-skip: none;
}
.letter-format-a4 u,
.letter-format-a4 .body-content u,
.letter-format-a4 .letter-u {
  text-decoration: none !important;
  border-bottom: 0.07em solid currentColor;
  padding-bottom: 0.03em;
  /* يمنع انهيار الحدود على أسطر متعددة بشكل متقطّع */
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
/* تسطير عبر style مضمّن من المحرر (عند styleWithCSS) — اجعله متصلاً أيضاً
   ولاصقاً بالنص كالوورد (offset صغير يكفي فقط لتخطّي الحروف النازلة) */
.letter-format-a4 [style*="text-decoration: underline"],
.letter-format-a4 [style*="text-decoration:underline"],
.letter-format-a4 [style*="text-decoration-line: underline"],
.letter-format-a4 [style*="text-decoration-line:underline"] {
  text-decoration-line: underline !important;
  text-decoration-thickness: 0.07em !important;
  text-decoration-skip-ink: none !important;
  text-underline-offset: 0.08em !important;
  text-decoration-color: currentColor !important;
  -webkit-text-decoration-skip: none !important;
}
/* السماح بإلغاء التسطير صراحةً */
.letter-format-a4 [style*="text-decoration: none"],
.letter-format-a4 [style*="text-decoration:none"],
.letter-format-a4 [style*="text-decoration-line: none"],
.letter-format-a4 [style*="text-decoration-line:none"] {
  text-decoration: none !important;
  text-decoration-line: none !important;
  border-bottom: none !important;
}
/* الخانات المرتبطة داخل النص */
.letter-format-a4 .field-slot { font-weight: bold; }
.letter-format-a4 .field-slot.empty {
  display: inline-block;
  min-width: 90px;
  border-bottom: 1px dotted #000;
  min-height: 1em;
  vertical-align: bottom;
}

/* التوقيع */
.letter-format-a4 .signature {
  margin: var(--sign-gap-top) 15mm 0 auto;
  text-align: center;
  float: left;
  width: fit-content;
  clear: both;
}
.letter-format-a4 .signature p { margin: 3px 0; text-align: center; }
.letter-format-a4 .signature-name { font-weight: bold; font-size: 18pt; }
.letter-format-a4 .signature-title { font-weight: bold; font-size: 15pt; }

/* ---------- الباركود (QR: الاسم ورقم الجواز والرقم المتسلسل) ---------- */
.letter-format-a4 .letter-barcode {
  position: absolute;
  bottom: 30mm;
  right: 16mm;
  z-index: 10;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5mm;
}
/* الرمز القصير المطبوع تحت الباركود — للإدخال اليدوي عند تعذّر مسح الباركود */
.letter-format-a4 .letter-barcode .verify-short-code {
  font-size: 8pt;
  font-weight: bold;
  color: #000;
  white-space: nowrap;
}
.letter-format-a4 .letter-barcode .verify-short-code span {
  font-family: 'Courier New', Courier, monospace;
  letter-spacing: 1px;
  unicode-bidi: embed;
}
.letter-format-a4 .letter-barcode .verify-short-code:empty { display: none; }
.letter-format-a4 .letter-barcode .barcode-img {
  width: var(--barcode-size, 24mm);
  height: var(--barcode-size, 24mm);
  display: block;
  background: #fff;
  padding: 0;
  border: none;
  box-sizing: content-box;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* ---------- علامة المستخدم المخفية (تدقيق داخلي) ----------
   نص رمادي دقيق جداً أسفل يسار الهامش — يُطبع على الورقة فعلياً
   لكن يصعب ملاحظته إلا عند التدقيق القريب. */
.letter-format-a4 .letter-issuer-mark {
  position: absolute;
  left: 4mm;
  bottom: 3mm;
  z-index: 2;
  max-width: 55mm;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1;
  white-space: nowrap;
  font-family: 'Courier New', Consolas, monospace;
  font-size: 5pt;
  font-weight: normal;
  letter-spacing: 0.2pt;
  color: #c8c8c8 !important;
  opacity: 1;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}
.letter-format-a4 .letter-issuer-mark-text {
  color: inherit !important;
}
/* تبقى مطبوعة حتى مع ترويسة خارجية (الترويسة/الفوتر فقط يُخفيان) */
.letter-format-a4.external-letterhead .letter-issuer-mark {
  visibility: visible !important;
}

/* ---------- الفوتر ---------- */
.letter-format-a4 .letter-footer {
  position: absolute;
  bottom: 10mm;
  left: 0;
  right: 0;
  width: 100%;
  text-align: center;
  padding: 0 16mm;
  box-sizing: border-box;
  font-family: 'Sakkal Majalla', 'Traditional Arabic', 'Amiri', serif;
}
.letter-format-a4 .footer-line {
  border-top: 4px double #000;
  width: 100%;
  margin-bottom: 4px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.footer-content { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.footer-text-ar {
  margin: 0;
  font-size: 11pt;
  font-family: 'Sakkal Majalla', 'Traditional Arabic', serif;
  font-weight: bold;
  color: #000;
  display: block;
  text-align: center;
  width: 100%;
  white-space: nowrap;
}
.footer-text-en {
  margin: 0;
  font-size: 9.5pt;
  font-family: 'Times New Roman', serif;
  font-weight: bold;
  color: #000;
  display: block;
  text-align: center;
  width: 100%;
  direction: ltr;
  white-space: nowrap;
}
.icon-contact {
  color: #b45f06 !important;
  font-family: sans-serif;
  font-size: 1.2em;
  margin: 0 2px;
  vertical-align: middle;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.num-span { unicode-bidi: embed; direction: ltr; }

/* ---------- طباعة بترويسة خارجية ----------
   تُخفى الترويسة والفوتر مع الإبقاء على حيّزهما فارغاً (للطباعة على ورق
   يحمل ترويسة مطبوعة مسبقاً)، فيبقى المحتوى في مكانه تماماً كما يظهر. */
.letter-format-a4.external-letterhead .header-container,
.letter-format-a4.external-letterhead .letter-footer {
  visibility: hidden !important;
}

/* ---------- الطباعة ---------- */
body { margin: 0; padding: 0; }
.print-page-wrapper {
  width: 210mm;
  margin: 0 auto;
  page-break-after: always;
}

@media print {
  @page { size: A4; margin: 0 !important; }
  html, body { margin: 0 !important; padding: 0 !important; width: 210mm !important; }
  .letter-format-a4 {
    box-shadow: none !important;
    margin: 0 !important;
    width: 210mm !important;
    min-height: 297mm !important;
    overflow: visible !important;
  }
}
