/* ============================================================
   الهوية البصرية الرسمية للوثائق (خطابات / تقارير / محاضر / تعاميم)
   وزارة التعليم — نظام المدارس المتكاملة
   يُستخدم داخل التطبيق (معاينة) وفي نافذة الطباعة و PDF.
   ============================================================ */

:root,
.doc-root {
  --moe-green: #4a2c81;
  --moe-green-dark: #3c2469;
  --moe-green-soft: #f2effa;
  --moe-gold: #7355a3;
  --doc-ink: #292233;
  --doc-muted: #6c6376;
  --doc-line: #ddd8e4;
  --doc-page: #ffffff;
}

/* ---------- الصفحة A4 ---------- */
.doc-root {
  direction: rtl;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color: var(--doc-ink);
  background: #f2effa;
  margin: 0;
  padding: 0;
  font-size: 13.5px;
  line-height: 1.9;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.doc-page {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  margin: 12mm auto;
  padding: 16mm 18mm 24mm;
  background: var(--doc-page);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  box-sizing: border-box;
  page-break-after: always;
  break-after: page;
  display: flex;
  flex-direction: column;
}
.doc-page:last-child {
  page-break-after: auto;
  break-after: auto;
}
.doc-page.landscape {
  width: 297mm;
  min-height: 210mm;
}

/* ---------- الرأس الموحّد ---------- */
.doc-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 2.5px solid var(--moe-green);
  break-inside: avoid;
}
.doc-head .side {
  font-size: 12px;
  line-height: 1.7;
  color: var(--doc-ink);
}
.doc-head .side.left {
  text-align: left;
  color: var(--doc-muted);
  direction: ltr;
  font-family: "Segoe UI", sans-serif;
}
.doc-head .side strong {
  display: block;
  font-weight: 700;
}
.doc-head .crest img {
  width: 118px;
  height: auto;
  max-height: 90px;
  object-fit: contain;
}
.doc-head-rule {
  height: 3px;
  margin-top: 3px;
  background: linear-gradient(90deg, var(--moe-gold), var(--moe-green) 45%, var(--moe-green-dark));
  border-radius: 2px;
}

/* ---------- بيانات الخطاب ---------- */
.doc-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 16px;
  margin: 14px 0 6px;
  font-size: 12.5px;
  break-inside: avoid;
}
.doc-meta .cell {
  display: flex;
  gap: 6px;
  border: 1px solid var(--doc-line);
  border-radius: 6px;
  padding: 6px 10px;
  background: #faf8fd;
}
.doc-meta .cell b {
  color: var(--moe-green-dark);
  font-weight: 700;
  white-space: nowrap;
}

.doc-subject {
  margin: 16px 0 10px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--moe-green-dark);
  border: 1.5px solid var(--moe-green);
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--moe-green-soft);
  break-inside: avoid;
}

.doc-body {
  flex: 1;
  text-align: justify;
  font-size: 14px;
  line-height: 2.1;
}
.doc-body p {
  margin: 0 0 10px;
  text-indent: 12mm;
}
.doc-body p.plain {
  text-indent: 0;
}
.doc-salutation {
  font-weight: 700;
  margin: 4px 0 12px;
}
.doc-closing {
  margin-top: 14px;
  font-weight: 600;
}

/* ---------- العناوين ---------- */
.doc-h1 {
  font-size: 20px;
  color: var(--moe-green-dark);
  margin: 18px 0 8px;
  padding-inline-start: 10px;
  border-inline-start: 5px solid var(--moe-gold);
  break-after: avoid;
}
.doc-h2 {
  font-size: 15.5px;
  color: var(--moe-green-dark);
  margin: 14px 0 6px;
  break-after: avoid;
}
.doc-note {
  font-size: 12px;
  color: var(--doc-muted);
}

/* ---------- الجداول ---------- */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 14px;
  font-size: 12.5px;
  break-inside: avoid;
}
.doc-table thead th {
  background: var(--moe-green);
  color: #fff;
  font-weight: 600;
  padding: 8px 9px;
  border: 1px solid var(--moe-green-dark);
  text-align: right;
}
.doc-table tbody td {
  border: 1px solid var(--doc-line);
  padding: 7px 9px;
  vertical-align: top;
  text-align: right;
  white-space: pre-wrap;
}
.doc-table tbody tr:nth-child(even) td {
  background: #f7f4fb;
}
.doc-table .label {
  width: 34%;
  background: var(--moe-green-soft) !important;
  font-weight: 600;
  color: var(--moe-green-dark);
}
.doc-table tr {
  break-inside: avoid;
}

/* ---------- المؤشرات ---------- */
.doc-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0 14px;
  break-inside: avoid;
}
.doc-kpi {
  border: 1px solid var(--doc-line);
  border-top: 3px solid var(--moe-green);
  border-radius: 8px;
  padding: 8px 10px;
  background: #faf8fd;
  text-align: center;
}
.doc-kpi .k-label {
  font-size: 11.5px;
  color: var(--doc-muted);
}
.doc-kpi .k-value {
  font-size: 19px;
  font-weight: 700;
  color: var(--moe-green-dark);
}
.doc-bar {
  height: 8px;
  border-radius: 999px;
  background: #e7e0f2;
  overflow: hidden;
}
.doc-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--moe-green), #7355a3);
}

