/* ==========================================================================
   Codifica Core Design Tokens v2.0 (2026)
   نظام التصميم والهوية الموحد لمنظومة Codifica Hub
   المنصات: Hub · Drill · Exam · Tools · App
   الوضع الافتراضي الإلزامي: Dark Mode (الوضع الداكن)
   معايير الوصول: WCAG 2.2 AA (تباين ≥ 4.5:1 للنص العادي، ≥ 3:1 للكبير)
   الاتجاه: RTL-First مع خواص منطقية بالكامل (Logical Properties Only)
   خطوط مستضافة محليًا 100% بدون أي روابط CDN
   ========================================================================== */

/* ── ١. استضافة خط IBM Plex Sans Arabic محليًا ── */
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-arabic-300.woff2') format('woff2'),
       url('/fonts/plexarabic-arabic-300.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFE;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-arabic-400.woff2') format('woff2'),
       url('/fonts/plexarabic-arabic-400.woff2') format('woff2'),
       url('/fonts/plex-arabic-400-arabic-1.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFE;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-arabic-500.woff2') format('woff2'),
       url('/fonts/plexarabic-arabic-500.woff2') format('woff2'),
       url('/fonts/plex-arabic-500-arabic-3.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFE;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-arabic-600.woff2') format('woff2'),
       url('/fonts/plexarabic-arabic-600.woff2') format('woff2'),
       url('/fonts/plex-arabic-600-arabic-5.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFE;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-arabic-700.woff2') format('woff2'),
       url('/fonts/plexarabic-arabic-700.woff2') format('woff2'),
       url('/fonts/plex-arabic-700-arabic-7.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFE;
}

/* الأحرف اللاتينية المرافقة للخط */
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-latin-400.woff2') format('woff2'),
       url('/fonts/plexarabic-latin-400.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-latin-600.woff2') format('woff2'),
       url('/fonts/plexarabic-latin-600.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/assets/eco/v1/fonts/plexarabic-latin-700.woff2') format('woff2'),
       url('/fonts/plexarabic-latin-700.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F;
}

/* ── ٢. متغيرات ورموز التصميم الأساسية (Design Tokens) ── */
:root {
  /* الخطوط */
  --font-sans: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  /* سلّم الخطوط المتناغم */
  --text-xs: 0.78rem;     /* 12.5px */
  --text-sm: 0.875rem;    /* 14px */
  --text-base: 0.96rem;   /* 15.36px */
  --text-md: 1.05rem;     /* 16.8px */
  --text-lg: 1.25rem;     /* 20px */
  --text-xl: 1.5rem;      /* 24px */
  --text-2xl: 1.85rem;    /* 29.6px */
  --text-3xl: 2.35rem;    /* 37.6px */

  /* سلّم المسافات الثماني (8pt Spacing Scale) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* أنصاف أقطار الحواف (Border Radii) */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* أبعاد الترويسة والعناصر الرئيسية */
  --header-height: 60px;
  --container-max: 1180px;

  /* هوية العلامة التجارية (Brand Colors) */
  --brand: #0A7C94;
  --brand-hover: #0D96B3;
  --brand-active: #086377;
  --brand-surface: rgba(10, 124, 148, 0.12);
  --brand-border: rgba(10, 124, 148, 0.35);
  --brand-glow: rgba(10, 124, 148, 0.25);

  /* الثيم الداكن الافتراضي الصافي (Dark Theme - Default) */
  --bg-app: #080B11;
  --bg-surface: #0F141C;
  --bg-surface-hover: #151C27;
  --bg-surface-active: #1C2534;
  --bg-muted: #1A2230;
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-default: rgba(255, 255, 255, 0.15);
  --border-bold: rgba(255, 255, 255, 0.28);
  --border-focus: #0D96B3;

  --text-primary: #F2F5F8;       /* تباين 15.5:1 على bg-app */
  --text-secondary: #9BA8BA;     /* تباين 7.1:1 على bg-app */
  --text-muted: #6B7A90;         /* تباين 4.6:1 */
  --text-inverse: #080B11;

  /* حالات التغذية الراجعة (Feedback States) */
  --state-success: #10B981;
  --state-success-bg: rgba(16, 185, 129, 0.14);
  --state-success-border: rgba(16, 185, 129, 0.35);
  
  --state-warning: #F59E0B;
  --state-warning-bg: rgba(245, 158, 11, 0.14);
  --state-warning-border: rgba(245, 158, 11, 0.35);

  --state-danger: #EF4444;
  --state-danger-bg: rgba(239, 68, 68, 0.14);
  --state-danger-border: rgba(239, 68, 68, 0.35);

  /* حلقة التركيز للوصولية (Accessible Focus Ring) */
  --focus-ring: 0 0 0 2px var(--bg-app), 0 0 0 4px var(--border-focus);

  /* الانتقالات */
  --trans-fast: 0.12s cubic-bezier(0.16, 1, 0.3, 1);
  --trans-normal: 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── ٣. الثيم الفاتح المتوازن (Light Mode Override) ── */
html[data-theme="light"] {
  --bg-app: #FBFAF6;
  --bg-surface: #FFFFFF;
  --bg-surface-hover: #F6F4EE;
  --bg-surface-active: #EFECE3;
  --bg-muted: #F3EFE6;

  --border-subtle: #EBE6DC;
  --border-default: #DAD4C8;
  --border-bold: #B8B0A0;
  --border-focus: #0A7C94;

  --text-primary: #1B2432;       /* تباين 14.2:1 */
  --text-secondary: #46525F;     /* تباين 6.8:1 */
  --text-muted: #6B7A8D;         /* تباين 4.55:1 */
  --text-inverse: #FFFFFF;

  --state-success: #059669;
  --state-success-bg: #E6F7F1;
  --state-success-border: #A7F3D0;

  --state-warning: #D97706;
  --state-warning-bg: #FEF3C7;
  --state-warning-border: #FDE68A;

  --state-danger: #DC2626;
  --state-danger-bg: #FEE2E2;
  --state-danger-border: #FECACA;

  --focus-ring: 0 0 0 2px var(--bg-app), 0 0 0 4px var(--brand);
}

/* ── ٤. تطبيق القواعد الأساسية والخواص المنطقية (Base & Logical Rules) ── */
html {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  box-sizing: border-box;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: inherit;
  background-color: inherit;
  color: inherit;
  min-height: 100vh;
}

/* تطبيق الخواص المنطقية على العناوين والفقرات */
h1, h2, h3, h4, h5, h6 {
  margin-block-start: 0;
  margin-block-end: var(--space-3);
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.25;
}

p {
  margin-block-start: 0;
  margin-block-end: var(--space-4);
  color: var(--text-secondary);
}

a {
  color: var(--brand);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--trans-fast);
}
a:hover {
  color: var(--brand-hover);
}

