/* =====================================================================
   نظام توثيق الخطابات — شركة أوائل النخبة
   الهوية: كحلي وذهبي من الورق الرسمي، والخاتم المثمّن توقيعٌ بصري وحيد
   ===================================================================== */

:root {
  /* الهوية */
  --navy-950: #0C1A30;
  --navy-900: #112443;
  --navy-800: #16305A;
  --navy-700: #1E3A63;          /* كحلي الشعار */
  --navy-500: #3D5E8C;
  --navy-100: #E3E9F2;
  --navy-50:  #F1F4F9;
  --gold-500: #D8A34D;          /* ذهبي الشعار */
  --gold-400: #E4BC75;
  --gold-700: #8C6420;          /* ذهبي مقروء على الأبيض (5.1:1) */
  --gold-100: #F7ECD8;

  /* الأسطح */
  --ground: #F4F3EE;
  --surface: #FFFFFF;
  --surface-2: #FAF9F6;
  --line: #E2DFD6;
  --line-strong: #CFCABD;
  --ink: #17223A;
  --ink-2: #3E4A60;
  --muted: #5E687B;             /* 5.6:1 على الأبيض */

  /* الحالات */
  --ok: #1D6B47;      --ok-bg: #E6F2EB;
  --warn: #8A5A0B;    --warn-bg: #FBF0DB;
  --danger: #A3352B;  --danger-bg: #F9E8E6;
  --info: #1E3A63;    --info-bg: #E8EEF7;
  --idle: #555F70;    --idle-bg: #ECEEF2;

  /* المقاييس */
  --radius: 10px;
  --radius-sm: 7px;
  --rail-w: 268px;
  --shadow-1: 0 1px 2px rgba(17, 36, 67, .06), 0 2px 6px rgba(17, 36, 67, .05);
  --shadow-2: 0 6px 18px -6px rgba(17, 36, 67, .18), 0 2px 4px rgba(17, 36, 67, .06);
  --ease: cubic-bezier(.16, 1, .3, 1);

  --font-ui: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  --font-display: 'Reem Kufi', 'IBM Plex Sans Arabic', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;

  /* زخرفة هندسية (شبكة نجوم ثمانية) للشريط الجانبي */
  --girih: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23D8A34D' stroke-width='1'%3E%3Crect x='16' y='16' width='24' height='24'/%3E%3Crect x='16' y='16' width='24' height='24' transform='rotate(45 28 28)'/%3E%3Cpath d='M0 28h11M45 28h11M28 0v11M28 45v11'/%3E%3C/g%3E%3C/svg%3E");
}

[data-theme="dark"] {
  --ground: #0D1626;
  --surface: #142036;
  --surface-2: #18263F;
  --line: #24344F;
  --line-strong: #31446A;
  --ink: #E8ECF3;
  --ink-2: #C3CBD8;
  --muted: #9AA6BA;
  --navy-50: #18263F;
  --navy-100: #22355A;
  --gold-700: #E4BC75;
  --gold-100: #3A2F1C;
  --ok: #6FCB9C;      --ok-bg: #173527;
  --warn: #F0C46E;    --warn-bg: #3A2C12;
  --danger: #F08C80;  --danger-bg: #3D1D1B;
  --info: #9DB7E0;    --info-bg: #1C2C48;
  --idle: #AEB7C6;    --idle-bg: #222F45;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 8px 22px -8px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

/* ---------- أساسيات ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--ground);
  font-feature-settings: 'tnum' 1;
}
h1, h2, h3, h4 { color: var(--ink); line-height: 1.35; margin: 0; }
a { color: var(--navy-700); text-underline-offset: 3px; }
[data-theme="dark"] a { color: var(--gold-400); }
::selection { background: var(--gold-400); color: var(--navy-950); }
:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; border-radius: 4px; }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 3px solid var(--ground); }

.skip-link {
  position: absolute; inset-inline-start: 1rem; top: -3rem; z-index: 100;
  background: var(--gold-500); color: var(--navy-950); padding: .5rem 1rem; border-radius: var(--radius-sm);
  font-weight: 600; transition: top .2s var(--ease);
}
.skip-link:focus { top: 1rem; }

/* الخاتم المثمّن */
.khatam { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 5; stroke-linejoin: round; }

.docno {
  font-family: var(--font-mono); font-size: .86em; letter-spacing: .02em;
  color: var(--navy-700); background: var(--navy-50); border: 1px solid var(--navy-100);
  padding: .08rem .45rem; border-radius: 5px; white-space: nowrap; text-decoration: none;
  unicode-bidi: isolate;
}
a.docno:hover { border-color: var(--navy-500); }
[data-theme="dark"] .docno { color: var(--gold-400); }

/* ---------- الهيكل ---------- */
.shell { display: flex; min-height: 100vh; }
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; width: 100%; max-width: 1320px; margin-inline: auto; padding: 1.75rem 2rem 2.5rem; outline: none; }

