/* --- إعدادات عامة وخطوط --- */
body {
    font-family: 'Cairo', sans-serif; /* استخدام خط Cairo */
    margin: 0;
    padding: 0;
    background-color: #f4f7f9;
    color: #333;
    direction: rtl; /* دعم اللغة العربية */
}

#app-container {
    max-width: 900px;
    margin: 20px auto;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden; /* لمنع تجاوز الهوامش */
}

/* --- الهيدر والتنقل --- */
.my-app {
    background-color: #4a90e2; 
    color: #fff;
    padding: 15px 20px;
    text-align: center;
}

header h1 {
    margin: 0;
    font-size: 1.8em;
}

.ai-icon {
    display: inline-block;
    transform: scaleX(-1); /* قلب الأيقونة لتبدو مناسبة مع النص العربي */
    margin-right: 5px;
}

nav {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 10px; /* مسافة بين الأزرار */
}

.nav-btn {
    padding: 10px 20px;
    font-family: 'Cairo', sans-serif;
    font-size: 1.3em;
    border: none;
    border-radius: 5px;
    background-color: #fff;
    color: #4a90e2;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
}

.nav-btn:hover {
    background-color: #e0e0e0;
}

.nav-btn.active {
    background-color: #2a5a8a; /* لون أغمق للزر النشط */
    color: #fff;
}

/* --- المحتوى الرئيسي والأقسام --- */
main {
    padding: 20px;
}

.content-section {
    display: none; /* إخفاء كل الأقسام افتراضيًا */
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    margin-top: 15px;
    background-color: #fdfdfd;
}

.content-section.active-section {
    display: block; /* إظهار القسم النشط فقط */
}

.content-section h2 {
    color: #4a90e2;
    border-bottom: 2px solid #4a90e2;
    padding-bottom: 5px;
    margin-top: 0;
}

/* --- قسم الدروس --- */
#lesson-content h3 {
    color: #2a5a8a;
}
#lesson-content code {
    background-color: #eef;
    padding: 2px 5px;
    border-radius: 3px;
    font-family: monospace;
}

/* --- قسم التمارين --- */
#exercise-area {
    text-align: center;
}

#question {
    font-size: 1.2em;
    margin-bottom: 15px;
    color: #555;
}

#answer-input {
    padding: 10px;
    margin-left: 10px; /* مسافة بجوار الزر */
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: 'Cairo', sans-serif;
}

#submit-answer-btn,
#next-question-btn,
#ask-ai-btn {
    padding: 10px 15px;
    background-color: #5cb85c; /* أخضر */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    transition: background-color 0.3s;
}

#submit-answer-btn:hover,
#next-question-btn:hover,
#ask-ai-btn:hover {
    background-color: #4cae4c; /* أخضر أغمق */
}

#next-question-btn {
    background-color: #f0ad4e; /* برتقالي */
    margin-top: 10px; /* مسافة فوق الزر */
}
#next-question-btn:hover {
    background-color: #ec971f; /* برتقالي أغمق */
}


#feedback {
    margin-top: 15px;
    font-weight: bold;
}

#feedback.correct {
    color: #5cb85c; /* أخضر */
}

#feedback.incorrect {
    color: #d9534f; /* أحمر */
}

/* --- قسم المساعد الذكي --- */
#chat-container {
    display: flex;
    flex-direction: column;
    height: 600px; /* ارتفاع ثابت لمنطقة الدردشة */
}

#chat-history {
    flex-grow: 1; /* يأخذ المساحة المتاحة */
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px;
    overflow-y: auto; /* شريط تمرير إذا زاد المحتوى */
    margin-bottom: 10px;
    background-color: #fff;
}

.message {
    margin-bottom: 10px;
    padding: 8px 12px;
    border-radius: 15px;
    max-width: 80%;
}

.user-message {
    background-color: #e2f0ff; /* أزرق فاتح لرسائل المستخدم */
    margin-right: auto; /* محاذاة لليسار (في الوضع العادي)، أو لليمين في RTL */
    border-bottom-right-radius: 0;
}

.ai-message {
    background-color: #f0f0f0; /* رمادي فاتح لرسائل المساعد */
    margin-left: auto; /* محاذاة لليمين (في الوضع العادي)، أو لليسار في RTL */
    border-bottom-left-radius: 0;
}

#chat-input {
    display: flex;
    gap: 10px;
}

#user-query {
    flex-grow: 1; /* يأخذ المساحة المتاحة */
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-family: 'Cairo', sans-serif;
}

#ask-ai-btn {
    background-color: #4a90e2; /* أزرق */
}
#ask-ai-btn:hover {
    background-color: #357ebd; /* أزرق أغمق */
}

/* --- الفوتر --- */
/*footer {
    text-align: center;
    margin-top: 20px;
    padding: 10px;
    font-size: 0.9em;
    color: #777;
    border-top: 1px solid #eee;
}*/
/*--------------------------------------*/
/*#exercises-section { 
    text-align: center;
}*/
/*-------------------------------------*/
.category-filters-container {
    margin-bottom: 25px; /* Espace avant la zone d'exercice */
    display: flex;
    justify-content: center;
    flex-wrap: wrap; /* Permet le retour à la ligne si trop de boutons */
    gap: 10px;
}

