/* =====================================================================
   الدفتر · نظام التصميم
   الهوية: «النقطة على السطر» — السطر خانة، والمعيّن شاهد.
   حبران فقط: حبر مستقر، وأزرق ينتظر إنسانًا.
   ===================================================================== */

/* ١. الرموز (فاتح) */
:root {
  color-scheme: light;
  --paper: #F4F6FB;          /* الطاولة */
  --sheet: #FFFFFF;          /* الورقة */
  --sheet-2: #FAFBFE;
  --ink: #17181C;            /* حبر مستقر */
  --ink-2: #464A55;
  --ink-3: #5F6573;          /* نص ثانوي: تباين 5.6 على الأبيض (كان 3.85 دون الحد) */
  --ink-4: #9AA0AD;          /* للخطوط والزخرفة فقط، لا للنص الصغير */
  --rule: #E6E9F1;           /* سطر الدفتر */
  --rule-2: #D5DAE6;
  --blue: #2B3FC4;           /* ينتظر إنسانًا */
  --blue-wet: #3D55F0;       /* حبر رطب، قبل أن يجفّ */
  --blue-tint: #EEF1FE;
  --blue-line: rgba(43, 63, 196, .22);
  --shadow-1: 0 1px 0 rgba(23, 24, 28, .04), 0 1px 2px rgba(23, 24, 28, .05);
  --shadow-2: 0 1px 0 rgba(23, 24, 28, .03), 0 6px 16px -6px rgba(23, 24, 28, .10), 0 2px 4px rgba(23, 24, 28, .04);
  --shadow-3: 0 24px 60px -18px rgba(23, 30, 70, .28), 0 8px 18px -8px rgba(23, 24, 28, .12);
  --glass: rgba(255, 255, 255, .72);

  /* الخطوط */
  --f-ui: "Vazirmatn", system-ui, sans-serif;
  --f-display: "Markazi Text", "Vazirmatn", serif;
  --t-11: 11px; --t-12: 12px; --t-13: 13px; --t-14: 14px; --t-15: 15px;
  --t-17: 17px; --t-20: 20px; --t-24: 24px; --t-30: 30px; --t-40: 40px;

  /* المسافات والحواف */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;
  --r-1: 6px; --r-2: 10px; --r-3: 14px; --r-4: 20px;

  /* الحركة: كل حركة في المنتج تأخذ قيمها من هنا */
  --ease-out: cubic-bezier(.23, 1, .32, 1);        /* دخول واستجابة */
  --ease-io: cubic-bezier(.77, 0, .175, 1);        /* حركة على الشاشة */
  --ease-sheet: cubic-bezier(.32, .72, 0, 1);      /* الأوراق والأدراج */
  --ease-ink: cubic-bezier(.2, .7, .1, 1);         /* انتشار الحبر */
  --spring: linear(0, .06 2%, .23 5%, .48 9%, .74 14%, .9 19%, .99 24%, 1.03 29%, 1.04 34%, 1.03 41%, 1.01 50%, 1 62%, .998 75%, 1);
  --d-press: 140ms; --d-fast: 180ms; --d-ui: 240ms; --d-sheet: 480ms; --d-dry: 720ms;
}

/* ٢. الرموز (ليلي) — الورق داكن والحبر فاتح */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0C0E13;
  --sheet: #13161D;
  --sheet-2: #171B23;
  --ink: #ECEEF4;
  --ink-2: #B9BECB;
  --ink-3: #848A99;
  --ink-4: #5B6170;
  --rule: #222733;
  --rule-2: #2D3342;
  --blue: #8796FF;
  --blue-wet: #A6B1FF;
  --blue-tint: #1B2140;
  --blue-line: rgba(135, 150, 255, .28);
  --shadow-1: 0 0 0 1px rgba(255, 255, 255, .03);
  --shadow-2: 0 0 0 1px rgba(255, 255, 255, .04), 0 10px 24px -10px rgba(0, 0, 0, .6);
  --shadow-3: 0 0 0 1px rgba(255, 255, 255, .05), 0 30px 70px -20px rgba(0, 0, 0, .7);
  --glass: rgba(19, 22, 29, .74);
}

/* ٣. الأساس */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--f-ui); font-size: var(--t-14); line-height: 1.7;
  font-feature-settings: "kern"; -webkit-font-smoothing: antialiased;
  transition: background-color 400ms ease, color 400ms ease;
}
/* لا تباعد حروف على العربية أبدًا: يقطع اتصال الحروف */
* { letter-spacing: 0; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: 0; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.display { font-family: var(--f-display); font-weight: 600; line-height: 1.15; }
.muted { color: var(--ink-3); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--blue-tint); color: var(--ink); }

/* ٤. المعيّن: العلامة الأم في كل المنتج */
.dia {
  display: inline-block; width: var(--dia, 8px); height: var(--dia, 8px);
  transform: rotate(45deg) scale(.86); border-radius: 1.5px; flex: none;
  background: var(--ink);
}
.dia.is-missing { background: transparent; box-shadow: inset 0 0 0 1.25px var(--ink-4); }
.dia.is-need { background: var(--blue); }
.dia.is-ask { background: transparent; box-shadow: inset 0 0 0 1.25px var(--blue); }
.dia.is-review { background: linear-gradient(135deg, var(--ink) 50%, transparent 50%); box-shadow: inset 0 0 0 1.25px var(--ink); }
.dia.is-out { background: transparent; box-shadow: inset 0 0 0 1px var(--rule-2); }

