/* =====================================================================
   منصة نماذج مدرسة قدرات الأجيال العالمية — الهوية والطباعة
   =====================================================================
   مبدأ الملف: ما تراه على الشاشة هو **نفس العناصر** التي تُطبع. لا توجد
   نسخة للعرض وأخرى للطباعة، ولا نافذة منبثقة — فالجوال يطبع كاللابتوب.
   ===================================================================== */

:root {
  /* بصمة نسخة ملف التنسيق — يقرأها qgs-app.js ويقارنها برقمه.
     اختلافهما يعني أن المتصفح يخلط ملفًا جديدًا بآخر قديم محفوظًا عنده. */
  --qgs-build: 21;

  --brand: #0d4c5c;
  --brand-2: #0a3c49;
  --brand-3: #2f7a8c;
  --brand-tint: #e8f1f3;
  --brand-tint-2: #f3f8f9;
  --gold: #b8944c;
  --gold-dark: #8f7038;
  --gold-soft: #faf5e9;
  --gold-line: #e3d2a9;

  --text: #10262c;
  --text-2: #3f5a62;
  --muted: #6b8189;
  --surface: #ffffff;
  --surface-soft: #f5f9fa;
  --surface-sunk: #eaf1f3;
  --border: #dde7ea;
  --border-strong: #c3d4d8;

  --crit: #b4453c;
  --crit-soft: #fbecea;

  --r: 14px;
  --r-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 39, 45, .05), 0 6px 20px rgba(15, 39, 45, .06);
  --shadow-paper: 0 10px 34px rgba(16, 38, 44, .17);

  --font-ui: "IBM Plex Sans Arabic", "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  --font-display: "Readex Pro", "Cairo", "Segoe UI", Tahoma, sans-serif;
  /* خط المستند — تبديله هنا يغيّر كل النماذج دفعة واحدة.
     البدائل الجاهزة داخل المجلد: "Cairo" · "Tajawal" · "Almarai" · "Noto Sans Arabic" */
  --font-doc: "Cairo", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;

  /* مقاس الورقة — يُبدَّل إلى عرضي من جافاسكربت عند الحاجة */
  --page-w: 210mm;
  --page-h: 296.8mm;
  --scale: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface-sunk);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

/* ============================ شريط علوي ============================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 8px rgba(15, 39, 45, .05);
}
.topbar .mark { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar .mark img { height: 30px; width: auto; }
.topbar .mark b { font-family: var(--font-display); font-size: 14.5px; color: var(--brand); white-space: nowrap; }
.topbar .doc-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .actions { display: flex; gap: 8px; align-items: center; }

.btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  min-height: 38px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.gold { background: var(--gold); border-color: var(--gold); }
.btn.gold:hover { background: var(--gold-dark); border-color: var(--gold-dark); }
.btn.ghost { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--surface-sunk); color: var(--text); }
.btn.small { min-height: 32px; padding: 5px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ============================ التخطيط ============================ */
.wrap {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--brand-tint-2), var(--surface));
}
.panel-head h1 { margin: 0; font-family: var(--font-display); font-size: 18px; color: var(--brand); line-height: 1.5; }
.panel-head p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }

/* ============================ نموذج التعبئة ============================ */
.fields { padding: 14px 16px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
/* لا يتمدد الحقل رأسيًا ليطابق حقلًا أطول بجانبه */
.field > input, .field > select { align-self: start; }
.field.full { grid-column: 1 / -1; }
.field > label { font-size: 12px; font-weight: 700; color: var(--text-2); }
.field input[type="text"],
.field input[type="url"],
.field textarea,
.field select {
  font: inherit;
  font-size: 13.5px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 68px; line-height: 1.8; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 0;
  border-color: var(--brand-3);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.field input[type="file"] { font-size: 12px; }
.field .hint { font-size: 11px; color: var(--muted); }

/* منتقي التاريخ الهجري — نلبسه هوية المدرسة ونُبقيه ثلاثة أعمدة حتى على الجوال */
.hijri-date-inputs { grid-template-columns: 1fr 1.5fr 1fr !important; gap: 6px !important; }
.hijri-date-inputs select {
  font: inherit !important;
  font-size: 13px !important;
  padding: 9px 8px !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--r-sm) !important;
  background: var(--surface) !important;
  color: var(--text);
}
.hijri-date-inputs select:focus {
  outline: 0;
  border-color: var(--brand-3) !important;
  box-shadow: 0 0 0 3px var(--brand-tint);
}

/* اختيار وضع التاريخ: تاريخ محدد / من-إلى / نص حر */
.mode-pick { font: inherit; font-size: 12.5px; padding: 7px 9px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); background: var(--surface-soft); color: var(--text-2); margin-bottom: 2px; }
/* «من» و«إلى» فوق بعضهما: لكل واحد منتقٍ هجري كامل العرض ليبقى مقروءًا */
.range-pick { display: grid; grid-template-columns: 1fr; gap: 10px; }
.range-pick > div {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-soft);
}
.range-pick label.sub { font-size: 11px; color: var(--muted); font-weight: 700; }

