/* ═══════════════════════════════════════════════════════════════
   js/forms/forms-theme.css
   طراحی مشترک فرم‌ها + تنظیمات چاپ A4 یکصفحه‌ای
   فونت: Shabnam (متن ثابت) + Mikhak (مقادیر پرشده)
   ═══════════════════════════════════════════════════════════════ */

/* ── فونت اصلی (متن ثابت و برچسب‌ها) ── */
@font-face {
  font-family: 'Shabnam';
  src: url('../../lib/fonts/Shabnam.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'Shabnam';
  src: url('../../lib/fonts/Shabnam-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}

/* ── فونت نیمه‌دست‌نویس برای مقادیر پر شده ── */
@font-face {
  font-family: 'FormHand';
  src: url('../../lib/fonts/Mikhak-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF;
}

/* ═══════════════════════════════════════════════════════════
   تنظیمات صفحه A4 (حذف حاشیه پیش‌فرض مرورگر)
   ═══════════════════════════════════════════════════════════ */
@page {
  size: A4 portrait;
  margin: 0;
}

/* ═══════════════════════════════════════════════════════════
   شیت A4 — بدون min-height اجباری (منشأ سرریز صفحه دوم)
   ═══════════════════════════════════════════════════════════ */
.form-sheet {
  width: 210mm;
  /* ⚠️ min-height حذف شد — ارتفاع را محتوا تعیین می‌کند */
  height: auto;
  background: #fff;
  box-sizing: border-box;
  padding: 6mm 6mm 4mm;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  direction: rtl;
  color: #000;
  font-family: 'Shabnam', 'Vazirmatn', Tahoma, sans-serif;
  font-size: 12.5px;
  line-height: 1.7;
}

/* ── پایه ── */
.form-sheet.fs, .form-sheet .fs {
  font-family: 'Shabnam', 'Vazirmatn', Tahoma, sans-serif;
  direction: rtl;
  color: #000;
  font-size: 12.5px;
  line-height: 1.7;
}
.form-sheet .fs * { box-sizing: border-box; }

/* ── سرتیتر: [لوگو | عنوان | کد فرم] ── */
.form-sheet .fs-head {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 5px;
}
.form-sheet .fs-head td {
  border: 1.4px solid #000;
  vertical-align: middle;
  text-align: center;
  padding: 3px 6px;
}
.form-sheet .fs-head .fs-logo { width: 17%; padding: 2px; }
.form-sheet .fs-head .fs-logo img {
  display: block;
  margin: 0 auto;
  width: 58px;
  height: 58px;
  object-fit: contain;
}
.form-sheet .fs-head .fs-title {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.4;
}
.form-sheet .fs-head .fs-code {
  width: 22%;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.4;
}
.form-sheet .fs-head .fs-code bdi {
  display: block;
  direction: ltr;
  font-weight: 800;
}

/* ── جدول اصلی ── */
.form-sheet .fs-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.form-sheet .fs-grid + .fs-grid { margin-top: -1.4px; }
.form-sheet .fs-grid td,
.form-sheet .fs-grid th {
  border: 1.4px solid #000;
  padding: 3px 6px;
  vertical-align: top;
  font-size: 12.5px;
  font-weight: 400;
  text-align: right;
  line-height: 1.65;
}

/* ── برچسب‌ها (بزرگ‌تر از متن معمولی) ── */
.form-sheet .fs-lbl {
  font-size: 14.5px;
  font-weight: 800;
}

.form-sheet .fs-val { font-weight: 400; }

/* ── ارتفاع‌های فشرده‌شده (کاهش یافته) ── */
.form-sheet .fs-grid td.fs-tall  { height: 240px; }   /* قبلاً 330 */
.form-sheet .fs-grid td.fs-mid   { height: 70px; }    /* قبلاً 90 */
.form-sheet .fs-grid td.fs-small { height: 42px; }    /* قبلاً 52 */
.form-sheet .fs-grid td.fs-center { text-align: center; vertical-align: middle; }
.form-sheet .fs-grid td.fs-bottom { vertical-align: bottom; }
.form-sheet .fs-grid td.fs-left   { text-align: left; }
.form-sheet .fs-grid td.fs-noborder { border: none; }

/* ── خانه‌ی کنار عمودی ── */
.form-sheet .fs-side {
  width: 26px;
  padding: 2px !important;
  text-align: center !important;
  vertical-align: middle !important;
  font-weight: 800;
  background: #d9e2f3;
  font-size: 11.5px;
}
.form-sheet .fs-side.gray { background: #d9d9d9; }
.form-sheet .fs-side > span {
  display: inline-block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  letter-spacing: 0;
}

/* ── نوار عنوان بخش ── */
.form-sheet .fs-bar {
  background: #d9d9d9;
  font-weight: 800;
  text-align: center !important;
  font-size: 15px;
}

/* ── خط‌چین و چک‌باکس ── */
.form-sheet .fs-dots {
  display: inline-block;
  min-width: 60px;
  border-bottom: 1px dotted #000;
  padding: 0 4px;
  line-height: 1.6;
  vertical-align: baseline;
  text-align: center;
}
.form-sheet .fs-dots.w40  { min-width: 40px; }
.form-sheet .fs-dots.w60  { min-width: 58px; }
.form-sheet .fs-dots.w90  { min-width: 88px; }
.form-sheet .fs-dots.w120 { min-width: 115px; }
.form-sheet .fs-dots.w160 { min-width: 150px; }
.form-sheet .fs-dots.w220 { min-width: 200px; }

.form-sheet .fs-dline {
  border-bottom: 1px dotted #000;
  min-height: 22px;
  padding: 2px 4px;
}

.form-sheet .fs-cb {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1.2px solid #000;
  vertical-align: middle;
  text-align: center;
  line-height: 10px;
  font-size: 10px;
  font-weight: 800;
  margin: 0 3px;
}
.form-sheet .fs-cb.on::before { content: '✓'; }
.form-sheet .fs-opt {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 12px;
  white-space: nowrap;
}

/* ── امضا و پاورقی ── */
.form-sheet .fs-sign {
  text-align: left;
  font-weight: 700;
  font-size: 11px;
  padding-top: 10px;
}
.form-sheet .fs-sign small {
  display: block;
  font-weight: 400;
  text-align: center;
}
.form-sheet .fs-note {
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  margin-top: 6px;
}

/* ── شبکه‌ی شمارنده‌ها (فرم ۳۸) ── */
.form-sheet .fs-count td {
  border: 1px dotted #000 !important;
  border-left: none !important;
  border-right: none !important;
  height: 40px;
  vertical-align: middle;
}
.form-sheet .fs-count td:first-child { border-right: none !important; }

/* ── قاب بیرونی (فرم ۵۰) — ارتفاع را محتوا تعیین می‌کند ── */
.form-sheet .fs-frame {
  border: 1.4px solid #000;
  padding: 12px 16px;
  /* min-height حذف شد */
}

/* ── متن بند ── */
.form-sheet .fs-para {
  text-align: justify;
  line-height: 1.95;
  font-size: 12.5px;
}
.form-sheet .fs-para.bold {
  font-weight: 800;
  font-size: 13.5px;
}

/* ── مقادیر پرشده (نیمه‌دست‌نویس) ── */
.form-sheet .fs-hand,
.form-sheet .fs-val,
.form-sheet .fs-dots:not(:empty) {
  font-family: 'FormHand', 'Mikhak', 'Shabnam', 'Vazirmatn', Tahoma, sans-serif;
  font-weight: 700;
  font-size: 1.15em;
  line-height: 1.45;
  letter-spacing: 0;
}

.form-sheet .fs-hand bdi,
.form-sheet .fs-val bdi,
.form-sheet .fs-dots bdi {
  font-size: inherit;
}

.form-sheet .fs-dots:empty,
.form-sheet .fs-dots:has(> :only-child) {
  font-family: inherit;
  font-weight: inherit;
  font-size: inherit;
}

/* ── حالت فشرده (۳۴ و ۳۷ و ۴۸ و ۵۰) ── */
.form-sheet .fs.compact { font-size: 11.5px; line-height: 1.65; }
.form-sheet .fs.compact .fs-grid td { font-size: 11.5px; padding: 3px 5px; }
.form-sheet .fs.compact .fs-head .fs-logo img { width: 50px; height: 50px; }
.form-sheet .fs.compact .fs-head .fs-title { font-size: 14px; }
.form-sheet .fs.compact .fs-dline { min-height: 20px; }
.form-sheet .fs.compact .fs-lbl { font-size: 13.5px; font-weight: 800; }
.form-sheet .fs.compact .fs-bar { font-size: 14px; font-weight: 800; }
.form-sheet .fs.compact .fs-grid td.fs-tall  { height: 200px; }
.form-sheet .fs.compact .fs-grid td.fs-mid   { height: 60px; }
.form-sheet .fs.compact .fs-grid td.fs-small { height: 36px; }
.form-sheet .fs.compact .fs-para { line-height: 1.85; }

/* ═══════════════════════════════════════════════════════════
   ناحیه چاپ
   ═══════════════════════════════════════════════════════════ */
#formPrintArea {
  width: 210mm;
  background: #fff;
  margin: 0 auto;
  direction: rtl;
}

/* ═══════════════════════════════════════════════════════════
   پیش‌نمایش روی صفحه (غیر چاپ)
   ═══════════════════════════════════════════════════════════ */
@media screen {
  #formPrintArea {
    padding: 20px 0;
    background: #e2e8f0;
  }
  .form-sheet {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-radius: 3px;
    margin-bottom: 16px;
  }
}

/* ═══════════════════════════════════════════════════════════
   چاپ
   ═══════════════════════════════════════════════════════════ */
@media print {
  /* پایه — همه چیز در A4 */
  html, body {
    width: 210mm;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* فقط ناحیه چاپ دیده شود */
  body > *:not(#formPrintArea) {
    display: none !important;
  }
  #formPrintArea {
    display: block !important;
    width: 210mm;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
  }

  /* شیت‌ها — هر کدام دقیقاً یک صفحه */
  .form-sheet,
  .form-sheet-a4 {
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 6mm 6mm 4mm !important;
    width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    /* ⭐ هر شیت یک صفحه‌ی مستقل */
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-after: always;
    break-after: page;
    overflow: hidden;
  }

  /* ⭐ آخرین شیت — دیگر page-break نمی‌زند (جلوگیری از صفحه‌ی خالی) */
  #formPrintArea > .form-sheet:last-child,
  #formPrintArea > .form-sheet-a4:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  /* ⭐ اگر تنها یک شیت داریم، هیچ page-break نباشد */
  #formPrintArea > .form-sheet:only-child,
  #formPrintArea > .form-sheet-a4:only-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }

  /* عناصر غیرضروری */
  .no-print,
  .app-header,
  .bottom-nav,
  .form-actions,
  .wizard-nav,
  .fs-toolbar,
  #formPrintArea button {
    display: none !important;
  }

  /* جدول‌ها و ردیف‌ها نباید نصف شوند */
  .fs-grid, .fs-table, table, tr, td, th {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* حفظ رنگ‌های پس‌زمینه */
  .form-sheet .fs-side,
  .form-sheet .fs-bar,
  .form-sheet .fs-side.gray {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
