/* تخطيط النماذج بنفس تصميم ملفات Word، للتعبئة على الشاشة والطباعة/PDF */

.doc {
  --ink: #102B4E;
  --line: #B9DDD0;
  --bar: #087F62;
  --bar-ink: #FFFFFF;
  --soft: #DFF5ED;
  --label: #006A52;
  --th: #087F62;
  --year: #006A52;
  background: #FFFFFF;
  color: var(--ink);
  border: 1px solid var(--moe-color-border-subtle);
  border-radius: var(--moe-radius-card);
  padding: var(--moe-space-5);
  font-family: var(--moe-font-family);
  font-size: 15px;
  line-height: 1.6;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.doc.theme-blue {
  --ink: #1F2D3A;
  --line: #BBD7EA;
  --bar: #0B4F7E;
  --soft: #D3E6F7;
  --label: #0B3F6E;
  --th: #0A89A6;
  --year: #0B4F7E;
}

/* ---------- الترويسة ---------- */
.doc-head { display: grid; grid-template-columns: 1fr 2.2fr 1fr; border: 1px solid var(--line); margin-block-end: var(--moe-space-3); }
.doc-head__org { padding: var(--moe-space-3); text-align: center; font-size: 14px; display: flex; flex-direction: column; justify-content: center; }
.doc-head__title { border-inline: 1px solid var(--line); display: flex; flex-direction: column; text-align: center; }
.doc-head__title h1 { font-size: 18px; color: var(--label); margin: 0; padding: var(--moe-space-4) var(--moe-space-3); font-weight: 700; flex: 1; display: grid; place-items: center; }
.doc-head__sub { color: var(--label); font-size: 15px; padding-inline: var(--moe-space-3); }
.doc-head__sub:last-of-type { padding-block-end: var(--moe-space-2); }
.doc-head__year { margin-block-start: auto; background: var(--year); color: #FFFFFF; padding: var(--moe-space-3); font-size: 15px; font-weight: 700; }
.doc-head__logo { display: grid; place-items: center; padding: var(--moe-space-2) var(--moe-space-3); }
.doc-head__logo img { inline-size: 130px; block-size: auto; }

.theme-blue .doc-head { border: 0; grid-template-columns: 1fr 2fr 1fr; }
.theme-blue .doc-head__org { text-align: start; justify-content: flex-start; font-size: 13px; }
.theme-blue .doc-head__title { background: #D6EEF5; border: 0; justify-content: center; padding: var(--moe-space-3); }
.theme-blue .doc-head__title h1 { font-weight: 700; font-size: 19px; color: var(--ink); padding: 0; }
.theme-blue .doc-head__sub--1 { font-weight: 700; font-size: 16px; color: var(--ink); }
.theme-blue .doc-head__sub--2 { font-weight: 700; color: var(--th); font-size: 16px; }

/* ---------- عناوين الأقسام ---------- */
.doc-sec { margin-block-end: var(--moe-space-3); break-inside: auto; }
.doc-bar { display: flex; align-items: stretch; margin: 0 0 2px; font-size: 16px; font-weight: 700; color: var(--bar-ink); border: 1px solid var(--line); break-after: avoid; }
.doc-bar__title { order: 1; flex: 1; background: var(--bar); padding: var(--moe-space-1) var(--moe-space-4); }
.doc-bar__note { order: 2; background: var(--bar); padding: var(--moe-space-1) var(--moe-space-3); font-size: 12px; opacity: .9; }
.doc-bar__num { order: 0; flex: 0 0 56px; display: grid; place-items: center; background: var(--soft); color: var(--label); border-inline-end: 1px solid var(--line); }

.theme-blue .doc-bar { border: 0; background: var(--soft); color: var(--ink); }
.theme-blue .doc-bar__num { order: 0; flex: 0 0 40px; background: none; font-size: 20px; font-weight: 700; color: var(--bar); }
.theme-blue .doc-bar__title { flex: 0 1 auto; background: var(--bar); color: #FFFFFF; font-weight: 700; font-size: 17px; padding: var(--moe-space-2) var(--moe-space-6); }
.theme-blue .doc-bar__note { background: none; color: var(--ink); font-weight: 700; align-self: center; }

/* ---------- شبكة الحقول ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-block-end: 0; }
.cell { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; border-block-end: 1px solid var(--line); }
.cell:nth-child(odd):not(.cell--wide) { border-inline-end: 1px solid var(--line); }
.cell--wide { grid-column: 1 / -1; grid-template-columns: minmax(120px, 17%) 1fr; }
.cell__label { background: var(--soft); color: var(--label); padding: var(--moe-space-2) var(--moe-space-3); display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 700; font-size: 14px; }
.cell__value { padding: var(--moe-space-2) var(--moe-space-3); display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; }
.doc-label small { display: block; font-weight: 400; font-size: 11px; }
.theme-blue .cell__label { justify-content: flex-start; text-align: start; color: var(--ink); }
.theme-green .cell__label { color: var(--ink); }

.doc-cols { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); border: 1px solid var(--line); border-block-end: 0; }
.doc-cols__item { display: flex; flex-direction: column; border-inline-end: 1px solid var(--line); border-block-end: 1px solid var(--line); }
.doc-cols__item:last-child { border-inline-end: 0; }
.doc-cols__item .cell__label { min-height: 36px; }
.doc-cols__item .cell__value { align-items: center; text-align: center; flex: 1; }
.doc-cols + .doc-grid { border-block-start: 0; }

.doc-static { line-height: 1.7; }
.doc-auto { font-weight: 700; }

/* ---------- الإدخال داخل المستند ---------- */
.doc .ctl { min-height: 40px; padding: 6px 10px; font-size: 15px; border-color: #9AA3AE; background: #FFFFFF; }
.doc .ctl--short { max-width: 140px; }
.doc .ctl--line { border: 0; border-block-end: 1px dashed #9AA3AE; border-radius: 0; resize: none; overflow: hidden; min-height: 38px; }
.doc .ctl--line:focus { border-block-end: 2px solid var(--bar); outline: none; background: #FAFCFF; }
.date-pair { display: flex; flex-direction: column; gap: 2px; align-items: stretch; }
.date-pair .ctl { max-width: 220px; }
.doc-cols__item .date-pair { align-items: center; }
.hijri-preview { font-size: 13px; color: var(--label); min-height: 1.2em; }
.with-suffix { display: inline-flex; align-items: center; gap: var(--moe-space-2); }
.with-suffix .ctl { flex: 1; min-width: 0; }
.with-suffix > span { color: var(--moe-color-text-secondary); white-space: nowrap; }

.choices { display: flex; flex-wrap: wrap; gap: var(--moe-space-1) var(--moe-space-2); }
.doc-cols__item .choices { justify-content: center; }
.choice { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 2px var(--moe-space-3) 2px var(--moe-space-2); border: 1px solid #C9D0D8; border-radius: var(--moe-radius-badge); cursor: pointer; background: #FFFFFF; user-select: none; }
.choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--bar); flex: none; }
.choice:has(input:checked) { border-color: var(--bar); background: var(--soft); color: var(--label); font-weight: 700; }
.choice:has(input:focus-visible) { outline: 3px solid var(--moe-color-focus); outline-offset: 2px; }
.choice--block { display: flex; border-radius: var(--moe-radius-control); align-items: flex-start; padding-block: var(--moe-space-2); font-weight: 400 !important; }
.choice--block input { margin-block-start: 4px; }

.is-missing { box-shadow: inset 0 0 0 2px var(--moe-color-danger-fg); }
.cell__value .field-error { margin: 0; }

/* القيم المطبوعة */
.choices--print { gap: 2px var(--moe-space-4); }
.mark { display: inline-flex; align-items: baseline; gap: 4px; color: #4A5562; }
.mark--on { color: var(--ink); font-weight: 700; }
.box { font-size: 1.15em; line-height: 1; }
.mark--on .box { color: var(--bar); }
.blank { display: block; min-height: 1.4em; border-block-end: 1px dotted #9AA3AE; width: 100%; }
.date-print { line-height: 1.5; }

/* ---------- خطاب الطلب ---------- */
.doc-letter { display: grid; grid-template-columns: 2fr 1fr; gap: var(--moe-space-3); }
.doc-letter__body { background: #E2F3F9; padding: var(--moe-space-3) var(--moe-space-4); font-size: 14px; }
.doc-letter__body p { margin: 0; }
.doc-letter__to { font-size: 17px; margin-block-end: var(--moe-space-1) !important; }
.doc-letter__meta { margin: 0; border: 1px solid var(--line); padding: var(--moe-space-2) var(--moe-space-3); display: flex; flex-direction: column; gap: var(--moe-space-2); }
.doc-letter__meta > div { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: var(--moe-space-2); }
.doc-letter__meta dt { font-weight: 700; font-size: 14px; }
.doc-letter__meta dd { margin: 0; }

/* ---------- القوائم والأسطر ---------- */
.doc-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); }
.doc-list li, .doc-lines li { display: grid; grid-template-columns: 56px 1fr; border-block-end: 1px solid var(--line); }
.doc-list li:last-child, .doc-lines li:last-child { border-block-end: 0; }
.doc-list__num, .doc-lines__num { background: var(--soft); color: var(--label); display: grid; place-items: center; font-weight: 700; }
.doc-list li > span:last-child { padding: var(--moe-space-1) var(--moe-space-3); font-weight: 700; }
.doc-lines { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); }
.doc-lines li { grid-template-columns: 56px 1fr; min-height: 40px; }
.doc-lines--plain li { grid-template-columns: 1fr; }
.doc-lines li > textarea, .doc-lines__text { padding: var(--moe-space-2) var(--moe-space-3); }
.doc-lines__text { min-height: 38px; display: block; background-image: linear-gradient(to top, #9AA3AE 1px, transparent 1px); background-size: 100% 100%; background-repeat: no-repeat; background-position: bottom 10px center; background-size: calc(100% - 24px) 1px; }
.doc-lines__text:not(:empty) { background: none; }
.theme-blue .doc-lines__num { background: none; color: var(--ink); }
.add-line { margin-block-start: var(--moe-space-2); }

/* ---------- الجداول ---------- */
.doc-table-wrap { overflow-x: auto; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.doc-table th, .doc-table td { border: 1px solid var(--line); padding: var(--moe-space-2); vertical-align: middle; }
.doc-table thead th { background: var(--th); color: #FFFFFF; font-weight: 700; text-align: center; font-size: 13px; }
.doc-table .sub th { background: var(--th); font-size: 12px; padding: 2px; }
.doc-table .sub th:empty { border-block-start-color: var(--th); }
.doc-table .col-num { width: 32px; text-align: center; }
.doc-table .col-wide { min-width: 200px; }
.doc-table td.fixed { font-size: 13px; text-align: center; font-weight: 700; }
.doc-table td.fixed.strong { text-align: start; font-size: 14px; }
.doc-table td.fixed.col-wide { text-align: start; }
.theme-blue .doc-table td.fixed:nth-child(2) { font-weight: 700; }
.doc-table td.input { min-width: 120px; }
.doc-table td.input .ctl { min-height: 38px; font-size: 14px; }
.doc-table .col-opt { text-align: center; width: 56px; }
.opt-cell { display: grid; place-items: center; min-height: 40px; cursor: pointer; }
.opt-cell input { width: 20px; height: 20px; accent-color: var(--bar); margin: 0; }
.opt-cell__text { display: none; }

/* ---------- مجموعات المجالات ---------- */
.doc-groups { display: grid; grid-template-columns: repeat(var(--groups), minmax(0, 1fr)); border: 1px solid var(--line); }
.doc-group { border-inline-end: 1px solid var(--line); }
.doc-group:last-child { border-inline-end: 0; }
.doc-group legend { display: block; width: 100%; float: inline-start; background: #D6EEF5; color: var(--ink); text-align: center; padding: var(--moe-space-2); margin: 0; font-size: 15px; }
.doc-group ul { clear: both; list-style: none; margin: 0; padding: var(--moe-space-2) var(--moe-space-3); display: flex; flex-direction: column; gap: var(--moe-space-1); font-size: 14px; }
.doc-groups .mark { align-items: flex-start; }

/* ---------- الاعتماد ---------- */
.doc-sign .sign-name { display: flex; align-items: center; gap: var(--moe-space-2); font-weight: 700; }
.doc-sign td:nth-child(3) { font-weight: 700; }
.doc-sign td.col-num { font-weight: 700; color: var(--label); }
.doc-sign td:nth-child(3) { text-align: center; }
.doc-sign .sign-box { min-width: 160px; height: 56px; background-image: linear-gradient(#9AA3AE, #9AA3AE); background-repeat: no-repeat; background-size: calc(100% - 24px) 1px; background-position: center bottom 14px; }
.doc-sign output { font-weight: 700; }

.doc-foot { display: flex; flex-wrap: wrap; gap: var(--moe-space-2); justify-content: center; margin-block-start: var(--moe-space-3); padding-block-start: var(--moe-space-2); border-block-start: 1px solid var(--line); font-size: 12px; color: #4A5562; }

/* ---------- قائمة البنود مع مربعات الاختيار ---------- */
.doc-checklist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); }
.doc-checklist li { display: grid; grid-template-columns: 56px 1fr; border-block-end: 1px solid var(--line); }
.doc-checklist li:last-child { border-block-end: 0; }
.doc-checklist__num { display: grid; place-items: center; font-weight: 700; color: var(--label); border-inline-end: 1px solid var(--line); }
.doc-checklist__row { display: grid; grid-template-columns: 1fr 96px; align-items: center; cursor: pointer; }
.doc-checklist__text { padding: var(--moe-space-2) var(--moe-space-3); font-weight: 700; }
.doc-checklist__box { display: grid; place-items: center; align-self: stretch; border-inline-start: 1px solid var(--line); }
.doc-checklist__box input { width: 22px; height: 22px; accent-color: var(--bar); margin: 0; }
.doc-checklist__row:has(input:checked) { background: var(--soft); }
.box--on { color: var(--bar); }

/* إجراءات التنفيذ داخل جدول الأنشطة */
.doc-table td.input--checks .choices { gap: 4px 6px; }
.doc-table td.input--checks .choice { min-height: 34px; font-size: 13px; padding-inline: 6px 10px; }
.doc-table td.input--checks .choices--print { display: grid; grid-template-columns: repeat(3, auto); gap: 2px var(--moe-space-2); font-size: 11.5px; }
.doc-table td.input--checks .mark { white-space: nowrap; }
.doc-table td.input--checks { min-width: 260px; }
.doc-link { color: var(--label); word-break: break-all; font-size: 12px; }

/* ---------- الجوال: تكديس الخلايا أثناء التعبئة ---------- */
@media screen and (max-width: 760px) {
  .doc { padding: var(--moe-space-2); border-radius: var(--moe-radius-control); font-size: 15px; }
  .doc-head, .theme-blue .doc-head { grid-template-columns: 1fr auto; }
  .doc-head__org { display: none; }
  .doc-head__title { border-inline-start: 0; }
  .doc-head__logo img { inline-size: 96px; }
  .doc-bar { flex-wrap: wrap; }
  .doc-bar__num { flex-basis: 40px; }
  .doc-bar__title { flex: 1 1 0; }
  .theme-blue .doc-bar__title { padding-inline: var(--moe-space-3); }
  .doc-bar__note { order: 4; flex-basis: 100%; }
  .doc-grid, .doc-cols, .doc-groups, .doc-letter { grid-template-columns: 1fr; }
  .cell, .cell--wide { grid-template-columns: 1fr; border-inline-end: 0 !important; }
  .cell__label { justify-content: flex-start; text-align: start; }
  .doc-cols__item { border-inline-end: 0; }
  .doc-group { border-inline-end: 0; border-block-end: 1px solid var(--line); }
  .doc-list li { grid-template-columns: 40px 1fr; }
  .doc-lines li { grid-template-columns: 40px 1fr; }
  .doc-lines--plain li { grid-template-columns: 1fr; }

  /* جداول المؤشرات تتحول إلى بطاقات */
  .doc-table thead { display: none; }
  .doc-table, .doc-table tbody, .doc-table tr, .doc-table td { display: block; width: 100%; }
  .doc-table tr { border: 1px solid var(--line); margin-block-end: var(--moe-space-3); border-radius: var(--moe-radius-control); overflow: hidden; }
  .doc-table td { border: 0; border-block-end: 1px solid var(--line); text-align: start !important; }
  .doc-table td.col-num { width: auto; background: var(--th); color: #FFFFFF; font-weight: 700; }
  .doc-table td.col-num::before { content: "المؤشر "; }
  .doc-table td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; font-weight: 700; color: var(--label); margin-block-end: 2px; }
  .doc-table td.col-opt { display: inline-block; width: auto; border: 0; padding: var(--moe-space-1) var(--moe-space-2); }
  .doc-table td.col-opt::before { display: none; }
  .opt-cell { display: inline-flex; gap: 6px; min-height: 36px; padding: 0 var(--moe-space-3); border: 1px solid #C9D0D8; border-radius: var(--moe-radius-badge); }
  .opt-cell:has(input:checked) { border-color: var(--bar); background: var(--soft); font-weight: 700; }
  .opt-cell__text { display: inline; }
  .doc-sign td.col-num { display: none; }
  .doc-checklist li { grid-template-columns: 40px 1fr; }
  .doc-checklist__row { grid-template-columns: 1fr 64px; }
  .doc-table td.input--checks { min-width: 0; }
  .doc-sign .sign-box { display: none; }
}

/* ---------- الطباعة وPDF ---------- */
@page { size: A4 portrait; margin: 8mm 7mm; }

@media print {
  html, body { background: #FFFFFF !important; }
  .topbar, .no-print, .skip, .form-toolbar, .submit-bar, .add-line, .draft-note { display: none !important; }
  .main, .main--wide { max-width: none; padding: 0; margin: 0; }
  .doc { border: 0; border-radius: 0; padding: 0; font-size: 10.5pt; line-height: 1.45; }
  .doc-head__logo img { inline-size: 110px; }
  .doc-table { font-size: 9.5pt; }
  .doc-table thead { display: table-header-group; }
  .doc-table tr, .doc-list li, .doc-lines li, .cell, .doc-group, .doc-sign { break-inside: avoid; }
  .doc-table-wrap { overflow: visible; }
  .doc-table .col-wide { min-width: 0; width: 28%; }
  .doc-table td.input, .doc-table td.input--checks { min-width: 0; }
  .doc-table th, .doc-table td { padding: 4px; }
  .doc-sec--signatures { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
