/* === Widget de chat Bluewaive - autonome, préfixé .bw-chat pour ne rien casser sur la page === */

.bw-chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #2682B4, #1a5a8c);
  color: #fff;
  box-shadow: 0 8px 24px rgba(26, 90, 140, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.bw-chat-launcher:hover { transform: scale(1.06); box-shadow: 0 10px 28px rgba(26, 90, 140, 0.45); }
.bw-chat-launcher svg { width: 26px; height: 26px; }
.bw-chat-launcher-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.bw-chat-launcher .bw-chat-icon-close { display: none; }
.bw-chat-launcher[aria-expanded="true"] .bw-chat-icon-open { display: none; }
.bw-chat-launcher[aria-expanded="true"] .bw-chat-icon-close { display: block; }

.bw-chat-window {
  position: fixed;
  right: 24px;
  bottom: 96px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(22, 33, 62, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(0.9) translateY(12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.bw-chat-window.bw-chat-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

.bw-chat-header {
  background: linear-gradient(135deg, #2682B4, #1a5a8c);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.bw-chat-header-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bw-chat-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.4);
}
.bw-chat-header-title { font-family: 'Urbanist', sans-serif; font-weight: 800; font-size: 1rem; }
.bw-chat-header-subtitle { font-size: 0.78rem; opacity: 0.85; margin-top: 2px; }
.bw-chat-header-actions { display: flex; gap: 6px; }
.bw-chat-header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.bw-chat-header-btn:hover { background: rgba(255,255,255,0.28); }
.bw-chat-header-btn svg { width: 16px; height: 16px; }

.bw-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8faff;
  scroll-behavior: smooth;
}

.bw-chat-msg { display: flex; max-width: 88%; }
.bw-chat-msg-user { align-self: flex-end; }
.bw-chat-msg-assistant { align-self: flex-start; align-items: flex-end; gap: 8px; }

.bw-chat-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.bw-chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bw-chat-msg-user .bw-chat-bubble {
  background: #2682B4;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bw-chat-msg-assistant .bw-chat-bubble {
  background: #fff;
  color: #16213e;
  border: 1px solid #e6dcc5;
  border-bottom-left-radius: 4px;
}
.bw-chat-msg-error .bw-chat-bubble {
  background: #fdecea;
  color: #a12622;
  border: 1px solid #f3c4c0;
}

.bw-chat-bubble p { margin: 0 0 8px; }
.bw-chat-bubble p:last-child { margin-bottom: 0; }
.bw-chat-bubble ul { margin: 0 0 8px 18px; padding: 0; }
.bw-chat-bubble li { margin-bottom: 4px; }
.bw-chat-bubble a { color: inherit; text-decoration: underline; }
.bw-chat-bubble code {
  background: rgba(38, 130, 180, 0.1);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.82em;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}
.bw-chat-bubble pre {
  background: #16213e;
  color: #e8f2fb;
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0 0 8px;
}
.bw-chat-bubble pre code { background: none; color: inherit; padding: 0; }

.bw-chat-retry {
  margin-top: 6px;
  background: none;
  border: 1px solid #a12622;
  color: #a12622;
  border-radius: 6px;
  font-size: 0.78rem;
  padding: 4px 10px;
  cursor: pointer;
}
.bw-chat-retry:hover { background: #a12622; color: #fff; }

.bw-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #e6dcc5;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.bw-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9aa8c2;
  animation: bwChatBounce 1.2s infinite ease-in-out;
}
.bw-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.bw-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bwChatBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.bw-chat-form {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #e6dcc5;
  background: #fff;
}
.bw-chat-textarea {
  flex: 1;
  resize: none;
  border: 1px solid #e6dcc5;
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  max-height: 100px;
  color: #16213e;
}
.bw-chat-textarea:focus { outline: none; border-color: #2682B4; }
.bw-chat-textarea:disabled { background: #f4f5f7; }

.bw-chat-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: #2682B4;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.bw-chat-send:hover:not(:disabled) { background: #1a5a8c; }
.bw-chat-send:disabled { background: #b7c6d9; cursor: not-allowed; }
.bw-chat-send svg { width: 17px; height: 17px; }

@media (max-width: 480px) {
  .bw-chat-window {
    right: 12px;
    left: 12px;
    bottom: 88px;
    width: auto;
    height: calc(100vh - 160px);
  }
  .bw-chat-launcher { right: 16px; bottom: 16px; }
}
