/* ====== IMPROVED CHATBOT DESIGN - MAFQOOD STYLE ====== */

/* Chatbot Container */
#chatbot-widget {
  z-index: 2147483646 !important;
  pointer-events: auto !important;
  font-family: 'Cairo', 'Open Sans', sans-serif;
}

/* Floating Bubble Button */
.chatbot-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5c1073, #8a2be2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  box-shadow:
    0 8px 25px rgba(92, 16, 115, 0.4),
    0 0 0 2px rgba(255, 255, 255, 0.1);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 2147483647 !important;
  overflow: hidden;
}

.chatbot-bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: left 0.6s ease;
}

.chatbot-bubble:hover {
  transform: scale(1.1) rotate(5deg);
  box-shadow:
    0 12px 35px rgba(92, 16, 115, 0.5),
    0 0 0 3px rgba(255, 255, 255, 0.2);
}

.chatbot-bubble:hover::before {
  left: 100%;
}

.chatbot-bubble:active {
  transform: scale(0.95);
}

.chatbot-bubble i {
  font-size: 1.8rem;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
}

/* Chat Panel - FIXED HEIGHT ONLY */
.chatbot-panel {
  position: fixed;
  bottom: 28px;
  right: 112px;
  width: 400px;
  /* العرض الأصلي */
  max-width: calc(100% - 140px);
  height: 520px;
  /* تقليل الارتفاع من 580px إلى 520px */
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(248, 245, 250, 0.98));
  border-radius: 20px;
  box-shadow:
    0 25px 70px rgba(92, 16, 115, 0.25),
    0 0 0 1px rgba(92, 16, 115, 0.1);
  display: none;
  overflow: hidden;
  flex-direction: column;
  border: 2px solid rgba(92, 16, 115, 0.15);
  z-index: 2147483647 !important;
  pointer-events: auto;
  backdrop-filter: blur(10px);
  transform-origin: bottom right;
  animation: panelSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes panelSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.chatbot-panel.open {
  display: flex;
  animation: panelSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Chat Header - تقليل الارتفاع قليلاً */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  /* تقليل padding العلوي والسفلي */
  background: linear-gradient(135deg, #5c1073, #8a2be2);
  color: #fff;
  position: relative;
  z-index: 2147483648;
  border-bottom: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  /* منع التقلص */
}

.chatbot-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="50" viewBox="0 0 200 50"><circle cx="20" cy="25" r="3" fill="rgba(255,255,255,0.2)"/><circle cx="180" cy="25" r="3" fill="rgba(255,255,255,0.2)"/></svg>') repeat;
  opacity: 0.3;
}

