/* مذكرة منصور — ورشة الصياغة القانونية
   الأساس: style «framed-sheet» من ورقة tasteskill (seed 20261021).
   التوكنز والأبعاد والحركة من الورقة كما وردت؛ الاتجاه معكوس إلى RTL والخط عربي — شرط المشروع.
   الوجه المختار: إطار بلون المنتج المنخفض التشبّع (أزرق-رمادي مؤسسي) بدل #f9fbfc. */

/* ---------- 1. التوكنز (من الورقة) ----------
   اللوحة النهارية: ورق دافئ مائل للكريمي، وحبر فحمي ناعم — لا أبيض نقي ولا أسود نقي.
   الهدف: تباين مريح (حوالي 11:1 على النص) بدل 17:1 القاسي. */
:root {
  --ground: #f7f4ee;          /* أرضية دافئة ورقية — تخفّف الوهج */
  --surface: #fffdf9;         /* الورقة: كريمي خفيف، لا أبيض ساطع */
  --raised: #f3efe7;          /* بئر داخلي / تمرير الصف */
  --active: #eae4d8;          /* العنصر النشط */
  --border: #e6e0d4;          /* حواف اللوحات */
  --rule: #efe9dd;            /* خطوط الصفوف */
  --control: #d5cec0;         /* المدخلات والأزرار المحدّدة */
  --text: #2a2723;            /* حبر فحمي دافئ — مريح للقراءة الطويلة */
  --muted: #5d5749;           /* نص ثانوي — يجتاز AA على الورقة والأرضية معاً */
  --faint: #6f695c;           /* أخفّ رمادي يجتاز 4.5:1 — لا أفتح من هذا */
  --accent: #2563a8;          /* أزرق سماوي مؤسسي — هادئ ورسمي */
  --accent-ink: #ffffff;
  --primary: #2a2723;         /* الزر الأساسي: نفس الحبر */
  --primary-ink: #fffdf9;
  --positive: #1f7a51;
  --negative: #b3372f;
  --warning: #8a5a12;
  --chart-1: #2563a8;
  --chart-2: #1f8a8a;
  --chart-3: #a8701a;
  --chart-muted: #d8d2c6;
  --grid: var(--rule);
  --axis-ink: var(--muted);
  --ink: var(--text);
  --pill-positive-bg: #dff0e4; --pill-positive-ink: #14532d;
  --pill-negative-bg: #fbe4e1; --pill-negative-ink: #7f1d1a;
  --pill-warning-bg: #fbf0d9;  --pill-warning-ink: #7a4a0d;
  --pill-neutral-bg: #ece7dc;  --pill-neutral-ink: #4a453c;

  --radius-card: 8px;
  --radius-control: 6px;
  --radius-sheet: 16px;
  --sheet-inset: 8px;
  --row-height: 48px;
  --sidebar-width: 228px;
  --gap: 24px;
  --pad: 24px;
  --card-pad: 20px;
  --control-height: 32px;
  --nav-row: 32px;

  --fs-title: 22px; --fs-section: 16px; --fs-kpi: 28px; --fs-body: 14px; --fs-small: 12px;

  /* الخط العربي: عائلة واحدة تعمل عملها، والثانية للأرقام والهويات فقط */
  --font: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, monospace;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-press: 120ms; --t-hover: 150ms; --t-ui: 200ms;
}

/* السمة المسائية: رمادي عميق مائل للأزرق — لا أسود نقي (الأسود النقي يُحدث هالة حول النص)،
   وحبر عاجي — لا أبيض نقي (الأبيض النقي يوهج). التباين ~10:1. */
:root[data-theme="dark"] {
  --ground: #12151a;          /* أرضية ليلية عميقة، مائلة للأزرق */
  --surface: #1a1e25;         /* الورقة أرفع بدرجة واحدة */
  --raised: #232830;          /* بئر داخلي / تمرير الصف */
  --active: #2b313b;          /* العنصر النشط */
  --border: #262c35;          /* حواف اللوحات */
  --rule: #21262e;            /* خطوط الصفوف */
  --control: #3a414d;         /* المدخلات */
  --text: #e6e3dc;            /* حبر عاجي دافئ */
  --muted: #a8aeb8;           /* نص ثانوي — يجتاز AA */
  --faint: #8c939e;           /* أخفّ رمادي يجتاز 4.5:1 */
  --accent: #6da8e8;          /* نفس الأزرق مرفوع الإضاءة للّيل — سماوي مريح */
  --accent-ink: #0a1524;
  --primary: #e6e3dc;
  --primary-ink: #15181d;
  --positive: #4fbf87;
  --negative: #e5766a;
  --warning: #d8a642;
  --chart-1: #6da8e8; --chart-2: #56c2bd; --chart-3: #d8a642; --chart-muted: #3c434e;
  --grid: #2a3038;
  --pill-positive-bg: #16301f; --pill-positive-ink: #6fd39a;
  --pill-negative-bg: #331c1a; --pill-negative-ink: #f0907f;
  --pill-warning-bg: #2e2413;  --pill-warning-ink: #e0b055;
  --pill-neutral-bg: #262c35;  --pill-neutral-ink: #cfd4db;
}

