/* ============================================================================
   حصِّل — طبقة الهوية
   مولَّد من brand/tokens.json بـ`python3 brand/build.py`.
   ⛔ لا يُعدَّل هذا الملف بيده؛ كل تغييرٍ يُعاد من المصدر.
   ========================================================================== */

:root {
  color-scheme: light dark;
  --ink-900: #07140F;
  --ink-800: #0C1F18;
  --ink-700: #16332A;
  --ink-600: #2A4A40;
  --ink-500: #46655B;
  --ink-400: #6B8780;
  --ink-300: #9BB0A9;
  --ink-200: #C6D5CF;
  --ink-100: #E3ECE8;
  --ink-50: #F2F7F5;
  --brand-900: #042E25;
  --brand-800: #06402F;
  --brand-700: #07543E;
  --brand-600: #0A6B4F;
  --brand-500: #0E8763;
  --brand-400: #2BA47D;
  --brand-300: #67C4A4;
  --brand-200: #A4DEC9;
  --brand-100: #D3F0E5;
  --brand-50: #EDF9F4;
  --brass-900: #3E2A08;
  --brass-800: #5E400F;
  --brass-700: #855B16;
  --brass-600: #A87420;
  --brass-500: #C4902F;
  --brass-400: #D9AB55;
  --brass-300: #E8C684;
  --brass-200: #F3DEB6;
  --brass-100: #FAEFDC;
  --brass-50: #FDF8EF;
  --danger-700: #7E1710;
  --danger-600: #A3251C;
  --danger-500: #C13A2F;
  --danger-300: #E8A69F;
  --danger-100: #FBE6E3;
  --danger-50: #FEF4F2;
  --info-700: #0E3F63;
  --info-600: #135882;
  --info-500: #1C78AC;
  --info-300: #9BCAE5;
  --info-100: #E4F1F9;
  --paper: #FBFAF7;
  --surface: #FFFFFF;
  --sunken: #F4F2EC;
  --text: var(--ink-900);
  --text-muted: var(--ink-500);
  --text-faint: var(--ink-400);
  --border: #E3ECE8;
  --border-strong: #C6D5CF;
  --accent: var(--brand-600);
  --accent-hover: var(--brand-700);
  --on-accent: #ffffff;
  --money: var(--brass-700);
  --s0: 0;
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.25rem;
  --s6: 1.5rem;
  --s8: 2rem;
  --s10: 2.5rem;
  --s12: 3rem;
  --s16: 4rem;
  --s20: 5rem;
  --s24: 6rem;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;
  --sh-sm: 0 1px 2px rgba(7, 20, 15, 0.06), 0 1px 1px rgba(7, 20, 15, 0.04);
  --sh-md: 0 2px 6px rgba(7, 20, 15, 0.07), 0 8px 20px -8px rgba(7, 20, 15, 0.10);
  --sh-lg: 0 4px 12px rgba(7, 20, 15, 0.08), 0 24px 48px -16px rgba(7, 20, 15, 0.14);
  --sh-focus: 0 0 0 3px rgba(14, 135, 99, 0.28);
  --t-fast: 120ms;
  --t-base: 200ms;
  --t-slow: 360ms;
  --t-seal: 900ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --font-sans: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --max-content: 1120px;
  --max-invoice: 560px;
  --max-text: 68ch;
  --gutter-mobile: 16px;
  --gutter: 24px;
  --st-draft-fg: #46655B;
  --st-draft-bg: #F2F7F5;
  --st-sent-fg: #135882;
  --st-sent-bg: #E4F1F9;
  --st-paid-fg: #07543E;
  --st-paid-bg: #D3F0E5;
  --st-overdue-fg: #A3251C;
  --st-overdue-bg: #FBE6E3;
  --st-void-fg: #6B8780;
  --st-void-bg: #F4F2EC;
  --st-refunded-fg: #855B16;
  --st-refunded-bg: #FAEFDC;
}