/* ---------- التوقيع والختم ---------- */
.doc-sign {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  break-inside: avoid;
  page-break-inside: avoid;
}
.doc-sign .box {
  border: 1px solid var(--doc-line);
  border-radius: 10px;
  padding: 10px 14px 16px;
  text-align: center;
  background: #fff;
}
.doc-sign .role {
  font-size: 12px;
  color: var(--doc-muted);
}
.doc-sign .name {
  font-weight: 700;
  margin: 4px 0 26px;
}
.doc-sign .line {
  border-top: 1px dashed var(--doc-line);
  padding-top: 6px;
  font-size: 11.5px;
  color: var(--doc-muted);
}
.doc-stamp {
  margin: 14px auto 0;
  width: 116px;
  height: 116px;
  border: 2.5px double var(--moe-green);
  border-radius: 50%;
  color: var(--moe-green);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.5;
  opacity: 0.85;
  break-inside: avoid;
}
.doc-stamp b {
  font-size: 12px;
}

/* ---------- المرفقات / النسخ / المراجع ---------- */
.doc-extras {
  margin-top: 16px;
  font-size: 12px;
  color: var(--doc-ink);
  break-inside: avoid;
}
.doc-extras .row {
  margin-bottom: 4px;
}
.doc-extras b {
  color: var(--moe-green-dark);
}

/* ---------- التذييل وترقيم الصفحات ---------- */
.doc-foot {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1.5px solid var(--moe-green);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 10.5px;
  color: var(--doc-muted);
  break-inside: avoid;
}
.doc-foot .page-no b {
  color: var(--moe-green-dark);
}

/* ---------- صفحة الغلاف ---------- */
.doc-cover {
  text-align: center;
  justify-content: center;
  gap: 6px;
}
.doc-cover .logos {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}
.doc-cover .logos img {
  width: 170px;
  height: auto;
  max-height: 130px;
  object-fit: contain;
}
.doc-cover .ministry {
  font-size: 16px;
  font-weight: 700;
  color: var(--moe-green-dark);
}
.doc-cover .admin {
  font-size: 13px;
  color: var(--doc-muted);
}
.doc-cover .title {
  margin: 28px auto 10px;
  font-size: 30px;
  font-weight: 700;
  color: var(--moe-green-dark);
  max-width: 150mm;
  line-height: 1.6;
}
.doc-cover .divider {
  width: 70mm;
  height: 3px;
  margin: 6px auto 18px;
  background: linear-gradient(90deg, transparent, var(--moe-gold), transparent);
}
.doc-cover .period {
  font-size: 15px;
  font-weight: 600;
}
.doc-cover .cover-meta {
  margin: 26px auto 0;
  width: 130mm;
  border: 1px solid var(--doc-line);
  border-radius: 10px;
  overflow: hidden;
}
.doc-cover .cover-meta div {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 12.5px;
  border-bottom: 1px solid var(--doc-line);
}
.doc-cover .cover-meta div:last-child {
  border-bottom: 0;
}
.doc-cover .cover-meta b {
  color: var(--moe-green-dark);
}

/* ---------- الفهرس ---------- */
.doc-toc li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px dotted var(--doc-line);
  font-size: 13px;
}
.doc-toc {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
}
.doc-toc .dots {
  flex: 1;
  border-bottom: 1px dotted var(--doc-line);
  transform: translateY(-4px);
}
.doc-toc .pg {
  font-weight: 700;
  color: var(--moe-green-dark);
}

/* ---------- رمز التحقق ---------- */
.doc-verify {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--doc-muted);
}
.doc-verify .qr {
  width: 46px;
  height: 46px;
  display: block;
  border: 1px solid var(--doc-line);
  background: #fff;
}

/* ---------- شريط أدوات المعاينة (لا يُطبع) ---------- */
.doc-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  padding: 10px;
  background: #2f1c52;
  color: #fff;
  font-size: 13px;
}
.doc-toolbar button {
  font: inherit;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: var(--moe-green);
  color: #fff;
  cursor: pointer;
}
.doc-toolbar button.ghost {
  background: transparent;
}

/* ---------- الاستجابة للشاشات الصغيرة ---------- */
@media screen and (max-width: 820px) {
  .doc-page {
    width: auto;
    min-height: 0;
    margin: 8px;
    padding: 14px;
  }
  .doc-meta,
  .doc-kpis {
    grid-template-columns: 1fr 1fr;
  }
  .doc-sign {
    grid-template-columns: 1fr;
  }
  .doc-cover .title {
    font-size: 22px;
  }
}

/* ---------- الطباعة ---------- */
@page {
  size: A4 portrait;
  margin: 12mm;
}
@page landscape {
  size: A4 landscape;
}
@media print {
  .doc-root {
    background: #fff;
  }
  .doc-toolbar,
  .no-print {
    display: none !important;
  }
  .doc-page {
    width: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    box-shadow: none;
    border: 0;
  }
  .doc-page.landscape {
    page: landscape;
  }
  .doc-table,
  .doc-sign,
  .doc-stamp,
  .doc-head,
  .doc-kpi,
  .doc-subject,
  .doc-foot {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  thead {
    display: table-header-group;
  }
  tfoot {
    display: table-footer-group;
  }
}
