/* ── Chatbot Widget ── */

#cb-chat-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 998;
  width: 58px;
  height: 58px;
  background: #1a1a2e;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(26,26,46,.45);
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  border: none;
  outline: none;
}
#cb-chat-btn:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(26,26,46,.55); }
#cb-chat-btn svg { width: 28px; height: 28px; fill: #fff; }

/* Badge "nouveau message" */
#cb-chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}
#cb-chat-badge.visible { display: block; }

/* ── Widget principal ── */
#cb-chat-widget {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 997;
  width: 370px;
  max-height: 560px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
  border: 1.5px solid #f0f0f0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .2s;
}
#cb-chat-widget.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
#cb-chat-header {
  background: #1a1a2e;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.cb-chat-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cb-chat-avatar svg { width: 20px; height: 20px; fill: #fff; }
.cb-chat-header-info { flex: 1; }
.cb-chat-header-name { font-size: 14px; font-weight: 700; color: #fff; }
.cb-chat-header-status { font-size: 11px; color: rgba(255,255,255,.6); display: flex; align-items: center; gap: 4px; margin-top: 1px; }
.cb-chat-header-status::before { content: ''; width: 6px; height: 6px; background: #22c55e; border-radius: 50%; display: inline-block; }
#cb-chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,.7);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
#cb-chat-close:hover { color: #fff; background: rgba(255,255,255,.1); }
#cb-chat-close svg { width: 18px; height: 18px; }

/* Messages */
#cb-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f7f8fc;
  scroll-behavior: smooth;
}
#cb-chat-messages::-webkit-scrollbar { width: 4px; }
#cb-chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

.cb-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
}
.cb-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.cb-msg.bot  { align-self: flex-start; }

.cb-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
.cb-msg.bot .cb-msg-avatar  { background: #1a1a2e; }
.cb-msg.user .cb-msg-avatar { background: #0A66C2; }
.cb-msg-avatar svg { width: 14px; height: 14px; fill: #fff; }

.cb-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}
.cb-msg.bot .cb-msg-bubble {
  background: #fff;
  color: #111;
  border: 1px solid #eee;
  border-bottom-left-radius: 4px;
}
.cb-msg.user .cb-msg-bubble {
  background: #1a1a2e;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.cb-typing span {
  width: 6px;
  height: 6px;
  background: #bbb;
  border-radius: 50%;
  animation: cbTypingBounce .9s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: .15s; }
.cb-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes cbTypingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); background: #1a1a2e; }
}

/* Formulaire contact */
#cb-contact-form {
  padding: 16px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}
#cb-contact-form p {
  font-size: 12px;
  color: #666;
  margin-bottom: 10px;
  line-height: 1.5;
}
.cb-cf-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.cb-cf-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid #eee;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.cb-cf-row input:focus { border-color: #1a1a2e; }
.cb-cf-skip {
  font-size: 11px;
  color: #aaa;
  cursor: pointer;
  text-align: center;
  margin-top: 4px;
  text-decoration: underline;
}
.cb-cf-skip:hover { color: #666; }

/* Input zone */
#cb-chat-input-zone {
  padding: 12px 14px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
#cb-chat-input {
  flex: 1;
  border: 1.5px solid #eee;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
  transition: border-color .15s;
}
#cb-chat-input:focus { border-color: #1a1a2e; }
#cb-chat-input::placeholder { color: #bbb; }
#cb-chat-send {
  width: 38px;
  height: 38px;
  background: #1a1a2e;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
#cb-chat-send:hover { background: #0A66C2; }
#cb-chat-send svg { width: 16px; height: 16px; fill: #fff; }
#cb-chat-send:disabled { opacity: .4; cursor: default; }

/* ── RTL — Arabe / Tunisien ── */
.cb-msg-bubble[dir="rtl"] {
  font-family: 'Segoe UI', 'Arial', 'Noto Sans Arabic', sans-serif;
  text-align: right;
  line-height: 1.8;
  letter-spacing: 0;
}
/* Bulle bot RTL : arrondi miroir */
.cb-msg.bot .cb-msg-bubble[dir="rtl"] {
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 16px;
}
/* Bulle user RTL : arrondi miroir */
.cb-msg.user .cb-msg-bubble[dir="rtl"] {
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 16px;
}
/* Textarea RTL */
#cb-chat-input[dir="rtl"] {
  text-align: right;
  font-family: 'Segoe UI', 'Arial', 'Noto Sans Arabic', sans-serif;
}

@media(max-width: 480px) {
  #cb-chat-widget { width: calc(100vw - 24px); right: 12px; bottom: 90px; max-height: 70vh; }
  #cb-chat-btn { right: 12px; }
}