/* ---------- 2. الأساس ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--text);
  font: var(--fs-body)/22px var(--font);
  -webkit-font-smoothing: antialiased;
  direction: rtl; text-align: right;
}
h1, h2, h3, h4, p, figure, ul, ol, dl, dd { margin: 0; }
ul[class], ol[class] { padding: 0; list-style: none; }
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num, table, .kpi-value, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-num); }
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 3. الصدفة: إطار مصبوغ + ورقة بيضاء ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100svh;
}
/* الإطار: الشريط الجانبي والعلوي على أرضية واحدة، بلا فاصل بينهما */
.frame { background: var(--ground); display: flex; flex-direction: column; min-height: 100svh; }
.sidebar {
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 12px; overflow: auto; flex: 1;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; flex: none; border-radius: 8px;
  background: var(--text); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 600; font-size: 15px;
}
.brand-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-scope { font-size: var(--fs-small); color: var(--faint); }
.group-label { margin: 20px 8px 6px; font-size: var(--fs-small); color: var(--faint); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: var(--nav-row); padding: 0 8px; border-radius: 8px;
  color: var(--muted); cursor: pointer; border: 0; background: none; width: 100%; text-align: right;
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.nav-item svg { width: 16px; height: 16px; flex: none; stroke-width: 1.5; }
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--active); color: var(--text); }
.nav-item .count {
  margin-inline-start: auto; font-size: 11px; font-weight: 500;
  background: var(--active); color: var(--muted);
  border-radius: 999px; padding: 1px 7px; font-variant-numeric: tabular-nums;
}
.sidebar .bottom { margin-top: auto; padding-top: 16px; }
.who { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.who-av {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  background: var(--active); color: var(--muted);
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
}

/* الورقة: بيضاء، مُزاحة 8px من الحافة اليمنى والسفلية، حافة 1px، بلا ظل */
.sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sheet);
  margin: var(--sheet-inset) var(--sheet-inset) var(--sheet-inset) 0;
  min-width: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
.topbar {
  height: 48px; flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--rule);
}
.topbar .crumb { color: var(--muted); font-size: var(--fs-small); }
.topbar .crumb b { color: var(--text); font-weight: 500; }
.topbar .spacer { flex: 1; }
.canvas { padding: var(--pad); overflow: auto; min-width: 0; }

/* ---------- 4. صف العنوان والمرشّحات ---------- */
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.title-row h1 { font-size: var(--fs-title); line-height: 1.2; font-weight: 600; letter-spacing: -0.01em; }
.title-row .sub { margin-top: 4px; color: var(--muted); font-size: var(--fs-small); }
.title-actions { display: flex; align-items: center; gap: 8px; }

.filters { display: flex; align-items: center; gap: 8px; margin-bottom: var(--gap); flex-wrap: wrap; }
.filters .spacer { flex: 1; }
.stamp { color: var(--faint); font-size: var(--fs-small); }

