/**
 * base.css
 * ------------------------------------------------------------
 * منصة أ/ إسماعيل عماد التعليمية
 * الأساس العام لكل صفحات المنصة.
 *
 * المكان: /css/base.css
 *
 * المرجع:
 *   - Master Design System (بنود 06، 11، 45، 46، 62، 63)
 *   - الوثيقة الأصلية (بنود 10، 11، 12، 13، 45، 116، 123)
 *
 * ⚠️ قاعدة صارمة:
 *   - كل القيم تأتي من tokens.css.
 *   - ممنوع كتابة قيم مباشرة هنا إلا للضرورة القصوى.
 *   - أي إضافة جديدة تُضاف أولًا في tokens.css.
 *
 * يحتوي على:
 *   01 — Reset
 *   02 — HTML / Body
 *   03 — RTL + Fonts
 *   04 — Typography (Headings / Paragraphs / Links)
 *   05 — Lists + Media + Forms (Reset)
 *   06 — Selection + Scrollbar
 *   07 — Safe Area
 *   08 — Accessibility Helpers
 * ------------------------------------------------------------
 */


/* ============================================================
   استيراد الـ Design Tokens
   ------------------------------------------------------------
   ملاحظة: الترتيب مهم.
   tokens.css يجب أن يأتي قبل base.css في كل صفحة.
   لكن هنا نكرّره كـ @import للحماية إن نُسي في الصفحة.
   ============================================================ */
@import url('./tokens.css');


/* ============================================================
   01 — RESET
   المرجع: تطبيق نظيف موحد على كل المتصفحات.
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

button {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

a {
  text-decoration: none;
  color: inherit;
}

ul,
ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}


/* ============================================================
   02 — HTML / BODY
   المرجع: Design System — البنود 06، 07
   القاعدة: الأبيض هو الخلفية الأساسية.
   ============================================================ */

html {
  font-size: 16px;              /* 1rem = 16px */
  background-color: var(--color-bg);
}

body {
  font-family: var(--font-arabic);
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image: var(--paper-grid);
  background-size: var(--paper-grid-size) var(--paper-grid-size);
  background-attachment: scroll;
  overflow-x: hidden;
}


/* ============================================================
   03 — RTL + FONTS
   المرجع: الوثيقة الأصلية — بنود 10، 12
   القاعدة: العربية RTL هي الأساس.
   ============================================================ */

html[dir="rtl"] body {
  direction: rtl;
  text-align: right;
}

html[dir="ltr"] body {
  direction: ltr;
  text-align: left;
}

/* الأرقام الإنجليزية تُعرض بخط Inter داخل النص العربي */
.num,
[data-num] {
  font-family: var(--font-english);
  font-weight: var(--fw-bold);
  direction: ltr;
  unicode-bidi: embed;
}


/* ============================================================
   04 — TYPOGRAPHY
   المرجع: Design System — البند 11
   القاعدة: عناوين قصيرة + واضحة + قوية.
   ============================================================ */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-arabic);
  color: var(--color-text);
  line-height: var(--lh-tight);
  font-weight: var(--fw-extrabold);
}

/* العناوين الكبرى فقط بخط العرض (كوفي)، والعناوين الصغيرة بخط المتن للوضوح */
h1 {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: var(--fw-black);
}

h2 {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-extrabold);
}

h3 {
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
}

h4 {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}

h5 {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
}

h6 {
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
}

p {
  font-size: var(--fs-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--color-text);
}

small,
.text-sm {
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
}

.text-xs {
  font-size: var(--fs-xs);
  line-height: var(--lh-normal);
}

.text-muted {
  color: var(--color-text-muted);
}

.text-bold {
  font-weight: var(--fw-bold);
}

.text-center {
  text-align: center;
}

/* رابط نصي داخل النص */
.link {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  text-decoration-color: var(--color-yellow);
  font-weight: var(--fw-bold);
  transition: color var(--transition-fast);
}

.link:hover {
  color: var(--color-primary-dark);
}


/* ============================================================
   05 — LISTS + MEDIA + FORMS (Reset إضافي)
   ============================================================ */

button,
input,
textarea,
select {
  font-family: inherit;
}

textarea {
  resize: vertical;
}

/* إزالة خلفية autofill في كروم */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--color-surface) inset;
  -webkit-text-fill-color: var(--color-text);
  transition: background-color 5000s ease-in-out 0s;
}

/* placeholder */
::placeholder {
  color: var(--color-text-muted);
  opacity: 1;
}


/* ============================================================
   06 — SELECTION + SCROLLBAR
   ============================================================ */

::selection {
  background-color: var(--color-yellow);
  color: var(--color-text);
}

/* Scrollbar خفيف على الويب */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border-strong);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}


/* ============================================================
   07 — SAFE AREA
   المرجع: الوثيقة الأصلية — بند 13
   الاستخدام: Header / Bottom Navigation / Chat Input
   ============================================================ */

:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* الكلاس ده بيُستخدم لتطبيق padding سفلي آمن */
.safe-bottom {
  padding-bottom: var(--safe-bottom);
}

.safe-top {
  padding-top: var(--safe-top);
}


/* ============================================================
   08 — ACCESSIBILITY HELPERS
   المرجع: الوثيقة الأصلية — بند 123
   ============================================================ */

/* للنصوص المخفية بصريًا لكن مقروءة من قارئ الشاشة */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* إخفاء العنصر بالكامل */
.hidden {
  display: none !important;
}

/* إظهار عند وجود سبب فقط */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* إزالة outline افتراضي مع الحفاظ على وصولية لوحة المفاتيح */
:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 6px var(--color-yellow);
}


/* ============================================================
   09 — CONTAINER (هيكل عام للصفحات)
   المرجع: Design System — البند 46
   الاستخدام: أي محتوى يحتاج عرض محدود على الشاشات الكبيرة.
   ============================================================ */

.container {
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  padding-inline: var(--space-16);
}

@media (min-width: 1024px) {
  .container {
    max-width: 900px;
  }
}


/* ============================================================
   10 — REDUCED MOTION
   المرجع: Design System — البند 39
   احترام تفضيل المستخدم بتقليل الحركة.
   ============================================================ */

@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;
  }
}