/* ===== CHATBOT API - STYLES CSS ===== */

/* Variables CSS pour la cohérence des couleurs */
:root {
  /* Couleurs principales pour le chatbot API (différentes du chatbot de recherche) */
  --api-primary-color: #059669; /* Vert émeraude */
  --api-primary-hover: #047857;
  --api-secondary-color: #7c3aed; /* Violet */
  --api-accent-color: #f59e0b; /* Orange/ambre */
  
  /* Couleurs de fond */
  --api-bg-primary: #ffffff;
  --api-bg-secondary: #f0fdf4;
  --api-bg-chat: #ecfdf5;
  --api-bg-overlay: rgba(0, 0, 0, 0.5);
  
  /* Couleurs des messages */
  --api-user-message-bg: #d1fae5;
  --api-user-message-border: #059669;
  --api-bot-message-bg: #f0f9ff;
  --api-bot-message-border: #0ea5e9;
  
  /* Couleurs du texte */
  --api-text-primary: #1e293b;
  --api-text-secondary: #64748b;
  --api-text-muted: #94a3b8;
  --api-text-white: #ffffff;
  
  /* Ombres */
  --api-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --api-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --api-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --api-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 */
  --api-radius-sm: 0.375rem;
  --api-radius-md: 0.5rem;
  --api-radius-lg: 0.75rem;
  --api-radius-xl: 1rem;
  --api-radius-full: 9999px;
  
  /* Transitions */
  --api-transition-fast: 0.15s ease-in-out;
  --api-transition-normal: 0.3s ease-in-out;
  --api-transition-slow: 0.5s ease-in-out;
}

/* ===== RESET ET BASE ===== */
.api-chatbot-container,
.api-chatbot-container * {
  font-family: 'Noto Sans Arabic', 'Cairo', 'Amiri', 'Tajawal', Arial, sans-serif;
  direction: rtl;
  text-align: right;
  box-sizing: border-box;
}

/* ===== BULLE FLOTTANTE ===== */
.api-chatbot-bubble {
  position: fixed !important; /* Force fixed position */
  bottom: 20px;
  left: 20px; /* Positionné à gauche contrairement au chatbot de recherche */
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, #10b981, #059669, #047857); /* Dégradé de vert harmonieux */
  border-radius: var(--api-radius-full);
  cursor: pointer;
  box-shadow: var(--api-shadow-lg);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--api-transition-normal);
  border: none;
  outline: none;
  overflow: hidden;
  padding: 8px;
}

.api-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(--api-radius-full);
  transition: opacity var(--api-transition-normal);
  opacity: 0;
}

.api-chatbot-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 20px 40px -10px rgba(5, 150, 105, 0.4);
}

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

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

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

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

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

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

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

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

/* ===== CONTENEUR PRINCIPAL DU CHAT ===== */
.api-chatbot-container {
  position: fixed;
  bottom: 100px;
  left: 20px; /* Positionné à gauche */
  width: 400px;
  max-width: calc(100vw - 40px);
  height: 550px;
  max-height: calc(100vh - 140px);
  background: var(--api-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: 10001;
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(16, 185, 129, 0.2);
  animation: api-slideInUp var(--api-transition-normal);
  backdrop-filter: blur(20px);
}

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

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

/* ===== EN-TÊTE DU CHAT ===== */
.api-chatbot-header {
  background: linear-gradient(135deg, #10b981, #059669, #047857); /* Dégradé harmonieux avec la bulle */
  color: var(--api-text-white);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 24px 24px 0 0;
  position: relative;
  overflow: hidden;
}

.api-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;
}

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

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

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

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

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

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

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

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

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

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

.api-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);
}

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

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

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

.api-chatbot-messages::-webkit-scrollbar-track {
  background: rgba(16, 185, 129, 0.1);
  border-radius: 4px;
}

.api-chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(16, 185, 129, 0.3);
  border-radius: 4px;
}

.api-chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(16, 185, 129, 0.5);
}

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

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

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

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

.api-chatbot-message-user .api-chatbot-message-avatar {
  background: linear-gradient(135deg, #10b981, #059669);
}

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

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

.api-chatbot-message-content {
  max-width: 75%;
  background: var(--api-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);
}

.api-chatbot-message-user .api-chatbot-message-content {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: 20px 20px 8px 20px;
}

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

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

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

.api-chatbot-message-user .api-chatbot-message-time {
  text-align: right;
}

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

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

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

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

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

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

.api-chatbot-token-info {
    font-size: 12px;
    color: var(--api-text-secondary);
    text-align: center;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    border-radius: 12px;
    border: 1px solid rgba(16, 185, 129, 0.2);
    font-weight: 500;
}

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

.api-chatbot-input {
  flex: 1;
  background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
  border: 2px solid rgba(16, 185, 129, 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(--api-transition-fast);
  outline: none;
  font-weight: 400;
}

.api-chatbot-input:focus {
  border-color: var(--api-primary-color);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.15);
  background: var(--api-bg-primary);
}

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

.api-chatbot-send-button {
  background: linear-gradient(135deg, #10b981, #059669);
  color: var(--api-text-white);
  border: none;
  border-radius: 20px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--api-transition-fast);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.api-chatbot-send-button:hover:not(:disabled) {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

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

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

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

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

.api-chatbot-welcome-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  background: var(--api-bg-secondary);
  border-radius: var(--api-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.api-chatbot-welcome-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--api-text-primary);
  margin-bottom: 8px;
}

.api-chatbot-welcome-text {
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

.api-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;
}

