/* ===== VARIABLES THEMES ===== */
:root {
  --boa-primary: #00b2bc;
  --boa-primary-dark: #009199;
  --boa-primary-rgb: 0, 178, 188;
}

/* ===== THEME LIGHT (defaut) ===== */
#boa-chat-window {
  --boa-bg: #ffffff;
  --boa-bg-messages: #f4f6f8;
  --boa-bg-bot: #ffffff;
  --boa-border-bot: #e2e8f0;
  --boa-text: #1e293b;
  --boa-text-muted: #94a3b8;
  --boa-input-bg: #ffffff;
  --boa-input-border: #d1d5db;
  --boa-border-area: #e8e8e8;
  --boa-bg-area: #ffffff;
  --boa-scrollbar: rgba(0,0,0,0.12);
  --boa-scrollbar-hover: rgba(0,0,0,0.22);
}

/* ===== THEME DARK ===== */
#boa-chat-window.boa-dark {
  --boa-bg: #000000;
  --boa-bg-messages: #0a0a0a;
  --boa-bg-bot: #1a1a1a;
  --boa-border-bot: #2a2a2a;
  --boa-text: #e8e8e8;
  --boa-text-muted: #777777;
  --boa-input-bg: #111111;
  --boa-input-border: #333333;
  --boa-border-area: #1a1a1a;
  --boa-bg-area: #000000;
  --boa-scrollbar: rgba(255,255,255,0.12);
  --boa-scrollbar-hover: rgba(255,255,255,0.22);
}

/* ===== BOUTON FLOTTANT ===== */
#boa-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  /* needed for notification badge positioning */
  overflow: visible;
  background: linear-gradient(135deg, var(--boa-primary), var(--boa-primary-dark));
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(var(--boa-primary-rgb), 0.45), 0 0 0 0 rgba(var(--boa-primary-rgb), 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  animation: boa-pulse 2.5s infinite;
}

#boa-chat-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(var(--boa-primary-rgb), 0.55);
  animation: none;
}

@keyframes boa-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(var(--boa-primary-rgb), 0.5), 0 0 0 0 rgba(var(--boa-primary-rgb), 0.6); }
  50% { box-shadow: 0 4px 20px rgba(var(--boa-primary-rgb), 0.5), 0 0 0 16px rgba(var(--boa-primary-rgb), 0); }
}

#boa-chat-btn svg {
  width: 28px;
  height: 28px;
  fill: white;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

/* Badge notification */
#boa-chat-btn .boa-notif {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid white;
  animation: boa-notif-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
}

@keyframes boa-notif-pop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* ===== FENETRE CHAT ===== */
#boa-chat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 380px;
  height: 540px;
  min-width: 300px;
  min-height: 350px;
  max-width: 90vw;
  max-height: 85vh;
  background: var(--boa-bg);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

/* ===== POIGNEE REDIMENSIONNEMENT ===== */
#boa-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 22px;
  height: 22px;
  cursor: nw-resize;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 5px;
  gap: 2px;
  opacity: 0.35;
  transition: opacity 0.2s;
}

#boa-resize-handle:hover {
  opacity: 0.8;
}

#boa-resize-handle .boa-grip-row {
  display: flex;
  gap: 2px;
}

#boa-resize-handle .boa-grip-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: white;
}

#boa-chat-window.boa-resizing {
  transition: none;
  user-select: none;
}

/* Animation fermeture */
#boa-chat-window.boa-closing {
  animation: boa-close 0.35s ease forwards;
}

@keyframes boa-close {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  40% { opacity: 0.8; transform: translateY(-6px) scale(1.02); }
  100% { opacity: 0; transform: translateY(30px) scale(0.85); }
}

#boa-chat-window.boa-dark {
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.06);
}

#boa-chat-window.boa-dark #boa-chat-header {
  background: linear-gradient(135deg, #007a80, #005558);
}

#boa-chat-window.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(30px) scale(0.85);
}

/* Animation ouverture */
#boa-chat-window.boa-opening {
  animation: boa-open 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes boa-open {
  0% { opacity: 0; transform: translateY(40px) scale(0.8); }
  60% { opacity: 1; transform: translateY(-8px) scale(1.02); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== HEADER ===== */
#boa-chat-header {
  background: linear-gradient(135deg, var(--boa-primary), var(--boa-primary-dark));
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Segoe UI', Arial, sans-serif;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

#boa-chat-header span {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#boa-chat-header .boa-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

#boa-chat-header .boa-status-dot {
  width: 10px;
  height: 10px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
  animation: boa-status-pulse 1.8s infinite;
}

@keyframes boa-status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7); }
  50% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
}