/* الوضع الليلي يتبع النظام، ويُجاوَز بـdata-theme على <html>. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --paper: #07140F;
  --surface: #0C1F18;
  --sunken: #050F0B;
  --text: #E3ECE8;
  --text-muted: #9BB0A9;
  --text-faint: var(--ink-400);
  --border: #16332A;
  --border-strong: var(--ink-600);
  --accent: #2BA47D;
  --accent-hover: var(--brand-300);
  --on-accent: var(--ink-900);
  --money: #D9AB55;
  --st-draft-fg: var(--ink-300);   --st-draft-bg: var(--ink-700);
  --st-sent-fg: var(--info-300);   --st-sent-bg: var(--info-700);
  --st-paid-fg: var(--brand-200);  --st-paid-bg: var(--brand-800);
  --st-overdue-fg: var(--danger-300); --st-overdue-bg: var(--danger-700);
  --st-void-fg: var(--ink-300);    --st-void-bg: var(--ink-800);
  --st-refunded-fg: var(--brass-300); --st-refunded-bg: var(--brass-800);
  }
}
:root[data-theme="dark"] {
  --paper: #07140F;
  --surface: #0C1F18;
  --sunken: #050F0B;
  --text: #E3ECE8;
  --text-muted: #9BB0A9;
  --text-faint: var(--ink-400);
  --border: #16332A;
  --border-strong: var(--ink-600);
  --accent: #2BA47D;
  --accent-hover: var(--brand-300);
  --on-accent: var(--ink-900);
  --money: #D9AB55;
  --st-draft-fg: var(--ink-300);   --st-draft-bg: var(--ink-700);
  --st-sent-fg: var(--info-300);   --st-sent-bg: var(--info-700);
  --st-paid-fg: var(--brand-200);  --st-paid-bg: var(--brand-800);
  --st-overdue-fg: var(--danger-300); --st-overdue-bg: var(--danger-700);
  --st-void-fg: var(--ink-300);    --st-void-bg: var(--ink-800);
  --st-refunded-fg: var(--brass-300); --st-refunded-bg: var(--brass-800);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  font-weight: 400;
  direction: rtl;
  text-align: right;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s6) 0; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ── المقياس الطباعي ─────────────────────────────────────────────────────── */
.t-display {
  font-family: var(--font-sans);
  font-size: 2.75rem;
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.t-h1 {
  font-family: var(--font-sans);
  font-size: 2rem;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.t-h2 {
  font-family: var(--font-sans);
  font-size: 1.5rem;
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.t-h3 {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: 0;
}
.t-body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  font-weight: 400;
  letter-spacing: 0;
}
.t-small {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  line-height: 1.6;
  font-weight: 400;
  letter-spacing: 0;
}
.t-micro {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  line-height: 1.5;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.t-amount {
  font-family: var(--font-mono);
  font-size: 2.25rem;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.t-amount_sm {
  font-family: var(--font-mono);
  font-size: 1rem;
  line-height: 1.4;
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

/* ── الأرقام والمبالغ ────────────────────────────────────────────────────────
   كل رقم في واجهة مالية يُعزل من الاتجاه، وإلّا انعكس مع لاحقته العربية
   (`1,250.00 ر.س` تُعرض `ر.س 1,250.00`). والعزل خاصّية CSS هنا لأننا نتحكّم
   في النسق — وفي الأرتفاكت والقوالب المقيّدة يُستعمل المحرفان ‪ و‬ بدلها. */
.num, .amount, .mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
}
.money { color: var(--money); font-weight: 600; }
.cur { font-family: var(--font-sans); font-size: 0.72em; color: var(--text-muted); margin-inline-start: 0.35em; font-weight: 500; }

/* ── التخطيط ─────────────────────────────────────────────────────────────── */
.wrap { max-width: var(--max-content); margin-inline: auto; padding-inline: var(--gutter-mobile); }
@media (min-width: 640px) { .wrap { padding-inline: var(--gutter); } }
.stack > * + * { margin-block-start: var(--s4); }
.stack-6 > * + * { margin-block-start: var(--s6); }
.stack-2 > * + * { margin-block-start: var(--s2); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── السطح ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s6);
  box-shadow: var(--sh-sm);
}
.card-flat { box-shadow: none; }
.card-pad-sm { padding: var(--s4); }

/* ورقةُ الفاتورة: حدٌّ علويٌّ نحاسيّ كخطّ الترويسة في الدفتر. */
.paper-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--brass-500);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-md);
  overflow: hidden;
}

