/* ==========================================================================
   WIDGET DE CHAT BIVOLINO - DESIGN LUXE SUR-MESURE
   ========================================================================== */

:root {
  --bv-primary: #000;
  --bv-primary-light: #182d4d;
  --bv-gold: #c5a059;
  --bv-gold-hover: #b38e45;
  --bv-gold-light: #fdfaf3;
  --bv-bg-light: #f8f9fa;
  --bv-surface: #ffffff;
  --bv-text-dark: #1e293b;
  --bv-text-muted: #64748b;
  --bv-border: #e2e8f0;
  --bv-success: #10b981;
  --bv-shadow-xl: 0 20px 35px -5px rgba(14, 27, 47, 0.25), 0 10px 15px -5px rgba(14, 27, 47, 0.1);
  --bv-radius: 16px;
  --bv-font: 'Playfair Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Bouton Déclencheur Flottant */
.bv-launcher-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bv-primary) 0%, #1a335a 100%);
  border: 2px solid var(--clay);
  color: #ffffff;
  box-shadow: var(--bv-shadow-xl);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bv-launcher-btn:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 28px rgba(197, 160, 89, 0.4);
}

.bv-launcher-icon {
  width: 28px;
  height: 28px;
  fill: currentColor;
  transition: transform 0.3s ease;
}

.bv-launcher-btn.active .bv-icon-chat {
  display: none;
}
.bv-launcher-btn:not(.active) .bv-icon-close {
  display: none;
}

.bv-unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background-color: var(--clay);
  border: 2px solid #ffffff;
  border-radius: 50%;
  animation: bv-pulse 2s infinite;
}

@keyframes bv-pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(197, 160, 89, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(197, 160, 89, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(197, 160, 89, 0); }
}

/* Fenêtre Principale du Chat */
.bv-chat-container {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 410px;
  max-width: calc(100vw - 48px);
  height: 620px;
  max-height: calc(100vh - 120px);
  background: var(--bv-surface);
  border-radius: var(--bv-radius);
  box-shadow: var(--bv-shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99998;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.96);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid rgba(197, 160, 89, 0.25);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.bv-chat-container.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* En-tête du Chat */
.bv-chat-header {
  background: linear-gradient(135deg, var(--bv-primary) 0%, #000 100%);
  color: #ffffff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--clay);
}

.bv-header-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bv-avatar-frame {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--clay);
  color: var(--bv-primary);
  font-size: 20px;
  font-weight: bold;
}

.bv-header-title {
  display: flex;
  flex-direction: column;
}

.bv-brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
}

.bv-status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #cbd5e1;
}

.bv-dot-online {
  width: 8px;
  height: 8px;
  background-color: var(--bv-success);
  border-radius: 50%;
}

.bv-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bv-header-btn {
  background: transparent;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.bv-header-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--clay);
}

/* Zone des Suggestions Rapides */
.bv-quick-chips {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bv-gold-light);
  overflow-x: auto;
  white-space: nowrap;
  border-bottom: 1px solid rgba(197, 160, 89, 0.15);
  scrollbar-width: none;
}
.bv-quick-chips::-webkit-scrollbar {
  display: none;
}

.bv-chip-btn {
  background: #ffffff;
  border: 1px solid #e5d8b8;
  color: var(--bv-primary);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.bv-chip-btn:hover {
  background: var(--bv-primary);
  color: #ffffff;
  border-color: var(--bv-primary);
  transform: translateY(-1px);
}

/* Corps des messages */
.bv-chat-messages {
  flex: 1;
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background-color: var(--bv-bg-light);
}

.bv-message-wrapper {
  display: flex;
  gap: 10px;
  max-width: 88%;
}

.bv-message-wrapper.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.bv-message-wrapper.assistant {
  align-self: flex-start;
}

.bv-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bv-primary);
  color: var(--clay);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  border: 1px solid var(--clay);
}

.bv-message-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.bv-message-wrapper.assistant .bv-message-bubble {
  background: var(--bv-surface);
  color: var(--bv-text-dark);
  border: 1px solid var(--bv-border);
  border-top-left-radius: 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.04);
}

.bv-message-wrapper.user .bv-message-bubble {
  background: linear-gradient(135deg, var(--bv-primary) 0%, #1e3a64 100%);
  color: #ffffff;
  border-top-right-radius: 4px;
}

.bv-message-bubble p {
  margin: 0 0 8px 0;
}
.bv-message-bubble p:last-child {
  margin-bottom: 0;
}

.bv-message-bubble ul {
  margin: 6px 0;
  padding-left: 20px;
}
.bv-message-bubble li {
  margin-bottom: 4px;
}

.bv-message-bubble a {
  color: var(--clay);
  text-decoration: underline;
  font-weight: 600;
}

.bv-tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #475569;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  margin-bottom: 8px;
}