/* Header actions (theme toggle + close) */
.boa-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#boa-theme-toggle,
#boa-sound-toggle,
#boa-fullscreen-toggle,
#boa-chat-close {
  cursor: pointer;
  opacity: 0.85;
  padding: 4px 6px;
  border-radius: 6px;
  transition: opacity 0.2s, background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#boa-theme-toggle:hover,
#boa-sound-toggle:hover,
#boa-fullscreen-toggle:hover,
#boa-chat-close:hover {
  opacity: 1;
  background: rgba(255,255,255,0.15);
}

#boa-theme-toggle svg,
#boa-sound-toggle svg,
#boa-fullscreen-toggle svg {
  width: 18px;
  height: 18px;
  fill: white;
}

#boa-chat-close {
  font-size: 18px;
  line-height: 1;
}

/* ===== MESSAGES ===== */
#boa-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, #05cdd715, #ffffff);
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 12px;
  scroll-behavior: smooth;
  transition: background 0.3s ease;
}

/* Scrollbar invisible */
#boa-chat-messages::-webkit-scrollbar {
  display: none;
}

#boa-chat-messages {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.boa-dark #boa-chat-messages {
  background: #0a0a0a;
}

/* Message row layout */
.boa-msg-row {
  display: flex;
  gap: 8px;
  animation: boa-msg-in 0.3s ease;
}

.boa-msg-row.bot {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 88%;
}

.boa-msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
  flex-direction: row-reverse;
  max-width: 82%;
}

.boa-msg-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

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

/* Avatar bot */
.boa-avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
  background: var(--boa-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.boa-avatar svg {
  width: 18px;
  height: 18px;
}

/* Horodatage */
.boa-time {
  font-size: 11px;
  color: var(--boa-text-muted);
  padding: 0 4px;
}

.boa-msg {
  padding: 11px 15px;
  border-radius: 14px;
  line-height: 1.55;
  word-break: break-word;
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

@keyframes boa-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.boa-msg.bot {
  background: var(--boa-bg-bot);
  border: 1px solid var(--boa-border-bot);
  color: var(--boa-text);
  border-bottom-left-radius: 4px;
}

.boa-msg.user {
  background: linear-gradient(135deg, var(--boa-primary), var(--boa-primary-dark));
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(var(--boa-primary-rgb), 0.3);
}

/* Formatage des listes dans les reponses bot */
.boa-msg.bot ol {
  margin: 6px 0 0 16px;
  padding: 0;
}

.boa-msg.bot li {
  margin-bottom: 4px;
}

.boa-response-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.boa-response-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: rgba(var(--boa-primary-rgb), 0.1);
  color: var(--boa-primary-dark);
}

.boa-response-badge-warn {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

.boa-followup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.boa-followup-btn {
  background: transparent;
  border: 1px solid rgba(var(--boa-primary-rgb), 0.45);
  color: var(--boa-primary-dark);
  border-radius: 18px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.boa-followup-btn:hover {
  background: rgba(var(--boa-primary-rgb), 0.14);
  transform: translateY(-1px);
}

.boa-citations {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(var(--boa-primary-rgb), 0.08);
  border: 1px solid rgba(var(--boa-primary-rgb), 0.18);
  max-width: 100%;
  overflow-x: hidden;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-sizing: border-box;
}

.boa-citations ul,
.boa-citations li,
.boa-citations a {
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.boa-citations-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--boa-text);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  user-select: none;
  padding: 2px 0;
}

.boa-citations-title::-webkit-details-marker {
  display: none;
}

.boa-citations-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--boa-text-muted);
  transition: transform 0.25s ease;
}

.boa-citations[open] .boa-citations-chevron {
  transform: rotate(180deg);
}

.boa-citations[open] .boa-citations-title {
  margin-bottom: 6px;
}

.boa-citations-body {
  animation: boa-citations-open 0.25s ease;
}