/* الشريط الجانبي (يمين الشاشة في RTL) */
.rail {
  position: sticky; top: 0; height: 100vh; width: var(--rail-w); flex: 0 0 var(--rail-w);
  display: flex; flex-direction: column; gap: 1.1rem;
  padding: 1.25rem 1rem 1rem;
  color: #D9E0EC;
  background:
    var(--girih) 0 0 / 56px 56px,
    linear-gradient(180deg, var(--navy-800), var(--navy-950));
  background-blend-mode: soft-light, normal;
  border-inline-end: 1px solid rgba(216, 163, 77, .35);
  overflow-y: auto;
  z-index: 40;
}
.rail::before { /* إطفاء النقش في منتصف الشريط حتى تبقى القائمة واضحة */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, transparent 0, rgba(12, 26, 48, .78) 22%, rgba(12, 26, 48, .78) 78%, transparent 100%);
}
.rail > * { position: relative; }
.rail__brand { display: flex; align-items: center; gap: .75rem; padding: .25rem .25rem .9rem; border-bottom: 1px solid rgba(216, 163, 77, .28); }
.rail__emblem { width: 58px; height: auto; flex: none; }
.rail__names { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.rail__wordmark { width: 150px; height: auto; }
.rail__tag { font-size: .78rem; color: var(--gold-400); letter-spacing: .01em; }

.rail__cta {
  display: flex; align-items: center; justify-content: center; gap: .55rem;
  background: var(--gold-500); color: var(--navy-950) !important; font-weight: 700; text-decoration: none;
  padding: .7rem 1rem; border-radius: var(--radius-sm);
  box-shadow: 0 6px 14px -8px rgba(216, 163, 77, .9);
  transition: background .18s var(--ease), transform .18s var(--ease);
}
.rail__cta:hover { background: var(--gold-400); }
.rail__cta:active { transform: translateY(1px); }

.rail__nav { display: flex; flex-direction: column; gap: .15rem; }
.rail__group { margin: .9rem .75rem .3rem; font-size: .74rem; font-weight: 600; color: #8D9AB2; }
.rail__link {
  position: relative; display: flex; align-items: center; gap: .75rem;
  padding: .58rem .75rem; border-radius: var(--radius-sm);
  color: #D3DAE6 !important; text-decoration: none; font-weight: 500;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.rail__link i { width: 1.1rem; text-align: center; color: #93A3BF; transition: color .16s; }
.rail__link:hover { background: rgba(255, 255, 255, .06); color: #fff !important; }
.rail__link.is-active { background: rgba(216, 163, 77, .14); color: #fff !important; }
.rail__link.is-active i { color: var(--gold-400); }
.rail__mark { margin-inline-start: auto; color: var(--gold-500); font-size: .8rem; stroke-width: 7; }

.rail__foot { margin-top: auto; display: flex; align-items: center; gap: .5rem; padding-top: .9rem; border-top: 1px solid rgba(216, 163, 77, .22); }
.rail__user { flex: 1; min-width: 0; display: flex; align-items: center; gap: .6rem; text-decoration: none; color: #fff !important; padding: .35rem; border-radius: var(--radius-sm); }
.rail__user:hover, .rail__user.is-active { background: rgba(255, 255, 255, .06); }
.rail__user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.rail__user-text strong { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail__user-text small { color: #9AA8C0; font-size: .74rem; }
.rail__tools { display: flex; gap: .25rem; }
.rail__tools form { margin: 0; }
.rail .icon-btn { color: #C2CCDC; }
.rail .icon-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.avatar {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 50%; background: var(--gold-500); color: var(--navy-950); font-weight: 700;
}

.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink-2); cursor: pointer;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.icon-btn:hover { background: var(--navy-50); color: var(--ink); }
.theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-icon-dark { display: none; }

/* الشريط العلوي */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 2rem; background: color-mix(in srgb, var(--ground) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line);
}
.topbar__menu { display: none; }
.topbar__date { margin-inline-start: auto; color: var(--muted); font-size: .85rem; }
.quickfind {
  position: relative; flex: 0 1 520px; display: flex; align-items: center;
}
.quickfind > i { position: absolute; inset-inline-start: .9rem; color: var(--muted); font-size: .9rem; pointer-events: none; }
.quickfind input {
  width: 100%; height: 42px; padding-inline: 2.5rem 2.6rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
  font: inherit; transition: border-color .16s, box-shadow .16s;
}
.quickfind input::placeholder { color: var(--muted); }
.quickfind input:focus { outline: none; border-color: var(--navy-500); box-shadow: 0 0 0 3px rgba(61, 94, 140, .18); }
.quickfind kbd {
  position: absolute; inset-inline-end: .6rem; font: 500 .75rem var(--font-mono);
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .4rem;
}

.colophon {
  display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 1rem 2rem; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line);
}

/* ---------- ترويسة الصفحة ---------- */
.page-head {
  position: relative; display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding-bottom: 1rem; margin-bottom: 1.6rem;
}
.page-title { font-family: var(--font-display); font-weight: 600; font-size: 1.75rem; letter-spacing: 0; text-wrap: balance; }
.page-sub { margin: .15rem 0 0; color: var(--muted); }
.page-head__actions { display: flex; gap: .5rem; flex-wrap: wrap; }
/* خط ذهبي ينتهي بشريطين مائلين كحلي وذهبي كما في ترويسة الورق الرسمي */
.page-rule { position: absolute; inset-inline: 0; bottom: 0; height: 1px; background: linear-gradient(90deg, var(--gold-500) 0, rgba(216, 163, 77, .35) 100%); }
.page-rule i { position: absolute; bottom: -2px; width: 26px; height: 5px; transform: skewX(-35deg); inset-inline-start: 0; background: var(--gold-500); }
.page-rule i + i { inset-inline-start: 30px; background: var(--navy-700); }
[data-theme="dark"] .page-rule i + i { background: var(--navy-500); }

.section-title { font-size: 1rem; font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.section-title .khatam { color: var(--gold-500); font-size: .85rem; stroke-width: 7; }

/* ---------- الأسطح ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.panel__body { padding: 1.25rem; }
.panel__foot { padding: .85rem 1.25rem; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.panel + .panel { margin-top: 1.25rem; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.25rem; align-items: start; }
.grid-halves { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 1.25rem; }

/* شريط الأرقام (سجل) */
.ledger {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1);
  margin-bottom: 1.5rem; overflow: hidden;
}
.ledger__cell { padding: 1rem 1.25rem; text-decoration: none; color: inherit; border-inline-start: 1px solid var(--line); transition: background .16s; }
.ledger__cell:first-child { border-inline-start: 0; }
a.ledger__cell:hover { background: var(--surface-2); }
.ledger__label { display: flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .84rem; }
.ledger__value { display: block; font-size: 1.65rem; font-weight: 700; line-height: 1.2; margin-top: .25rem; color: var(--ink); }
.ledger__cell--lead { background: var(--navy-700); color: #fff; }
.ledger__cell--lead .ledger__label { color: var(--gold-400); }
.ledger__cell--lead .ledger__value { color: #fff; }
a.ledger__cell--lead:hover { background: var(--navy-800); }

/* ---------- الأزرار ---------- */
.btn { font-weight: 600; border-radius: var(--radius-sm); padding: .5rem 1rem; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; transition: background .16s var(--ease), border-color .16s, color .16s, box-shadow .16s; }
.btn-sm { padding: .3rem .7rem; font-size: .85rem; }
.btn-lg { padding: .7rem 1.4rem; font-size: 1rem; }
.btn-primary { --bs-btn-bg: var(--navy-700); --bs-btn-border-color: var(--navy-700); --bs-btn-hover-bg: var(--navy-800); --bs-btn-hover-border-color: var(--navy-800); --bs-btn-active-bg: var(--navy-900); --bs-btn-active-border-color: var(--navy-900); --bs-btn-disabled-bg: var(--navy-500); --bs-btn-disabled-border-color: var(--navy-500); color: #fff; }
.btn-gold { background: var(--gold-500); border: 1px solid var(--gold-500); color: var(--navy-950); }
.btn-gold:hover { background: var(--gold-400); border-color: var(--gold-400); color: var(--navy-950); }
.btn-outline { background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink); }
.btn-outline:hover { border-color: var(--navy-500); color: var(--navy-700); background: var(--surface); }
[data-theme="dark"] .btn-outline:hover { color: var(--gold-400); }
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--navy-50); color: var(--ink); }
.btn-ghost-danger { background: transparent; border: 1px solid transparent; color: var(--danger); }
.btn-ghost-danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn[aria-busy="true"] { pointer-events: none; opacity: .85; }
.btn .spinner { width: 1em; height: 1em; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- النماذج ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.1rem 1.25rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; min-width: 0; }
.form-label { font-weight: 600; font-size: .9rem; color: var(--ink-2); margin-bottom: .35rem; }
.req { color: var(--danger); margin-inline-start: .2rem; }
.form-control, .form-select {
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background-color: var(--surface); color: var(--ink);
  min-height: 42px; font: inherit; padding: .45rem .8rem;
}
.form-select { background-position: left .75rem center; padding-inline-end: 2.25rem; }
textarea.form-control { min-height: 96px; resize: vertical; }
.form-control::placeholder { color: var(--muted); opacity: 1; }
.form-control:focus, .form-select:focus { border-color: var(--navy-500); box-shadow: 0 0 0 3px rgba(61, 94, 140, .18); background-color: var(--surface); color: var(--ink); }
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--danger); background-image: none; padding-inline-end: .8rem; }
.invalid-feedback { color: var(--danger); font-size: .84rem; margin-top: .3rem; }
.form-hint { color: var(--muted); font-size: .82rem; margin-top: .3rem; }
input[type="date"].form-control { direction: rtl; }
[data-theme="dark"] .form-select { --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23C3CBD8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); }

.switch { display: inline-flex; align-items: center; gap: .65rem; cursor: pointer; user-select: none; font-weight: 500; }
.switch__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track { width: 40px; height: 22px; border-radius: 22px; background: var(--line-strong); position: relative; transition: background .18s var(--ease); flex: none; }
.switch__track::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: inset-inline-start .18s var(--ease); }
.switch__input:checked + .switch__track { background: var(--navy-700); }
.switch__input:checked + .switch__track::after { inset-inline-start: 21px; }
.switch__input:focus-visible + .switch__track { outline: 2px solid var(--gold-500); outline-offset: 2px; }

/* منطقة رفع الملف */
.dropzone {
  position: relative; display: flex; align-items: center; gap: 1rem;
  padding: 1.35rem; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-2);
  transition: border-color .16s, background .16s; cursor: pointer;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--navy-500); background: var(--navy-50); }
