/* /chatbox/chatbox.css
   Treedon Chatbox — vert unique (#198754) partout (aucun #5a2fe6)
   Responsive mobile + desktop
*/

:root{
  --td-green: #198754;              /* ✅ Couleur unique Treedon */
  --td-green-dark: #157347;
  --td-green-soft: rgba(25,135,84,.10);

  --td-text: #0f172a;
  --td-muted: #6b7280;

  --td-bg: #ffffff;
  --td-panel: #f7f7fb;

  --td-border: rgba(0,0,0,.10);
  --td-shadow: 0 10px 30px rgba(0,0,0,.12);

  --td-radius: 14px;
  --td-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

/* ================= Root container ================= */
#td-chatbox-root{
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 2147483000;
  font-family: var(--td-font);
}

/* ================= Floating button ================= */
.td-chatfab{
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 999px;
  background: var(--td-green);
  box-shadow: var(--td-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  border: 2px solid rgba(255,255,255,.65);
}

.td-chatfab:hover{
  background: var(--td-green-dark);
}

.td-chatfab-icon{
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 20px;
}


.td-chatfab-badge{
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ff3b30;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* ================= Chat window ================= */
.td-chatwin{
  position: fixed;
  right: 18px;
  bottom: 88px;

  /* ✅ 80% largeur max, style messenger */
  width: min(80vw, 420px);
  max-width: 420px;

  height: 540px;
  max-height: calc(100vh - 110px);

  background: var(--td-bg);
  border: 1px solid var(--td-border);
  border-radius: var(--td-radius);
  box-shadow: var(--td-shadow);
  overflow: hidden;

  display: flex;
  flex-direction: column;
}

/* ================= Header ================= */
.td-chathead{
  background: linear-gradient(135deg, var(--td-green) 0%, var(--td-green-dark) 100%);
  padding: 12px 12px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.td-chathead-left{
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.td-chathead-avatar{
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(255,255,255,.95);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 2px solid rgba(255,255,255,.55);
  font-size: 20px;
  cursor: pointer;
}

.td-chathead-meta{ min-width: 0; }

.td-chathead-title{
  font-size: 14px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.td-chathead-sub{
  margin-top: 2px;
  font-size: 12px;
  opacity: .9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.td-chathead-actions{
  display: flex;
  align-items: center;
  gap: 8px;
}

.td-iconbtn{
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.15);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.td-iconbtn:hover{
  background: rgba(255,255,255,.25);
}

/* ================= Messages area ================= */
.td-chatmsgs{
  flex: 1;
  overflow-y: auto;
  background: var(--td-panel);
  padding: 14px 12px;
}

/* message wrapper */
.td-msg{
  display: flex;
  margin-bottom: 10px;
}

/* visitor → RIGHT */
.td-msg.visitor{ justify-content: flex-end; }

/* bot → LEFT */
.td-msg.bot{ justify-content: flex-start; }

/* agent → LEFT */
.td-msg.agent{ justify-content: flex-start; }

/* bubble */
.td-bubble{
  max-width: 78%;
  background: #fff;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,.06);
  word-break: break-word;
}

/* bot bubble: LEFT green border */
.td-msg.bot .td-bubble{
  background: #fff;
  border: 1px solid rgba(0,0,0,.08);
  border-left: 4px solid var(--td-green);
  border-right: none;
  border-radius: 4px 14px 14px 4px;
}

/* agent bubble: LEFT border, light blue tint */
.td-msg.agent .td-bubble{
  background: #f0f7ff;
  border: 1px solid rgba(25,100,200,.12);
  border-left: 4px solid #4a90d9;
  border-right: none;
  border-radius: 4px 14px 14px 4px;
}

/* visitor bubble: RIGHT green border, green tint */
.td-msg.visitor .td-bubble{
  background: var(--td-green);
  color: #fff;
  border: none;
  border-radius: 14px 4px 4px 14px;
  box-shadow: 0 4px 14px rgba(25,135,84,.18);
}
.td-msg.visitor .td-txt{
  color: #fff;
}
.td-msg.visitor .td-time{
  color: rgba(255,255,255,.7);
}

.td-who{
  font-size: 12px;
  font-weight: 800;
  color: rgba(15,23,42,.85);
  margin-bottom: 4px;
}

.td-txt{
  font-size: 14px;
  color: var(--td-text);
  white-space: pre-wrap;
}

.td-time{
  margin-top: 6px;
  font-size: 11px;
  color: var(--td-muted);
}

/* ================= Footer / composer ================= */
.td-chatfoot{
  background: #fff;
  border-top: 1px solid rgba(0,0,0,.08);
  padding: 10px 10px;
}

.td-chathint{
  background: var(--td-green-soft);
  color: #0b3d2a;
  border: 1px solid rgba(25,135,84,.22);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  margin-bottom: 8px;
}

.td-chatrow{
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.td-chatinput{
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 12px;
  padding: 10px 10px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.td-chatinput:focus{
  border-color: rgba(25,135,84,.55);
  box-shadow: 0 0 0 3px rgba(25,135,84,.16);
}

.td-chatsend{
  width: 92px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--td-green);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(25,135,84,.22);
}

.td-chatsend:hover{
  background: var(--td-green-dark);
}

/* ================= Avatar circle user (support) ================= */
.td-avatar-circle{
  width: 100%;
  height: 100%;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.td-avatar-user{
  background: rgba(255,255,255,.92);
}

/* simple user icon (CSS only) => vert Treedon */
.td-ic-user{
  width: 18px;
  height: 18px;
  display: inline-block;
  border-radius: 999px;
  position: relative;
}
.td-ic-user:before{
  content: "";
  position: absolute;
  top: 1px;
  left: 4px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--td-green);
}
.td-ic-user:after{
  content: "";
  position: absolute;
  top: 12px;
  left: 2px;
  width: 14px;
  height: 8px;
  border-radius: 10px 10px 12px 12px;
  background: var(--td-green);
}

/* ================= Links inside chat (optional) ================= */
.td-chatmsgs a{
  color: var(--td-green);
  text-decoration: underline;
}
.td-chatmsgs a:hover{
  color: var(--td-green-dark);
}

/* ================= Mobile responsive ================= */
@media (max-width: 480px){
  #td-chatbox-root{
    right: 12px;
    bottom: 12px;
  }

  .td-chatwin{
    right: 12px;
    bottom: 96px;
    width: calc(100vw - 24px);
    max-width: none;
    height: calc(100vh - 120px);
    max-height: none;
    border-radius: 16px;
  }

  .td-chatfab{
    width: 56px;
    height: 56px;
  }
}

/* ================= AI Badge on bot messages ================= */
.td-ai-badge{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, rgba(25,135,84,.12), rgba(25,135,84,.06));
  border: 1px solid rgba(25,135,84,.2);
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  color: var(--td-green);
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: .3px;
}
.td-ai-badge::before{
  content: "✨";
  font-size: 9px;
}

/* ================= Typing Indicator ================= */
.td-typing{
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}
.td-typing-dot{
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--td-green);
  opacity: .4;
  animation: td-dot-bounce 1.4s infinite ease-in-out both;
}
.td-typing-dot:nth-child(1){ animation-delay: 0s; }
.td-typing-dot:nth-child(2){ animation-delay: .2s; }
.td-typing-dot:nth-child(3){ animation-delay: .4s; }

@keyframes td-dot-bounce{
  0%, 80%, 100%{ transform: scale(0.6); opacity: .4; }
  40%{ transform: scale(1); opacity: 1; }
}

.td-typing-wrap{
  display: flex;
  justify-content: flex-start;
  padding: 4px 12px;
}
.td-typing-bubble{
  background: #fff;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 14px;
  border-left: 4px solid var(--td-green);
  box-shadow: 0 4px 14px rgba(0,0,0,.06);
  min-width: 70px;
}
.td-typing-label{
  font-size: 11px;
  color: var(--td-muted);
  padding: 4px 16px 0;
  font-weight: 600;
}

/* ================= Typewriter effect for AI messages ================= */
.td-typewriter .td-txt{
  overflow: hidden;
}
.td-typewriter .td-txt .td-cursor{
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--td-green);
  margin-left: 2px;
  animation: td-blink .7s step-end infinite;
  vertical-align: text-bottom;
}
@keyframes td-blink{
  0%, 100%{ opacity: 1; }
  50%{ opacity: 0; }
}

/* ================= AI-powered bot bubble styling ================= */
.td-msg.bot.td-ai .td-bubble{
  background: linear-gradient(135deg, #eaf7f0 0%, #f0faf4 50%, #fff 100%);
  border-left: 4px solid var(--td-green);
  border-right: none;
  border-radius: 4px 14px 14px 4px;
  box-shadow: 0 4px 16px rgba(25,135,84,.10);
}

/* Bot avatar icon (small circle left of bubble) */
.td-msg.bot .td-bot-avatar{
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 999px;
  background: var(--td-green);
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  margin-top: 2px;
  align-self: flex-start;
  box-shadow: 0 2px 8px rgba(25,135,84,.18);
}
.td-msg.agent .td-bot-avatar{
  background: #4a90d9;
}
