/* ====================================================
   متغيرات الألوان - الوضع الفاتح
==================================================== */
:root {
    --bg: #f1f5f9;
    --text: #0f172a;
    --card: #ffffff;
    --primary: #6366f1;       /* اللون الأساسي (بنفسجي) */
    --secondary: #64748b;     /* لون النصوص الثانوية */
    --accent: #f59e0b;        /* لون التمييز (ذهبي) */
    --danger: #ef4444;        /* لون الخطر (أحمر) */
    --success: #10b981;       /* لون النجاح (أخضر) */
    --border: #e2e8f0;        /* لون الحدود */
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --header-bg: #ffffff;
}

/* ====================================================
   متغيرات الألوان - الوضع المظلم
==================================================== */
body.dark {
    --bg: #020617;
    --text: #f8fafc;
    --card: #1e293b;
    --primary: #818cf8;
    --secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.3);
    --header-bg: #0f172a;
}

/* ====================================================
   تنسيق الجسم الرئيسي
==================================================== */
body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    /* خلفية متدرجة للوضع الفاتح */
    background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #dbeafe 100%);
    background-attachment: fixed;
    color: var(--text);
    margin: 0;
    padding: 0;
    transition: all 0.3s ease;
    line-height: 1.6;
}

/* خلفية متدرجة للوضع المظلم */
body.dark {
    background: linear-gradient(135deg, #020617 0%, #0f172a 50%, #1e293b 100%);
    background-attachment: fixed;
}

/* ====================================================
   شريط التمرير المخصص
==================================================== */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
    background: linear-gradient(var(--primary), #8b5cf6);
    border-radius: 20px;
}

/* ====================================================
   الحاوية الرئيسية
==================================================== */
.container {
    max-width: 1100px;
    margin: auto;
    padding: 20px;
    padding-bottom: 100px; /* مسافة إضافية لزر المساعد الذكي */
}

/* ====================================================
   الترويسة (Header)
==================================================== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    padding: 15px 25px;
    /* خلفية شفافة مع تأثير التضبيب */
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(14px);
    border-radius: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* ترويسة الوضع المظلم */
body.dark header {
    background: rgba(15, 23, 42, 0.75);
}

/* شعار التطبيق */
.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

/* نص الشعار بتدرج لوني */
.logo span {
    background: linear-gradient(90deg, var(--primary), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* زر تبديل الوضع (ليلي/نهاري) */
.theme-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
}

.theme-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.1);
}

/* ====================================================
   شبكة الإحصائيات (التبويبات)
==================================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

/* صندوق إحصائية واحدة */
.stat-box {
    background: var(--card);
    padding: 20px;
    border-radius: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* تأثير الرفع عند التمرير */
.stat-box:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
}

/* التبويب النشط */
.stat-box.active {
    border-color: var(--primary);
    background: linear-gradient(145deg, var(--card), var(--bg));
}

.stat-box h4 { margin: 0; font-size: 0.95rem; color: var(--secondary); font-weight: 500; }
.stat-box p  { margin: 8px 0 0; font-size: 1.8rem; font-weight: 800; color: var(--primary); }

/* ====================================================
   نموذج إضافة الملاحظة
==================================================== */
.note-form {
    background: var(--card);
    padding: 30px;
    border-radius: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border: 1px solid var(--border);
}

/* تنسيق عناصر الإدخال المشتركة */
input, textarea, select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

/* تأثير التركيز على عناصر الإدخال */
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* منطقة النص الحر */
textarea { min-height: 120px; resize: vertical; }

/* صف عناصر الإدخال المزدوج */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* ====================================================
   الأزرار
==================================================== */
/* الزر الأساسي */
.btn {
    padding: 14px 28px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s;
}

/* زر الإضافة الرئيسي بتدرج لوني */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.39);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.23);
}

/* أزرار الأيقونات الصغيرة */
.icon-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    position: relative;
}

/* حالات تمرير أزرار الأيقونات */
.icon-btn:hover          { background: var(--primary); color: white; border-color: var(--primary); transform: scale(1.05); }
.icon-btn.danger:hover   { background: var(--danger);  border-color: var(--danger); }
.icon-btn.success:hover  { background: var(--success); border-color: var(--success); }
.icon-btn.ai:hover       { background: var(--accent);  border-color: var(--accent); }
/* الحالة النشطة لأزرار التثبيت والتفضيل */
.icon-btn.active         { background: var(--primary); color: white; border-color: var(--primary); }
.icon-btn.fav-active     { background: var(--accent);  color: white; border-color: var(--accent); }

/* ====================================================
   لوحة المساعد الذكي
==================================================== */
/* زر المساعد العائم */
.ai-fab {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.3s;
    animation: pulseGlow 2s infinite; /* تأثير النبض */
}

.ai-fab:hover { transform: scale(1.1) rotate(5deg); }

/* نافذة محادثة المساعد */
.ai-panel {
    position: fixed;
    bottom: 100px;
    left: 30px;
    width: 350px;
    max-height: 500px;
    background: var(--card);
    border-radius: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    animation: slideInUp 0.3s ease;
}

/* رأس نافذة المساعد */
.ai-panel-header {
    padding: 15px 20px;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
}

/* منطقة عرض الرسائل */
.ai-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 350px;
}

/* فقاعة رسالة واحدة */
.ai-msg {
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 0.9rem;
    max-width: 85%;
}

