:root {
  /* ألوان عصرية واحترافية */
  --primary: #1a73e8;    /* أزرق جوجل الرسمي */
  --secondary: #34a853;  /* أخضر هادئ */
  --bg: #f8f9fa;         /* خلفية فاتحة جداً */
  --text-main: #3c4043;
  --text-sub: #5f6368;
}

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  margin: 0;
  padding: 0;
  direction: rtl;
  overflow-x: hidden;
  font-size: 15px;       /* حجم مناسب للجوال */
  line-height: 1.6;      /* مسافة بين الأسطر */
}

.container {
  max-width: 1000px;
  margin: auto;
  padding: 10px;
}

/* التبويبات العلوية بنظام الماتيريال ديزاين (أبيض وأزرق) */
.tabs-header {
  display: flex;
  background: #ffffff; /* خلفية بيضاء تجعل التطبيق أنظف */
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08); /* ظل خفيف وناعم */
  border-bottom: 1px solid #e0e0e0;
}

.tab-btn {
  flex: 1;
  padding: 15px 5px;
  border: none;
  background: none;
  color: #5f6368; /* رمادي هادئ للنصوص */
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  border-bottom: 3px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* تأثير التبويب المختار (Active) ✅ */
.tab-btn.active {
  color: #1a73e8; /* أزرق جوجل الرسمي */
  border-bottom: 3px solid #1a73e8; /* خط سفلي أزرق واضح */
  background: #f8fbff; /* خلفية زرقاء باهتة جداً */
}

/* تحسين حركة ظهور المحتوى */
.tab-content {
  display: none;
  padding: 15px 10px;
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-content.active {
  display: block;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: white;
  padding: 15px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  margin: 10px 0;
}

.grid {
  display: grid;
  grid-template-columns: 1fr; /* عمود واحد للجوال */
  gap: 12px;
}
@media (min-width: 768px) {
  .grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

label {
  display: block;
  margin-bottom: 4px;
  font-weight: bold;
  font-size: 12px;
  color: #666;
}

input, select {
  padding: 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px; /* أكبر للجوال */
  width: 100%;
  box-sizing: border-box;
  outline: none;
  background: #fafafa;
}
input:focus {
  border-color: var(--secondary);
  background: #fff;
}

button {
  padding: 14px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: bold;
  transition: 0.2s;
  font-size: 16px;
}

.btn-save {
  background: var(--primary);
  color: white;
  width: 100%;
  margin-top: 10px;
}

.btn-add {
  background: var(--secondary);
  color: white;
  width: 100%;
}

.btn-excel {
  background: #1d6f42;
  color: white;
  width: auto;
  padding: 8px 15px;
  font-size: 13px;
}

.btn-del {
    background-color: #fee2e2; /* أحمر فاتح جداً للخلفية */
    color: #dc2626;           /* أحمر غامق للنص */
    border: 1px solid #fecaca;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-del:hover {
    background-color: #dc2626; /* ينعكس اللون عند التمرير */
    color: white;
    transform: scale(1.05);
}

/* تأكد من أن خلية الجدول تسمح بظهور الزر */
td:last-child {
    min-width: 70px;
    white-space: nowrap;
}


/* الجداول */
.table-wrap {
  overflow-x: auto;
  background: white;
  border-radius: 10px;
  margin-top: 10px;
  -webkit-overflow-scrolling: touch; /* سلاسة التمرير */
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px; /* تقليل الحد الأدنى للجوال */
}
th, td {
  padding: 10px 6px;
  text-align: center;
  border-bottom: 1px solid #eee;
  font-size: 12px;
}
th {
  background: #f8f9fa;
  color: var(--primary);
  position: sticky;
  top: 0;
}

/* لوحة الإحصائيات */
#studentStatsCard {
  background: #e3f2fd;
  border: 1px solid #bbdefb;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* للجوال عمودين */
  gap: 5px;
  margin-top: 10px;
}
@media (min-width: 768px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
.stat-item {
  background: white;
  padding: 8px 2px;
  border-radius: 8px;
  text-align: center;
  font-size: 11px;
  box-shadow: inset 0 0 5px rgba(0,0,0,0.02);
}
.stat-item b {
  display: block;
  color: var(--primary);
  font-size: 13px;
  margin-top: 3px;
}

.calc-box {
  background: #fff3cd;
  color: #856404;
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  font-weight: bold;
  margin: 10px 0;
  border: 1px solid #ffeeba;
}

.range-fields {
  display: flex;
  gap: 15px;
  width: 100%;
}

.input-with-clear {
  flex: 1;
  position: relative;
}

.input-with-clear input {
  width: 100%;
  padding-right: 25px;
}

.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: #888;
  font-weight: bold;
}
.clear-btn:hover {
  color: #000;
}

.students-table-wrapper {
  width: 100%;
  overflow-x: auto; /* يسمح بالتمرير الأفقي */
}

#studentsTable {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px; /* يضمن أن الجدول لا ينضغط أكثر من اللازم */
}

#studentsTable th, #studentsTable td {
  padding: 8px;
  border: 1px solid #ccc;
  text-align: center;
}