.filter-btn {
    padding: 8px 15px;
    font-family: inherit;
    font-size: 0.95em;
    border: 1px solid #ccc;
    border-radius: 20px; /* Boutons arrondis */
    background-color: #f0f0f0;
    color: #555;
    cursor: pointer;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

.filter-btn:hover {
    background-color: #e0e0e0;
    border-color: #bbb;
}

.filter-btn.active {
    background-color: #4a90e2; /* Bleu pour le bouton actif */
    color: #fff;
    border-color: #4a90e2;
    font-weight: bold;
}

/* تنسيق حاوية أزرار الأسئلة الجاهزة */
.prompt-buttons {
    display: flex;
    flex-wrap: wrap; /* للسماح بالتفاف الأزرار */
    gap: 8px; /* المسافة بين الأزرار */
    padding: 10px 15px; /* حشوة حول الأزرار */
    /*border-top: 1px solid #eee; /* خط فاصل علوي (اختياري) */
    /*border-bottom: 1px solid #eee; /* خط فاصل سفلي (اختياري) */
    margin-bottom: 10px; /* مسافة قبل حقل الإدخال */
}

/* تنسيق أزرار الأسئلة الجاهزة */
.prompt-btn {
    color: #fefcfb;
    /*padding: 4px 8px;*/
    background: #0aa6d7;
    border-radius: 5px;
    transition: all 0.5s ease;
    font-family: inherit;
    padding: 6px 12px;
    border: 0px solid #007bff; 
    /*background-color: #e7f3ff; 
    color: #0056b3; 
    /*cursor: pointer;
    /*border-radius: 15px; /* زوايا دائرية */
    /*font-size: 0.85em; /* حجم خط أصغر قليلاً */
    /*transition: background-color 0.2s ease, color 0.2s ease;*/
    /*text-align: center;
}

.prompt-btn:hover {
    background: #2a5a8a;/*background-color: #d0e7ff; /* لون أغمق عند المرور */
}

.prompt-btn:disabled {
    background-color: #f8f9fa;
    color: #adb5bd;
    border-color: #ced4da;
    cursor: not-allowed;
}

/* حاوية معلومات المستوى */
.level-container {
    background-color: #f0f0f0;
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between; /* لتوزيع العناصر */
    gap: 15px; /* مسافة بين العناصر */
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.level-container span {
    font-size: 0.95em;
    color: #333;
}

#level-display {
    font-weight: bold;
    color: #007bff; /* لون مميز للمستوى */
    background-color: #e7f3ff;
    padding: 2px 6px;
    border-radius: 4px;
}

/* حاوية شريط الخبرة */
.xp-bar-container {
    flex-grow: 1; /* تجعل الشريط يأخذ المساحة المتاحة */
    height: 12px; /* ارتفاع الشريط */
    background-color: #e9ecef; /* لون خلفية الشريط */
    border-radius: 6px; /* زوايا دائرية */
    overflow: hidden; /* لإخفاء الزوايا الزائدة من الشريط الداخلي */
    border: 1px solid #ced4da;
}

/* شريط التقدم الفعلي */
.xp-bar-progress {
    height: 100%;
    width: 0%; /* يبدأ فارغًا */
    background-color: #28a745; /* لون شريط التقدم (أخضر) */
    border-radius: 6px;
    transition: width 0.4s ease-in-out; /* حركة ناعمة عند التغيير */
}

#xp-display {
    font-size: 0.85em;
    color: #6c757d;
    min-width: 70px; /* عرض أدنى لمنع التذبذب */
    text-align: right;
}

/* Optional: Style for the category display text */
#exercise-category {
    font-size: 0.9em;
    font-style: italic;
    color: #666;
    margin-top: -5px; /* Adjust spacing if needed */
    margin-bottom: 15px;
}

/* ============================
   Font Size Controls Styling
   ============================ */

/* Container for the font size buttons and indicator */
.font-size-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end; /* Place controls to the right */
    padding: 5px 10px;      /* Padding around controls */
    margin-bottom: 8px;     /* Space below controls */
    background-color: #f9f9f9; /* Light background for the control bar */
    border-bottom: 1px solid #e0e0e0; /* Separator line */
    border-radius: 4px 4px 0 0; /* Match potential chat container radius */
}

/* General styling for control buttons */
.font-size-controls .control-btn {
    background-color: #e0e0e0;
    border: 1px solid #c0c0c0;
    color: #333;
    padding: 4px 8px;
    margin: 0 3px; /* Small space between buttons/indicator */
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em; /* Adjust icon/text size inside button */
    line-height: 1; /* Prevent extra vertical space */
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.font-size-controls .control-btn:hover {
    background-color: #d0d0d0;
    border-color: #a0a0a0;
}

.font-size-controls .control-btn:focus {
    outline: 2px solid dodgerblue; /* Clear focus indicator */
    outline-offset: 1px;
}

/* Styling for disabled font size buttons */
.font-size-controls .control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #e8e8e8;
    border-color: #d0d0d0;
}