/* ── الأزرار ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font-family: var(--font-sans); font-size: 1rem; font-weight: 500; line-height: 1;
  padding: 0.8rem var(--s5);
  min-height: 48px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: var(--sunken); color: var(--text);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--sh-sm); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--sunken); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-muted); min-height: 40px; padding: 0.5rem var(--s3); }
.btn-quiet:hover { background: var(--sunken); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--danger-300); color: var(--danger-600); }
.btn-danger:hover { background: var(--danger-50); }
.btn-lg { min-height: 56px; font-size: 1.0625rem; padding: 1rem var(--s6); width: 100%; }
.btn-sm { min-height: 36px; font-size: 0.875rem; padding: 0.4rem var(--s3); }
.btn .ic { width: 20px; height: 20px; flex: 0 0 auto; }

/* ── الحقول ──────────────────────────────────────────────────────────────── */
.field { display: block; }
.field > .lbl {
  display: block; font-size: 0.875rem; font-weight: 500;
  color: var(--text); margin-block-end: var(--s2);
}
.field .hint { display: block; font-size: 0.75rem; color: var(--text-muted); margin-block-start: var(--s2); }
.field .err { display: block; font-size: 0.8125rem; color: var(--danger-600); margin-block-start: var(--s2); font-weight: 500; }
.input, .select, .textarea {
  display: block; width: 100%;
  font-family: var(--font-sans); font-size: 1rem; line-height: 1.5;
  padding: 0.75rem var(--s4);
  min-height: 48px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--sh-focus);
}
.input[aria-invalid="true"] { border-color: var(--danger-500); }
.input-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; direction: ltr; text-align: left; }
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
/* 🪤 شيفرون SVG لا تدرّجان: حيلة linear-gradient الشائعة تنتج **مثلّثين
   متجاورين** يقرآن كرقمٍ عربيّ غريب بجوار نصٍّ عربي، لا سهمًا. */
