/* ==========================================
   CHATBOT IA - DESIGN PREMIUM IBE CONSTRUCTION
   ========================================== */

.ibe-chatbot {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 9999;
  font-family: var(--font-main, "Inter", sans-serif);
  /* Always visible by défaut pour éviter les problèmes
     si le loader ou le JS principal ne s'exécutent pas. */
  opacity: 1;
  pointer-events: all;
  transition: opacity 0.6s ease;
}

/* Classe gardée pour compatibilité, mais non obligatoire */
.ibe-chatbot.visible {
  opacity: 1;
  pointer-events: all;
}

/* ==========================================
   CHATBOT BUTTON (FLOATING)
   ========================================== */
.chatbot-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #cc9461 0%, #b8834d 100%);
  box-shadow: 0 4px 20px rgba(204, 148, 97, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  position: relative;
  border: none;
}

.chatbot-button svg {
  width: 28px;
  height: 28px;
  color: #ffffff;
  transition: transform 0.3s ease;
}

.chatbot-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(204, 148, 97, 0.6);
}

.chatbot-button.active svg {
  transform: rotate(90deg);
}

/* Notification Badge */
.chatbot-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #e74c3c;
  color: #ffffff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  border: 2px solid #ffffff;
  animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
  }
}

/* Pulse Animation */
@keyframes pulse-chat {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }
}

.chatbot-button {
  animation: pulse-chat 2s ease-in-out infinite;
}

.chatbot-button:hover {
  animation: none;
}

/* ==========================================
   CHATBOT WINDOW
   ========================================== */
.chatbot-window {
  position: absolute;
  bottom: 80px;
  left: 0;
  width: 380px;
  height: 550px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  overflow: hidden;
}

.chatbot-window.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ==========================================
   CHATBOT HEADER
   ========================================== */
.chatbot-header {
  background: linear-gradient(135deg, #1a2f4b 0%, #2e3e5b 100%);
  color: #ffffff;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 16px 16px 0 0;
}

.chatbot-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-avatar {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: linear-gradient(135deg, #cc9461 0%, #b8834d 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chatbot-avatar svg {
  width: 24px;
  height: 24px;
  color: #ffffff;
}

.chatbot-header-text h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
}

.chatbot-status {
  font-size: 12px;
  color: #27ae60;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chatbot-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #27ae60;
  animation: pulse-status 2s ease-in-out infinite;
}

@keyframes pulse-status {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.chatbot-close {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.chatbot-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.chatbot-close svg {
  width: 20px;
  height: 20px;
  color: #ffffff;
}

/* ==========================================
   MESSAGES AREA
   ========================================== */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8f9fa;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: #cc9461;
  border-radius: 3px;
}

.chatbot-message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.user-message {
  align-self: flex-end;
}

.bot-message {
  align-self: flex-start;
}

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

.user-message .message-content {
  background: linear-gradient(135deg, #cc9461 0%, #b8834d 100%);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.bot-message .message-content {
  background: #ffffff;
  color: #1a2f4b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.message-time {
  font-size: 11px;
  color: #95a5a6;
  margin-top: 4px;
  padding: 0 4px;
}

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

/* ==========================================
   QUICK REPLIES
   ========================================== */
.chatbot-quick-replies {
  padding: 12px 20px;
  background: #ffffff;
  border-top: 1px solid #ecf0f1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-reply {
  padding: 8px 14px;
  background: #f8f9fa;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: 13px;
  color: #1a2f4b;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.quick-reply:hover {
  background: linear-gradient(135deg, #cc9461 0%, #b8834d 100%);
  color: #ffffff;
  border-color: #cc9461;
  transform: translateY(-2px);
}

/* ==========================================
   INPUT AREA
   ========================================== */
.chatbot-input-area {
  padding: 15px 20px;
  background: #ffffff;
  border-top: 1px solid #ecf0f1;
  display: flex;
  gap: 10px;
  align-items: center;
  border-radius: 0 0 16px 16px;
}

#chatbot-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
}

#chatbot-input:focus {
  border-color: #cc9461;
  box-shadow: 0 0 0 3px rgba(204, 148, 97, 0.1);
}

#chatbot-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #cc9461 0%, #b8834d 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(204, 148, 97, 0.3);
}

#chatbot-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(204, 148, 97, 0.5);
}

#chatbot-send svg {
  width: 20px;
  height: 20px;
  color: #ffffff;
}

/* ==========================================
   BODY SCROLL LOCK (when chatbot is fullscreen on mobile)
   ========================================== */
body.chatbot-open-mobile {
  overflow: hidden !important;
  position: fixed;
  width: 100%;
  height: 100%;
  height: -webkit-fill-available;
  touch-action: none;
}

/* ==========================================
   MOBILE RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
  .ibe-chatbot {
    bottom: 16px;
    right: 16px;
    left: auto;
  }

  .chatbot-button {
    width: 54px;
    height: 54px;
  }

  .chatbot-button svg {
    width: 24px;
    height: 24px;
  }

  /* Fullscreen overlay on mobile — Safari + Android */
  .chatbot-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100vh;
    height: -webkit-fill-available; /* Safari iOS fallback */
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    z-index: 10000;
    -webkit-transform: translateZ(0); /* GPU layer for Safari */
    transform: translateZ(0);
  }

  .chatbot-window .chatbot-header {
    border-radius: 0;
    padding: 16px 20px;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }

  .chatbot-window .chatbot-input-area {
    border-radius: 0;
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .chatbot-messages {
    padding: 15px;
    -webkit-overflow-scrolling: touch; /* smooth scroll on older iOS */
  }

  .quick-reply {
    font-size: 12px;
    padding: 6px 12px;
  }
}

/* ==========================================
   ANIMATIONS & EFFECTS
   ========================================== */

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 12px;
  width: fit-content;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cc9461;
  animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Smooth scrollbar for Firefox */
.chatbot-messages {
  scrollbar-width: thin;
  scrollbar-color: #cc9461 transparent;
}

/* ==========================================
   TYPING INDICATOR (AI RESPONSE)
   ========================================== */
.typing-indicator-wrapper {
  align-self: flex-start;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cc9461;
  animation: typing 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* ==========================================
   ENHANCED MOBILE RESPONSIVENESS (small phones)
   ========================================== */
@media (max-width: 480px) {
  .chatbot-header {
    padding: 14px 16px;
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
  }

  .chatbot-header-text h3 {
    font-size: 14px;
  }

  .chatbot-status {
    font-size: 11px;
  }

  .chatbot-avatar {
    width: 40px;
    height: 40px;
  }

  .chatbot-messages {
    padding: 12px;
  }

  .message-content {
    font-size: 13px;
    padding: 10px 14px;
  }

  .quick-reply {
    font-size: 11px;
    padding: 6px 10px;
  }

  #chatbot-input {
    font-size: 16px; /* 16px prevents iOS zoom on focus */
    padding: 10px 14px;
  }

  #chatbot-send {
    width: 40px;
    height: 40px;
  }

  .chatbot-button {
    width: 50px;
    height: 50px;
  }

  .chatbot-button svg {
    width: 22px;
    height: 22px;
  }
}

/* Landscape mobile — chatbot still fullscreen but shorter */
@media (max-width: 768px) and (orientation: landscape) {
  .chatbot-window {
    height: 100vh;
    height: 100dvh;
    max-height: none;
  }
}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  .chatbot-window {
    width: 360px;
    height: 520px;
  }
}

/* Large screens */
@media (min-width: 1440px) {
  .chatbot-window {
    width: 420px;
    height: 600px;
  }
}