/* ٥. الأزرار */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 999px; font-size: var(--t-14); font-weight: 600;
  background: var(--sheet); color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule-2);
  transition: transform var(--d-press) var(--ease-out), background-color var(--d-fast) ease, box-shadow var(--d-fast) ease;
  white-space: nowrap; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(.97); }
.btn--ink { background: var(--ink); color: var(--sheet); box-shadow: none; }
.btn--blue { background: var(--blue); color: #fff; box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 6px 14px -6px rgba(43, 63, 196, .55); }
:root[data-theme="dark"] .btn--blue { color: #0C0E13; }
.btn--ghost { background: transparent; box-shadow: none; color: var(--ink-2); }
.btn--sm { height: 32px; padding: 0 12px; font-size: var(--t-13); }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { box-shadow: inset 0 0 0 1px var(--ink-4); }
  .btn--ink:hover { background: #2A2C33; box-shadow: none; }
  :root[data-theme="dark"] .btn--ink:hover { background: #fff; }
  .btn--blue:hover { background: #2437B3; }
  .btn--ghost:hover { background: var(--rule); box-shadow: none; }
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--ink-2);
  transition: transform var(--d-press) var(--ease-out), background-color var(--d-fast) ease;
}
.icon-btn:active { transform: scale(.94); }
@media (hover: hover) and (pointer: fine) { .icon-btn:hover { background: var(--rule); color: var(--ink); } }
.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ٦. الشرائح (فلاتر) */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 999px; font-size: var(--t-13); font-weight: 500; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 8px; box-shadow: inset 0 0 0 1px var(--rule-2); background: var(--sheet);
  transition: background-color var(--d-fast) ease, color var(--d-fast) ease, box-shadow var(--d-fast) ease, transform var(--d-press) var(--ease-out);
}
.chip:active { transform: scale(.97); }
.chip .n { color: var(--ink-3); font-size: var(--t-12); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--sheet); box-shadow: none; }
.chip[aria-pressed="true"] .n { color: var(--ink-4); }
.chip--blue[aria-pressed="true"] { background: var(--blue); color: #fff; }
.chip--blue[aria-pressed="true"] .n { color: rgba(255,255,255,.7); }

/* ٧. الورقة (البطاقة) */
.sheet {
  background: var(--sheet); border-radius: var(--r-4); box-shadow: var(--shadow-2);
  position: relative;
}
/* حبيبات الورق: ملمس خفيف جدًا يجعل الورقة ورقًا لا لوحًا */
.sheet::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: .5; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .1  0 0 0 0 .12  0 0 0 0 .2  0 0 0 .045 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .sheet::before { mix-blend-mode: screen; opacity: .35; }
.sheet > * { position: relative; }
.sheet--ruled {
  /* ورق الدفتر: سطور خفيفة جدًا وهامش أزرق مزدوج على يمين الصفحة */
  background-image:
    linear-gradient(to left, transparent 30px, var(--blue-line) 30px, var(--blue-line) 31px, transparent 31px, transparent 34px, var(--blue-line) 34px, var(--blue-line) 35px, transparent 35px);
}
.eyebrow { font-size: var(--t-12); color: var(--ink-3); font-weight: 500; }
.kbd {
  font-family: var(--f-ui); font-size: 11px; color: var(--ink-3); padding: 1px 6px; border-radius: 6px;
  box-shadow: inset 0 0 0 1px var(--rule-2); background: var(--sheet-2); direction: ltr; display: inline-block; line-height: 18px;
}
.hair { height: 1px; background: var(--rule); border: 0; margin: 0; }

/* ٨. الرسائل المؤقتة (حبر رطب يمكن التراجع عنه) */
.toasts { position: fixed; inset-inline-start: 50%; bottom: 24px; transform: translateX(50%); z-index: 90; display: grid; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; min-width: 320px; max-width: min(92vw, 460px);
  padding: 12px 14px 12px 12px; border-radius: 14px; background: var(--ink); color: var(--sheet); box-shadow: var(--shadow-3);
  font-size: var(--t-14); position: relative; overflow: hidden;
  transition: transform 400ms ease, opacity 400ms ease;
  @starting-style { transform: translateY(16px) scale(.98); opacity: 0; }
}
.toast.is-leaving { transform: translateY(10px) scale(.98); opacity: 0; transition-duration: 200ms; }
.toast .dia { --dia: 10px; background: var(--blue-wet); box-shadow: 0 0 0 3px rgba(61, 85, 240, .25); }
.toast .grow { flex: 1; min-width: 0; }
.toast button { color: #A6B1FF; font-weight: 600; padding: 4px 8px; border-radius: 8px; }
.toast .fuse { position: absolute; inset-inline: 0; bottom: 0; height: 2px; background: var(--blue-wet); transform-origin: right; }
:root[data-theme="dark"] .toast { background: #ECEEF4; color: #13161D; }
:root[data-theme="dark"] .toast button { color: var(--blue); }

/* ٩. الحركة المخففة: نترك الشفافية ونلغي الانتقال */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
/* م-60: رسالة الانقطاع من core.js */
.net-note { position: fixed; inset-inline: 0; top: 0; z-index: 1000; padding: 10px 16px; text-align: center; background: var(--ink); color: var(--paper); font-size: 14px; }
.net-note[hidden] { display: none; }
