/* =====================================================
   OutMart Chat — Light + Dark Mode + Modern UI
   بدون تغيير HTML أو JS — نسخة متوافقة بالكامل
   ===================================================== */

/* 🎨 الوضع الفاتح الافتراضي */
:root {
  --bg: #e5e7eb;
  --card: #ffffff;
  --text: #111827;
  --bubble-user-bg: #ffffff;
  --bubble-admin-bg: linear-gradient(135deg, #004aad, #2563eb);
  --bubble-user-border: #d1d5db;
  --meta: #6b7280;
  --attachment-border: #cbd5e1;

  --input-bg: #f9fafb;
  --input-border: #d1d5db;
  --send-bg: linear-gradient(135deg, #ff7b00, #ff9800);
  --attach-bg: #f3f4f6;
  --attach-border: #d1d5db;
}

/* 🎨 الوضع الفاتح الإجباري */
html[data-theme="light"] {
  color-scheme: light;
  --bg: #e5e7eb;
  --card: #ffffff;
  --text: #111827;
  --bubble-user-bg: #ffffff;
  --bubble-admin-bg: linear-gradient(135deg, #004aad, #2563eb);
  --bubble-user-border: #d1d5db;
  --meta: #6b7280;
  --attachment-border: #cbd5e1;

  --input-bg: #f9fafb;
  --input-border: #d1d5db;
  --send-bg: linear-gradient(135deg, #ff7b00, #ff9800);
  --attach-bg: #f3f4f6;
  --attach-border: #d1d5db;
}

/* 🌙 الوضع الداكن التلقائي */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #f8fafc;
    --bubble-user-bg: #334155;
    --bubble-admin-bg: linear-gradient(135deg, #0284c7, #0369a1);
    --bubble-user-border: #475569;
    --meta: #cbd5e1;
    --attachment-border: #475569;

    --input-bg: #1e293b;
    --input-border: #334155;
    --send-bg: linear-gradient(135deg, #f97316, #fb923c);
    --attach-bg: #334155;
    --attach-border: #475569;
  }
}

/* 🌙 الوضع الداكن الإجباري */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --card: #1e293b;
  --text: #f8fafc;
  --bubble-user-bg: #334155;
  --bubble-admin-bg: linear-gradient(135deg, #0284c7, #0369a1);
  --bubble-user-border: #475569;
  --meta: #cbd5e1;
  --attachment-border: #475569;

  --input-bg: #1e293b;
  --input-border: #334155;
  --send-bg: linear-gradient(135deg, #f97316, #fb923c);
  --attach-bg: #334155;
  --attach-border: #475569;
}

/* 🧱 الخلفية العامة */
body {
  background: var(--bg);
  font-family: "Tajawal", sans-serif;
  direction: rtl;
  margin: 0;
  padding: 0;
  color: var(--text);
}

/* 🧩 منطقة الشات */
.chat-embed {
  max-width: 900px;
  margin: 20px auto;
  padding: 12px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
}

/* 📩 قائمة الرسائل */
.msgs,
#messages {
  height: 65vh;
  overflow-y: auto;
  padding: 14px;
  background: var(--bg);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: #9ca3af #e5e7eb;
}

/* 🔧 سكرول كروم */
.msgs::-webkit-scrollbar,
#messages::-webkit-scrollbar { width: 6px; }
.msgs::-webkit-scrollbar-thumb,
#messages::-webkit-scrollbar-thumb {
  background: #9ca3af;
  border-radius: 10px;
}

/* =====================================================
   💬 الرسائل (فقاعات)
   ===================================================== */

.msg {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  margin: 4px 0;
  animation: fadeIn 0.25s ease-out;
}

/* 🧑‍💼 الأدمن */
.msg.admin {
  align-self: flex-end;
}
.msg.admin .bubble {
  background: var(--bubble-admin-bg);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 10px 14px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* 👤 المستخدم */
.msg.user {
  align-self: flex-start;
}
.msg.user .bubble {
  background: var(--bubble-user-bg);
  color: var(--text);
  border: 1px solid var(--bubble-user-border);
  border-radius: 18px 18px 18px 4px;
  padding: 10px 14px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}

/* نص الفقاعة */
.bubble div:first-child {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
}

/* الوقت */
.meta {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 4px;
  align-self: flex-end;
  direction: ltr;
  color: var(--meta);
}

/* الصور داخل الرسائل */
img.attachment {
  max-width: 240px;
  border-radius: 10px;
  margin-top: 6px;
  border: 1px solid var(--attachment-border);
}

/* =====================================================
   📸 معاينة الصورة قبل الإرسال
   ===================================================== */

#uploadPreview {
  display: none;
  background: var(--card);
  border: 1px solid var(--attach-border);
  border-radius: 12px;
  padding: 8px;
  margin: 10px 0;
  gap: 10px;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

#uploadPreview img {
  max-height: 60px;
  border-radius: 8px;
  border: 1px solid var(--attachment-border);
}

/* =====================================================
   ✏️ منطقة الإدخال (فورم الرسائل)
   ===================================================== */

#chatForm {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  padding: 10px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--input-border);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* زر الإرفاق */
.attach-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 12px;
  background: var(--attach-bg);
  border: 1px dashed var(--attach-border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
}
.attach-btn:hover {
  background: var(--bubble-user-border);
}

/* حقل الكتابة */
#messageInput {
  flex: 1;
  height: 42px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 12px;
  padding: 0 12px;
  color: var(--text);
  outline: none;
}
#messageInput:focus {
  border-color: var(--bubble-admin-bg);
}

/* زر الإرسال */
.send-btn {
  width: 46px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: var(--send-bg);
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.15s;
}
.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.15);
}

/* =====================================================
   🟦 زر التبديل بين Light / Dark
   ===================================================== */

#themeToggle {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  background: var(--card);
  border: 1px solid var(--input-border);
  backdrop-filter: blur(8px);
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  z-index: 9999;
  transition: 0.25s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
#themeToggle:hover {
  transform: translateY(-2px);
}

/* =====================================================
   📱 موبايل
   ===================================================== */

@media (max-width: 768px) {
  .chat-embed {
    padding: 6px;
    border-radius: 0;
    box-shadow: none;
  }

  #messages {
    height: calc(100vh - 210px);
  }

  #themeToggle {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
  }
}

/* أنيميشن */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}