/* ── ٥. مكونات الأساس الموحدة (Component Primitives) ── */

/* الأزرار (Buttons) */
.btn-core, button.btn-core, a.btn-core {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding-block: var(--space-3);
  padding-inline: var(--space-5);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--trans-fast), border-color var(--trans-fast), transform var(--trans-fast), box-shadow var(--trans-fast);
  min-height: 40px;
  touch-action: manipulation;
}

.btn-core-primary {
  background-color: var(--brand);
  color: #FFFFFF !important;
  border-color: var(--brand);
}
.btn-core-primary:hover {
  background-color: var(--brand-hover);
  border-color: var(--brand-hover);
}
.btn-core-primary:active {
  background-color: var(--brand-active);
  transform: translateY(1px);
}

.btn-core-secondary {
  background-color: var(--bg-surface);
  color: var(--text-primary) !important;
  border-color: var(--border-default);
}
.btn-core-secondary:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--border-bold);
}

.btn-core:disabled, .btn-core[disabled] {
  opacity: 0.45;
  cursor: not-allowed !important;
  pointer-events: none;
}

/* حقول الإدخال (Inputs) */
.input-core, input.input-core, select.input-core, textarea.input-core {
  width: 100%;
  padding-block: var(--space-3);
  padding-inline: var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--trans-fast), box-shadow var(--trans-fast);
  min-height: 42px;
}
.input-core:hover {
  border-color: var(--border-bold);
}
.input-core:focus, .input-core:focus-visible {
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}
.input-core:disabled {
  background-color: var(--bg-muted);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* البطاقات (Cards) */
.card-core {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding-block: var(--space-5);
  padding-inline: var(--space-5);
  transition: border-color var(--trans-normal), box-shadow var(--trans-normal);
}
.card-core:hover {
  border-color: var(--border-default);
}

/* الشرائح والشارات (Badges/Pills) */
.badge-core {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding-block: 3px;
  padding-inline: 9px;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  line-height: 1.3;
}
.badge-core-success {
  background-color: var(--state-success-bg);
  color: var(--state-success);
  border-color: var(--state-success-border);
}
.badge-core-warning {
  background-color: var(--state-warning-bg);
  color: var(--state-warning);
  border-color: var(--state-warning-border);
}
.badge-core-danger {
  background-color: var(--state-danger-bg);
  color: var(--state-danger);
  border-color: var(--state-danger-border);
}

/* ── ٦. معايير الوصول والتركيز (Focus Visible) ── */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring) !important;
  border-radius: var(--radius-xs);
}

/* ── ٧. احترام تفضيلات تقليل الحركة (Reduced Motion) ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