/* رسائل المستخدم (على اليمين) */
.ai-msg.user { background: var(--bg); align-self: flex-end; border-bottom-left-radius: 2px; }
/* رسائل الذكاء الاصطناعي (على اليسار) */
.ai-msg.bot  { background: rgba(99, 102, 241, 0.1); color: var(--text); align-self: flex-start; border-bottom-right-radius: 2px; }

/* منطقة إدخال الرسالة */
.ai-input-area {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

.ai-input-area input { flex: 1; padding: 10px; font-size: 0.9rem; }

/* ====================================================
   أدوات التحكم (البحث والتصفية والترتيب)
==================================================== */
.controls {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

/* ====================================================
   شبكة الملاحظات وبطاقاتها
==================================================== */
/* الشبكة الرئيسية */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 25px;
}

/* بطاقة الملاحظة الواحدة */
.note-card {
    background: var(--card);
    padding: 25px;
    border-radius: 22px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: relative;
    animation: slideIn 0.4s ease-out;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* تأثير الرفع عند التمرير على البطاقة */
.note-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* بطاقة الملاحظة المثبتة */
.note-card.pinned {
    border: 2px solid var(--accent);
    background: linear-gradient(to bottom right, var(--card), rgba(245, 158, 11, 0.02));
}

/* عنوان الملاحظة */
.note-card h3 {
    margin: 0 0 12px;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

/* محتوى الملاحظة (اللون الافتراضي) */
.note-card p {
    margin: 0 0 20px;
    font-size: 1rem;
    color: var(--secondary);
    white-space: pre-wrap;
    opacity: 0.9;
}

/* ====================================================
   إصلاح لون الخط عند تطبيق لون مخصص على البطاقة
   المشكلة: في الوضع المظلم يصبح النص غير مقروء
   على الخلفيات الفاتحة
==================================================== */
/* إجبار النص على اللون الداكن عند وجود لون مخصص */
.note-card.note-colored p,
.note-card.note-colored .note-meta,
.note-card.note-colored .note-meta div {
    color: #1e293b;
    opacity: 1;
}

/* إجبار عنوان البطاقة على اللون الداكن أيضاً */
.note-card.note-colored h3 {
    color: #1e293b;
}

/* ====================================================
   بيانات الملاحظة الفرعية (التاريخ، آخر تعديل)
==================================================== */
.note-meta {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding-top: 18px;
    font-size: 0.85rem;
    color: var(--secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* أزرار تحكم البطاقة */
.note-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

/* ====================================================
   شارات تصنيف الملاحظة
==================================================== */
.badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    margin-bottom: 12px;
    font-weight: 600;
    width: fit-content;
}

/* ألوان شارات التصنيفات */
.badge-study    { background: rgba(99, 102, 241, 0.1); color: #4f46e5; }  /* دراسة */
.badge-work     { background: rgba(16, 185, 129, 0.1); color: #059669; }  /* عمل */
.badge-personal { background: rgba(245, 158, 11, 0.1); color: #d97706; }  /* شخصي */
.badge-trash    { background: rgba(239, 68, 68, 0.1);  color: #dc2626; }  /* محذوفة */

/* ====================================================
   منتقي ألوان البطاقة
==================================================== */
/* لوحة اختيار الألوان */
.color-options {
    position: absolute;
    bottom: 45px;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    display: none; /* مخفية افتراضياً */
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    box-shadow: var(--shadow);
    z-index: 10;
}

/* نقطة لون واحدة */
.color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.1);
    transition: 0.2s;
}

.color-dot:hover { transform: scale(1.2); }

/* ====================================================
   نافذة تأكيد الحذف (Modal)
==================================================== */
/* طبقة التعتيم الخلفية */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: none; /* مخفية افتراضياً */
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

/* محتوى النافذة */
.modal {
    background: var(--card);
    padding: 35px;
    border-radius: 28px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border);
}

/* ====================================================
   رسائل التنبيه العائمة (Toast)
==================================================== */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--text);
    color: var(--bg);
    padding: 15px 30px;
    border-radius: 16px;
    transform: translateY(120px); /* مخفية خارج الشاشة */
    transition: 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
    font-weight: 500;
}

/* إظهار التنبيه */
.toast.show { transform: translateY(0); }

/* ====================================================
   الحركات والانتقالات
==================================================== */
/* ظهور البطاقات بانزلاق من الأسفل */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* انزلاق لوحة المساعد من الأسفل */
@keyframes slideInUp {
    from { opacity: 0; transform: translateY(50px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* تأثير النبض لزر المساعد الذكي */
@keyframes pulseGlow {
    0%   { box-shadow: 0 0 0 0   rgba(99,102,241,0.4); }
    70%  { box-shadow: 0 0 0 18px rgba(99,102,241,0); }
    100% { box-shadow: 0 0 0 0   rgba(99,102,241,0); }
}

/* ====================================================
   التصميم المتجاوب (الشاشات الصغيرة)
==================================================== */
@media (max-width: 768px) {
    .controls  { grid-template-columns: 1fr; }        /* عمود واحد للأدوات */
    .form-row  { grid-template-columns: 1fr; }        /* عمود واحد للنموذج */
    .container { padding: 15px; }                     /* تقليل الهوامش */
    .ai-panel  { width: 90%; left: 5%; right: 5%; bottom: 85px; } /* لوحة AI متجاوبة */
}