/* =========================================================
   علِّمنا — نظام الخطوط المركزي
   Typography Tokens V4

   الخطوط المعتمدة:
   - العربية: IBM Plex Sans Arabic
   - English: IBM Plex Sans

   طريقة التطبيق:
   - الواجهة كلها تستخدم عائلة موحدة باسم Alamna UI.
   - fonts.css يختار ملف الخط الصحيح حسب Unicode لكل حرف.
   - لذلك العربي والإنجليزي يعملان معًا داخل أي صفحة وأي عنصر.
========================================================= */

:root {
    /* عائلة الواجهة الموحدة */
    --font-family-ui:
        'Alamna UI',
        Arial,
        sans-serif;

    /*
     * نبقي المتغيرين للتوافق مع ملفاتنا السابقة،
     * لكن كلاهما يستخدم النظام المختلط نفسه.
     */
    --font-family-ar: var(--font-family-ui);
    --font-family-en: var(--font-family-ui);
    --font-family-base: var(--font-family-ui);

    /* الأوزان */
    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* المقياس الأساسي */
    /*
     * معيار القراءة الملزم:
     * 13px هو الحد الأدنى المطلق للنصوص الميكروية فقط (شارة/عداد/تعليق مساعد قصير).
     * النص الثانوي يبدأ من 14px، والتفاعلات من 15px، والنص الأساسي من 16px.
     * يمنع إدخال font-size أقل من 13px في أي واجهة عامة/إدارة/بزنس.
     */
    --font-size-xs: 13px;
    --font-size-sm: 14px;
    --font-size-base: 16px;
    --font-size-md: 17px;
    --font-size-lg: 19px;
    --font-size-xl: 22px;
    --font-size-2xl: 26px;
    --font-size-3xl: 30px;
    --font-size-4xl: 34px;
    --font-size-5xl: 42px;

    /* ارتفاع السطر */
    --line-height-tight: 1.35;
    --line-height-heading: 1.5;
    --line-height-normal: 1.75;
    --line-height-relaxed: 1.9;

    /* دلالات عامة */
    --text-caption: var(--font-size-xs);
    --text-label: var(--font-size-sm);
    --text-action: 15px;
    --text-body: var(--font-size-base);
    --text-reading: var(--font-size-md);
    --text-item-title: var(--font-size-md);
    --text-card-title: var(--font-size-md);
    --text-section-title: var(--font-size-xl);
    --text-page-title: var(--font-size-2xl);
    --text-stat: var(--font-size-xl);
    --text-stat-large: var(--font-size-2xl);
    --text-display: clamp(var(--font-size-3xl), 3vw, var(--font-size-5xl));

    /* لوحة الإدارة */
    --admin-text-secondary: 14px;
    --admin-text-action: 15px;
    --admin-text-body: 16px;
    --admin-text-important: 17px;
    --admin-text-section-title: 19px;
    --admin-text-stat: 22px;
    --admin-text-page-title: 26px;
}

/*
 * لا نغير عائلة الخط حسب لغة الصفحة.
 * اتجاه RTL/LTR يبقى مسؤولية lang/dir،
 * أما اختيار الخط العربي أو الإنجليزي فيتم حسب الحروف نفسها.
 */
html:lang(ar),
html:lang(en) {
    --font-family-base: var(--font-family-ui);
}

html,
body,
button,
input,
select,
textarea {
    font-family: var(--font-family-base);
}

/* توافق مع العناصر التي تحمل lang صراحة */
:lang(ar),
:lang(en) {
    font-family: var(--font-family-ui);
}

/* الحقول والنصوص ذات الاتجاه المحدد تبقى على نفس النظام المختلط */
[dir="ltr"],
[dir="rtl"],
input[type="email"],
input[type="url"] {
    font-family: var(--font-family-ui);
}

body {
    font-size: var(--text-body);
    line-height: var(--line-height-normal);
}

button,
input,
select,
textarea {
    font-size: var(--text-body);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: inherit;
    line-height: var(--line-height-heading);
}

p {
    line-height: var(--line-height-normal);
}

.text-caption {
    font-size: var(--text-caption);
    line-height: var(--line-height-normal);
}

.text-label {
    font-size: var(--text-label);
    line-height: var(--line-height-normal);
}

.text-body {
    font-size: var(--text-body);
    line-height: var(--line-height-normal);
}

.text-reading {
    font-size: var(--text-reading);
    line-height: var(--line-height-relaxed);
}

.text-item-title,
.text-card-title {
    font-size: var(--text-item-title);
    line-height: var(--line-height-heading);
    font-weight: var(--font-weight-semibold);
}

.text-section-title {
    font-size: var(--text-section-title);
    line-height: var(--line-height-heading);
    font-weight: var(--font-weight-bold);
}

.text-page-title {
    font-size: var(--text-page-title);
    line-height: var(--line-height-heading);
    font-weight: var(--font-weight-bold);
}

.text-display {
    font-size: var(--text-display);
    line-height: var(--line-height-tight);
    font-weight: var(--font-weight-bold);
}

.text-stat,
.text-stat-large {
    line-height: var(--line-height-tight);
    font-weight: var(--font-weight-bold);
}

.text-stat {
    font-size: var(--text-stat);
}

.text-stat-large {
    font-size: var(--text-stat-large);
}

@media (max-width: 600px) {
    :root {
        --text-page-title: var(--font-size-xl);
        --text-section-title: var(--font-size-lg);
        --text-stat-large: var(--font-size-xl);
    }

    input,
    select,
    textarea {
        font-size: var(--font-size-md);
    }
}