.chatbot-title {
  font-weight: 800;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  gap: 10px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.chatbot-title i {
  font-size: 1.2rem;
}

.chatbot-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.chatbot-controls button {
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

.chatbot-controls button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
  border-color: rgba(255, 255, 255, 0.4);
}

/* Chat Body - تحسين توزيع الارتفاع */
.chatbot-body {
  display: flex;
  flex-direction: column;
  height: calc(100% - 60px);
  /* ارتفاع ثابت */
  padding: 15px 20px;
  /* تقليل padding */
  background: linear-gradient(135deg, #f9f7fa, #f0ecf3);
  overflow: hidden;
  /* منع التجاوز */
}

.chatbot-messages {
  flex: 1;
  /* يأخذ المساحة المتبقية */
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* تقليل الفجوة */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  /* تقليل padding */
  box-sizing: border-box;
}

/* Custom Scrollbar */
.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: rgba(92, 16, 115, 0.05);
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(92, 16, 115, 0.3);
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(92, 16, 115, 0.5);
}

/* Message Bubbles - FIXED VERSION */
.chat-msg {
  margin: 8px 0;
  /* تقليل الهامش */
  max-width: calc(100% - 50px);
  padding: 12px 16px;
  /* تقليل padding */
  border-radius: 18px;
  position: relative;
  line-height: 1.5;
  /* تقليل line-height */
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  animation: messageAppear 0.3s ease-out;
}

@keyframes messageAppear {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* رسائل المستخدم مع رمز داخلي */
.chat-msg.user {
  background: linear-gradient(135deg, #5c1073, #8a2be2);
  color: white;
  margin-left: auto;
  margin-right: 0;
  border-radius: 18px 18px 4px 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  text-align: right;
  box-shadow: 0 4px 12px rgba(92, 16, 115, 0.2);
  /* ظل أخف */
  padding: 12px 40px 12px 16px;
  /* تعديل padding */
  position: relative;
}

/* رسائل البوت مع رمز داخلي */
.chat-msg.bot {
  background: linear-gradient(135deg, #f0ecf3, #e8e3eb);
  color: #333;
  margin-right: auto;
  margin-left: 0;
  border-radius: 18px 18px 18px 4px;
  border: 1px solid rgba(92, 16, 115, 0.1);
  text-align: right;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  /* ظل أخف */
  padding: 12px 16px 12px 40px;
  /* تعديل padding */
  position: relative;
}

/* رمز المستخدم داخل الرسالة */
.chat-msg.user::after {
  content: '👤';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  /* أصغر قليلاً */
  opacity: 0.9;
}

/* رمز البوت داخل الرسالة */
.chat-msg.bot::before {
  content: '🤖';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  /* أصغر قليلاً */
  opacity: 0.9;
}

/* Input Form - تقليل الارتفاع */
.chatbot-form {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  /* تقليل padding */
  border-top: 2px solid rgba(92, 16, 115, 0.1);
  flex-shrink: 0;
  /* منع التقلص */
}

.chatbot-form input {
  flex: 1;
  padding: 12px 16px;
  /* تقليل padding */
  border-radius: 15px;
  border: 2px solid rgba(92, 16, 115, 0.2);
  background: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
  /* أصغر قليلاً */
  transition: all 0.3s ease;
  color: #333;
}

.chatbot-form input:focus {
  outline: none;
  border-color: #5c1073;
  box-shadow: 0 0 0 3px rgba(92, 16, 115, 0.1);
  background: white;
}

.chatbot-form input::placeholder {
  color: #999;
  font-size: 0.9rem;
  /* أصغر قليلاً */
}

.chatbot-form button {
  padding: 12px 20px;
  /* تقليل padding */
  background: linear-gradient(135deg, #5c1073, #8a2be2);
  color: #fff;
  border: none;
  border-radius: 15px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.95rem;
  /* أصغر قليلاً */
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  /* تقليل الفجوة */
  box-shadow: 0 4px 12px rgba(92, 16, 115, 0.3);
  /* ظل أخف */
  position: relative;
  overflow: hidden;
}

.chatbot-form button:hover {
  background: linear-gradient(135deg, #4a0e5e, #7a24d1);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(92, 16, 115, 0.4);
  /* ظل أخف */
}

.chatbot-form button:active {
  transform: translateY(0);
}

.chatbot-form button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.chatbot-form button:hover::before {
  left: 100%;
}

.chatbot-form button i {
  font-size: 1rem;
  /* أصغر قليلاً */
}

/* Fullscreen Mode */
.chatbot-panel.fullscreen {
  position: fixed !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0 !important;
  margin: 0 !important;
  animation: fullscreenOpen 0.4s ease-out;
}

@keyframes fullscreenOpen {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.chatbot-panel.fullscreen .chatbot-body {
  padding-top: 70px;
  height: 100%;
}

.chatbot-panel.fullscreen .chatbot-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 70px;
  display: flex;
  align-items: center;
  padding: 15px 25px;
  z-index: 2147483649;
  border-radius: 0;
}

.chatbot-panel.fullscreen .chatbot-messages {
  max-height: calc(100vh - 160px);
  /* تعديل الارتفاع */
  padding-bottom: 20px;
}

/* Welcome Message - تقليل الحجم */
.welcome-message {
  text-align: center;
  padding: 20px 15px;
  /* تقليل padding */
  background: linear-gradient(135deg, rgba(92, 16, 115, 0.05), rgba(138, 43, 226, 0.05));
  border-radius: 15px;
  margin-bottom: 15px;
  /* تقليل الهامش */
  border: 2px dashed rgba(92, 16, 115, 0.2);
}

.welcome-message h4 {
  color: #5c1073;
  font-size: 1.1rem;
  /* أصغر قليلاً */
  margin-bottom: 8px;
  /* تقليل الهامش */
  font-weight: 700;
}

.welcome-message p {
  color: #666;
  font-size: 0.9rem;
  /* أصغر قليلاً */
  margin: 6px 0;
  /* تقليل الهامش */
  line-height: 1.4;
  /* تقليل line-height */
}

/* Tooltips */
.chatbot-panel:hover::before {
  content: "مساعد مفقود الذكي";
  position: absolute;
  top: -42px;
  right: 12px;
  background: linear-gradient(135deg, #5c1073, #8a2be2);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  white-space: nowrap;
  z-index: 2147483650;
  pointer-events: none;
  box-shadow: 0 8px 25px rgba(92, 16, 115, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  animation: tooltipFade 0.3s ease-out;
}

@keyframes tooltipFade {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-bubble:hover::after {
  content: "اسأل مساعد مفقود";
  position: fixed;
  bottom: 104px;
  right: 28px;
  background: linear-gradient(135deg, #5c1073, #8a2be2);
  color: #fff;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
  white-space: nowrap;
  z-index: 2147483650;
  pointer-events: none;
  box-shadow: 0 8px 25px rgba(92, 16, 115, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  animation: bubbleTooltip 0.3s ease-out;
}

@keyframes bubbleTooltip {
  from {
    opacity: 0;
    transform: translateY(5px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Loading Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 15px;
  /* تقليل padding */
  background: rgba(92, 16, 115, 0.05);
  border-radius: 18px;
  width: fit-content;
  margin: 8px 0;
  /* تقليل الهامش */
}

.typing-indicator span {
  width: 7px;
  /* أصغر قليلاً */
  height: 7px;
  /* أصغر قليلاً */
  border-radius: 50%;
  background: #5c1073;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.6;
  }

  30% {
    transform: translateY(-4px);
    /* حركة أقل */
    opacity: 1;
  }
}

/* Quick Suggestions */
.quick-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  /* تقليل الفجوة */
  margin-top: 12px;
  /* تقليل الهامش */
  padding: 12px;
  /* تقليل padding */
  background: rgba(255, 255, 255, 0.8);
  border-radius: 15px;
  border: 1px solid rgba(92, 16, 115, 0.1);
}

.quick-suggestion {
  padding: 7px 14px;
  /* تقليل padding */
  background: linear-gradient(135deg, rgba(92, 16, 115, 0.1), rgba(138, 43, 226, 0.1));
  border: 1px solid rgba(92, 16, 115, 0.2);
  border-radius: 20px;
  color: #5c1073;
  font-size: 0.85rem;
  /* أصغر قليلاً */
  cursor: pointer;
  transition: all 0.3s ease;
}

.quick-suggestion:hover {
  background: linear-gradient(135deg, rgba(92, 16, 115, 0.2), rgba(138, 43, 226, 0.2));
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(92, 16, 115, 0.15);
  /* ظل أخف */
}

/* Responsive Design */
@media (max-width: 768px) {
  .chatbot-panel {
    right: 20px;
    left: 20px;
    width: auto;
    height: 65vh;
    /* تقليل الارتفاع على الجوال */
    bottom: 20px;
    max-width: calc(100% - 40px);
  }

  .chatbot-bubble {
    right: 20px;
    bottom: 20px;
    width: 60px;
    height: 60px;
  }

  .chatbot-bubble:hover::after {
    bottom: 90px;
    right: 20px;
  }

  .chatbot-panel:hover::before {
    top: -38px;
    right: 10px;
    font-size: 0.85rem;
    padding: 8px 14px;
  }

  /* تعديل الرموز للأجهزة المحمولة */
  .chat-msg.user,
  .chat-msg.bot {
    max-width: calc(100% - 40px);
    padding: 10px 35px 10px 12px;
  }

  .chat-msg.bot {
    padding: 10px 12px 10px 35px;
  }

  .chat-msg.user::after,
  .chat-msg.bot::before {
    font-size: 0.95rem;
    right: 10px;
    left: 10px;
  }
}

@media (max-width: 480px) {
  .chatbot-panel {
    right: 10px;
    left: 10px;
    height: 70vh;
    /* تقليل الارتفاع أكثر */
    max-width: calc(100% - 20px);
  }

  .chatbot-bubble {
    right: 15px;
    bottom: 15px;
    width: 56px;
    height: 56px;
  }

  .chatbot-form {
    flex-direction: column;
    gap: 8px;
  }

  .chatbot-form input,
  .chatbot-form button {
    width: 100%;
  }

  .chatbot-form button {
    justify-content: center;
  }

  /* تعديل إضافي للرموز على الشاشات الصغيرة */
  .chat-msg.user,
  .chat-msg.bot {
    max-width: calc(100% - 35px);
    padding: 10px 30px 10px 10px;
  }

  .chat-msg.bot {
    padding: 10px 10px 10px 30px;
  }

  .chat-msg.user::after,
  .chat-msg.bot::before {
    font-size: 0.9rem;
    right: 8px;
    left: 8px;
  }
}

/* Dark Mode Support */
.dark .chatbot-panel {
  background: linear-gradient(135deg, rgba(30, 30, 30, 0.95), rgba(45, 45, 45, 0.95));
  border-color: rgba(92, 16, 115, 0.3);
}

.dark .chatbot-body {
  background: linear-gradient(135deg, #1a1a1a, #2d2d2d);
}

.dark .chatbot-messages {
  background: rgba(30, 30, 30, 0.8);
  border-color: rgba(92, 16, 115, 0.2);
}

.dark .chat-msg.bot {
  background: linear-gradient(135deg, #2d2d2d, #404040);
  color: #e0e0e0;
  border-color: rgba(92, 16, 115, 0.3);
}

.dark .chat-msg.user {
  background: linear-gradient(135deg, #5c1073, #8a2be2);
  color: white;
  border-color: rgba(255, 255, 255, 0.1);
}

.dark .chatbot-form input {
  background: rgba(45, 45, 45, 0.9);
  border-color: rgba(92, 16, 115, 0.3);
  color: #e0e0e0;
}

.dark .chatbot-form input:focus {
  background: rgba(50, 50, 50, 0.95);
}

.dark .quick-suggestions {
  background: rgba(30, 30, 30, 0.8);
  border-color: rgba(92, 16, 115, 0.2);
}

.dark .quick-suggestion {
  background: linear-gradient(135deg, rgba(92, 16, 115, 0.15), rgba(138, 43, 226, 0.15));
  border-color: rgba(92, 16, 115, 0.3);
  color: #e0e0e0;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {

  .chatbot-bubble,
  .chatbot-panel,
  .chat-msg,
  .chatbot-form button,
  .typing-indicator span,
  .quick-suggestion {
    animation: none !important;
    transition: none !important;
  }
}

.chatbot-bubble:focus,
.chatbot-controls button:focus,
.chatbot-form button:focus,
.chatbot-form input:focus {
  outline: 3px solid #5c1073;
  outline-offset: 2px;
}

/* تحسين إضافي للرموز */
.chat-msg.user .msg-timestamp,
.chat-msg.bot .msg-timestamp {
  display: block;
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 4px;
  /* تقليل الهامش */
  text-align: left;
}

.chat-msg.user .msg-timestamp {
  color: rgba(255, 255, 255, 0.8);
}

.chat-msg.bot .msg-timestamp {
  color: rgba(0, 0, 0, 0.6);
}

.dark .chat-msg.bot .msg-timestamp {
  color: rgba(255, 255, 255, 0.6);
}