/* ============================================================
   SAHEL BOT — Widget CSS
   ============================================================ */

:root {
  --bot-primary:     #059669;
  --bot-primary-dk:  #047857;
  --bot-navy:        #0a4275;
  --bot-navy-dk:     #062c50;
  --bot-header-bg:   linear-gradient(135deg, #059669 0%, #0a4275 100%);
  --bot-user-bubble: linear-gradient(135deg, #0a4275 0%, #1a5a9a 100%);
  --bot-bot-bubble:  #eef3f8;
  --bot-text-dark:   #0f172a;
  --bot-text-muted:  #64748b;
  --bot-shadow:      0 20px 60px rgba(10, 66, 117, 0.2);
  --bot-radius:      20px;
}

/* ================================================================
   FLOATING BUTTON
   ================================================================ */

#sahel-bot-toggle {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  overflow: visible; /* badge doit sortir du bouton */
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  background: transparent;
  transform: scale(0);
  animation: bot-enter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 2s forwards;
  outline: none;
  transition: box-shadow 0.2s;
}

#sahel-bot-toggle:hover {
  box-shadow: 0 12px 40px rgba(10, 66, 117, 0.35);
}

#sahel-bot-toggle:focus-visible {
  outline: 3px solid var(--bot-primary);
  outline-offset: 3px;
}

/* Wrapper image — clip circulaire isolé du badge */
.bot-toggle-img {
  display: block;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.bot-toggle-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transform: scale(1.25);
  display: block;
}

@keyframes bot-enter {
  to { transform: scale(1); }
}

/* ---- Badge pulsant — positionné à l'extérieur du clip ---- */
.bot-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  background: #059669;
  border-radius: 50%;
  border: 2.5px solid #fff;
  animation: pulse-badge 1.8s ease infinite;
  pointer-events: none;
  z-index: 1;
}

.bot-badge.hidden {
  display: none;
}

@keyframes pulse-badge {
  0%   { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.75); }
  70%  { box-shadow: 0 0 0 8px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}


/* ================================================================
   CHAT WINDOW
   ================================================================ */

#sahel-bot-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 10000;
  width: 380px;
  height: 560px;
  max-height: calc(100dvh - 120px); /* ne jamais dépasser le viewport */
  border-radius: var(--bot-radius);
  box-shadow: var(--bot-shadow);
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#sahel-bot-window.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ================================================================
   HEADER
   ================================================================ */

.bot-header {
  background: var(--bot-header-bg);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.bot-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}

.bot-header-info {
  flex: 1;
  min-width: 0;
}

.bot-header-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
}

.bot-header-status {
  font-size: 0.72rem;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.bot-status-dot {
  width: 7px;
  height: 7px;
  background: #6ee7b7;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  animation: pulse-online 2s ease infinite;
}

@keyframes pulse-online {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.bot-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.bot-header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: background 0.2s;
  flex-shrink: 0;
  font-family: system-ui, sans-serif;
}

.bot-header-btn:hover {
  background: rgba(255,255,255,0.3);
}

.bot-header-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ================================================================
   MESSAGES ZONE
   ================================================================ */

.bot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.bot-messages::-webkit-scrollbar {
  width: 4px;
}
.bot-messages::-webkit-scrollbar-track {
  background: transparent;
}
.bot-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

/* ---- Message Row ---- */
.bot-msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: bot-slide-up 0.2s ease;
}

.bot-msg-row.user {
  flex-direction: row-reverse;
}

.bot-msg-row.no-anim {
  animation: none;
}

@keyframes bot-slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Avatar mini ---- */
.bot-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  align-self: flex-end;
}