/* شريط سفلي للجوال: قفزة للمعاينة وزر طباعة دائم تحت الإبهام */
.mobile-bar { display: none; }

/* جدول داخل نموذج التعبئة */
.tbl-field { display: grid; gap: 8px; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
.tbl-edit { width: 100%; border-collapse: collapse; min-width: 420px; }
.tbl-edit th {
  background: var(--surface-sunk);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}
.tbl-edit td { border-bottom: 1px solid var(--border); padding: 3px; }
.tbl-edit tr:last-child td { border-bottom: 0; }
.tbl-edit input { font: inherit; font-size: 13px; width: 100%; min-width: 80px; border: 0; background: transparent; padding: 7px 8px; border-radius: 5px; color: var(--text); }
.tbl-edit input:focus { outline: 2px solid var(--brand-3); outline-offset: -2px; background: var(--surface); }
.row-x { border: 0; background: transparent; color: var(--muted); font-size: 16px; line-height: 1; padding: 4px 9px; border-radius: 5px; cursor: pointer; }
.row-x:hover { color: var(--crit); background: var(--crit-soft); }


/* ============================ لوح المعاينة ============================ */
.preview { position: sticky; top: 64px; }
.prev-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}
.prev-bar .label { font-size: 12px; font-weight: 700; color: var(--text-2); margin-inline-end: auto; }
/* مفتاح اتجاه الورقة — نفس شكل مفتاح التكبير */
.orient { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.orient button { font: inherit; font-size: 11.5px; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 5px 12px; cursor: pointer; }
.orient button.on { background: var(--brand); color: #fff; }

.zoom { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.zoom button { font: inherit; font-size: 11.5px; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: 5px 10px; cursor: pointer; }
.zoom button.on { background: var(--gold); color: #fff; }
.pagecount { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.stage {
  padding: 18px 12px 26px;
  background: var(--surface-sunk);
  background-image: radial-gradient(circle at 1px 1px, rgba(15, 39, 45, .07) 1px, transparent 0);
  background-size: 20px 20px;
  max-height: calc(100vh - 140px);
  overflow: auto;
}

/* ============================ الورقة ============================ */
.sheet-slot {
  position: relative;
  width: calc(var(--page-w) * var(--scale));
  height: calc(var(--page-h) * var(--scale));
  margin: 0 auto 16px;
}
.sheet {
  position: absolute;
  /* فيزيائية لا منطقية: مع rtl يصير inset-inline-start يمينًا فتنزاح الورقة
     خارج إطارها بعد التصغير. المقياس يبدأ من الزاوية العليا اليسرى دائمًا. */
  top: 0;
  left: 0;
  right: auto;
  transform: scale(var(--scale));
  transform-origin: top left;
  width: var(--page-w);
  height: var(--page-h);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-paper);
  color: #000;
  font-family: var(--font-doc);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
[dir="rtl"] .sheet { transform-origin: top left; }

.sheet-bg {
  position: absolute;
  inset: 0;
  /* نسب مئوية لا متغيّرات: تُحسب من صندوق الورقة نفسه في أي محرّك */
  width: 100%;
  height: 100%;
  object-fit: fill;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}
/* حجاب أبيض خفيف أسفل الورقة يحفظ وضوح النص فوق الزخرفة */
.sheet::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 58mm;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(to top, rgba(255,255,255,.80) 0%, rgba(255,255,255,.48) 48%, rgba(255,255,255,0) 100%);
}
.sheet-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  padding: 12mm 16mm 10mm;
  display: flex;
  flex-direction: column;
}

/* ترويسة رسمية مرسومة — لا صورة، فتبقى حادة في أي مقاس */
.sheet-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 5mm;
  padding-bottom: 3mm;
  border-bottom: .7pt solid var(--gold-line);
  flex: none;
}
.sheet-head .logo-frame {
  border: .8pt solid var(--gold);
  border-radius: 2.4mm;
  padding: 1.6mm 3mm;
  background: rgba(255, 255, 255, .9);
}
.sheet-head img.qgs { width: 22mm; height: auto; max-height: 12mm; object-fit: contain; display: block; }
.sheet-head img.ministry { width: 21mm; height: auto; max-height: 15mm; object-fit: contain; display: block; }
.sheet-head .copy {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: .4mm;
  font-size: 8pt;
  line-height: 1.5;
  color: #000;
  font-weight: 600;
}
.sheet-head .copy strong { font-size: 8.6pt; font-weight: 700; }

.sheet-title {
  flex: none;
  margin: 4mm auto 3.5mm;
  max-width: 92%;
}
.sheet-title > span {
  display: block;
  border: 1pt solid var(--gold);
  border-radius: 2.4mm;
  background: rgba(255, 255, 255, .88);
  padding: 2.2mm 8mm;
  text-align: center;
  font-family: var(--font-display);
  font-size: 15pt;
  font-weight: 700;
  color: #000;
  line-height: 1.5;
}
.sheet-title.continued > span {
  font-size: 11pt;
  padding: 1.4mm 6mm;
  border-style: dashed;
  color: #333;
}

.sheet-body { flex: 1 1 auto; min-height: 0; overflow: hidden; }

.sheet-foot {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 4mm;
  padding-top: 2.4mm;
  border-top: .6pt solid var(--gold-line);
  font-size: 7.6pt;
  color: #3f4b52;
}
.sheet-foot .pageno { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ============================ متن المستند ============================ */
.doc-body { color: #000; font-size: 11pt; line-height: 1.85; }
.doc-body p { margin: 0 0 2.6mm; }
.doc-body h2, .doc-body h3 { color: #000; margin: 3mm 0 2mm; font-family: var(--font-display); }
.doc-body h2 { font-size: 13pt; }
.doc-body h3 { font-size: 11.5pt; }
.doc-body ul, .doc-body ol { margin: 0 0 2.6mm; padding-inline-start: 6mm; }
.doc-body li { margin-bottom: 1mm; }
.doc-body img { max-width: 100%; height: auto; display: block; margin: 2mm auto; }
.doc-body a { color: #0d4c5c; text-decoration: none; overflow-wrap: break-word; }

.doc-body table {
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin: 0 0 3.4mm;
  font-size: 10.4pt;
  background: rgba(255, 255, 255, .9);
}
.doc-body td, .doc-body th {
  border: .9pt solid #5f7076;
  padding: 1.9mm 2.2mm;
  text-align: right;
  vertical-align: top;
  line-height: 1.65;
  /* الكلمة لا تُشطر: إن لم تتسع في آخر السطر نزلت كاملة إلى السطر التالي.
     break-word لا يكسر إلا كلمة أطول من عرض الخانة كلها (رابط طويل مثلًا). */
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: none;
}
.doc-body .label-title {
  background: var(--brand-tint);
  font-weight: 700;
  text-align: center;
  color: #000;
}
.doc-body .section-content { min-height: 9mm; white-space: pre-wrap; }

/* الكلمة لا تُشطر أبدًا — ولا تخرج عن خانتها.
   الالتفاف ممنوع داخل الكلمة: إن لم تتسع نزلت كاملة إلى السطر التالي.
   وإن كانت أطول من الخانة كلها تولّى `fitWords` في qgs-app.js تصغير خط تلك
   الخانة وحدها حتى تتسع — فلا شطر ولا فيض. الروابط وحدها تُكسر (لا معنى
   لتصغير رابط طوله ٨٠ حرفًا). */
.doc-body td, .doc-body th {
  overflow-wrap: normal;
  word-break: keep-all;
  hyphens: none;
}
.doc-body td a, .doc-body th a { overflow-wrap: anywhere; word-break: break-all; }
.doc-body table { table-layout: fixed; }

/* أسطر مثبَّتة أثناء بناء الـPDF: كل سطر عنصر مستقل ممنوع من الالتفاف */
.doc-body .qgs-line { display: block; white-space: pre; }

/* الباركود يُرسم بعد الترقيم ⇒ نحجز مقاسه مسبقًا وإلا زاد ارتفاع الورقة بعد
   توزيع الصفحات فاختفى ما تحته. الحجز يجعل الترقيم صحيحًا من أول مرة. */
.doc-body span[data-qr] {
  display: block;
  width: 34mm;
  height: 34mm;
  margin: 1mm auto 1.5mm;
}
.doc-body span[data-qr] img { display: block; width: 34mm; height: 34mm; }
/* الباركود نفسه هو الرابط — لا نص تحته */
.doc-body a { text-decoration: none; color: inherit; }
.doc-body tbody tr:nth-child(even) td:not(.label-title) { background: rgba(240, 246, 246, .75); }

/* الورقة العرضية — للجداول العريضة */
body.landscape { --page-w: 296.8mm; --page-h: 209.8mm; }
body.landscape .sheet-inner { padding: 9mm 12mm 8mm; }
body.landscape .sheet::after { height: 32mm; }
body.landscape .doc-body { font-size: 9.6pt; line-height: 1.6; }
body.landscape .doc-body table { font-size: 8.6pt; }
body.landscape .doc-body td, body.landscape .doc-body th { padding: 1.3mm 1.6mm; line-height: 1.45; }

/* ============================ الفهرس ============================ */
.home { max-width: 1120px; margin: 0 auto; padding: 24px 18px 56px; }

.home-head { text-align: center; margin-bottom: 20px; }
.home-head .logos { display: flex; align-items: center; justify-content: center; gap: 22px; margin-bottom: 14px; }
.home-head .logos img { height: 52px; width: auto; }
.home-head h1 { margin: 0 0 6px; font-family: var(--font-display); font-size: 27px; color: var(--brand); }
.home-head p { margin: 0 auto; max-width: 58ch; color: var(--muted); font-size: 14px; }

/* شريط البحث والتبويب — يلتصق بالأعلى فيبقى في متناول اليد أثناء التمرير */
.home-bar {
  position: sticky;
  top: 58px;
  z-index: 20;
  display: grid;
  gap: 10px;
  padding: 12px 0 14px;
  margin-bottom: 8px;
  background: linear-gradient(180deg, var(--surface-sunk) 78%, rgba(234, 241, 243, 0));
}
.search { position: relative; }
.search input {
  font: inherit;
  font-size: 15px;
  width: 100%;
  min-height: 46px;
  padding: 10px 44px 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.search input:focus { outline: 0; border-color: var(--brand-3); box-shadow: 0 0 0 3px var(--brand-tint); }
.search::before {
  content: "";
  position: absolute;
  inset-inline-start: 16px;
  top: 50%;
  width: 15px; height: 15px;
  margin-top: -9px;
  border: 1.8px solid var(--muted);
  border-radius: 50%;
  pointer-events: none;
}
.search::after {
  content: "";
  position: absolute;
  inset-inline-start: 13px;
  top: 50%;
  width: 6px;
  margin-top: 4px;
  border-top: 1.8px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip b { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.chip:hover { border-color: var(--brand-3); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.on b { color: rgba(255, 255, 255, .75); }

/* بطاقة الأداة (صانع الباركود) */
.tool-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  margin-bottom: 22px;
  border: 1px solid var(--gold-line);
  border-radius: var(--r);
  background: linear-gradient(90deg, var(--gold-soft), var(--surface));
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.tool-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.tool-card svg { width: 30px; height: 30px; flex: none; color: var(--gold-dark); }
.tool-card strong { display: block; font-size: 14.5px; color: var(--brand); }
.tool-card span { font-size: 12px; color: var(--muted); line-height: 1.6; }

.group { margin-bottom: 24px; }
.group > h2 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 15.5px;
  color: var(--gold-dark);
  display: flex;
  align-items: center;
  gap: 10px;
}
.group > h2::after { content: ""; flex: 1; height: 1px; background: var(--gold-line); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  display: grid;
  gap: 7px;
  align-content: start;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.card:hover { border-color: var(--gold); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(15, 39, 45, .1); }
.card-top { display: flex; align-items: flex-start; gap: 9px; }
.card-top svg { width: 19px; height: 19px; flex: none; margin-top: 2px; color: var(--brand-3); }
.card strong { font-size: 14.5px; color: var(--brand); line-height: 1.5; }
.card > span { font-size: 11.5px; color: var(--muted); line-height: 1.65; }
.card-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.card em { font-style: normal; font-size: 10.5px; color: var(--gold-dark); }
.card i.draft {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--brand-tint);
  color: var(--brand);
}
.card.has-draft { border-color: var(--brand-3); }

.empty { text-align: center; color: var(--muted); padding: 36px 10px; }

/* رسالة فشل بناء الـPDF — تُصوَّر وتُرسل */
.pdf-error {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 13px 15px;
  border-top: 1px solid var(--crit);
  border-bottom: 1px solid var(--crit);
  background: var(--crit-soft);
}
.pdf-error strong { font-size: 13.5px; color: var(--crit); }
.pdf-error span { font-size: 12.5px; color: var(--text-2); }
.pdf-error code {
  font-size: 11px;
  line-height: 1.8;
  color: var(--text-2);
  background: rgba(255,255,255,.7);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  word-break: break-word;
  direction: ltr;
  text-align: left;
}
.pdf-error-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.home-note { margin-top: 26px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.9; }

/* ============================ صانع الباركود ============================ */
.tool { max-width: 620px; margin: 0 auto; padding: 20px 16px 60px; }
.tool-body { padding: 16px; display: grid; gap: 14px; }
.sizes { display: flex; flex-wrap: wrap; gap: 8px; }
.qr-stage { display: flex; justify-content: center; padding: 6px 0; }
.qr-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 20px;
  min-height: 250px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
  background: var(--surface-soft);
}
.qr-card img, .qr-card canvas {
  display: block;
  width: 240px; height: 240px;
  background: #fff;
  border-radius: 10px;
}
.qr-cap { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); text-align: center; }
.tool-actions { display: flex; gap: 10px; }
.tool-actions .btn { flex: 1; text-align: center; text-decoration: none; line-height: 22px; }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.hint.ok { color: var(--brand-3); font-weight: 600; }
.hint.bad { color: var(--crit); font-weight: 600; }

/* ============================ الجوال ============================ */
@media (max-width: 1040px) {
  .wrap { grid-template-columns: 1fr; padding-bottom: 76px; }
  .preview { position: static; }
  .stage { max-height: none; }

  .mobile-bar {
    display: flex;
    gap: 10px;
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 40;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 18px rgba(15, 39, 45, .08);
  }
  .mobile-bar .btn { flex: 1; justify-content: center; min-height: 44px; }
  .topbar .actions .btn.gold { display: none; }   /* لا نكرر زر الطباعة */
}
@media (max-width: 760px) {
  .cards { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { font-size: 14.5px; }

  .topbar { padding: 8px 12px; gap: 10px; }
  .topbar .mark b { display: none; }
  .topbar .doc-name { font-size: 12.5px; font-weight: 600; color: var(--text-2); }

  .wrap { padding: 10px; gap: 12px; }
  .fields { grid-template-columns: 1fr; padding: 12px; }
  .field.full { grid-column: 1; }
  .stage { padding: 12px 6px 18px; }

  /* ---- الفهرس على الجوال ---- */
  .home { padding: 16px 12px 40px; }
  .home-head { margin-bottom: 14px; }
  .home-head .logos { gap: 16px; margin-bottom: 10px; }
  .home-head .logos img { height: 40px; }
  .home-head h1 { font-size: 21px; }
  .home-head p { font-size: 13px; }

  .home-bar { top: 50px; padding: 10px 0 12px; gap: 9px; }
  .search input { min-height: 48px; font-size: 16px; }  /* ١٦px يمنع تكبير سفاري التلقائي */

  /* الفئات سطر واحد يُمرَّر أفقيًا بدل أن تتكدّس وتزيح المحتوى */
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    margin-inline: -12px;
    padding-inline: 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; min-height: 40px; }

  .tool-card { margin-bottom: 18px; padding: 13px 14px; gap: 12px; }
  .tool-card svg { width: 26px; height: 26px; }

  .card { padding: 14px; gap: 6px; }
  .card strong { font-size: 15px; }
  .card > span { font-size: 12px; }

  /* ---- صانع الباركود على الجوال ---- */
  .tool { padding: 14px 12px 44px; }
  .tool-body { padding: 13px; }
  .qr-card { padding: 14px; min-height: 0; }
  .qr-card img, .qr-card canvas { width: 200px; height: 200px; }
  .sizes { display: grid; grid-template-columns: repeat(3, 1fr); }
  .sizes .chip { justify-content: center; padding: 6px 6px; font-size: 12px; }
  .tool-actions { flex-direction: column; }
  .tool-actions .btn { min-height: 46px; }
}

/* ============================ الطباعة ============================
   القاعدة: تُخفى الواجهة كلها ويبقى الورق وحده بمقاسه الحقيقي.
   لا نافذة منبثقة ⇒ يعمل على الجوال كما على اللابتوب.
   ================================================================ */
@media print {
  /* الافتراضي ورق A4 طولي بلا هوامش؛ النماذج العرضية تحقن @page بديلًا من جافاسكربت */
  @page { size: A4 portrait; margin: 0; }

  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .topbar, .prev-bar, #form-panel, .no-print { display: none !important; }

  .wrap {
    display: block !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
  }
  .panel, .preview {
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: none !important;
    overflow: visible !important;
    position: static !important;
  }
  .stage {
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .sheet-slot {
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    position: static !important;
  }
  .sheet {
    /* relative لا static: الخلفية داخلها absolute، ولو صارت الورقة static
       لالتصقت كل الخلفيات بأول صفحة وخرجت بقية الصفحات بيضاء */
    position: relative !important;
    transform: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    break-after: page;
    page-break-after: always;
  }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* وسم النسخة في الشريط العلوي — للشاشة فقط، لا يظهر في المطبوع */
.ver-tag {
  margin-inline-start: auto;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
@media print { .ver-tag { display: none !important; } }

/* تنبيه «نسخة مختلطة» — يظهر فقط إذا اختلف رقم التنسيق عن رقم البرنامج */
.stale-note {
  display: grid;
  gap: 3px;
  padding: 11px 16px;
  background: var(--crit-soft);
  border-bottom: 1px solid var(--crit);
  color: var(--crit);
}
.stale-note strong { font-size: 13.5px; }
.stale-note span { font-size: 12.5px; color: var(--text-2); line-height: 1.8; }
@media print { .stale-note { display: none !important; } }

/* ---------- صور الشواهد: حذف صورة واحدة ---------- */
.thumbs-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  min-height: 24px;
}
.thumbs-count { font-size: 11.5px; color: var(--muted); }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb {
  position: relative;
  width: 78px;
  height: 78px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--surface-soft);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-x {
  position: absolute;
  top: 3px;
  inset-inline-end: 3px;
  width: 24px;
  height: 24px;
  line-height: 1;
  font-size: 16px;
  font-weight: 700;
  border: 0;
  border-radius: 50%;
  background: rgba(16, 38, 44, .72);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.thumb-x:hover { background: var(--crit); }

/* ---------- تجاهل مسوّدة من الفهرس ---------- */
/* الزر لا يُركَب فوق البطاقة: نحجز له شريطًا أسفلها فلا يغطّي نصًّا */
.card-wrap { position: relative; display: flex; }
.card-wrap > .card { flex: 1; padding-bottom: 46px; }
.card-x {
  position: absolute;
  bottom: 10px;
  inset-inline-start: 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}
.card-x:hover { color: var(--crit); border-color: var(--crit); background: var(--crit-soft); }

/* ---------- باركود داخل خانة جدول ---------- */
/* أصغر من باركود القسم، ومقاسه محجوز مسبقًا كما هناك حتى لا يتغيّر ارتفاع
   الصف بعد توزيع الصفحات. */
.doc-body span[data-qr][data-qr-size="16"],
.doc-body span[data-qr][data-qr-size="16"] img { width: 16mm; height: 16mm; }
.doc-body span[data-qr][data-qr-size="16"] { margin: 0.8mm auto; }
.doc-body td.qr-cell { text-align: center; vertical-align: middle; }
