/* =========================================================
   تصاميم أوراق العقود A4 — مطابقة للنماذج الأصلية
   ========================================================= */

.sheet {
  width: 210mm;
  height: 296mm;
  background: #fff;
  color: #000;
  direction: rtl;
  font-family: 'Simplified Arabic', 'Traditional Arabic', 'Arabic Typesetting', 'Segoe UI', Tahoma, serif;
  font-weight: 700;
  position: relative;
  overflow: hidden;
  padding: 6mm 8mm;
  display: flex;
  flex-direction: column;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.sheet .red { color: #d00000; }
.sheet .blue { color: #1230a0; }

/* القيم المدخلة */
.sheet .val { color: #10125e; font-weight: 800; }
.sheet .val.ltr { direction: ltr; unicode-bidi: embed; letter-spacing: .5px; }
.sheet .val.big { font-size: 1.15em; }
/* رقم السيارة المركب: كل جزء (الرقم، الفئة، رمز المحافظة، الاسم، الصنف) معزول
   باتجاهه الخاص وبفراغ ثابت — فلا تندمج الأرقام ولا تنتقل للجهة الثانية عند الطباعة */
.sheet .plate-val { direction: rtl; unicode-bidi: isolate; }
.sheet .plate-val bdi {
  display: inline-block;
  unicode-bidi: isolate;
  margin-inline: 1.2mm;
}
.sheet .plate-val bdi:first-child { margin-inline-start: 0; }
.sheet .plate-val bdi:last-child { margin-inline-end: 0; }
.sheet .blank { display: inline-block; min-width: 20mm; }

/* أماكن الصور (تُضاف لاحقاً من الإعدادات)
   العرض والارتفاع المكتوبان في الإعدادات = أبعاد الصورة الفعلية بالضبط،
   والعمود ثابت العرض فلا يتحرك النص الأوسط عند تغيير حجم الصورة */
.sheet .ph { margin-left: auto; margin-right: auto; }
.sheet img.ph { display: block; object-fit: fill; max-width: 100%; }
.sheet span.ph { display: flex; align-items: center; justify-content: center; max-width: 100%; }
.sheet .ph-empty {
  border: 1px dashed #9aa5bd;
  border-radius: 2mm;
  background: #f7f9fd;
}
.sheet .ph-empty i {
  font-style: normal;
  font-size: 8pt;
  color: #8a97b8;
  font-family: Tahoma, sans-serif;
  font-weight: 400;
  text-align: center;
  padding: 1mm;
}

/* صندوق الطرفين المشترك */
.parties {
  border: 1.2px solid #333;
  background: #fff;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.parties .party { padding: 3mm 5mm; }
.parties .party:first-child { border-left: 1.2px solid #333; }
.party-title { text-align: center; font-size: 14pt; font-weight: 800; margin-bottom: 1.5mm; }
.pf { font-size: 12.5pt; margin: 0; line-height: 1.55; }

/* صندوق التفاصيل المشترك */
.details { border: 1.2px solid #333; background: #fff; padding: 2mm 5mm; margin-top: 1.5mm; }
.dt-title { color: #d00000; font-size: 16pt; font-weight: 800; margin-bottom: 1.5mm; }
.dl { font-size: 13pt; margin: 0; line-height: 1.5; }
.dl-center { text-align: center; }
.red-line { color: #d00000; font-weight: 800; }

/* صورة الطرف الشخصية فوق توقيعه */
/* صورة شخصية مربعة 1:1 — مطابقة تماماً لما يُلتقط ويُقص في المحرر */
.party-photo {
  width: 20mm;
  height: 20mm;
  display: block;
  margin: 0;
  flex: 0 0 auto;
  object-fit: cover;
  border: 1.5px solid #55617e;
  border-radius: 1.5mm;
  background: #fff;
}
span.party-photo.pp-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #9aa5bd;
  background: #f7f9fd;
}
.pp-empty i {
  font-style: normal;
  font-size: 7.5pt;
  color: #8a97b8;
  font-family: Tahoma, sans-serif;
  font-weight: 400;
  text-align: center;
  padding: 1mm;
}

/* التواقيع المشتركة — مثبتة دائماً في أسفل الورقة ولا تُقص مهما طال المحتوى */
.sig-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 3mm 14mm 1mm;
  margin-top: auto;
  flex-shrink: 0;
  text-align: center;
}
/* الصورة الشخصية بطرف الورقة (يمين للطرف الأول ويسار للثاني) والاسم والصفة بجانبها */
.sig { min-width: 45mm; display: flex; align-items: center; gap: 3mm; }
.sig-row .sig:last-child { flex-direction: row-reverse; }
.sig-txt { flex: 1 1 auto; text-align: center; }
.sig-name { font-size: 14pt; min-height: 8mm; }
.sig-label { font-size: 14pt; font-weight: 800; border-top: 1px solid transparent; }

/* ============ العلامة المائية (خيار عام لكل العقود) ============
   صورة شفافة أمام نص العقد كله — لا تعترض الطباعة (img يُطبع دائماً)
   ولا تمنع التفاعل في المعاينة (pointer-events:none) */
.wm-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  overflow: hidden;
}
.wm-img { max-width: 72%; max-height: 60%; object-fit: contain; }

/* ============ الشهود (خيار عام) — صف تحت التواقيع مباشرة (الصف الثاني) ============ */
.witness-row {
  display: flex;
  flex-shrink: 0;
  padding: 1mm 14mm 1.5mm;
  gap: 8mm;
}
.witness-row .wit { text-align: center; }
.witness-row .wit-name { min-height: 7mm; font-size: 13pt; font-weight: 800; }
.witness-row .wit-name .blank { min-width: 42mm; }
.witness-row .wit-label { font-size: 12pt; font-weight: 800; color: #d00000; }
.wr-full { justify-content: space-between; }        /* على طول الورقة */
.wr-full .wit { flex: 0 0 auto; }
.wr-center { justify-content: center; gap: 45mm; }   /* بالمنتصف */

/* =========================================================
   1) عقد بيع سيارة  (t-car-sale)
   ========================================================= */
.t-car-sale .cs-head { display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 3mm; }
.t-car-sale .cs-h-left {
  width: 62mm;
  flex: 0 0 62mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}
.t-car-sale .cs-car { width: 52mm; height: 34mm; }
.t-car-sale .cs-h-mid { flex: 1; text-align: center; }
/* ألوان عقد بيع السيارة مطابقة للنموذج الأصلي: النصوص والقيم سوداء،
   العناوين الحمراء حمراء، واسم المكتب أزرق */
.t-car-sale .val { color: #000; }
.sheet .val.inh { color: inherit; }
.t-car-sale .cs-office {
  font-family: 'Simplified Arabic', 'Traditional Arabic', Tahoma, serif;
  font-size: 30pt;
  line-height: 1.15;
  color: #1e4fd8;
  font-weight: 900;
  letter-spacing: 1px;
}
.t-car-sale .cs-sub1 { font-size: 15pt; font-weight: 800; }
.t-car-sale .cs-sub2 { font-size: 12pt; font-weight: 800; letter-spacing: 1px; }
.t-car-sale .cs-adr { font-size: 11.5pt; font-weight: 700; }
/* رقم الهاتف: آخر سطر في وسط الترويسة تحت العنوان مباشرة */
.t-car-sale .cs-phones { font-size: 12pt; font-weight: 800; direction: ltr; margin-top: 0.5mm; text-align: center; }
.t-car-sale .cs-h-right {
  width: 52mm;
  flex: 0 0 52mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  overflow: hidden;
}
.t-car-sale .cs-logo { width: 50mm; height: 40mm; margin: 0 auto; }
/* الفاصل الأخضر المزدوج تحت الترويسة — كما في النموذج الأصلي */
.t-car-sale .cs-rule {
  border-top: 2.5px solid #1e9e3e;
  border-bottom: 2.5px solid #1e9e3e;
  height: 1mm;
  margin: 1.5mm 0;
}
.t-car-sale .cs-date-line {
  display: flex;
  justify-content: space-between;
  font-size: 12pt;
  font-weight: 800;
  margin: 1mm 0;
}
.t-car-sale .cs-legal { display: flex; justify-content: space-between; font-size: 13pt; margin: 1.5mm 0 2.5mm; }
/* بيانات الطرفين بمحاذاة النقطتين عموديّاً (جدولي) مثل النموذج الأصلي:
   عمود الوسم يمين + عمود النقطتين ثابت + قيمة يسار — فتصطف النقطتان في خطٍ واحد */
.t-car-sale .cs-parties .party { padding: 2mm 5mm; }
.t-car-sale .cs-parties .pf {
  display: grid;
  grid-template-columns: 25mm 3mm 1fr;
  align-items: baseline;
  font-size: 12.5pt;
  margin: 0;
}
.t-car-sale .cs-parties .party-title { margin-bottom: 1mm; }
.t-car-sale .cs-parties .pl { white-space: nowrap; }
.t-car-sale .cs-parties .pc { text-align: center; }
.t-car-sale .cs-parties .val { padding-inline-start: 1mm; }
/* جسم العقد مرن: يتقلص عند الحاجة فلا تُقص التواقيع والصور الشخصية أبداً */
.t-car-sale .cs-body { margin-top: 1.5mm; flex: 1 1 auto; min-height: 0; overflow: hidden; }
/* المسافة بين الأسطر (السنوية، اللون، ببدل قدره، وقد قبض، والباقي) = صفر */
.t-car-sale .cs-line { font-size: 12.5pt; margin: 0; line-height: 1.5; }
.t-car-sale .cs-center { text-align: center; }
/* سطر رقم السيارة: الأجزاء (الرقم والفئة، المحافظة، الصنف) موزعة على عرض السطر */
.t-car-sale .cs-plate-line { display: flex; align-items: baseline; gap: 2mm; }
.t-car-sale .cs-plate-line .cs-pl-l { white-space: nowrap; }
.t-car-sale .cs-plate-line .plate-val { flex: 1; display: flex; justify-content: space-around; align-items: baseline; }
.t-car-sale .plate-val bdi { margin: 0; }
/* صف السنوية: الوسم يميناً (يلتف سطرين) + الرقم + من نوع + موديل — كما في النموذج */
.t-car-sale .cs-annual { display: grid; grid-template-columns: 21mm 32mm 1.5fr 1fr; align-items: center; column-gap: 2mm; }
.t-car-sale .cs-annual .cs-an-l { line-height: 1.3; }
.t-car-sale .cs-annual > .val { text-align: center; }
/* صف اللون والشاصي والمحرك: ثلاثة أزواج بمواضع ثابتة */
.t-car-sale .cs-veh { display: grid; grid-template-columns: 1.15fr 1.25fr 1fr; column-gap: 2mm; }
/* صفوف المبالغ: الوسم يميناً + عمود الأرقام محاذى + الكتابة يساراً */
.t-car-sale .cs-money { display: grid; grid-template-columns: 52mm 30mm 1fr; align-items: baseline; column-gap: 2.5mm; }
.t-car-sale .cs-money .cs-mo-n { text-align: center; direction: ltr; }
.t-car-sale .cs-agree { color: #d00000; font-size: 12pt; font-weight: 800; margin: 2mm 0 1mm; }
.t-car-sale .cs-cl { font-size: 10pt; font-weight: 700; margin: 1mm 0; line-height: 1.45; text-align: justify; }
.t-car-sale .cs-org { color: #d00000; font-size: 12.5pt; font-weight: 800; display: flex; justify-content: space-between; padding: 0 2mm; margin: 2.2mm 0 1mm; }
.t-car-sale .cs-notes { font-size: 11pt; margin: 1.5mm 0; line-height: 1.5; }
.t-car-sale .cs-sigs { padding: 2mm 14mm 1mm; }

/* =========================================================
   2) عقد بيع دراجة  (t-bike-sale) — أرضية زرقاء فاتحة
   ========================================================= */
.t-bike-sale { background: #d9e2f3; padding: 5mm 7mm; }
.t-bike-sale .bs-head { display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 2mm; margin-bottom: 2mm; }
.bs-h-left { width: 42mm; flex: 0 0 42mm; display: flex; flex-direction: column; gap: 1.5mm; align-items: center; overflow: hidden; }
.bs-light { width: 20mm; height: 27mm; }
.bs-tuk { width: 36mm; height: 24mm; }
.bs-h-right { width: 42mm; flex: 0 0 42mm; display: flex; flex-direction: column; gap: 1.5mm; align-items: center; overflow: hidden; }
.bs-logo { width: 26mm; height: 26mm; }
.bs-moto { width: 37mm; height: 25mm; }
.t-bike-sale .bs-h-mid { flex: 1; text-align: center; padding-top: 2mm; }
.t-bike-sale .bs-office {
  font-size: 34pt;
  line-height: 1.15;
  color: #e00000;
  font-weight: 800;
  letter-spacing: 2px;
}
.t-bike-sale .bs-sub1 { font-size: 14pt; font-weight: 800; color: #1230a0; }
.t-bike-sale .bs-sub2 { font-size: 13pt; font-weight: 800; color: #1230a0; }
.t-bike-sale .bs-phones { font-size: 14pt; font-weight: 800; direction: ltr; text-decoration: underline; }
.t-bike-sale .bs-sub3 { font-size: 12pt; font-weight: 800; }
.t-bike-sale .bs-owner-line {
  display: grid;
  grid-template-columns: 1fr 1fr max-content;
  align-items: baseline;
  gap: 2mm;
  font-size: 14pt;
  font-weight: 800;
  margin: 1mm 1mm 1.5mm;
}
.sheet .bs-no { white-space: nowrap; }
/* «عنوان» يُحاذى فوق بداية عمود المشتري تماماً (منتصف المربع) */
.sheet .bs-owner-adr { justify-self: start; }

/* عقود الدراجات: البيانات المدخلة (أسماء الطرفين وغيرها) بالأزرق */
.t-bike-sale .val, .t-bike-drive .val { color: #1b2fd4; }
.t-bike-sale .bs-parties { border-radius: 1mm; }
.t-bike-sale .bs-details { flex: 0 0 auto; min-height: 0; overflow: hidden; border-radius: 1mm; }
.t-bike-sale .bs-sigs { padding: 3mm 16mm 1mm; }

/* =========================================================
   3) عقد إيجار دراجة — الغرض القيادة فقط  (t-bike-drive)
   ========================================================= */
.t-bike-drive { padding: 5mm 7mm; background: #d9e2f3; }
.t-bike-drive .bd-head { display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 2mm; margin-bottom: 2mm; }
.t-bike-drive .bd-h-mid { flex: 1; text-align: center; padding-top: 1mm; }
.t-bike-drive .bd-office {
  font-size: 26pt;
  line-height: 1.2;
  color: #e00000;
  font-weight: 800;
  letter-spacing: 3px;
}
.t-bike-drive .bd-phones { font-size: 13pt; font-weight: 800; direction: ltr; }
.t-bike-drive .bd-sub1 {
  display: inline-block;
  background: #1f3fae;
  color: #fff;
  font-size: 13pt;
  font-weight: 800;
  padding: .5mm 4mm;
  margin: .5mm 0;
}
.t-bike-drive .bd-sub2 { font-size: 12.5pt; font-weight: 800; color: #1230a0; }
.t-bike-drive .bd-license {
  display: inline-block;
  background: #1f3fae;
  color: #fff;
  font-size: 12pt;
  font-weight: 800;
  padding: .5mm 5mm;
  margin: .5mm 0;
}
.t-bike-drive .bd-adr { font-size: 12pt; font-weight: 800; }
.t-bike-drive .bd-owner-line {
  display: grid;
  grid-template-columns: 1fr 1fr max-content;
  align-items: baseline;
  gap: 2mm;
  font-size: 13.5pt;
  font-weight: 800;
  margin: 1mm 1mm 1.5mm;
}
.t-bike-drive .bd-title {
  text-align: center;
  color: #e00000;
  font-size: 19pt;
  font-weight: 800;
  letter-spacing: 1.5px;
  margin: 1.5mm 0 1mm;
}
.t-bike-drive .bd-details { flex: 0 0 auto; min-height: 0; overflow: hidden; }
.t-bike-drive .bd-sigs { padding: 3mm 16mm 1mm; }

/* =========================================================
   4) عقد إيجار سيارة — الغرض القيادة فقط  (t-car-drive)
   ========================================================= */
.t-car-drive .cd-head,
.t-estate-sale .cd-head,
.t-house-rent .cd-head { display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 3mm; }
.cd-h-left {
  width: 62mm;
  flex: 0 0 62mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}
.cd-car { width: 55mm; height: 36mm; }
.cd-h-mid { flex: 1; text-align: center; }
.cd-office {
  font-family: 'Simplified Arabic', 'Traditional Arabic', Tahoma, serif;
  font-size: 30pt;
  line-height: 1.15;
  color: #d00000;
  font-weight: 900;
  letter-spacing: 1px;
}
.cd-sub1 { font-size: 16pt; font-weight: 800; }
.cd-sub2 { font-size: 12pt; font-weight: 800; letter-spacing: 5px; }
.cd-adr { font-size: 12pt; font-weight: 700; }
.cd-phones { font-size: 13pt; font-weight: 800; direction: ltr; }
.cd-h-right {
  width: 52mm;
  flex: 0 0 52mm;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  overflow: hidden;
}
.cd-logo { width: 50mm; height: 40mm; margin: 0 auto; }
.cd-rule { border-top: 2.5px double #000; margin: 2mm 0 1mm; }
.cd-date-line { text-align: right; color: #d00000; font-size: 13pt; font-weight: 800; margin: 1mm 0; }
.cd-date-line.with-no { display: flex; justify-content: space-between; }
.t-car-drive .cd-legal {
  display: flex;
  justify-content: space-between;
  font-size: 13.5pt;
  margin: 2mm 0 3mm;
}
.cd-parties .pf { font-size: 12.5pt; margin: 0; line-height: 1.6; }
.drive-title {
  text-align: center;
  color: #e00000;
  font-size: 21pt;
  font-weight: 800;
  letter-spacing: 1px;
  margin: 4mm 0 2mm;
}
/* جسم مرن في كل العقود: التواقيع والصور الشخصية لا تُقص أبداً من أسفل الورقة */
.drive-body { padding: 0 1mm; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.drive-body .dl { font-size: 13pt; margin: 0; line-height: 1.5; }
.rent-line { font-size: 14pt !important; }
.t-car-drive .cd-sigs { padding: 3mm 14mm 1mm; }

/* =========================================================
   5) عقد بيع عقار  (t-estate-sale) — بنفس روح التصميم
   ========================================================= */
.t-estate-sale .drive-body .dl { margin: 0; }
.t-estate-sale .cd-sigs { padding: 3mm 14mm 1mm; }

/* =========================================================
   6) عقد إيجار بيت  (t-house-rent) — مطابق للنموذج الأصلي
   الترويسة كعقد إيجار السيارة (صورة يسار + المكتب بالوسط + صورة يمين)،
   والجسم بلا أي نقاط: القيم المُدخلة تُطبع مكان الفراغات مباشرة
   ========================================================= */
.t-house-rent .hr-title {
  text-align: center;
  color: #1230a0;
  font-size: 24pt;
  font-weight: 900;
  letter-spacing: 3px;
  margin: 3mm 0 3mm;
}
.t-house-rent .hr-body {
  padding: 0 2mm;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
/* سطرا الفريقين: العنوان بعرض ثابت ثم النقطتان ثم الاسم — فتتحاذى القيمتان تماماً */
.t-house-rent .hr-party {
  display: flex;
  align-items: baseline;
  font-size: 14pt;
  font-weight: 800;
  line-height: 1.9;
}
.t-house-rent .hr-party .hr-l { flex: 0 0 45mm; }
.t-house-rent .hr-party .hr-c { flex: 0 0 4mm; }
.t-house-rent .hr-party .val { flex: 1 1 auto; }
.t-house-rent .hr-body .dl { font-size: 13pt; line-height: 1.85; margin: 0; }
.t-house-rent .hr-intro { margin-top: 2mm; }
.t-house-rent .hr-sub { padding-right: 8mm; }        /* الأسطر الفرعية مُزاحة قليلاً */
.t-house-rent .hr-sub .hr-mahalla { margin-right: 18mm; }
.t-house-rent .hr-para { text-align: justify; margin-top: 1.5mm; }
.t-house-rent .hr-org {
  color: #1230a0;
  font-size: 13pt;
  font-weight: 800;
  margin-top: 3mm;
}
.t-house-rent .hr-notes {
  font-size: 12pt;
  font-weight: 400;
  margin-top: 2mm;
  line-height: 1.7;
}
.t-house-rent .hr-notes .blank { min-width: 120mm; }
/* التواقيع: المستأجر | الشاهد | الشاهد | المؤجر — أربعة أعمدة متساوية على عرض الورقة */
.t-house-rent .hr-sigs { padding: 4mm 6mm 1mm; }
.t-house-rent .hr-sigs .sig {
  min-width: 0;
  flex: 1 1 0;
  justify-content: center;
}
.t-house-rent .sig-name { font-size: 13pt; min-height: 8mm; }
.t-house-rent .sig-label { font-size: 13pt; font-weight: 800; color: #1230a0; }

/* ============ الطباعة ============ */
@media print {
  /* قطع الصفحة بين الأوراق المتعددة فقط — الورقة الأخيرة بلا قطع فلا تظهر أوراق فارغة */
  .sheet { page-break-after: always; page-break-inside: avoid; }
  .sheet:last-child { page-break-after: auto; }
  .sheet .ph-empty { border: none !important; background: transparent !important; }
  .sheet .ph-empty i { visibility: hidden; }
  .sheet .pp-empty { border: none !important; background: transparent !important; }
  .sheet .pp-empty i { visibility: hidden; }
}
