/* ===== CHATBOT ÉDUCATIF EN ARABE - STYLES CSS ===== */

/* Variables CSS pour la cohérence des couleurs */
:root {
  /* Couleurs principales éducatives */
  --primary-color: #2563eb; /* Bleu éducatif */
  --primary-hover: #1d4ed8;
  --secondary-color: #059669; /* Vert succès */
  --accent-color: #7c3aed; /* Violet créatif */
  
  /* Couleurs de fond */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-chat: #f1f5f9;
  --bg-overlay: rgba(0, 0, 0, 0.5);
  
  /* Couleurs des messages */
  --user-message-bg: #dbeafe;
  --user-message-border: #3b82f6;
  --bot-message-bg: #f0f9ff;
  --bot-message-border: #0ea5e9;
  
  /* Couleurs du texte */
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-white: #ffffff;
  
  /* Ombres */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  /* Rayons de bordure */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 0.15s ease-in-out;
  --transition-normal: 0.3s ease-in-out;
  --transition-slow: 0.5s ease-in-out;
}

/* ===== RESET ET BASE ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Support RTL global */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

/* Police arabe optimisée */
.chatbot-container,
.chatbot-container * {
  font-family: 'Noto Sans Arabic', 'Cairo', 'Amiri', 'Tajawal', Arial, sans-serif;
  direction: rtl;
  text-align: right;
}

/* ===== BULLE FLOTTANTE ===== */
.chatbot-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, #3b82f6, #2563eb, #1d4ed8); /* Dégradé de bleu harmonieux */
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-normal);
  border: none;
  outline: none;
  overflow: hidden;
  padding: 8px;
}

.chatbot-bubble::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
  border-radius: var(--radius-full);
  transition: opacity var(--transition-normal);
  opacity: 0;
}

.chatbot-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 20px 40px -10px rgba(59, 130, 246, 0.4);
}

.chatbot-bubble:hover::before {
  opacity: 1;
}

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

/* Image de la bulle */
.chatbot-bubble-image {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-full);
  object-fit: cover;
  transition: transform var(--transition-fast);
  z-index: 1;
  position: relative;
}

.chatbot-bubble.active .chatbot-bubble-image {
  transform: rotate(5deg) scale(1.05);
}

/* Icône de la bulle (pour compatibilité) */
.chatbot-bubble-icon {
  width: 28px;
  height: 28px;
  fill: var(--text-white);
  transition: transform var(--transition-fast);
}

.chatbot-bubble.active .chatbot-bubble-icon {
  transform: rotate(180deg);
}

/* Badge de notification */
.chatbot-notification-badge {
  position: absolute;
  top: -5px;
  left: -5px;
  background: #ef4444;
  color: var(--text-white);
  border-radius: var(--radius-full);
  width: 20px;
  height: 20px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== CONTENEUR PRINCIPAL DU CHAT ===== */
.chatbot-container {
  position: fixed;
  bottom: 100px;
  right: 20px;
  width: 400px;
  max-width: calc(100vw - 40px);
  height: 550px;
  max-height: calc(100vh - 140px);
  background: var(--bg-primary);
  border-radius: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.1);
  z-index: 1001;
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(59, 130, 246, 0.2);
  animation: slideInUp var(--transition-normal);
  backdrop-filter: blur(20px);
}