/* ---------- 5. اللوحات والشبكة ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); }
.grid.top { align-items: start; }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: var(--card-pad); min-width: 0;
}
.panel > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel h2 { font-size: var(--fs-section); line-height: 1.3; font-weight: 600; }
.panel .meta { color: var(--faint); font-size: var(--fs-small); }

.chart-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.chart-head h3 { font-size: var(--fs-body); line-height: 20px; font-weight: 500; }
.chart { position: relative; min-width: 0; }

.card-link {
  display: inline-flex; align-items: center; gap: 2px; padding: 0; border: 0;
  background: none; color: var(--text); font-weight: 500; cursor: pointer;
  text-underline-offset: 3px; font-size: var(--fs-small);
}
.card-link:hover { text-decoration: underline; }

/* ---------- 6. صفوف القوائم ---------- */
.rows { display: grid; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 0;
  border: 0; background: none; width: 100%; text-align: right; cursor: pointer;
  transition: background-color var(--t-hover) ease;
}
.row + .row { border-top: 1px solid var(--rule); border-radius: 0; }
.row:hover { background: var(--raised); }
.row:first-child { border-radius: var(--radius-card) var(--radius-card) 0 0; }
.row:last-child { border-radius: 0 0 var(--radius-card) var(--radius-card); }
.row .r-main { min-width: 0; flex: 1; }
.row .r-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r-sub { color: var(--muted); font-size: var(--fs-small); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.row .r-end { flex: none; display: flex; align-items: center; gap: 10px; }
.r-when { color: var(--faint); font-size: var(--fs-small); white-space: nowrap; }

/* ---------- 7. الجداول ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  height: 36px; padding: 0 12px; text-align: right; font-weight: 400;
  font-size: var(--fs-small); color: var(--muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: calc((var(--row-height) - 22px) / 2) 12px; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background-color var(--t-hover) ease; cursor: pointer; }
tbody tr:hover td { background: var(--raised); }
tbody tr[aria-selected="true"] td { background: var(--active); }
th.n, td.n { text-align: left; font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: var(--fs-small); color: var(--muted); margin-top: 2px; }
.truncate { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 8. الشارات ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 11px; font-weight: 500;
  background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap;
  flex: none;
}
.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }

/* ---------- 9. أدوات التحكم ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control-height); padding: 0 12px;
  border-radius: var(--radius-control); border: 1px solid var(--control);
  background: var(--surface); font-weight: 500; cursor: pointer; font-size: var(--fs-body);
  transition: background-color var(--t-hover) ease, transform var(--t-press) var(--ease-out);
}
.btn:hover { background: var(--raised); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { background: var(--text); filter: brightness(0.92); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--raised); }
.btn.sm { height: 28px; padding: 0 10px; font-size: var(--fs-small); }

.field { display: grid; gap: 8px; }
.field label { font-weight: 500; font-size: var(--fs-body); }
.field .hint { color: var(--muted); font-size: var(--fs-small); }
.input, select.input, textarea.input {
  height: 38px; padding: 0 12px; border: 1px solid var(--control);
  border-radius: var(--radius-control); background: var(--surface); width: 100%;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.7; }
.input::placeholder { color: var(--faint); }
select.input { cursor: pointer; }

.search { position: relative; }
.search input { padding-inline-start: 34px; }
.search svg { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); pointer-events: none; }

.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); margin-bottom: var(--gap); }
.tabs button { position: relative; padding: 10px 0; color: var(--muted); background: none; border: 0; cursor: pointer; font-size: var(--fs-body); transition: color var(--t-hover) ease; }
.tabs button[aria-selected="true"] { color: var(--text); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: 0; bottom: -1px; height: 2px; background: var(--text); }

.segmented { display: inline-flex; width: max-content; max-width: 100%; padding: 2px; border-radius: 8px; background: var(--raised); }
.segmented button { height: 28px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: var(--fs-small); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); }

.switch { appearance: none; width: 32px; height: 20px; border-radius: 999px; background: var(--control); position: relative; cursor: pointer; transition: background-color var(--t-ui) ease; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: transform var(--t-ui) var(--ease-out); }
.switch:checked { background: var(--text); }
.switch:checked::after { transform: translateX(-12px); }
html[dir="ltr"] .switch:checked::after { transform: translateX(12px); }

/* ---------- 10. الحالات الفارغة ---------- */
.empty { display: grid; place-items: center; min-height: 96px; padding: 16px; border: 1px dashed var(--control); border-radius: var(--radius-control); color: var(--muted); text-align: center; }
.skeleton { background: var(--raised); border-radius: 4px; }
.rows .empty, .grid > .empty, li > .empty { grid-column: 1 / -1; width: 100%; }

/* ---------- 11. قائمة الخطابات (المعرض) ---------- */
.tpl-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.tpl {
  display: grid; gap: 6px; text-align: right; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--surface); cursor: pointer;
  transition: border-color var(--t-hover) ease, transform var(--t-press) var(--ease-out);
}
.tpl:hover { border-color: var(--control); }
.tpl:active { transform: translateY(1px); }
.tpl b { font-size: var(--fs-body); font-weight: 600; }
.tpl small { color: var(--muted); font-size: var(--fs-small); line-height: 1.7; font-weight: 400; }
.tpl .tag { justify-self: start; background: var(--raised); color: var(--muted); border-radius: 999px; padding: 1px 9px; font-size: 11px; font-weight: 500; }
.tpl[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- 12. الوحدات المميّزة (signature) ---------- */
/* شريط أنواع المستندات: الصف يُوزَّع على الأنواع، والنوع المختار يحمل خطاً سفلياً 2px */
.kind-strip { display: flex; gap: 28px; border-bottom: 1px solid var(--border); }
.kind-strip .ks {
  position: relative; padding: 10px 0 12px; background: none; border: 0; cursor: pointer;
  text-align: right; color: var(--muted); transition: color var(--t-hover) ease;
}
.kind-strip .ks:hover { color: var(--text); }
.kind-strip .ks[aria-selected="true"] { color: var(--text); }
.kind-strip .ks[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: 0; bottom: -1px; height: 2px; background: var(--accent); }
.kind-strip .ks .kv { display: block; font-size: var(--fs-kpi); font-weight: 400; line-height: 1.15; letter-spacing: -0.01em; margin-top: 2px; }
.kind-strip .ks .kv small { font-size: 0.5em; color: var(--muted); }
.kind-strip .ks .kl { font-size: var(--fs-small); }

/* شريط KPI: حاوية واحدة مقسومة بخطوط 1px */
.kpis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.kpi { padding: 16px var(--card-pad); }
.kpi + .kpi { border-inline-start: 1px solid var(--border); }
.kpi-label { color: var(--muted); font-size: var(--fs-small); }
.kpi-value { margin-top: 6px; font-size: var(--fs-kpi); line-height: 1.15; font-weight: 400; letter-spacing: -0.01em; }
.kpi-value small { font-size: 0.55em; color: var(--muted); font-weight: 400; margin-inline-start: 4px; }
.kpi .delta { margin-top: 4px; font-size: var(--fs-small); color: var(--muted); }

/* ---------- 13. الحالة: مرشّح النوع على شكل شرائح، والجدول ---------- */
.listbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.listbar .spacer { flex: 1; }

/* ---------- 14. الاستجابة ---------- */
.menu-toggle { display: none; }
.backdrop { display: none; }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .frame {
    position: fixed; inset: 0; z-index: 30; width: 280px; max-width: 84vw;
    transform: translateX(100%); transition: transform var(--t-ui) var(--ease-out);
    border-inline-start: 1px solid var(--border);
  }
  .frame.open { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(20,16,10,.38); opacity: 0; pointer-events: none; transition: opacity var(--t-ui) ease; }
  .backdrop.open { opacity: 1; pointer-events: auto; }
  .sheet { margin: var(--sheet-inset); }
  .menu-toggle { display: inline-flex; }
  .canvas { padding: 16px; }
  .grid > * { grid-column: 1 / -1 !important; }
  .kpis { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi + .kpi { border-inline-start: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--border); }
  .kpi:nth-child(2n) { border-inline-start: 1px solid var(--border); }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .title-row { align-items: flex-start; }
  .kind-strip { overflow-x: auto; }
  .segmented { display: flex; width: 100%; }
  .segmented button { flex: 1; }
}
@media (max-width: 480px) {
  .canvas { padding: 12px; }
  .panel { padding: 16px; }
  .row .r-end .r-when { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation: none !important; }
}

/* ---------- 15. الحركة: تغذية راجعة فقط (لا مداخل على شاشات التطبيق) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .row, .tpl, tbody tr, .nav-item { will-change: background-color; }
}

/* ============================================================
   16. الشعار
   العلامة: «م» مرسومة كقلم/مِحبر — تجريد للأرشيف القانوني:
   قوس الحبر مغلق بإطار الورقة. تعمل بحجم ٣٠px وبـfavicon.
   ============================================================ */
.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: "Amiri", Georgia, "Times New Roman", serif;
  font-weight: 700; font-size: 22px;
  line-height: 1; padding-bottom: 5px;
}
.brand-mark svg { width: 24px; height: 24px; display: block; }

/* ---------- 17. صفحة الدخول ---------- */
.login {
  position: fixed; inset: 0; z-index: 60; overflow: auto;
  background: var(--ground);
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-ui) ease;
}
.login.open { opacity: 1; pointer-events: auto; }
.login[hidden] { display: none; }

