/* إعدادات المتغيرات والتصميم العام */
:root {
  --font-family: 'Tajawal', sans-serif;
  
  /* لوحة الألوان الاحترافية الداكنة */
  --bg-dark: #0b0f19;
  --bg-sidebar: #0f172a;
  --card-bg: rgba(30, 41, 59, 0.45);
  --card-border: rgba(255, 255, 255, 0.08);
  
  --primary: #2563eb;
  --primary-glow: rgba(37, 99, 235, 0.4);
  --accent: #8b5cf6;
  --accent-glow: rgba(139, 92, 246, 0.4);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  /* الحالات */
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-info: #06b6d4;
  
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --border-radius: 16px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  background-image: 
    radial-gradient(at 0% 0%, rgba(37, 99, 235, 0.1) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.1) 0px, transparent 50%);
}

/* تنسيق لوحة التحكم الأساسية */
.dashboard-container {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* القائمة الجانبية (Sidebar) */
.sidebar {
  background-color: var(--bg-sidebar);
  border-left: 1px solid var(--card-border);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.brand-icon {
  font-size: 2.2rem;
  color: #0088cc;
  filter: drop-shadow(0 0 10px rgba(0, 136, 204, 0.4));
}

.sidebar-brand h2 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* الإحصائيات السريعة الجانبية */
.mini-stats {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.m-stat-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.m-stat-title {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.m-stat-value {
  font-weight: 700;
  font-size: 1.2rem;
}

/* أزرار الإجراءات */
.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: auto;
  margin-bottom: 2rem;
}

.action-btn {
  background-color: rgba(37, 99, 235, 0.15);
  border: 1px solid var(--primary);
  color: var(--text-main);
  border-radius: 12px;
  padding: 0.85rem;
  font-family: var(--font-family);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: var(--transition-fast);
}

.action-btn:hover {
  background-color: var(--primary);
  box-shadow: 0 0 15px var(--primary-glow);
  transform: translateY(-2px);
}

.action-btn.accent {
  background-color: rgba(139, 92, 246, 0.15);
  border-color: var(--accent);
}

.action-btn.accent:hover {
  background-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
  border-color: var(--accent);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  border-top: 1px solid var(--card-border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pulse-indicator {
  width: 8px;
  height: 8px;
  background-color: var(--color-success);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* المحتوى الرئيسي */
.main-content {
  padding: 2.5rem;
  overflow-y: auto;
  max-height: 100vh;
}

.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2.5rem;
}

.main-header h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
  background: linear-gradient(135deg, #fff 0%, var(--text-muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* الأنماط الزجاجية (Glassmorphism) */
.glass {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius);
}

/* كروت الـ KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.kpi-card {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  transition: transform var(--transition-fast);
}

.kpi-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.15);
}

.kpi-icon {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.kpi-info h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.kpi-info p {
  font-size: 1.8rem;
  font-weight: 800;
}

/* خلفيات الأيقونات */
.urgency-high-bg {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--color-danger);
}
.positive-bg {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
}
.rating-bg {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--color-warning);
}

/* الرسوم البيانية */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.chart-card {
  padding: 1.5rem;
}

.chart-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--text-main);
}

.chart-container {
  position: relative;
  height: 220px;
  width: 100%;
}

/* شريط البحث والتصفية */
.filter-bar {
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box i {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition-fast);
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.filter-controls {
  display: flex;
  gap: 0.75rem;
}

.filter-controls select {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  font-family: var(--font-family);
  padding: 0.75rem 1.5rem 0.75rem 0.75rem;
  border-radius: 12px;
  cursor: pointer;
  outline: none;
  font-size: 0.9rem;
}

.filter-controls select:focus {
  border-color: var(--primary);
}

/* قسم الرسائل والكروت */
.section-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}

.section-title-bar h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.results-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* تصميم كرت الرسالة */
.message-card {
  padding: 1.5rem;
  cursor: pointer;
  transition: var(--transition-normal);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message-card:hover {
  transform: scale(1.005);
  background: rgba(30, 41, 59, 0.65);
  border-color: rgba(255, 255, 255, 0.15);
}

.msg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.msg-sender-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sender-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
}

.sender-name-details h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.1rem;
}

.sender-name-details span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.msg-badges {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  text-transform: uppercase;
}

