/* ═══════════════════════════════════════════════════════════════
   صقل الواجهة — سبتمبر ٢٠٢٦
   ═══════════════════════════════════════════════════════════════

   اتكتب بعد مراجعة بصرية على الإنتاج (لقطات + قياس فعلي للتباين
   وأحجام اللمس والخطوط). كل قاعدة هنا بتصلّح حاجة **اتشافت**،
   مش تحسين نظري.

   النمط: Minimalism / Swiss — اللي مرجع التصميم بيوصّي بيه
   للوحات التحكم: شبكة منضبطة، تباين عالي، لون بمعنى مش بزينة.

   ⚠️ الملف ده **آخر ملف** في الترتيب عن قصد: شغله إنه يضبط
   الأرضيات (حد أدنى لحجم الخط والتباين) فوق أي حاجة سابقة.
   ═══════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────
   ١) أرضية حجم الخط
   ───────────────────────────────────────────────────────────────
   القياس لقى ٤١ عنصر أصغر من 12px — أغلبهم تسميات تحت الأرقام
   (10px و11px مكتوبين بالإيد). النص الرمادي الصغير على خلفية
   غامقة أصعب حاجة تتقرا، والتسمية هي اللي بتدّي الرقم معناه.  */
:root { --fs-floor: 12px; }

.text-\[10px\],
.text-\[11px\] { font-size: var(--fs-floor) !important; }

/* الباقي مكتوب `font-size:11px` inline في الشريط العلوي والقايمة
   — الكلاسات فوق مابتمسكهمش، فبنسمّيهم بالمعرّف. */
#sidebar-head .sb-label div,
#topbar-level, #topbar-xp-value, #topbar-xp span,
#me-email, #online-users-list span, #online-users-list div {
  font-size: var(--fs-floor) !important;
}

/* ───────────────────────────────────────────────────────────────
   ٢) أرضية التباين
   ───────────────────────────────────────────────────────────────
   `text-slate-500` (#64748B) على السطح الغامق = 3.3:1 — تحت
   الحد (4.5:1). و`/40` و`/50` بيوصّلوها لـ2:1 وأقل.
   التوكنات نفسها سليمة (7.7:1 و4.5:1)، المشكلة في الأماكن اللي
   بتتخطاها وتكتب لون Tailwind مباشرة.                         */
[data-theme="dark"] .text-slate-500,
html:not([data-theme="light"]) .text-slate-500 { color: var(--color-text-dim) !important; }

[data-theme="dark"] .text-slate-500\/40,
[data-theme="dark"] .text-slate-500\/50,
html:not([data-theme="light"]) .text-slate-500\/40,
html:not([data-theme="light"]) .text-slate-500\/50 { color: var(--color-text-dim) !important; }

/* ───────────────────────────────────────────────────────────────
   ٢ب) الأزرق كان بيعمل شغلانتين وفاشل في الاتنين
   ───────────────────────────────────────────────────────────────
   `--color-primary` كان `#3B82F6` ومستخدم في مكانين متعارضين:

     • **كنص** على سطح غامق  →  3.6:1  ❌
     • **كخلفية** لنص أبيض   →  3.7:1  ❌

   لون واحد ماينفعش يعمل الاتنين: اللي يقرا كنص لازم يبقى فاتح،
   واللي يشيل نص أبيض لازم يبقى غامق. القياس لقى ١٥ عنصر من
   الـ٢٣ راجعين للتعارض ده لوحده.

   الفصل: التوكن الأساسي بقى **لون النص** (هو المستخدم ٤٩ مرة
   مقابل ١١ كخلفية)، والخلفيات المصمتة ليها توكن خاص.
       #60A5FA كنص على #182235     = 6.3:1  ✅
       أبيض على #2563EB            = 5.3:1  ✅                    */
html:not([data-theme="light"]) {
  --color-primary: #60A5FA;
  --color-primary-solid: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-primary-active: #1E40AF;
}

/* ⚠️ **كل** مكان بيستخدمه كخلفية لازم يتغطّى، مش أغلبهم.
   تفتيح التوكن من غير ما نغطّي خلفية واحدة = نص أبيض على أزرق
   فاتح، يعني نبقى صلّحنا ١٥ وكسرنا واحدة. الجرد لقى ١١ في ملفات
   CSS/HTML + اتنين مكتوبين inline جوّه جافاسكربت.                */
html:not([data-theme="light"]) :is(
  .btn-primary, .bg-crm-primary, #obNext, #ma-avatar,
  .acc-subtab.active, #obDots span.active,
  .skip-to-content, .view-toggle.active
) {
  background: var(--color-primary-solid) !important;
  border-color: var(--color-primary-solid) !important;
}
html:not([data-theme="light"]) :is(
  .btn-primary, .bg-crm-primary, #obNext, #ma-avatar,
  .acc-subtab.active, .skip-to-content, .view-toggle.active
) { color: #fff !important; }

/* الخلفيات المكتوبة inline في الجافاسكربت — قاعدة عامة بتمسكهم
   كلهم، بما فيهم أي واحدة تتكتب بعدين. */
html:not([data-theme="light"]) [style*="background:var(--color-primary)"],
html:not([data-theme="light"]) [style*="background: var(--color-primary)"] {
  background: var(--color-primary-solid) !important;
}

/* ───────────────────────────────────────────────────────────────
   ٢ج) أرقام القمع — كانت بلون الخلفية نفسها تقريبًا
   ───────────────────────────────────────────────────────────────
   الرقم جوّه شريط القمع كان `#2563EB` فوق شريط أزرق = 3.6:1.
   النص اللي فوق شريط ملوّن لازم يبقى أبيض بظل خفيف عشان يفضل
   مقروء مهما كان طول الشريط تحته.                              */
#funnel-chart .absolute {
  color: #fff !important;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .55);
}