.chatbot-container.active {
  display: flex;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ===== EN-TÊTE DU CHAT ===== */
.chatbot-header {
  background: linear-gradient(135deg, #3b82f6, #2563eb, #1d4ed8);
  color: var(--text-white);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 24px 24px 0 0;
  position: relative;
  overflow: hidden;
}

.chatbot-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
  pointer-events: none;
}

.chatbot-header-content {
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.chatbot-avatar {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.chatbot-avatar-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.chatbot-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.chatbot-subtitle {
  font-size: 13px;
  opacity: 0.9;
  margin: 0;
  font-weight: 400;
}

.chatbot-full-search {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--text-white);
  text-decoration: none;
  padding: 10px;
  border-radius: 12px;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.chatbot-full-search:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
  color: var(--text-white);
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.chatbot-full-search-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.chatbot-close {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--text-white);
  cursor: pointer;
  padding: 10px;
  border-radius: 12px;
  transition: all var(--transition-fast);
  backdrop-filter: blur(10px);
}

.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.chatbot-close-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ===== ZONE DES MESSAGES ===== */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Scrollbar personnalisée */
.chatbot-messages::-webkit-scrollbar {
  width: 8px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: rgba(59, 130, 246, 0.1);
  border-radius: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(59, 130, 246, 0.3);
  border-radius: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(59, 130, 246, 0.5);
}

/* ===== MESSAGES ===== */
.chatbot-message {
  display: flex;
  gap: 12px;
  animation: fadeInUp 0.4s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-message.user {
  flex-direction: row-reverse;
}

.chatbot-message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chatbot-message.user .chatbot-message-avatar {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.chatbot-message.bot .chatbot-message-avatar {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
}

.chatbot-message-avatar-icon {
  width: 18px;
  height: 18px;
  fill: var(--text-white);
}

.chatbot-message-content {
  max-width: 75%;
  background: var(--bg-primary);
  padding: 16px 20px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  position: relative;
  backdrop-filter: blur(10px);
}

.chatbot-message.user .chatbot-message-content {
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 20px 20px 8px 20px;
}

.chatbot-message.bot .chatbot-message-content {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 1px solid rgba(14, 165, 233, 0.2);
  border-radius: 20px 20px 20px 8px;
}

.chatbot-message-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  margin: 0;
  word-wrap: break-word;
  font-weight: 400;
}

.chatbot-message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: left;
  font-weight: 500;
}

/* ===== INDICATEUR DE FRAPPE ===== */
.chatbot-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bot-message-bg);
  border: 1px solid var(--bot-message-border);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  max-width: 75%;
}

.chatbot-typing-dots {
  display: flex;
  gap: 4px;
}

.chatbot-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-secondary);
  border-radius: var(--radius-full);
  animation: typingDot 1.4s infinite ease-in-out;
}