/* ألوان الشارات (Badges) */
.badge-pending {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-analyzed {
  background-color: rgba(6, 182, 212, 0.15);
  color: var(--color-info);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.badge-resolved {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-high {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-medium {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-low {
  background-color: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.msg-body {
  font-size: 0.95rem;
  line-height: 1.5;
  color: #cbd5e1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msg-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.ai-summary-excerpt {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-summary-excerpt i {
  color: var(--accent);
}

.stars {
  color: var(--color-warning);
  font-size: 0.85rem;
  display: flex;
  gap: 2px;
}

/* حالات التحميل والخطأ */
.loading-state, .empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.loading-state i {
  font-size: 2rem;
  color: var(--primary);
}

.empty-state i {
  font-size: 2.5rem;
  color: var(--text-muted);
}

/* الأزرار الدائرية */
.icon-button {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.icon-button:hover {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

/* لوحة التفاصيل الجانبية (Drawer) */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  display: none;
  backdrop-filter: blur(4px);
}

.details-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 500px;
  height: 100vh;
  z-index: 100;
  background: #0f172a;
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--transition-normal);
  padding: 2rem;
}

.details-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 1.5rem;
}

.drawer-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.close-drawer {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.close-drawer:hover {
  color: var(--text-main);
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.detail-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.detail-section h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.detail-content-box {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1rem;
  line-height: 1.6;
  font-size: 0.95rem;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.edit-form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.edit-form-group label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.edit-form-group select, .edit-form-group input, .edit-form-group textarea {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 0.75rem;
  border-radius: 12px;
  font-family: var(--font-family);
  outline: none;
}

.edit-form-group select:focus, .edit-form-group input:focus, .edit-form-group textarea:focus {
  border-color: var(--primary);
}

.save-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.9rem;
  font-family: var(--font-family);
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.save-btn:hover {
  background: #1d4ed8;
  box-shadow: 0 0 10px var(--primary-glow);
}

/* المودالات واللوغات */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.8);
  z-index: 101;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.modal.open {
  display: flex;
}

.modal-content {
  width: 600px;
  max-width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
}

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
}

.modal-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 600;
  font-size: 1.1rem;
}

.console-log {
  background: #090d16;
  border: 1px solid var(--card-border);
  color: #10b981;
  padding: 1rem;
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.85rem;
  overflow-y: auto;
  flex: 1;
  min-height: 250px;
  direction: ltr;
  text-align: left;
}

/* فئات الألوان والنصوص المساعدة */
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-info { color: var(--color-info); }

/* التوافق مع الشاشات المتنقلة وتحويل الواجهة لتطبيق جوال */
@media (max-width: 1024px) {
  .dashboard-container {
    grid-template-columns: 1fr;
    padding-bottom: 20px; /* مسافة إضافية في الأسفل */
  }
  
  .sidebar {
    height: auto;
    position: relative;
    padding: 1.25rem 1rem;
    border-left: none;
    border-bottom: 1px solid var(--card-border);
    background: linear-gradient(135deg, #0f172a 0%, #0b0f19 100%);
  }

  .sidebar-brand {
    justify-content: center;
    margin-bottom: 1rem;
  }

  .mini-stats {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
  }

  .mini-stats .m-stat-card {
    flex: 1 1 calc(33.33% - 0.5rem);
    min-width: 90px;
    padding: 0.75rem;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.25rem;
  }

  .mini-stats .m-stat-value {
    font-size: 1.1rem;
  }

  .sidebar-footer {
    display: flex !important; /* السماح بعرض زر اللوغ والتحكم بالكونسول في الجوال */
    width: 100%;
    margin-top: 0.5rem;
  }

  .main-content {
    padding: 1rem;
  }

  .main-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.5rem 0;
  }

  .main-header h1 {
    font-size: 1.5rem;
  }

  .header-controls {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.5rem;
  }

  .header-btn {
    width: 100%;
    justify-content: center;
    padding: 0.75rem 0.5rem !important;
    font-size: 0.8rem !important;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.5rem !important;
  }

  .kpi-card {
    padding: 0.75rem !important;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
  }

  .kpi-icon {
    width: 40px !important;
    height: 40px !important;
    font-size: 1rem !important;
  }

  .kpi-info h3 {
    font-size: 0.75rem;
  }

  .kpi-info p {
    font-size: 1.1rem !important;
  }

  .charts-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .chart-card {
    padding: 1rem !important;
  }

  .filter-bar {
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem !important;
  }

  .search-box {
    width: 100%;
  }

  .filter-controls {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .filter-controls select {
    width: 100%;
  }
  
  #filter-status {
    grid-column: span 2; /* نجعل خيار الحالة يأخذ العرض الكامل لجعل التنسيق متوازن */
  }

  /* تصميم الكروت لتناسب التطبيق */
  .message-card {
    padding: 1rem !important;
    border-radius: 12px;
  }

  .msg-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .msg-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
  }

  .msg-badges .badge {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }

  .msg-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    border-top: 1px solid var(--card-border);
    padding-top: 0.75rem;
    margin-top: 0.75rem;
  }

  .ai-summary-excerpt {
    width: 100%;
  }

  .msg-footer > div:last-child {
    width: 100%;
    justify-content: space-between;
    flex-direction: row-reverse;
  }

  /* تحسين لوحة التفاصيل الجانبية لتصبح شاشة كاملة مثل التطبيقات */
  .details-drawer {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    max-width: 100%;
  }
}

/* تنسيق أزرار الهيدر الجديدة للويب */
.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-btn {
  padding: 0.65rem 1.25rem !important;
  font-size: 0.85rem !important;
  border-radius: 10px !important;
}