/* ───────────────────────────────────────────────────────────────
   ٣) بطاقات المؤشرات — تسلسل واضح
   ─────────────────────────────────────────────────────────────── */
.kpi-sub {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  margin-top: 4px;
  line-height: 1.45;
}

/* الرقم أكبر حاجة، التسمية فوقه أصغر وأهدى — عين المدير بتنزل
   من العام للخاص، مش العكس. */
.kpi-label { font-size: var(--fs-xs); letter-spacing: .01em; }
.kpi-value { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* ───────────────────────────────────────────────────────────────
   ٤) بطاقات المسار — اللون على الحافة مش كلمة مكررة
   ───────────────────────────────────────────────────────────────
   كانت كل بطاقة بتكتب اسم الحالة مرتين: عنوان فوق وشارة ملوّنة
   تحت بنفس النص. شلنا الشارة، ونقلنا معلومة اللون لشريط رفيع —
   نفس الإشارة البصرية من غير تكرار.                            */
.pipe-card {
  position: relative;
  overflow: hidden;
  min-height: 92px;
}
.pipe-card::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  inset-block: 0;
  width: 3px;
  background: var(--pipe-accent, var(--color-divider));
  border-start-start-radius: var(--radius-md);
  border-end-start-radius: var(--radius-md);
}
.pipe-card.status-new            { --pipe-accent: #60A5FA; }
.pipe-card.status-no_answer      { --pipe-accent: #A78BFA; }
.pipe-card.status-not_interested { --pipe-accent: #F59E0B; }
.pipe-card.status-contacted      { --pipe-accent: #2DD4BF; }
.pipe-card.status-interested     { --pipe-accent: #38BDF8; }
.pipe-card.status-meeting_set    { --pipe-accent: #818CF8; }
.pipe-card.status-negotiation    { --pipe-accent: #FB923C; }
.pipe-card.status-hot            { --pipe-accent: #F87171; }
.pipe-card.status-closed_won     { --pipe-accent: #4ADE80; }
.pipe-card.status-closed_lost    { --pipe-accent: #64748B; }
.pipe-card.status-rejected       { --pipe-accent: #64748B; }

/* ───────────────────────────────────────────────────────────────
   ٥) أهداف اللمس
   ───────────────────────────────────────────────────────────────
   القياس لقى ٢٤ هدف أصغر من 44×44 — منهم عناصر القايمة (43px).
   على الموبايل ده الفرق بين ضغطة تظبط وضغطة تودّيك مكان تاني. */
/* ⚠️ `min-height` لوحده مايكفيش: زرار أيقونة 32×32 بيبقى 32×44 —
   طوله ظبط وعرضه لأ، والإصبع بيقيس الاتنين. */
@media (pointer: coarse) {
  button, a[href], select,
  input[type="checkbox"], input[type="radio"] { min-height: 44px; }
  .btn-icon, button.btn-icon { min-width: 44px; min-height: 44px; }
  .btn, .chip { min-height: 44px; display: inline-flex; align-items: center; }
}
#main-nav a, #main-nav button,
#sb-collapse-btn, #logout-btn { min-height: 44px; }

/* ───────────────────────────────────────────────────────────────
   ٦) البحث في الشريط العلوي — واحد مش اتنين
   ───────────────────────────────────────────────────────────────
   على الموبايل كان فيه صندوق بحث **وجنبه** زرار بحث تاني. والصندوق
   متضغوط لـ~120px فباين فيه حرفين بس — لا هو بيبحث ولا سايب مكان.

   الحل: نخفي الصندوق تحت 768px ونسيب زرار لوحة الأوامر — هو أصلاً
   بيفتح بحث بملء الشاشة، وده أنسب للموبايل من خانة ضيقة.         */
@media (max-width: 767px) {
  #global-search { display: none !important; }
  #global-search + .ti-search,
  #global-search ~ i.ti-search { display: none !important; }
  #global-search:is(:focus) { display: block !important; }
}

/* ───────────────────────────────────────────────────────────────
   ٧) حلقة التركيز — لوحة المفاتيح لازم تبان
   ───────────────────────────────────────────────────────────────
   شرط في مرجع التصميم («Focus states visible for keyboard nav»)
   وشرط وصولية في أي عقد شركات.                                 */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--color-accent, #60A5FA);
  outline-offset: 2px;
  border-radius: var(--radius-sm, 6px);
}

/* ───────────────────────────────────────────────────────────────
   ٨) الحركة — هادية ومحترمة لتفضيل المستخدم
   ─────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