.chatbot-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.chatbot-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingDot {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===== RÉSULTATS DE RECHERCHE ===== */
.chatbot-results {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chatbot-result-item {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 16px;
  padding: 16px;
  transition: all var(--transition-fast);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.chatbot-result-item:hover {
  border-color: var(--primary-color);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}

.chatbot-result-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 6px;
  line-height: 1.4;
}

.chatbot-result-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 10px;
}

.chatbot-result-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chatbot-result-tag {
  background: linear-gradient(135deg, #e0f2fe, #bfdbfe);
  color: var(--primary-color);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
  border: 1px solid rgba(59, 130, 246, 0.15);
}

/* ===== ZONE DE SAISIE ===== */
.chatbot-input-area {
  padding: 20px 24px;
  background: var(--bg-primary);
  border-top: 1px solid rgba(59, 130, 246, 0.15);
  border-radius: 0 0 24px 24px;
}

.chatbot-input-container {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.chatbot-input {
  flex: 1;
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 2px solid rgba(59, 130, 246, 0.2);
  border-radius: 20px;
  padding: 14px 18px;
  font-size: 15px;
  font-family: inherit;
  direction: rtl;
  text-align: right;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  transition: all var(--transition-fast);
  outline: none;
  font-weight: 400;
}

.chatbot-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
  background: var(--bg-primary);
}

.chatbot-input::placeholder {
  color: var(--text-muted);
  direction: rtl;
  text-align: right;
  font-weight: 400;
}

.chatbot-send-button {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: var(--text-white);
  border: none;
  border-radius: 20px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.chatbot-send-button:hover:not(:disabled) {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

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

.chatbot-send-button:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.chatbot-send-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* ===== SUGGESTIONS RAPIDES ===== */
.chatbot-suggestions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  justify-content: center;
}

.chatbot-suggestion {
  background: linear-gradient(135deg, #e0f2fe, #bfdbfe);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: var(--primary-color);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.chatbot-suggestion:hover {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: var(--text-white);
  border-color: var(--primary-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ===== MESSAGE DE BIENVENUE ===== */
.chatbot-welcome {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
}

.chatbot-welcome-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, #e0f2fe, #bfdbfe);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.chatbot-welcome-icon svg {
  width: 28px;
  height: 28px;
  fill: var(--primary-color);
}

.chatbot-welcome-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.chatbot-welcome-text {
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 480px) {
  .chatbot-container {
    width: calc(100vw - 70px);
    height: calc(100vh - 170px);
    bottom: 90px;
    right: 30px;
    left: 10px;
    border-radius: 20px;
  }
  
  .chatbot-bubble {
    bottom: 15px;
    right: 15px;
    width: 64px;
    height: 64px;
  }
  
  .chatbot-bubble-image {
    width: 48px;
    height: 48px;
  }
  
  .chatbot-bubble-icon {
    width: 24px;
    height: 24px;
  }
  
  .chatbot-header {
    padding: 16px 20px;
    border-radius: 20px 20px 0 0;
  }
  
  .chatbot-messages {
    padding: 16px;
  }
  
  .chatbot-input-area {
    padding: 16px 20px;
    border-radius: 0 0 20px 20px;
  }
  
  .chatbot-message-content {
    max-width: 85%;
  }
}

@media (max-width: 320px) {
  .chatbot-container {
    width: calc(100vw - 10px);
    right: 5px;
    left: 5px;
  }
  
  .chatbot-bubble {
    right: 10px;
    width: 60px;
    height: 60px;
  }
  
  .chatbot-bubble-image {
    width: 44px;
    height: 44px;
  }
}

/* ===== ÉTATS DE CHARGEMENT ===== */
.chatbot-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--text-secondary);
}

.chatbot-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--bg-secondary);
  border-top: 2px solid var(--primary-color);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
  margin-left: 8px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ===== ACCESSIBILITÉ ===== */
.chatbot-container:focus-within {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

.chatbot-bubble:focus,
.chatbot-send-button:focus,
.chatbot-input:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* ===== ANIMATIONS D'ENTRÉE ===== */
.chatbot-fade-in {
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chatbot-slide-in {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ===== THÈME SOMBRE (OPTIONNEL) ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1e293b;
    --bg-secondary: #334155;
    --bg-chat: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --user-message-bg: #1e40af;
    --bot-message-bg: #0f172a;
  }
  
  .chatbot-input {
    background: var(--bg-secondary);
    color: var(--text-primary);
  }
  
  .chatbot-result-item {
    background: var(--bg-secondary);
    border-color: #475569;
  }
}

/* ===== UTILITAIRES ===== */
.chatbot-hidden {
  display: none !important;
}

.chatbot-visible {
  display: block !important;
}

.chatbot-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Indicateur du chatbot (pour intégration externe) ===== */
.chatbot-indicator {
    position: fixed !important;
    bottom: 100px !important;
    right: 30px !important;
    background: #2563eb !important;
    color: white !important;
    padding: 12px 24px !important; /* Converti 0.75rem (12px) et 1.5rem (24px) pour une base de 16px */
    border-radius: 2rem !important;
    font-size: 16px !important; /* Converti 1rem (16px) pour une base de 16px */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
    animation: bounce 2s infinite !important;
    z-index: 998 !important;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

.chatbot-indicator::after {
    content: '';
    position: absolute !important;
    bottom: -5px !important;
    right: 20px !important;
    width: 0 !important;
    height: 0 !important;
    border-left: 5px solid transparent !important;
    border-right: 5px solid transparent !important;
    border-top: 5px solid #2563eb !important;
}


/* Animation de fadeOut */
@keyframes fadeOut {
    from {
        opacity: 1 !important;
        transform: translateY(0) !important;
    }
    to {
        opacity: 0 !important;
        transform: translateY(20px) !important;
    }
}