@keyframes boa-citations-open {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.boa-citations-note {
  font-size: 12px;
  color: var(--boa-text-muted);
  margin-bottom: 6px;
}

.boa-citations ul {
  margin: 0;
  padding-left: 16px;
}

.boa-citations li {
  margin-bottom: 4px;
  color: var(--boa-text);
}

.boa-citations a {
  color: var(--boa-primary-dark);
  text-decoration: none;
}

.boa-citations a:hover {
  text-decoration: underline;
}

/* ===== SUGGESTIONS RAPIDES ===== */
.boa-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  animation: boa-msg-in 0.3s ease;
}

.boa-suggestion-btn {
  background: transparent;
  border: 1px solid var(--boa-primary);
  color: var(--boa-primary);
  border-radius: 18px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: 'Segoe UI', Arial, sans-serif;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.boa-suggestion-btn:hover {
  background: var(--boa-primary);
  color: white;
  transform: scale(1.05);
}

/* ===== INDICATEUR CHARGEMENT ===== */
.boa-msg.loading {
  background: var(--boa-bg-bot);
  border: 1px solid var(--boa-border-bot);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.boa-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.boa-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--boa-primary);
  display: inline-block;
  animation: boa-bounce 1.4s ease-in-out infinite;
}

.boa-dots span:nth-child(2) { animation-delay: 0.16s; }
.boa-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes boa-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== INDICATEUR "EN TRAIN D'ECRIRE" ===== */
#boa-typing-indicator {
  padding: 4px 16px;
  font-size: 12px;
  color: var(--boa-text-muted);
  font-family: 'Segoe UI', Arial, sans-serif;
  font-style: italic;
  background: var(--boa-bg-area);
  border-top: 1px solid var(--boa-border-area);
  transition: opacity 0.2s, max-height 0.2s;
  max-height: 30px;
  overflow: hidden;
}

#boa-typing-indicator.boa-typing-hidden {
  opacity: 0;
  max-height: 0;
  padding: 0 16px;
  border-top: none;
}

.boa-typing-dots span {
  animation: boa-typing-dot 1.4s infinite;
}

.boa-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.boa-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes boa-typing-dot {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* ===== SAISIE ===== */
#boa-chat-input-area {
  display: flex;
  padding: 12px 14px;
  border-top: 1px solid var(--boa-border-area);
  background: var(--boa-bg-area);
  gap: 10px;
  align-items: center;
  transition: background 0.3s ease, border-color 0.3s ease;
}

#boa-chat-input {
  flex: 1;
  border: 1px solid var(--boa-input-border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 12px;
  font-family: 'Segoe UI', Arial, sans-serif;
  outline: none;
  resize: none;
  background: var(--boa-input-bg);
  color: var(--boa-text);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.3s ease, color 0.3s ease;
}

#boa-chat-input::placeholder {
  color: var(--boa-text-muted);
}

#boa-chat-input:focus {
  border-color: var(--boa-primary);
  animation: boa-input-glow 1.5s ease infinite;
}

@keyframes boa-input-glow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(var(--boa-primary-rgb), 0.15); }
  50% { box-shadow: 0 0 0 5px rgba(var(--boa-primary-rgb), 0.3); }
}

#boa-chat-send {
  background: linear-gradient(135deg, var(--boa-primary), var(--boa-primary-dark));
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 8px rgba(var(--boa-primary-rgb), 0.3);
}

#boa-chat-send:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(var(--boa-primary-rgb), 0.45);
}

#boa-chat-send:hover svg {
  transform: translateX(3px);
}

#boa-chat-send svg {
  width: 18px;
  height: 18px;
  fill: white;
  transition: transform 0.3s ease;
}

/* Animation envoi */
#boa-chat-send.boa-sending svg {
  animation: boa-send-fly 0.6s ease;
}

@keyframes boa-send-fly {
  0% { transform: translateX(0) scale(1); opacity: 1; }
  40% { transform: translateX(20px) scale(0.5); opacity: 0; }
  41% { transform: translateX(-20px) scale(0.5); opacity: 0; }
  100% { transform: translateX(0) scale(1); opacity: 1; }
}

/* ===== PLEIN ECRAN ===== */
#boa-chat-window.boa-fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  bottom: 0;
  right: 0;
  border-radius: 0;
  max-width: none;
  max-height: none;
}

#boa-chat-window.boa-fullscreen #boa-resize-handle {
  display: none;
}


/* ===== RESPONSIVE MOBILE ===== */
@media (max-width: 420px) {
  #boa-chat-window {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 90px;
    height: 70vh;
  }
}