/* الحاوية الأساسية */
#iconsContainer {
    display: grid;
    /* في الجوال: 3 أعمدة متساوية */
    grid-template-columns: repeat(3, 1fr); 
    gap: 8px; /* مسافة معقولة للجوال */
    margin: 15px 0;
    direction: rtl;
}

/* الشاشات الكبيرة (الكمبيوتر والتابلت) */
@media (min-width: 768px) {
    #iconsContainer {
        /* في الكمبيوتر: 5 أعمدة أو أكثر حسب المساحة */
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }
}

/* تصميم البطاقة */
.icon-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px 4px; /* تقليل الحشو ليتناسب مع الجوال */
    text-align: center;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    flex-direction: column; /* أيقونة فوق النص لتوفير المساحة العرضية */
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
}

/* تمييز العنصر المختار */
.icon-card.active {
    background-color: #f0f7ff !important;
    border: 2px solid #007bff !important; /* إطار أزرق واضح */
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.2);
}

/* تنسيق الأيقونة والنص */
.icon-card .emoji { font-size: 18px; margin-bottom: 4px; }
.icon-card .text { 
    font-size: 10px; /* نص صغير ليتناسب مع 3 أعمدة */
    font-weight: bold; 
    color: #444;
    white-space: nowrap; /* منع انقسام النص لسطرين */
    overflow: hidden;
    text-overflow: ellipsis;
}

#toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #323232;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 9999;
    box-shadow: 0 3px 5px -1px rgba(0,0,0,.2), 0 6px 10px 0 rgba(0,0,0,.14);
    transition: all 0.3s ease;
}

.toast-hidden {
    opacity: 0;
    visibility: hidden;
    bottom: 0px !important;
}

.toast-success { background-color: #2e7d32 !important; }
.toast-error { background-color: #d32f2f !important; }

/* تنسيق خلية الحالة لمنع تمدد الجدول */
td:nth-last-child(2) { 
    max-width: 200px; /* حدد عرضاً أقصى مناسباً للرسالة */
    word-wrap: break-word; /* كسر الكلمات الطويلة */
    overflow-wrap: break-word;
    font-size: 10px; /* تصغير الخط لرسائل الخطأ التقنية */
    color: #d32f2f;
    line-height: 1.2;
}

/* تحسين شكل رسالة الخطأ لتظهر كصندوق صغير */
.error-msg {
    display: block;
    margin-top: 5px;
    padding: 5px;
    background: #fff5f5;
    border-radius: 4px;
    border: 1px solid #fed7d7;
    max-height: 60px; /* تحديد أقصى ارتفاع */
    overflow-y: auto; /* إظهار شريط تمرير داخلي إذا كان الخطأ طويلاً جداً */
}

.icons-full-width {
    grid-column: 1 / -1; /* يمتد من أول عمود لآخر عمود */
    margin-top: 10px;
    margin-bottom: 15px;
}

/* توزيع الأيقونات بشكل مريح */
.flex-icons {
    display: flex;
    flex-wrap: wrap; /* للسماح بالنزول لسطر جديد في الشاشات الصغيرة */
    gap: 12px;       /* المسافة بين الأيقونات */
    justify-content: flex-start; /* محاذاة لليمين */
}

/* تحسين مظهر كل أيقونة */
.flex-icons .icon-item { /* استبدل .icon-item باسم الكلاس لديك */
    flex: 0 1 auto;
    min-width: 80px;  /* عرض أدنى للأيقونة لتبدو متناسقة */
    text-align: center;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
}

.pdf-mode .no-pdf {
  display: none !important;
}
