/* ============================================================
   ALTURIS — CHATBOT WIDGET
   ============================================================
   Bot hybride : FAQ d'abord, IA en secours.
   À inclure simplement avec :
     <link rel="stylesheet" href="chatbot.css">
     <script src="chatbot.js" defer></script>
   ============================================================ */

#alturis-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #E63946;
  color: white;
  border: none;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px -8px rgba(230, 57, 70, 0.6), 0 2px 6px rgba(0,0,0,0.15);
  transition: all .25s cubic-bezier(.4,0,.2,1);
  font-family: 'Quicksand', 'DM Sans', system-ui, sans-serif;
}
#alturis-chat-fab:hover { transform: scale(1.08); }
#alturis-chat-fab.open #alturis-fab-avatar { opacity: 0; transform: scale(0.7); }
#alturis-chat-fab.open::after {
  content: '×';
  position: absolute;
  font-size: 32px;
  font-weight: 300;
  color: white;
  line-height: 1;
}
#alturis-chat-fab #alturis-fab-avatar {
  transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
}
#alturis-chat-fab .badge-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  background: #10B981;
  border-radius: 50%;
  border: 2px solid white;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.2); }
}

#alturis-chat-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 130px);
  background: white;
  border-radius: 18px;
  box-shadow: 0 20px 60px -10px rgba(0,0,0,0.25);
  display: none;
  flex-direction: column;
  z-index: 9997;
  overflow: hidden;
  font-family: 'DM Sans', system-ui, sans-serif;
  border: 1px solid #E8E5E1;
  animation: slideUp .3s cubic-bezier(.4,0,.2,1);
}
#alturis-chat-window.open { display: flex; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.alturis-chat-header {
  padding: 18px 20px;
  background: linear-gradient(135deg, #14110F 0%, #2A2520 100%);
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.alturis-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #E63946;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.alturis-chat-header-text { flex: 1; min-width: 0; }
.alturis-chat-header-text .name {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 15px;
}
.alturis-chat-header-text .status {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.alturis-chat-header-text .status::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #10B981;
  border-radius: 50%;
}
.alturis-chat-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s ease;
}
.alturis-chat-close:hover { background: rgba(255,255,255,0.2); }

.alturis-lang-switch {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.08);
  padding: 2px;
  border-radius: 8px;
}
.lang-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.6);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s ease;
  font-family: inherit;
}
.lang-btn:hover { color: white; background: rgba(255,255,255,0.08); }
.lang-btn.active { color: white; background: #E63946; }

/* RTL support for Arabic */
#alturis-chat-window[dir="rtl"] .alturis-msg.bot { align-self: flex-end; border-bottom-left-radius: 16px; border-bottom-right-radius: 4px; }
#alturis-chat-window[dir="rtl"] .alturis-msg.user { align-self: flex-start; border-bottom-right-radius: 16px; border-bottom-left-radius: 4px; }
#alturis-chat-window[dir="rtl"] .alturis-chat-input { direction: rtl; }
#alturis-chat-window[dir="rtl"] .alturis-chat-input input { text-align: right; }
#alturis-chat-window[dir="rtl"] .alturis-chat-header { direction: rtl; }
#alturis-chat-window[dir="rtl"] .alturis-typing { align-self: flex-end; }
#alturis-chat-window[dir="rtl"] .alturis-suggestions { direction: rtl; }

.alturis-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  background: #FAFAFA;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.alturis-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: msgIn .2s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.alturis-msg.bot {
  background: white;
  color: #14110F;
  border: 1px solid #E8E5E1;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.alturis-msg.user {
  background: #E63946;
  color: white;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.alturis-msg a { color: inherit; font-weight: 600; text-decoration: underline; }
.alturis-msg.bot a { color: #E63946; }
.alturis-msg.bot strong { color: #14110F; }

.alturis-typing {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: white;
  border: 1px solid #E8E5E1;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}
.alturis-typing span {
  width: 7px;
  height: 7px;
  background: #71717A;
  border-radius: 50%;
  animation: typing 1.2s ease-in-out infinite;
}
.alturis-typing span:nth-child(2) { animation-delay: 0.15s; }
.alturis-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.alturis-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 12px;
  background: #FAFAFA;
}
.alturis-suggestion-btn {
  background: white;
  border: 1px solid #E8E5E1;
  color: #3F3F46;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .2s ease;
}
.alturis-suggestion-btn:hover {
  background: #FCE9EB;
  border-color: #E63946;
  color: #E63946;
}

.alturis-listing-card {
  background: white;
  border: 1px solid #E8E5E1;
  border-radius: 12px;
  overflow: hidden;
  margin-top: 8px;
  text-decoration: none;
  color: inherit;
  display: block;
  cursor: pointer;
  transition: all .2s ease;
}
.alturis-listing-card:hover {
  border-color: #14110F;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.alturis-listing-card .photo {
  width: 100%;
  height: 110px;
  background: #F4F4F5 center/cover no-repeat;
}
.alturis-listing-card .body { padding: 10px 12px; }
.alturis-listing-card .price { font-family: 'Quicksand', sans-serif; font-weight: 700; color: #E63946; font-size: 14px; }
.alturis-listing-card .title { font-size: 13px; font-weight: 600; color: #14110F; margin: 2px 0; line-height: 1.3; }
.alturis-listing-card .meta { font-size: 11px; color: #71717A; }

.alturis-chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  background: white;
  border-top: 1px solid #E8E5E1;
  flex-shrink: 0;
}
.alturis-chat-input input {
  flex: 1;
  background: #F4F4F5;
  border: 1.5px solid transparent;
  padding: 11px 14px;
  border-radius: 22px;
  font-family: inherit;
  font-size: 14px;
  color: #14110F;
  outline: none;
  transition: all .2s ease;
}
.alturis-chat-input input:focus { background: white; border-color: #E63946; }
.alturis-chat-input button {
  width: 44px;
  height: 44px;
  background: #E63946;
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s ease;
  flex-shrink: 0;
}
.alturis-chat-input button:hover { background: #D02838; }
.alturis-chat-input button:disabled { opacity: 0.4; cursor: not-allowed; }

.alturis-chat-foot {
  padding: 8px 14px;
  font-size: 10px;
  color: #71717A;
  text-align: center;
  background: white;
  border-top: 1px solid #F4F4F5;
}
.alturis-chat-foot a { color: #E63946; }

@media (max-width: 480px) {
  #alturis-chat-window {
    bottom: 80px;
    right: 12px;
    left: 12px;
    width: auto;
    height: calc(100vh - 110px);
    border-radius: 14px;
  }
  #alturis-chat-fab { bottom: 16px; right: 16px; }
}