.select {
  appearance: none; padding-inline-end: var(--s10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%2346655B' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: left var(--s4) center;
  background-size: 12px 8px;
  background-repeat: no-repeat;
}
/* الوضع الليلي: الشيفرون مُضمَّن في الـURL فلا يرث currentColor — يُعاد بلونٍ فاتح. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%239BB0A9' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
}
:root[data-theme="dark"] .select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%239BB0A9' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }

/* ── الوسوم والحالات ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: var(--s2);
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.01em;
  padding: 0.3rem 0.65rem; border-radius: var(--r-pill);
  background: var(--sunken); color: var(--text-muted);
  white-space: nowrap;
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: 0 0 auto;
}
.badge-draft    { color: var(--st-draft-fg);    background: var(--st-draft-bg); }
.badge-sent     { color: var(--st-sent-fg);     background: var(--st-sent-bg); }
.badge-paid     { color: var(--st-paid-fg);     background: var(--st-paid-bg); }
.badge-overdue  { color: var(--st-overdue-fg);  background: var(--st-overdue-bg); }
.badge-void     { color: var(--st-void-fg);     background: var(--st-void-bg); }
.badge-refunded { color: var(--st-refunded-fg); background: var(--st-refunded-bg); }

/* ── الجداول ─────────────────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
table.data th, table.data td {
  text-align: right; padding: var(--s3) var(--s4);
  border-block-end: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
  color: var(--text-muted); text-transform: none;
  background: var(--sunken); white-space: nowrap;
}
/* الصفّ الأخير بلا خطّ — ويشمل th لأن جداول «مفتاح/قيمة» تضع th في كل صفّ،
   وإغفاله يترك نصف خطٍّ معلَّقًا تحت آخر صفّ. */
table.data tbody tr:last-child td,
table.data tbody tr:last-child th { border-block-end: 0; }
table.data tbody tr:hover { background: var(--sunken); }
table.data td.n { font-family: var(--font-mono); font-variant-numeric: tabular-nums; direction: ltr; text-align: left; }

/* ── التنبيهات ───────────────────────────────────────────────────────────── */
.note {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s4); border-radius: var(--r-md);
  border: 1px solid var(--border); background: var(--sunken);
  font-size: 0.9375rem; line-height: 1.6;
}
.note .ic { width: 20px; height: 20px; flex: 0 0 auto; margin-block-start: 2px; }
.note-error   { background: var(--danger-50);  border-color: var(--danger-300); color: var(--danger-700); }
.note-success { background: var(--brand-50);   border-color: var(--brand-200);  color: var(--brand-800); }
.note-warn    { background: var(--brass-50);   border-color: var(--brass-200);  color: var(--brass-800); }
.note-info    { background: var(--info-100);   border-color: var(--info-300);   color: var(--info-700); }

/* ── مفاتيح الاختيار (شريحة) ─────────────────────────────────────────────── */
.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--sunken); border-radius: var(--r-md); border: 1px solid var(--border); }
.seg button {
  font-family: var(--font-sans); font-size: 0.875rem; font-weight: 500;
  padding: 0.5rem var(--s4); min-height: 40px;
  border: 0; border-radius: calc(var(--r-md) - 3px);
  background: transparent; color: var(--text-muted); cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--sh-sm); }

/* ── الأيقونات ───────────────────────────────────────────────────────────── */
.ic { width: 24px; height: 24px; display: inline-block; vertical-align: middle; }
.ic-sm { width: 18px; height: 18px; }

/* ── الشعار ──────────────────────────────────────────────────────────────── */
.brandmark { display: inline-flex; align-items: center; gap: var(--s3); }
.brandmark svg { width: 32px; height: 32px; flex: 0 0 auto; }
.brandmark .nm { font-size: 1.375rem; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }

/* ── خاتم «مدفوعة» ──────────────────────────────────────────────────────────
   الحركة الوحيدة في النظام. تُلغى كاملةً تحت prefers-reduced-motion. */
.seal {
  display: grid; place-items: center;
  width: 96px; height: 96px; margin-inline: auto;
  border-radius: 50%;
  color: var(--brand-600);
  background: var(--brand-50);
  border: 2px solid var(--brand-200);
}
.seal .ic { width: 44px; height: 44px; stroke-width: 2; }
.seal-in { animation: seal-pop var(--t-seal) var(--ease) both; }
@keyframes seal-pop {
  0%   { transform: scale(0.72) rotate(-8deg); opacity: 0; }
  55%  { transform: scale(1.06) rotate(2deg);  opacity: 1; }
  100% { transform: scale(1) rotate(0);        opacity: 1; }
}

.spin { animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--sunken) 25%, var(--border) 50%, var(--sunken) 75%);
  background-size: 200% 100%;
  animation: sweep 1.3s ease-in-out infinite;
  border-radius: var(--r-sm);
  min-height: 1em;
}
@keyframes sweep { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── الطباعة: الفاتورة تُطبع ورقةً نظيفة ────────────────────────────────── */
@media print {
  :root { --paper: #fff; --surface: #fff; --text: #000; --border: #bbb; }
  .no-print { display: none !important; }
  .paper-sheet { box-shadow: none; border: 1px solid #bbb; }
  body { background: #fff; }
}