/* Animation de frappe (Typing Indicator) */
.bv-typing-indicator {
  display: none;
  align-self: flex-start;
  background: var(--bv-surface);
  border: 1px solid var(--bv-border);
  padding: 12px 18px;
  border-radius: 14px;
  border-top-left-radius: 4px;
  gap: 5px;
}

.bv-typing-indicator.active {
  display: flex;
}

.bv-typing-dot {
  width: 7px;
  height: 7px;
  background: var(--clay);
  border-radius: 50%;
  animation: bv-typing 1.4s infinite ease-in-out;
}
.bv-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.bv-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Zone de saisie */
.bv-chat-input-area {
  padding: 14px 16px;
  background: var(--bv-surface);
  border-top: 1px solid var(--bv-border);
}

.bv-input-form {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bv-bg-light);
  border: 1px solid var(--bv-border);
  border-radius: 24px;
  padding: 4px 6px 4px 16px;
  transition: border-color 0.2s;
}

.bv-input-form:focus-within {
  border-color: var(--clay);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(197, 160, 89, 0.15);
}

.bv-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--bv-text-dark);
  outline: none;
}

.bv-chat-input::placeholder {
  color: #94a3b8;
}

.bv-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--clay);
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.bv-send-btn:hover {
  background: var(--bv-gold-hover);
  transform: scale(1.05);
}

.bv-chat-footer-note {
  text-align: center;
  font-size: 11px;
  color: var(--bv-text-muted);
  margin-top: 8px;
}

/* Responsive Mobile */
#bv-chat-root, #bv-chat-root * { box-sizing: border-box; }
#bv-chat-root .bv-chat-header,
#bv-chat-root .bv-quick-chips,
#bv-chat-root .bv-chat-input-area { flex-shrink: 0; }
#bv-chat-root .bv-chat-messages { min-height: 0; min-width: 0; overscroll-behavior: contain; }
#bv-chat-root .bv-message-wrapper,
#bv-chat-root .bv-message-bubble { min-width: 0; overflow-wrap: anywhere; }
#bv-chat-root .bv-message-bubble img { max-width: 100%; height: auto; }
#bv-chat-root .bv-message-bubble pre { max-width: 100%; overflow-x: auto; }
#bv-chat-root .bv-chat-input { width: 0; min-width: 0; }
#bv-chat-root .bv-chip-btn { flex-shrink: 0; }

@media (max-width: 768px) {
  #bv-chat-root .bv-chat-container {
    top: var(--bv-viewport-top, 0px);
    left: var(--bv-viewport-left, 0px);
    bottom: auto;
    right: auto;
    width: var(--bv-viewport-width, 100%);
    height: 100vh;
    height: var(--bv-viewport-height, 100dvh);
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
    transform: none;
    transition: opacity .2s ease;
  }
  #bv-chat-root .bv-chat-header { padding: calc(8px + env(safe-area-inset-top)) 10px 8px; gap: 8px; }
  #bv-chat-root .bv-header-profile { gap: 8px; min-width: 0; }
  #bv-chat-root .bv-avatar-frame { width: 34px; height: 34px; flex-shrink: 0; }
  #bv-chat-root .bv-brand-name { font-size: 15px; }
  #bv-chat-root .bv-header-actions { gap: 0; flex-shrink: 0; }
  #bv-chat-root .bv-header-btn { width: 44px; height: 44px; padding: 10px; }
  #bv-chat-root .bv-quick-chips { padding: 8px 10px; }
  #bv-chat-root .bv-chat-messages { padding: 12px 10px; }
  #bv-chat-root .bv-message-wrapper { max-width: 100%; gap: 7px; }
  #bv-chat-root .bv-message-bubble { padding: 10px 12px; }
  #bv-chat-root .bv-chat-input-area { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  #bv-chat-root .bv-input-form { width: 100%; margin: 0; gap: 6px; padding: 4px 4px 4px 12px; }
  #bv-chat-root .bv-chat-input { font-size: 16px; height: 44px; margin: 0; padding: 0; }
  #bv-chat-root .bv-send-btn { width: 44px; height: 44px; margin: 0; }
  #bv-chat-root .bv-chat-footer-note { margin-top: 4px; }
  #bv-chat-root .bv-launcher-btn { bottom: calc(16px + env(safe-area-inset-bottom)); right: 16px; }
  #bv-chat-root .bv-launcher-btn.active { visibility: hidden; pointer-events: none; }
  body.bv-mobile-chat-open { overflow: hidden; }
}