/* اليمين (في RTL): هوية + شعار كبير + شريط مزايا */
.login-brand {
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px 56px; position: relative; overflow: hidden;
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
}
.login-brand::before {
  content: ""; position: absolute; inset-inline-end: -120px; inset-block-start: -120px;
  width: 380px; height: 380px; border-radius: 50%;
  background: var(--accent); opacity: .07;
}
.login-brand::after {
  content: ""; position: absolute; inset-inline-start: -80px; inset-block-end: -140px;
  width: 300px; height: 300px; border-radius: 50%;
  background: var(--accent); opacity: .05;
}
.login-lockup { display: flex; align-items: center; gap: 14px; position: relative; }
.login-lockup .brand-mark { width: 46px; height: 46px; border-radius: 13px; font-size: 24px; }
.login-lockup .brand-mark svg { width: 32px; height: 32px; }
.login-lockup .nm { font-size: 20px; font-weight: 600; line-height: 1.1; }
.login-lockup .sc { font-size: 12px; color: var(--muted); margin-top: 2px; }

.login-pitch { position: relative; max-width: 40ch; }
.login-pitch h2 { font-size: 30px; line-height: 1.35; font-weight: 600; letter-spacing: -0.01em; }
.login-pitch p { margin-top: 14px; color: var(--muted); line-height: 1.95; font-size: 14px; }
.login-feats { margin-top: 32px; display: grid; gap: 12px; position: relative; }
.login-feats li { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.login-feats .tick {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  background: var(--pill-positive-bg); color: var(--pill-positive-ink);
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
}
.login-foot { color: var(--faint); font-size: 12px; position: relative; }

/* اليسار: النموذج في بطاقة */
.login-form-wrap {
  display: grid; place-items: center; padding: 40px 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px;
}
.login-card h1 { font-size: 21px; font-weight: 600; }
.login-card .sub { margin-top: 6px; color: var(--muted); font-size: 13px; }
.login-form { margin-top: 26px; display: grid; gap: 16px; }
.login-form .field label { font-size: 13px; }
.login-form .input { height: 42px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-inline-end: 42px; }
.pw-toggle {
  position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.pw-toggle:hover { background: var(--raised); color: var(--text); }
.login-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.login-row label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; cursor: pointer; }
.login-row a { color: var(--accent); font-weight: 500; font-size: 13px; }
.login-row a:hover { text-decoration: underline; }
.btn.block { width: 100%; height: 42px; }
.login-err {
  display: none; gap: 8px; align-items: center;
  background: var(--pill-negative-bg); color: var(--pill-negative-ink);
  border-radius: 8px; padding: 10px 12px; font-size: 13px;
}
.login-err.show { display: flex; }
.login-sep { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 12px; }
.login-sep::before, .login-sep::after { content: ""; height: 1px; background: var(--rule); flex: 1; }
.login-alt { display: grid; gap: 10px; }
.login-hint {
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule);
  color: var(--faint); font-size: 12px; line-height: 1.9;
}
.login-hint b { color: var(--muted); font-weight: 500; }
.login-theme {
  position: absolute; inset-inline-start: 20px; inset-block-start: 20px; z-index: 2;
}

@media (max-width: 900px) {
  .login { grid-template-columns: minmax(0, 1fr); }
  .login-brand { display: none; }
  .login-form-wrap { min-height: 100svh; }
}
@media (max-width: 480px) {
  .login-card { padding: 24px; border: 0; background: transparent; }
  .login-form-wrap { place-items: start center; padding-top: 56px; }
}

/* ============================================================
   18. معاينة الخطاب — ورقة A4 مُصغّرة داخل اللوحة
   الورقة بيضاء دائماً (كالطباعة)، والمقياس يُصغّر بالـzoom لا بالخط.
   ============================================================ */