/* ---- Content wrapper ---- */
.bot-msg-content {
  max-width: 76%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bot-msg-row.user .bot-msg-content {
  align-items: flex-end;
}

/* ---- Bubble ---- */
.bot-bubble {
  padding: 10px 14px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
}

.bot-msg-row.bot .bot-bubble {
  background: var(--bot-bot-bubble);
  color: var(--bot-text-dark);
  border-radius: 4px 18px 18px 18px;
}

.bot-msg-row.user .bot-bubble {
  background: var(--bot-user-bubble);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

/* ---- Timestamp ---- */
.bot-msg-time {
  font-size: 0.68rem;
  color: #94a3b8;
  padding: 0 4px;
}

/* ---- Redirect chip ---- */
.bot-redirect-chip {
  display: inline-block;
  margin-top: 9px;
  padding: 5px 13px;
  background: #fff;
  border: 1.5px solid var(--bot-primary);
  color: var(--bot-primary);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  line-height: 1.4;
}

.bot-redirect-chip:hover {
  background: var(--bot-primary);
  color: #fff;
  text-decoration: none;
}

.bot-redirect-chip:focus-visible {
  outline: 2px solid var(--bot-primary);
  outline-offset: 2px;
}

/* ================================================================
   TYPING INDICATOR
   ================================================================ */

.bot-typing-bubble {
  background: var(--bot-bot-bubble);
  border-radius: 4px 18px 18px 18px;
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.bot-typing-dot {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typing-dot 1.2s ease infinite;
  flex-shrink: 0;
}

.bot-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.bot-typing-dot:nth-child(3) { animation-delay: 0.30s; }

@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1;   }
}

/* ================================================================
   SUGGESTIONS CHIPS
   ================================================================ */

.bot-suggestions {
  padding: 8px 14px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  border-top: 1px solid #f1f5f9;
}

.bot-suggestions::-webkit-scrollbar {
  display: none;
}

.bot-suggestion-chip {
  flex-shrink: 0;
  padding: 6px 13px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  color: var(--bot-text-dark);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  font-family: inherit;
}

.bot-suggestion-chip:hover {
  border-color: var(--bot-navy);
  color: var(--bot-navy);
  background: #e8eef5;
}

.bot-suggestion-chip:focus-visible {
  outline: 2px solid var(--bot-navy);
  outline-offset: 2px;
}

/* ================================================================
   INPUT AREA
   ================================================================ */

.bot-input-area {
  padding: 10px 14px 12px;
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
  background: #fff;
}

.bot-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.bot-textarea {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 0.875rem;
  color: var(--bot-text-dark);
  resize: none;
  max-height: 90px;
  min-height: 38px;
  height: 38px;
  overflow-y: auto;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  background: #f8fafc;
}

.bot-textarea:focus {
  border-color: var(--bot-primary);
  background: #fff;
}

.bot-textarea::placeholder {
  color: #94a3b8;
}

.bot-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bot-primary) 0%, var(--bot-navy) 100%);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.1s;
  font-size: 0.95rem;
  font-family: inherit;
}

.bot-send-btn:hover:not(:disabled) {
  opacity: 0.85;
}

.bot-send-btn:active:not(:disabled) {
  transform: scale(0.9);
}

.bot-send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.bot-send-btn:focus-visible {
  outline: 2px solid var(--bot-primary);
  outline-offset: 2px;
}

.bot-footer-text {
  font-size: 0.65rem;
  color: #94a3b8;
  text-align: center;
  margin-top: 7px;
  letter-spacing: 0.01em;
}

/* ================================================================
   RESPONSIVE
   ================================================================ */

/* ---- Tablette (641px – 900px) ---- */
@media (min-width: 641px) and (max-width: 900px) {
  #sahel-bot-window {
    width: 340px;
    height: 480px;
    right: 16px;
    bottom: 88px;
  }

  #sahel-bot-toggle {
    right: 16px;
    bottom: 20px;
  }
}

/* ---- Mobile (≤ 640px) ---- */
@media (max-width: 640px) {
  /* Fenêtre plein écran — on réécrit explicitement chaque propriété positionnelle */
  #sahel-bot-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }

  /* Bouton flottant */
  #sahel-bot-toggle {
    bottom: 18px;
    right: 18px;
    width: 54px;
    height: 54px;
  }

  /* Masquer le bouton quand le chat est ouvert */
  #sahel-bot-mount:has(#sahel-bot-window.open) #sahel-bot-toggle {
    display: none;
  }

/* Masquer suggestions (gain de place) */
  .bot-suggestions {
    display: none;
  }

  /* Bouton d'envoi plus grand (cible tactile) */
  .bot-send-btn {
    width: 46px;
    height: 46px;
    font-size: 1.05rem;
  }

  /* Réduire paddings */
  .bot-messages {
    padding: 12px 10px;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
  }

  /* Safe-area iPhone notch / barre home */
  .bot-input-area {
    padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  }

  /* Bulles plus larges sur petit écran */
  .bot-msg-content {
    max-width: 85%;
  }

  /* Header : safe-area top sur iPhone plein écran */
  .bot-header {
    padding-top: max(14px, calc(env(safe-area-inset-top) + 8px));
  }
}

/* ---- Très petits écrans (≤ 360px) ---- */
@media (max-width: 360px) {
  #sahel-bot-toggle {
    bottom: 14px;
    right: 14px;
    width: 50px;
    height: 50px;
  }
}

/* ================================================================
   REDUCED MOTION
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
  #sahel-bot-toggle {
    animation: none;
    transform: scale(1);
    transition: none;
  }

  .bot-badge,
  .bot-typing-dot,
  .bot-status-dot,
  .bot-msg-row {
    animation: none !important;
  }

  #sahel-bot-window {
    transition: opacity 0.15s ease;
  }
}
