/* ========= القواعد العامة ========= */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  /* font-family: 'Amiri','Tajawal',serif; */
  background: #698163;
  padding: 20px;
  direction: rtl;
  min-height: 100vh;
}
/* تضمين الخطوط المحلية باستخدام @font-face */

/* ========== ITF Qomra Arabic (محلي) ========== */
@font-face {
  font-family: 'ITF Qomra Arabic';
  src: url('../fonts/itfQomraArabic-Light.otf') format('opentype');
  font-weight: 300;       /* Light */
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'ITF Qomra Arabic';
  src: url('../fonts/itfQomraArabic-Regular.otf') format('opentype');
  font-weight: 400;       /* Regular */
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'ITF Qomra Arabic';
  src: url('../fonts/itfQomraArabic-Medium.otf') format('opentype');
  font-weight: 600;       /* Medium (يمكنك جعله 500 إن أردت أخف) */
  font-style: normal;
  font-display: swap;
}

/* متغيرات لتبديل الخط بسهولة */
:root{
  --font-base: 'ITF Qomra Arabic', 'Tajawal', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  --font-heading: 'ITF Qomra Arabic', 'Tajawal', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
}

/* تطبيق الخط */
html, body {
  font-family: var(--font-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* العناوين والهيدر والجداول */
.main-title,
.sarh,
.items-table th,
.approval-table th {
  font-family: var(--font-heading);
  font-weight: 600; /* يستخدم Medium */
}

/* النص العام */
body, td, th, input, select, textarea, button {
  font-weight: 400; /* Regular افتراضيًا */
}

/* عناصر خفيفة الوزن (اختياري) */
.muted, .info-label {
  font-weight: 300; /* Light */
}

/* التأكد من استخدام الخط في الطباعة أيضًا */
@media print {
  html, body, td, th, input, select, textarea, button, .main-title, .sarh {
    font-family: 'ITF Qomra Arabic', Arial, sans-serif !important;
  }
}



.document-container {
  max-width: 900px;
  margin: 0 auto;
  background: #fff;
  padding: 30px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
  border-radius: 10px;
  position: relative;
}

.sarh {
  text-align: right;
  font-size: 24px;
  font-weight: bold;
  color: #698163;
}

.main-title {
  text-align: center;
  font-size: 32px;
  font-weight: bold;
  color: #000;
  margin-bottom: 30px;
  padding: 15px;
  border-bottom: 3px solid #698163;
}

/* ========= رأس الصفحة ========= */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 25px;
}

.supplier-info, .company-info {
  width: 50%;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  color: #000;
  margin-bottom: 10px;
  border-bottom: 2px solid #698163;
  padding-bottom: 5px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  margin-bottom: 8px;
}

.info-label {
  width: 120px;
  color: #000;
  font-weight: 600;
}

.info-value { flex: 1; color: #000; }

/* فقط مدخلات رأس الصفحة (لا تلمس الجدول/الموافقات) */
.header .info-input,
.header .currency-select {
  flex: 1;
  border: none;
  border-bottom: 2px solid #698163;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  padding: 5px 0;
  color: #000;
  transition: border-color .3s;
}
.header .info-input:focus,
.header .currency-select:focus { outline: none; border-bottom-color: #000; }

/* ========= جدول الأصناف ========= */
.table-section { margin: 30px 0; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  border: 2px solid #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}

.items-table th {
  background: #698163;
  color: #fff;
  border: 1px solid #000;
  padding: 8px 6px;           /* تقليل ارتفاع رأس الجدول */
  text-align: center;
  font-size: 13px;           /* تصغير حجم خط العناوين */
  font-weight: bold;
}

.items-table td {
  border: 1px solid #000;
  padding: 3px 5px;              /* صفوف أنحف لجدول أقل ارتفاعاً */
  text-align: center;
  font-size: 12px;              /* تصغير خط محتوى الجدول */
  background: #fff;
  color: #000;
}

/* مدخلات الجدول: بلا حدود */
.items-table input {
  width: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-family: inherit;
  font-size: 13px;
  padding: 4px;
  color: #000;
}
.items-table input:focus { outline: 2px solid #698163; border-radius: 4px; }

/* حقول النص داخل جدول الأصناف: ارتفاع ديناميكي حسب النص */
.items-table textarea {
  width: 100%;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.3;
  padding: 2px 4px;
  resize: vertical;          /* يمكن تكبيرها يدوياً عند الحاجة */
  height: auto;              /* الارتفاع يعتمد على النص */
  min-height: 32px;          /* حد أدنى معقول لكل صف */
  box-sizing: border-box;
}

/* سطر المجموع الكلي – شاشة */
.items-table tfoot .total-row td,
.total-row td {
  background-color: #fff3cd !important; /* أصفر باهت */
  color: #333 !important;
  font-weight: 700;
}

/* ========= أزرار ========= */
.add-row-btn {
  background: #698163;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  margin: 10px 0;
  transition: background .3s;
}
.add-row-btn:hover { background: #000; }

.print-btn {
  background: #000;
  color: #fff;
  border: none;
  padding: 12px 25px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 16px;
  margin-top: 20px;
  transition: background .3s;
}
.print-btn:hover { background: #698163; }

/* ========= ملاحظات/تواقيع ========= */
.footer-section {
  margin-top: 30px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.signature-box {
  width: 200px;
  height: 80px;
  border: 2px dashed #698163;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #000; font-size: 14px; text-align: center;
}

.notes-section { flex: 1; margin-left: 20px; }
.notes-textarea {
  width: 100%; height: 80px;
  border: 2px solid #698163; border-radius: 8px;
  padding: 10px; font-family: inherit; font-size: 14px; resize: vertical; color: #000;
}
.notes-textarea:focus { outline: none; border-color: #000; }

/* صندوق الملاحظات الإضافية (شاشة) */
.additional-notes-section {
  border: 2px solid #698163;
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

#additionalNotes {
  width: 100%;
  min-height: 80px;
  border: 1px solid #698163;
  border-radius: 6px;
  padding: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  color: #000;
}
#additionalNotes:focus { outline: none; border-color: #000; }

/* ========= الموافقات ========= */
.approval-section { margin-top: 30px; }

.approval-table {
  width: 100%; border-collapse: collapse;
  border: 2px solid #000; border-radius: 8px;
  overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,.1);
  margin-bottom: 20px;
}

.approval-table th {
  background: #698163; color: #fff;
  border: 1px solid #000;
  padding: 12px 8px; text-align: center; font-size: 13px; font-weight: bold;
}

.approval-table td {
  border: 1px solid #000;
  padding: 8px; text-align: center; font-size: 13px; background: #fff; height: 45px; color: #000;
}

.approval-label { background: #f8f9fa !important; font-weight: bold; color: #000; }

.approval-input {
  width: 100%;
  border: none;                 /* لا حدود هنا */
  background: transparent;
  text-align: center;
  font-family: inherit; font-size: 12px; padding: 4px; color: #000;
}
.approval-input:focus { outline: 2px solid #698163; border-radius: 4px; }

.signature-cell {
  height: 60px; background: #f8f9fa; border: 2px dashed #698163; position: relative;
}
.signature-cell::after {
  content: "";
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  color: #698163; font-size: 11px;
}

/* ========= روابط الأزرار (بدون خط) ========= */
.nav-btn { text-decoration: none; display: inline-block; }
.nav-btn:link, .nav-btn:visited, .nav-btn:hover, .nav-btn:active, .nav-btn:focus {
  text-decoration: none; color: #fff; outline: none;
}

/* ========= إعدادات الصفحة للطباعة ========= */
/* نضبط فقط حجم الصفحة والهامش، ونترك الباقي للتنسيق الافتراضي مع تصغير بسيط للأحجام */
@page {
  size: A4 portrait;
  margin: 5mm;        /* تقليل الهامش لاستغلال ارتفاع الصفحة أكثر */
}

@media print {
  html, body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-size: 10px;   /* خط صغير ليتحمل عدد بنود أكبر */
    line-height: 1.2;  /* تباعد بسيط بين الأسطر */
  }

  /* إخفاء زر/رابط العودة فقط */
  .back-to-main,
  .back-btn,
  .return-btn,
  a[href="index.html"] {
    display: none;
  }

  /* إزالة الظلال والإطارات القوية في الطباعة */
  .document-container {
    max-width: 100%;
    box-shadow: none;
    border-radius: 0;
  }

  /* الجداول بخط أصغر وعرض كامل */
  table {
    width: 100%;
    font-size: 9px;     /* خط الجداول يبقى صغيراً ليتحمّل عدداً أكبر من الصفوف */
  }

  th,
  td {
    padding: 2px 3px;   /* تقليل الهوامش داخل الخلايا */
  }

  /* تصغير عنوان النموذج قليلاً في الطباعة */
  .main-title {
    font-size: 18px;
    margin: 8px 0;
  }
}

/* (اختياري) إبقاء سهم select في الشاشة */
@media screen {
  select { -webkit-appearance: auto; appearance: auto; }
}
/* ===== إصلاح تسرّب الحدود في بطاقة المورّد/الشركة عند الطباعة + جعل الأصناف أقل طولاً ===== */
@media print {
  /* حافة داخلية خفيفة للحاوية مع إلغاء الـ flex حتى لا يُجبر الجدول أن يملأ ارتفاع الصفحة */
  .document-container {
    padding: 4mm !important;
    border-radius: 0 !important;
    min-height: auto !important;
    display: block !important;
  }

  /* جدول الأصناف يأخذ ارتفاعه الطبيعي فقط */
  .table-section {
    display: block !important;
  }

  .items-table,
  .items-table tbody,
  .items-table tr {
    height: auto !important;
  }

  /* حقول النص داخل جدول الأصناف في الطباعة: نجعل الصف أطول قليلاً ليرتفع الجدول */
  .items-table textarea {
    height: auto !important;
    min-height: 26px !important;   /* زيادة ارتفاع كل صنف */
    line-height: 1.2 !important;
    font-size: 10px !important;    /* تكبير النص داخل تفاصيل الصنف */
  }

  /* صف الرأس: لا تسمح بالتكسّر الغريب */
  .header {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    gap: 12px !important;
    page-break-inside: avoid !important;
  }

  /* البطاقتان بداخل الرأس: مقاس دقيق يأخذ الـ gap بالاعتبار */
  .supplier-info,
  .company-info {
    width: calc(50% - 6px) !important;
    border: 1px solid #000 !important;
    background: #fff !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    page-break-inside: avoid !important;
  }

  /* منع تمدّد المحتوى داخل البطاقات */
  .supplier-info *,
  .company-info * {
    max-width: 100% !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  /* صفوف الحقول لا تلتف بطريقة تسبب دفع الحدود */
  .info-row {
    flex-wrap: nowrap !important;
  }

  /* اجعل الليبل ثابت العرض والمدخل يتمدّد بأمان */
  .info-label {
    width: 110px !important;
    flex: 0 0 auto !important;
  }
  .header .info-input,
  .header .currency-select {
    min-width: 0 !important;
  }
  
  /* منع تقسيم العناصر عبر الصفحات قدر الإمكان */
  .document-container {
    page-break-inside: avoid !important;
  }
  
  .header {
    page-break-inside: avoid !important;
    page-break-after: avoid !important;
  }
  
  .items-table {
    page-break-inside: auto !important;
  }
  
  .items-table tr {
    page-break-inside: avoid !important;
    page-break-after: auto !important;
  }
  
  .items-table thead {
    display: table-header-group !important;
  }
  
  .approval-section {
    page-break-inside: avoid !important;
    page-break-before: auto !important;
  }
  
  .approval-table {
    page-break-inside: avoid !important;
  }
}

textarea {
    width: 100%;
    height: 80px;
    padding: 5px;
    font-family: inherit;
    font-size: 13px;
    border: none;
    border-radius: 8px;
    resize: vertical;
    color: #000;
}

textarea:focus {
    outline: none;
    border-color: #000;
}