.dropzone.is-invalid { border-color: var(--danger); }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone__icon { width: 52px; height: 52px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--navy-700); color: var(--gold-400); font-size: 1.35rem; }
.dropzone__title { font-weight: 600; display: block; }
.dropzone__meta { color: var(--muted); font-size: .85rem; }
.dropzone.has-file .dropzone__icon { background: var(--ok); color: #fff; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; }
.register { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .92rem; }
.register thead th {
  position: sticky; top: 0; z-index: 1; text-align: start; font-weight: 600; font-size: .8rem; color: var(--muted);
  background: var(--surface-2); padding: .7rem 1rem; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.register td { padding: .78rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.register tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.register tbody tr { transition: background .12s; }
.register tbody tr:hover td { background: var(--navy-50); }
.register tbody tr:last-child td { border-bottom: 0; }
.register .num { text-align: left; font-variant-numeric: tabular-nums; } /* نهاية السطر في جدول RTL حتى مع dir="ltr" على الخلية */
.register .title-cell { font-weight: 600; color: var(--ink); }
.register .title-cell a { color: inherit; text-decoration: none; }
.register .title-cell a:hover { color: var(--navy-700); text-decoration: underline; }
.register .sub { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }
.register .actions { text-align: end; white-space: nowrap; }
.row-link { cursor: pointer; }

/* ---------- الحالات ---------- */
.status { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px; white-space: nowrap; }
.status__dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status--active { color: var(--ok); background: var(--ok-bg); }
.status--archived { color: var(--idle); background: var(--idle-bg); }
.status--cancelled { color: var(--danger); background: var(--danger-bg); }
.tag { display: inline-block; font-size: .78rem; font-weight: 600; padding: .1rem .55rem; border-radius: 5px; background: var(--gold-100); color: var(--gold-700); white-space: nowrap; }
.tag--navy { background: var(--navy-50); color: var(--navy-700); }
[data-theme="dark"] .tag--navy { color: var(--ink-2); }

/* ---------- التنبيهات ---------- */
.flashes { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1.25rem; }
.flash {
  display: flex; align-items: center; gap: .7rem; padding: .7rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid; font-weight: 500; animation: flash-in .32s var(--ease);
}
.flash > span { flex: 1; }
.flash--success { color: var(--ok); background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash--danger { color: var(--danger); background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash--warning { color: var(--warn); background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.flash--info, .flash--message { color: var(--info); background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 20%, transparent); }
.flash__close { border: 0; background: none; color: inherit; opacity: .7; width: 28px; height: 28px; border-radius: 6px; cursor: pointer; }
.flash__close:hover { opacity: 1; background: rgba(0, 0, 0, .05); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- عناصر متفرقة ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; align-items: end; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.filters .filters__q, .filters .filters__dates { grid-column: span 2; }
.filters input, .filters select { min-width: 0; }
.filters .form-label { font-size: .8rem; margin-bottom: .2rem; }
.filters .form-control, .filters .form-select { min-height: 38px; }
.filters__more { display: contents; }
.result-meta { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1.25rem; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--line); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .9rem 1.25rem; border-top: 1px solid var(--line); }
.pager__pages { display: flex; gap: .25rem; }
.pager__btn, .pager__num { display: inline-flex; align-items: center; gap: .4rem; min-width: 36px; height: 36px; justify-content: center; padding: 0 .7rem; border-radius: var(--radius-sm); text-decoration: none; color: var(--ink-2); border: 1px solid var(--line); background: var(--surface); font-weight: 500; }
.pager__btn:hover, .pager__num:hover { border-color: var(--navy-500); color: var(--navy-700); }
.pager__num.is-current { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
.pager__btn.is-disabled { opacity: .45; pointer-events: none; }
.pager__gap { padding: 0 .3rem; color: var(--muted); }

.empty { text-align: center; padding: 3rem 1.5rem; }
.empty__icon { position: relative; width: 84px; height: 84px; margin: 0 auto 1rem; display: grid; place-items: center; color: var(--navy-700); font-size: 1.5rem; }
.empty__icon .khatam { position: absolute; inset: 0; width: 100%; height: 100%; color: var(--gold-500); stroke-width: 2.2; }
.empty__title { font-size: 1.05rem; font-weight: 700; margin-bottom: .3rem; }
.empty__text { color: var(--muted); max-width: 46ch; margin: 0 auto 1.1rem; }

.dl { display: grid; grid-template-columns: 9.5rem 1fr; gap: .1rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-weight: 500; padding: .55rem 0; border-bottom: 1px dashed var(--line); }
.dl dd { margin: 0; padding: .55rem 0; border-bottom: 1px dashed var(--line); font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.dl dt:last-of-type, .dl dd:last-of-type { border-bottom: 0; }

/* أعمدة شهرية */
.months { display: flex; align-items: flex-end; gap: .5rem; height: 220px; padding-top: 1.2rem; }
.months__col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .3rem; }
.months__bar { width: 100%; max-width: 34px; min-height: 3px; border-radius: 5px 5px 2px 2px; background: var(--navy-700); }
.months__col:last-child .months__bar { background: var(--gold-500); }
.months__val { font-size: .78rem; font-weight: 700; color: var(--ink-2); }
.months__label { font-size: .72rem; color: var(--muted); white-space: nowrap; }

.ledger--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.filters--simple { grid-template-columns: minmax(0, 420px) auto; }

/* توزيع حسب النوع */
.bars { display: flex; flex-direction: column; gap: .8rem; }
.bar__row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .3rem .75rem; align-items: center; font-size: .88rem; }
.bar__track { grid-column: 1 / -1; height: 8px; border-radius: 8px; background: var(--navy-50); overflow: hidden; }
.bar__fill { display: block; height: 100%; border-radius: 8px; background: var(--navy-700); }
.bar__row:nth-child(2n) .bar__fill { background: var(--gold-500); }
.bar__count { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- ختم التوثيق (صفحة الوثيقة) ---------- */
.seal { text-align: center; padding: 1.5rem 1.25rem 1.25rem; }
.seal__frame { position: relative; width: 236px; aspect-ratio: 1; margin: 0 auto 1rem; display: grid; place-items: center; }
.seal__frame .khatam { position: absolute; inset: 0; width: 100%; height: 100%; color: var(--gold-500); stroke-width: 1.4; }
.seal__frame .khatam--inner { inset: 14px; width: calc(100% - 28px); height: calc(100% - 28px); color: var(--navy-700); stroke-width: .8; opacity: .45; }
.seal__qr { position: relative; width: 132px; height: 132px; padding: 6px; background: #fff; border-radius: 6px; box-shadow: var(--shadow-1); }
.seal__qr img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.seal__number { margin: .35rem 0 .6rem; }
.seal__caption { color: var(--muted); font-size: .84rem; margin: .6rem 0 0; }
.seal--cancelled .seal__frame .khatam { color: var(--danger); }
.seal--archived .seal__frame .khatam { color: var(--idle); }

.preview { background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
.preview iframe { display: block; width: 100%; height: 760px; border: 0; border-radius: 0 0 var(--radius) var(--radius); background: #fff; }
.preview img { display: block; max-width: 100%; margin: 0 auto; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding-inline-start: 1.5rem; padding-bottom: 1rem; }
.timeline li::before { content: ''; position: absolute; inset-inline-start: 4px; top: .55rem; bottom: -.3rem; width: 1px; background: var(--line-strong); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ''; position: absolute; inset-inline-start: 0; top: .45rem; width: 9px; height: 9px; transform: rotate(45deg); background: var(--gold-500); }
.timeline__what { font-weight: 600; }
.timeline__meta { display: block; color: var(--muted); font-size: .8rem; }
.timeline__detail { display: block; font-size: .86rem; color: var(--ink-2); }

.inline-status { display: flex; gap: .5rem; }
.inline-status .form-select { min-height: 38px; }

/* ---------- تسجيل الدخول ---------- */
.login-body { background: var(--ground); }
.login {
  min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
}
.login__brand {
  position: relative; overflow: hidden; color: #DCE3EE;
  background: var(--girih) 0 0 / 64px 64px, radial-gradient(120% 90% at 80% 10%, var(--navy-700), var(--navy-950) 70%);
  background-blend-mode: soft-light, normal;
  display: flex; flex-direction: column; justify-content: space-between; padding: 3rem;
}
.login__brand::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(12,26,48,.2), rgba(12,26,48,.75)); pointer-events: none; }
.login__brand > * { position: relative; z-index: 1; }
.login__lockup { display: flex; align-items: center; gap: 1rem; }
.login__lockup img:first-child { width: 92px; }
.login__lockup img:last-child { width: 220px; }
.login__seal { position: absolute; z-index: 0 !important; width: 520px; height: 520px; inset-inline-end: -150px; bottom: -150px; color: var(--gold-500); stroke-width: .6; opacity: .45; }
.login__seal--inner { width: 380px; height: 380px; inset-inline-end: -80px; bottom: -80px; stroke-width: .5; opacity: .3; }
.login__statement { max-width: 30rem; }
.login__statement h2 { font-family: var(--font-display); font-size: 2.1rem; font-weight: 600; color: #fff; line-height: 1.4; text-wrap: balance; }
.login__statement p { color: #B9C5D8; margin: .75rem 0 0; font-size: 1.02rem; }
.login__meta { display: flex; gap: 1.5rem; flex-wrap: wrap; color: #9FAEC6; font-size: .85rem; }
.login__meta strong { color: var(--gold-400); font-weight: 600; }
.login__panel { display: grid; place-items: center; padding: 2.5rem 1.5rem; }
.login__card { width: 100%; max-width: 400px; }
.login__card h1 { font-family: var(--font-display); font-weight: 600; font-size: 1.6rem; }
.login__card .lead { color: var(--muted); font-size: 1rem; margin: .3rem 0 1.75rem; }
.login__card .field + .field { margin-top: 1rem; }
.pw { position: relative; }
.pw .form-control { padding-inline-end: 2.75rem; }
.pw__toggle { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); }
.login__mobile-brand { display: none; }

/* ---------- صفحة الخطأ ---------- */
.error-page { max-width: 520px; margin: 3rem auto; text-align: center; }
.error-page .empty__icon { width: 120px; height: 120px; font-size: 2rem; }
.error-code { font-family: var(--font-mono); color: var(--gold-700); font-size: .95rem; }

/* ---------- التجاوب ---------- */
@media (max-width: 1180px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (min-width: 641px) and (max-width: 1180px) {
  .ledger:not(.ledger--4) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ledger:not(.ledger--4) .ledger__cell:nth-child(4) { border-inline-start: 0; }
  .ledger:not(.ledger--4) .ledger__cell:nth-child(n+4) { border-top: 1px solid var(--line); }
}
@media (max-width: 920px) {
  .grid-halves { grid-template-columns: 1fr; }
  .rail { position: fixed; inset-block: 0; inset-inline-start: 0; transform: translateX(100%); transition: transform .26s var(--ease); box-shadow: var(--shadow-2); }
  .rail.is-open { transform: none; }
  .rail-scrim { position: fixed; inset: 0; background: rgba(12, 26, 48, .45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 35; }
  .rail.is-open + .rail-scrim { opacity: 1; pointer-events: auto; }
  .topbar__menu { display: inline-grid; }
  .topbar { padding: .6rem 1rem; }
  .topbar__date { display: none; }
  .content { padding: 1.25rem 1rem 2rem; }
  .colophon { padding: 1rem; }
  .login { grid-template-columns: 1fr; }
  .login__brand { display: none; }
  .login__mobile-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: 1.75rem; }
  .login__mobile-brand img:first-child { width: 64px; }
  .login__mobile-brand img:last-child { width: 170px; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .page-title { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .filters__q, .filters .filters__dates { grid-column: 1 / -1; }
  .ledger { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .ledger .ledger__cell { border-inline-start: 0; border-top: 1px solid var(--line); }
  .ledger .ledger__cell:first-child { grid-column: 1 / -1; border-top: 0; }
  .ledger .ledger__cell:nth-child(odd):not(:first-child) { border-inline-start: 1px solid var(--line); }
  .filters--simple { grid-template-columns: 1fr; }
  .docno { font-size: .78em; padding-inline: .3rem; }
  .dl { grid-template-columns: 1fr; }
  .dl dt { border-bottom: 0; padding-bottom: 0; }
  .register .hide-sm { display: none; }
  .quickfind kbd { display: none; }
  .preview iframe { height: 520px; }
  .pager__btn { padding: 0 .5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- الطباعة ---------- */
@media print {
  .rail, .topbar, .colophon, .page-head__actions, .flashes, .no-print { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .panel { box-shadow: none; border-color: #ccc; }
}