.preview-sheet {
  background: #ffffff;
  color: #2a2723;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 30px 30px 34px;
  box-shadow: 0 1px 2px rgba(20,16,10,.05);
  direction: rtl;
  text-align: right;
  font-size: 13.5px;
  line-height: 2.05;
}
.preview-sheet .pc p { margin: 0 0 10px; }
.preview-sheet .basmala {
  text-align: center; font-weight: 600; font-size: 14.5px;
  margin-bottom: 22px !important; color: #2a2723;
}
.preview-sheet .toPrince { margin-bottom: 2px !important; }
.preview-sheet .princeName { font-weight: 600; margin-bottom: 18px !important; }
.preview-sheet .greet { margin-bottom: 18px !important; }
.preview-sheet .subj {
  font-weight: 600; margin-bottom: 16px !important;
  border-bottom: 0.5px solid #ece7dc; padding-bottom: 10px;
}
.preview-sheet .lead { text-align: justify; }
.preview-sheet .reasonHead { font-weight: 500; margin-top: 4px !important; }
.preview-sheet .reasonList {
  margin: 0 0 12px !important; padding-inline-start: 20px !important;
  list-style: disc !important;
}
.preview-sheet .reasonList li { margin-bottom: 4px; text-align: justify; }
.preview-sheet .sig { margin-top: 26px !important; font-weight: 500; }
.preview-sheet .sigName { margin-top: 6px !important; color: #6b6559; }
.preview-sheet .mono {
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
  background: #f3efe7; border-radius: 4px; padding: 0 5px; font-size: .92em;
}

/* بطاقة القالب المختارة */
.tpl[aria-pressed="true"], .tpl.selected { border-color: var(--accent); }
.tpl-grid { position: relative; }

/* ============================================================
   19. مستند الخطاب — A4 رسمي جاهز للطباعة/التصدير
   هذا هو «القالب الذي يُصدَّر PDF»: مقاس حقيقي 210×297mm.
   لا يتأثر بالسمة: أبيض دائماً، كالورق الرسمي.
   ============================================================ */
.letter-doc {
  /* ورقة A4 حقيقية: العرض والارتفاع مثبّتان، والمحتوى يجب أن يدخل داخلهما */
  width: 210mm;
  height: 297mm;
  padding: 15mm 18mm 12mm;
  background: #ffffff;
  color: #1a1a1a;
  direction: rtl; text-align: right;
  font-family: "IBM Plex Sans Arabic", "Segoe UI", sans-serif;
  font-size: 11.5pt;
  line-height: 1.75;
  box-sizing: border-box;
  overflow: hidden;
  display: flex; flex-direction: column;
}

/* ============================================================
   رأس المستند وتذييله — بنية واحدة خفيفة وأنيقة.
   خط شعري واحد (0.75px) أعلى وأسفل، بلا خطوط مزدوجة ولا خلفيات.
   الرأس والتذييل يتقاسمان الشبكة نفسها (شعار · نص · بيان) فيبدوان وحدة.
   ============================================================ */
.letter-doc .doc-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center; gap: 10px;
  padding-bottom: 7px; margin-bottom: 13px;
  border-bottom: 0.5px solid #ddd8cc;
  flex: none;
}
.letter-doc .doc-head .mk {
  width: 30px; height: 30px; flex: none; border-radius: 7px;
  background: #2563a8; color: #fff;
  display: grid; place-items: center;
  font-family: "Amiri", Georgia, "Times New Roman", serif;
  font-weight: 700; font-size: 19px; line-height: 1; padding-bottom: 3px;
}
.letter-doc .doc-head .ttl { font-size: 13pt; font-weight: 600; line-height: 1.25; letter-spacing: -0.1px; }
.letter-doc .doc-head .ttl small {
  display: block; font-size: 8.5pt; font-weight: 400;
  color: #7a746a; margin-top: 1px; letter-spacing: 0;
}
.letter-doc .doc-head .meta {
  text-align: left; font-size: 8.5pt; color: #7a746a; line-height: 1.6;
}
.letter-doc .doc-head .meta .mono { font-family: var(--font-num); color: #43403a; }

/* البسملة */
.letter-doc .basmala {
  text-align: center; font-size: 14pt; font-weight: 600;
  margin: 14px 0 16px;
}

/* المخاطبة */
.letter-doc .toPrince { font-size: 12.5pt; margin-bottom: 2px; }
.letter-doc .princeName { font-size: 13pt; font-weight: 600; margin-bottom: 10px; }
.letter-doc .greet { margin-bottom: 10px; }

/* الموضوع: سطر مميّز — مسطرة رقيقة لا صندوق مصبوغ */
.letter-doc .subj {
  font-weight: 600; font-size: 12pt;
  margin: 0 0 12px;
  padding: 0 0 6px;
  border-bottom: 0.5px solid #e6e1d6;
}

/* متن الخطاب: مضبوط الطرفين */
.letter-doc p { margin: 0 0 9px; text-align: justify; }
.letter-doc .lead { text-indent: 0; }
.letter-doc .reasonHead { font-weight: 500; margin-top: 4px; }
.letter-doc .reasonList {
  margin: 0 0 10px !important; padding-inline-start: 22px !important;
  list-style: disc !important;
}
.letter-doc .reasonList li { margin-bottom: 3px; text-align: justify; }
.letter-doc .reasonDet { color: #444; font-size: 10.5pt; }

/* فقرة البيانات — مساطر أفقية رقيقة فقط، بلا إطار ولا خلفيات */
.letter-doc .facts {
  margin: 0 0 12px;
  border-top: 0.5px solid #e6e1d6;
  border-bottom: 0.5px solid #e6e1d6;
}
.letter-doc .facts .frow {
  display: grid; grid-template-columns: 40mm 1fr;
  border-bottom: 0.5px solid #f0ece2;
}
.letter-doc .facts .frow:last-child { border-bottom: 0; }
.letter-doc .facts .fk {
  padding: 5px 0 5px 10px; background: none;
  font-size: 10pt; color: #7a746a;
}
.letter-doc .facts .fv { padding: 5px 10px 5px 0; font-size: 10.5pt; }
.letter-doc .facts .fv.mono { font-family: var(--font-num); }

/* الخاتمة والتوقيع */
.letter-doc .sig { margin-top: 16px; font-weight: 500; }
.letter-doc .dua { margin-top: 2px; color: #43403a; }
.letter-doc .signBlock {
  margin-top: 22px;
  display: flex; justify-content: flex-start; gap: 50px;
}
.letter-doc .signBlock .col { min-width: 55mm; }
.letter-doc .signBlock .role { font-size: 10.5pt; color: #555; margin-bottom: 3px; }
.letter-doc .signBlock .nm { font-weight: 600; font-size: 12pt; }
.letter-doc .signBlock .line {
  margin-top: 16px; border-top: 0.5px solid #c9c3b6; padding-top: 4px;
  font-size: 9.5pt; color: #7a746a;
}
.letter-doc .doc-foot {
  margin-top: auto; padding-top: 6px;
  border-top: 0.5px solid #ddd8cc;
  font-size: 8pt; color: #8d877c;
  display: grid; grid-template-columns: 1fr auto;
  align-items: center; gap: 10px;
  flex: none; letter-spacing: 0.1px;
}
.letter-doc .doc-foot .mono { font-family: var(--font-num); color: #6f695c; }

/* جدول البنود داخل المستند — مساطر رقيقة بلا إطار */
.letter-doc .calc-table {
  width: 100%; border-collapse: collapse; margin-top: 4px;
}
.letter-doc .calc-table th {
  height: auto; padding: 7px 0; text-align: right;
  color: #7a746a; font-weight: 500; font-size: 10pt;
  border-bottom: 0.5px solid #ddd8cc;
}
.letter-doc .calc-table td {
  padding: 7px 0; border-bottom: 0.5px solid #f0ece2; font-size: 11pt;
}
.letter-doc .calc-table .n { text-align: left; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.letter-doc .calc-table tr:last-child td { border-bottom: 0; }
.letter-doc .calc-table .tot td {
  font-weight: 600; font-size: 11.5pt;
  border-top: 0.5px solid #ddd8cc; border-bottom: 0; padding-top: 9px;
}

/* شريط أدوات التصدير داخل اللوحة */
.export-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 14px 20px; border-top: 1px solid var(--rule);
}
.export-bar .note { color: var(--faint); font-size: 12px; margin-inline-start: auto; }

/* ---- مقاس الورقة على الشاشة (معاينة مُصغّرة) ---- */
.sheet-stage {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 22px;
  overflow: auto;
}
.sheet-stage .letter-doc {
  margin: 0 auto;
  border-radius: 3px;
  box-shadow: 0 2px 10px rgba(20,16,10,.10);
  /* نُصغّر بالـzoom لا بالخط حتى تبقى النسب */
  zoom: 0.62;
}
@media (max-width: 900px) { .sheet-stage .letter-doc { zoom: 0.42; } }
@media (max-width: 600px) { .sheet-stage .letter-doc { zoom: 0.30; } }

/* ---- نافذة معاينة المستند: بديل حقيقي عن التنبيهات ---- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--text) 42%, transparent);
  padding: 24px;
  opacity: 0; visibility: hidden;
  transition: opacity var(--t-hover) ease, visibility var(--t-hover);
}
.modal.open { opacity: 1; visibility: visible; }
.modal-box {
  width: min(920px, 100%); max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 18px 50px rgba(20, 16, 10, .26);
  overflow: hidden;
  transform: translateY(8px);
  transition: transform var(--t-hover) var(--ease-out);
}
.modal.open .modal-box { transform: none; }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--rule); flex: none;
}
.modal-head h2 { font-size: var(--fs-title); font-weight: 600; margin: 0; }
.modal-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.modal-head .x {
  margin-inline-start: auto; flex: none;
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.modal-head .x:hover { border-color: var(--control); color: var(--text); }
.modal-body { padding: 18px; overflow: auto; background: var(--ground); }
.modal-foot {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 14px 20px; border-top: 1px solid var(--rule); flex: none;
}
.modal-foot .note { color: var(--faint); font-size: 12px; margin-inline-start: auto; }
@media (max-width: 700px) { .modal { padding: 12px; } .modal-body { padding: 12px; } }

/* حاوية التصدير المخفية: مقاس ١:١ حقيقي — لا تُطبع ولا تُرى */
#pdfBox {
  position: fixed; inset-inline-start: -10000px; top: 0;
  width: 794px; background: #fff; z-index: -1;
  pointer-events: none;
}
#pdfBox .letter-doc { zoom: 1; }

/* ============================================================
   محرر اللائحة — أقسام، صفوف متكررة، وفهرس جانبي
   ============================================================ */

/* شريط توجيه علوي: أي مرحلة أنت فيها */
.editor-steps {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-bottom: var(--gap);
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--surface);
}
.editor-steps button {
  display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 12px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: var(--fs-small); font-family: inherit;
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.editor-steps button:hover { background: var(--raised); color: var(--text); }
.editor-steps button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.editor-steps .n {
  display: grid; place-items: center; width: 17px; height: 17px; flex: none;
  border-radius: 50%; background: currentColor; opacity: .25;
}
.editor-steps button[aria-pressed="true"] .n { opacity: .32; }
.editor-steps .n b { font-size: 10px; color: var(--text); font-weight: 600; }
.editor-steps button[aria-pressed="true"] .n b { color: #fff; }
.editor-steps .sepc { color: var(--faint); font-size: 12px; }

/* قسم تحرير واحد */
.ed-sec { display: grid; gap: 14px; }
.ed-sec + .ed-sec { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--rule); }
.ed-sec > header { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ed-sec > header h3 { font-size: 13px; font-weight: 600; margin: 0; }
.ed-sec > header .meta { color: var(--faint); font-size: var(--fs-small); font-weight: 400; }
.ed-sec .two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* صف قابل للتكرار (وقائع، أسانيد، طلبات) */
.ed-row { display: flex; gap: 8px; align-items: flex-start; }
.ed-row .idx {
  flex: none; width: 22px; height: 22px; margin-top: 9px;
  display: grid; place-items: center; border-radius: 50%;
  background: var(--raised); color: var(--muted);
  font-size: 11px; font-family: var(--font-num); font-variant-numeric: tabular-nums;
}
.ed-row .grow { flex: 1; min-width: 0; }
.ed-row .del {
  flex: none; width: 30px; height: 30px; margin-top: 5px;
  display: grid; place-items: center;
  border: 1px solid var(--control); border-radius: var(--radius-control);
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: color var(--t-hover) ease, border-color var(--t-hover) ease;
}
.ed-row .del:hover { color: var(--danger, #b4232a); border-color: var(--danger, #b4232a); }
.ed-row .del[disabled] { opacity: .35; cursor: not-allowed; }

/* رقائق الاختيار (أسباب الاسترحام) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--control); background: var(--surface);
  color: var(--muted); cursor: pointer;
  font-size: var(--fs-small); font-family: inherit;
  transition: color var(--t-hover) ease, border-color var(--t-hover) ease,
              background-color var(--t-hover) ease;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.on {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-color: var(--accent); color: var(--accent); font-weight: 500;
}
.ed-add {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border: 1px dashed var(--control); border-radius: var(--radius-control);
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: var(--fs-small); font-family: inherit;
  transition: color var(--t-hover) ease, border-color var(--t-hover) ease;
}
.ed-add:hover { color: var(--accent); border-color: var(--accent); }

/* الفاصل بين الطلبات الأصلية والاحتياطية */
.ed-break {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: var(--fs-small);
}
.ed-break::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.ed-break .tag {
  border: 1px solid var(--accent); color: var(--accent);
  border-radius: 999px; padding: 1px 9px; font-size: 11px;
}
.ed-break .tag + .tag { border-color: var(--control); color: var(--muted); }

/* فهرس المعاينة: بنود المستند، للتنقّل السريع */
.prev-index {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 20px 16px;
}
.prev-index button {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 11px; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 11px; font-family: inherit;
  transition: color var(--t-hover) ease, border-color var(--t-hover) ease;
}
.prev-index button:hover { color: var(--accent); border-color: var(--accent); }

/* عدّاد الأحرف أسفل المتن */
.count { color: var(--faint); font-size: 11px; font-family: var(--font-num); }

/* الجدول القانوني المختصر أعلى المحرر */
.kpi.inline { display: flex; align-items: baseline; gap: 8px; }

/* ============================================================
   مستند اللائحة — غلاف + أقسام مرقّمة (A4 حقيقي، متعدد الصفحات)
   ============================================================ */

/* الغلاف: يأخذ الشاشة كاملة، ويُطبع في أول صفحة ثم تبدأ اللائحة */
.letter-doc.cover {
  height: auto; min-height: 0;
  padding-top: 34mm; padding-bottom: 22mm;
}
.letter-doc.cover .cov-rule { height: 2px; background: #1a1a1a; margin: 0 0 22px; }
.letter-doc.cover .cov-kicker {
  font-size: 11pt; color: #2563a8; font-weight: 600;
  letter-spacing: .02em; margin-bottom: 10px;
}
.letter-doc.cover .cov-title {
  font-size: 27pt; font-weight: 600; line-height: 1.35; margin: 0 0 8px;
}
.letter-doc.cover .cov-sub {
  font-size: 14pt; color: #555; margin: 0 0 34px; line-height: 1.7;
}
.letter-doc.cover .cov-parties {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin-bottom: 26px;
}
.letter-doc.cover .cov-party {
  border: 1px solid #dcdcdc; border-radius: 6px; padding: 13px 15px;
}
.letter-doc.cover .cov-party .lab {
  color: #2563a8; font-size: 9.5pt; font-weight: 600;
  margin-bottom: 5px; text-transform: none;
}
.letter-doc.cover .cov-party .val { font-size: 12pt; font-weight: 600; line-height: 1.5; }
.letter-doc.cover .cov-party .sub { color: #666; font-size: 9.5pt; margin-top: 3px; }
.letter-doc.cover .cov-meta {
  display: grid; grid-template-columns: repeat(3, auto);
  justify-content: space-between; gap: 18px;
  border-top: 1px solid #e2e2e2; padding-top: 16px;
}
.letter-doc.cover .cov-meta .k { color: #888; font-size: 9pt; margin-bottom: 3px; }
.letter-doc.cover .cov-meta .v { font-size: 12pt; font-weight: 600; }
.letter-doc.cover .cov-meta .v.mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.letter-doc.cover .cov-amount {
  margin-top: 26px; padding: 14px 18px;
  background: #f4f6f9; border-inline-start: 3px solid #2563a8; border-radius: 4px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
}
.letter-doc.cover .cov-amount .k { font-size: 11pt; color: #555; }
.letter-doc.cover .cov-amount .v {
  font-size: 19pt; font-weight: 600;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
}

/* نصوص الغلاف بالكامل — بلا فهرس غلاف */
.letter-doc.cover .doc-foot { margin-top: 30px; }

/* قسم مرقّم داخل اللائحة */
.letter-doc .sec { margin-top: 18px; }
.letter-doc .sec:first-of-type { margin-top: 4px; }
/* قسم مُكمَّل من الورقة السابقة: ترويسة «تابع» أوضح */
.letter-doc .sec.cont { margin-top: 0; }
.letter-doc .sec.cont .sec-head { border-bottom-style: dashed; }
.letter-doc .sec.cont .sec-head .meta {
  color: #2563a8; font-weight: 600;
}
.letter-doc .sec-head {
  display: flex; align-items: baseline; gap: 9px;
  border-bottom: 0.5px solid #e6e1d6;
  padding-bottom: 5px; margin-bottom: 9px;
}
.letter-doc .sec-head .no {
  flex: none; width: 18px; height: 18px;
  display: grid; place-items: center; border-radius: 4px;
  background: #2563a8; color: #fff;
  font-size: 9pt; font-weight: 600;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
}
.letter-doc .sec-head h4 { margin: 0; font-size: 12.5pt; font-weight: 600; letter-spacing: -0.1px; }
.letter-doc .sec-head .meta { color: #8d877c; font-size: 8.5pt; font-weight: 400; margin-inline-start: auto; }

/* قائمة الوقائع والأسانيد */
.letter-doc ol.numList, .letter-doc ul.dotList {
  margin: 0 !important; padding-inline-start: 26px !important;
}
.letter-doc ol.numList { list-style: decimal !important; }
.letter-doc ul.dotList { list-style: disc !important; }
.letter-doc ol.numList > li, .letter-doc ul.dotList > li {
  margin-bottom: 7px; text-align: justify;
  padding-inline-start: 3px;
}
.letter-doc ol.numList > li::marker { font-family: var(--font-num); color: #2563a8; font-weight: 600; }
.letter-doc ul.dotList > li::marker { color: #2563a8; }

/* جدول الطلبات — مساطر رقيقة بلا إطار */
.letter-doc .req-table {
  width: 100%; border-collapse: collapse; margin-top: 2px;
}
.letter-doc .req-table th {
  padding: 6px 0; text-align: right; background: none;
  color: #7a746a; font-weight: 500; font-size: 10pt;
  border-bottom: 0.5px solid #ddd8cc;
}
.letter-doc .req-table td {
  padding: 7px 0; border-bottom: 0.5px solid #f0ece2;
  font-size: 11pt; vertical-align: top;
}
.letter-doc .req-table tr:last-child td { border-bottom: 0; }
.letter-doc .req-table .no {
  width: 30px; text-align: center; color: #2563a8; font-weight: 600;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
}
.letter-doc .req-table tr.reserve td { color: #5d5749; font-style: italic; }
.letter-doc .req-table tr.reserve .no { color: #8d877c; }

/* إمضاء داخل اللائحة */
.letter-doc .seal { margin-top: 22px; font-size: 11pt; }
.letter-doc .seal .lead { color: #7a746a; font-size: 10pt; }
.letter-doc .seal .line { margin-top: 24px; border-top: 0.5px solid #c9c3b6; width: 62mm; }
.letter-doc .seal .who { font-size: 9.5pt; color: #5d5749; padding-top: 4px; }

/* ============================================================
   مستند العقد — امتداد للغة الورقة نفسها، بلا زخرفة
   ============================================================ */
.letter-doc.contract { font-size: 11pt; line-height: 1.68; }

/* بطاقة عنوان العقد على الصفحة الأولى */
.letter-doc .ct-cover { text-align: center; margin: 6mm 0 9mm; }
.letter-doc .ct-cover .ct-kicker {
  font-size: 8.5pt; letter-spacing: 3px; color: #7a746a; margin-bottom: 7px;
}
.letter-doc .ct-cover .ct-title {
  font-family: "Amiri", Georgia, serif; font-weight: 700;
  font-size: 26pt; line-height: 1.15; margin: 0 0 5px; color: #2563a8;
}
.letter-doc .ct-cover .ct-sub { font-size: 11.5pt; color: #43403a; margin-bottom: 9px; }
.letter-doc .ct-cover .ct-meta {
  display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 18px;
  font-size: 9pt; color: #7a746a;
  border-top: 0.5px solid #e6e1d6; border-bottom: 0.5px solid #e6e1d6;
  padding: 6px 0;
}
.letter-doc .ct-cover .ct-meta b { color: #43403a; font-weight: 600; }

/* بند العقد */
.letter-doc .ct-sec { margin-bottom: 11px; }
.letter-doc .ct-sec + .ct-sec { margin-top: 0; }
.letter-doc .ct-p { margin: 0 0 5px; text-align: justify; }
.letter-doc .ct-p:last-child { margin-bottom: 0; }
.letter-doc .ct-sec .calc-table { margin: 7px 0 3px; }
.letter-doc .ct-table th:first-child, .letter-doc .ct-table td:first-child { width: 34px; }
.letter-doc .ct-table .no {
  text-align: center; color: #2563a8; font-weight: 600;
  font-family: var(--font-num); font-variant-numeric: tabular-nums;
}

/* بلوك التوقيع */
.letter-doc .ct-sign { margin-top: 14px; }
.letter-doc .ct-sign-title {
  font-weight: 600; font-size: 12pt; margin-bottom: 5px;
  padding-bottom: 4px; border-bottom: 0.5px solid #ddd8cc;
}
.letter-doc .ct-sum {
  margin-top: 20px; padding-top: 7px; border-top: 0.5px solid #e6e1d6;
  font-size: 10pt; color: #5d5749;
}
.letter-doc .ct-sum b { color: #1a1a1a; }

/* ---- ملخّص العقد في اللوحة (واجهة، لا مستند) ---- */
.ct-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); padding: 1px 0; }
.ct-cell { background: var(--surface); padding: 12px 20px; display: grid; gap: 3px; }
.ct-cell span { font-size: var(--fs-small); color: var(--faint); }
.ct-cell b { font-size: 15px; font-weight: 600; color: var(--text); }
.edit-sub {
  font-size: var(--fs-small); font-weight: 600; color: var(--muted);
  padding-top: 4px; border-top: 1px solid var(--rule);
}
.ed-sec > .edit-sub:first-of-type { border-top: 0; padding-top: 0; }
.ct-stat .ct-stat-grid { margin: 0 -20px; }

/* حذف صف محفوظ من الأرشيف */
.row-del {
  margin-inline-start: 6px; width: 22px; height: 22px;
  display: inline-grid; place-items: center; vertical-align: middle;
  border: 1px solid var(--control); border-radius: 5px;
  background: transparent; color: var(--faint);
  cursor: pointer; font-size: 11px; font-family: inherit;
  transition: color var(--t-hover) ease, border-color var(--t-hover) ease;
}
.row-del:hover { color: var(--danger, #b4232a); border-color: var(--danger, #b4232a); }

/* ---- الطباعة ---- */
@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  /* كل واجهة التطبيق تختفي — يبقى مستند الورقة فقط */
  .frame, .topbar, .backdrop, .login, .export-bar, .title-row, .tabs,
  .prev-index, .editor-steps, .menu-toggle, #logoutBtn, #themeBtn, .toast, #pdfBox,
  .modal-head, .modal-foot
  { display: none !important; }
  /* المعاينة المفتوحة عند الطباعة: يبقى متنها وحده */
  .modal { position: static !important; background: none !important; padding: 0 !important; visibility: visible !important; opacity: 1 !important; }
  .modal-box { border: 0 !important; box-shadow: none !important; max-height: none !important; border-radius: 0 !important; }
  .modal-body { padding: 0 !important; overflow: visible !important; background: none !important; }
  .app { display: block !important; }
  .sheet { border: 0 !important; margin: 0 !important; border-radius: 0 !important; }
  .canvas { padding: 0 !important; overflow: visible !important; }
  .panel, .sheet-stage {
    border: 0 !important; box-shadow: none !important; padding: 0 !important;
    background: none !important; margin: 0 !important; border-radius: 0 !important;
  }
  .panel > header { display: none !important; }
  /* الصفحة: مقاس A4 بالضبط. لا تُقصّ، وكل ورقة تبدأ صفحة جديدة */
  .letter-doc {
    width: 210mm !important;
    box-shadow: none !important; zoom: 1 !important;
    margin: 0 !important; border-radius: 0 !important;
    break-inside: avoid; page-break-inside: avoid;
    break-before: page; page-break-before: always;
    min-height: 0 !important; height: auto !important;
  }
  .letter-doc:first-of-type { break-before: auto; page-break-before: auto; }
  /* الغلاف ليس ورقة كاملة: يُطبع في أول الصفحة ثم تبدأ صفحة العرض بعده */
  .letter-doc.cover { height: auto !important; min-height: 0 !important; }
  .letter-doc.cover + .letter-doc { break-before: page; page-break-before: always; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { overflow: visible !important; }
}

/* ---------- 20. التنبيه (toast) ---------- */
.toast {
  position: fixed; inset-block-end: 24px; inset-inline-start: 50%;
  transform: translate(50%, 20px);
  background: var(--text); color: var(--surface);
  padding: 11px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 500;
  box-shadow: 0 6px 24px rgba(20,16,10,.22);
  opacity: 0; pointer-events: none;
  transition: opacity var(--t-ui) ease, transform var(--t-ui) var(--ease-out);
  z-index: 80; max-width: min(90vw, 420px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(50%, 0); }
.toast.bad { background: var(--negative); color: #fff; }