/* Styling for the font size indicator (e.g., 1.0x) */
#font-size-indicator {
    font-weight: bold;
    font-size: 1em;
    padding: 4px 8px;
    min-width: 35px; /* Prevent size changes from shifting layout */
    text-align: center;
    /*color: black;/*#4a90e2;/*#555;*/
    background-color: #fff;
    border: 0px solid #ccc;
    border-radius: 3px;
}

/* ============================
   Applying Font Size Variable
   ============================ */

/* Define a base font size (adjust as needed) */
:root {
    --base-chat-font-size: 16px; /* Or 1rem, 15px, etc. */
    /* Initialize the multiplier variable (JS will override this) */
    --chat-font-size-multiplier: 1.0;
}

/* Apply the calculated font size to message elements */
.message { /* Target both user and AI messages */
    font-size: calc(var(--base-chat-font-size) * var(--chat-font-size-multiplier));
    /* Ensure line-height scales reasonably (adjust if needed) */
    line-height: calc(1.5 * var(--chat-font-size-multiplier));
    /* Smooth transition for font size changes */
    transition: font-size 0.2s ease-in-out, line-height 0.2s ease-in-out;

    /* Keep existing essential styles */
    white-space: pre-wrap;
    word-wrap: break-word;
    padding: 8px 12px;
    margin-bottom: 10px;
    border-radius: 8px;
    max-width: 85%;
}

/* Optional: Scale other relevant elements if desired */
/*
#user-query,
.prompt-btn {
    font-size: calc(1rem * var(--chat-font-size-multiplier));
}
*/
.fa-sharp{
    font-size: 30px;
    color: #4a90e2;
}
/* --- KaTeX LTR Fix for RTL Pages --- */

/* استهداف جميع عناصر KaTeX (inline و display) */
.katex {
    direction: ltr; /* !مهم: اجبار الاتجاه الداخلي للصيغة ليكون من اليسار لليمين */
    text-align: left; /* ضمان محاذاة النص الداخلية لليسار (يتناسق مع LTR) */
    display: inline-block; /* يساعد في تجنب بعض مشاكل التداخل والالتفاف الغريبة */
}

/* يمكنك إضافة قواعد خاصة للصيغ المنفصلة إذا احتجت لمحاذاة مختلفة */
.katex-display {
    display: block; /* التأكد من أنها تأخذ عرض السطر بالكامل */
    /* text-align: center; */ /* إلغاء التعليق لمحاذاة الصيغ المنفصلة في المنتصف */
    /* text-align: right; */  /* إلغاء التعليق لمحاذاتها لليمين (قد يكون هذا هو الافتراضي على أي حال في صفحة RTL) */
    /* text-align: left; */   /* لمحاذاتها لليسار */
    margin-top: 0.5em; /* إضافة بعض الهامش العلوي للصيغ المنفصلة */
    margin-bottom: 0.5em; /* إضافة بعض الهامش السفلي للصيغ المنفصلة */
}

/* --- End KaTeX Fix --- */
.special-chars-container {
    margin-top: 8px; /* Espace au-dessus des boutons */
    margin-bottom: 15px; /* Espace sous les boutons */
    display: flex; /* Aligner les boutons horizontalement */
    gap: 8px; /* Espace entre les boutons */
    justify-content: center; /* Centrer les boutons (optionnel) */
  }
  
  .char-btn {
    padding: 5px 10px;
    font-size: 1.1em; /* Taille de police un peu plus grande pour les symboles */
    cursor: pointer;
    border: 1px solid #ccc;
    background-color: #f8f8f8;
    border-radius: 4px;
    min-width: 35px; /* Largeur minimale */
    text-align: center;
  }
  
  .char-btn:hover {
    background-color: #eee;
  }
  
  /* Optionnel: ajuster l'espacement global de l'exercice */
  #exercises-section .exercise-controls,
  #exercises-section p /* cibler d'autres éléments si nécessaire */ {
      margin-bottom: 10px; /* Ajuster l'espacement si les boutons prennent trop de place */
  }

  /* In your style.css or within <style> tags */
.message canvas {
    /* Ensure canvas behaves like a block element */
    display: block;
    /* Optional: Add a border or background */
    /* border: 1px solid #ccc; */
    /* background-color: #f9f9f9; */

    /* Let Chart.js handle width/height via container */
    max-width: 100%; /* Ensure it doesn't overflow the container */
    height: auto;   /* Maintain aspect ratio */
}

/* Style for the container div added in JS */
/* You might adjust max-width/max-height in the JS directly */
/* .message div[style*="max-width: 400px"] {
    resize: vertical; /* Optional: allow user resizing
    overflow: auto;
} */