.tp-chatbot {
  --tpc-primary: #1877f2;
  --tpc-primary-dark: #0d5bbd;
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 1060;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.tp-chatbot__toggle {
  width: 3.4rem;
  height: 3.4rem;
  border-radius: 50%;
  border: none;
  background: var(--tpc-primary);
  color: #fff;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(24, 119, 242, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.tp-chatbot__toggle:hover {
  transform: scale(1.06);
  background: var(--tpc-primary-dark);
  box-shadow: 0 16px 36px rgba(13, 91, 189, 0.5);
}
.tp-chatbot__toggle .tp-chatbot__close-icon { display: none; }
.tp-chatbot.is-open .tp-chatbot__open-icon { display: none; }
.tp-chatbot.is-open .tp-chatbot__close-icon { display: inline; }

.tp-chatbot__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 0.85rem;
  height: 0.85rem;
  padding: 0 0.2rem;
  background: #38bdf8;
  border: 2px solid #fff;
  border-radius: 999px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  box-sizing: border-box;
}
.tp-chatbot__badge.is-visible {
  display: flex;
}

.tp-chatbot__panel {
  position: absolute;
  right: 0;
  bottom: 4.2rem;
  width: min(92vw, 380px);
  height: min(72vh, 560px);
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 24px 60px rgba(12, 25, 41, 0.28);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(15, 40, 71, 0.08);
  touch-action: manipulation;
}
.tp-chatbot.is-open .tp-chatbot__panel { display: flex; animation: tpcIn 0.22s ease; }

@keyframes tpcIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.tp-chatbot__header {
  background: linear-gradient(135deg, var(--tpc-primary), var(--tpc-primary-dark));
  color: #fff;
  padding: 0.9rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.tp-chatbot__avatar {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}
.tp-chatbot__title { font-weight: 800; font-size: 0.95rem; line-height: 1.1; }
.tp-chatbot__subtitle { font-size: 0.72rem; opacity: 0.9; }
.tp-chatbot__header-close {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  opacity: 0.85;
}
.tp-chatbot__header-close:hover { opacity: 1; }

.tp-chatbot__body {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem;
  background: #f5f8fc;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.tp-chatbot__msg {
  max-width: 85%;
  padding: 0.6rem 0.8rem;
  border-radius: 0.9rem;
  font-size: 0.86rem;
  line-height: 1.5;
  white-space: pre-line;
  word-wrap: break-word;
}
.tp-chatbot__msg--bot {
  align-self: flex-start;
  background: #fff;
  color: #1e293b;
  border: 1px solid rgba(15, 40, 71, 0.07);
  border-bottom-left-radius: 0.25rem;
}
.tp-chatbot__msg--user {
  align-self: flex-end;
  background: var(--tpc-primary);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.tp-chatbot__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.tp-chatbot__link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(24, 119, 242, 0.1);
  color: var(--tpc-primary-dark);
}
.tp-chatbot__link:hover { background: rgba(24, 119, 242, 0.18); }

.tp-chatbot__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.9rem 0.5rem;
  background: #f5f8fc;
}
.tp-chatbot__chip {
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid rgba(24, 119, 242, 0.35);
  color: var(--tpc-primary-dark);
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.tp-chatbot__chip:hover { background: var(--tpc-primary); color: #fff; border-color: var(--tpc-primary); }
.tp-chatbot__chip--notify {
  border-color: rgba(56, 189, 248, 0.55);
  color: #0369a1;
  background: rgba(56, 189, 248, 0.12);
}
.tp-chatbot__chip--action {
  border-color: rgba(15, 40, 71, 0.18);
  background: #fff;
}

.tp-chatbot__typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.6rem 0.8rem;
}
.tp-chatbot__typing span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #94a3b8;
  animation: tpcBounce 1s infinite ease-in-out;
}
.tp-chatbot__typing span:nth-child(2) { animation-delay: 0.15s; }
.tp-chatbot__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tpcBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.tp-chatbot__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem;
  border-top: 1px solid rgba(15, 40, 71, 0.08);
  background: #fff;
}
.tp-chatbot__input {
  flex: 1;
  border: 1px solid rgba(15, 40, 71, 0.15);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font-size: 16px;
  outline: none;
  -webkit-text-size-adjust: 100%;
}
.tp-chatbot__input:focus { border-color: var(--tpc-primary); box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.12); }
.tp-chatbot__send {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: none;
  background: var(--tpc-primary);
  color: #fff;
  font-size: 1.05rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tp-chatbot__send:hover { background: var(--tpc-primary-dark); }
.tp-chatbot__send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Escalade vers un conseiller humain */
.tp-chatbot__handover { display: flex; margin: 0.25rem 0 0.4rem; }
.tp-chatbot__handover-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--tpc-primary);
  background: rgba(24, 119, 242, 0.08);
  color: var(--tpc-primary-dark);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.tp-chatbot__handover-btn:hover { background: var(--tpc-primary); color: #fff; }
.tp-chatbot__handover-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.tp-chatbot__escalation {
  background: #fff;
  border: 1px solid rgba(15, 40, 71, 0.12);
  border-radius: 14px;
  padding: 0.85rem;
  margin: 0.25rem 0 0.5rem;
  box-shadow: 0 4px 16px rgba(15, 40, 71, 0.08);
}
.tp-chatbot__escalation-title { font-size: 0.84rem; font-weight: 600; margin-bottom: 0.55rem; color: #0f2847; }
.tp-chatbot__field {
  width: 100%;
  border: 1px solid rgba(15, 40, 71, 0.15);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  font-size: 16px;
  margin-bottom: 0.5rem;
  outline: none;
  font-family: inherit;
  -webkit-text-size-adjust: 100%;
}
.tp-chatbot__field:focus { border-color: var(--tpc-primary); box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.12); }
.tp-chatbot__escalation-actions { display: flex; justify-content: flex-end; }
.tp-chatbot__escalation-actions { gap: 0.45rem; flex-wrap: wrap; }
.tp-chatbot__handover-btn--ghost {
  border-color: rgba(15, 40, 71, 0.16);
  background: #fff;
  color: #475569;
}
.tp-chatbot__handover-btn--ghost:hover {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #cbd5e1;
}
.tp-chatbot__escalation-status { font-size: 0.78rem; color: #b91c1c; margin-top: 0.35rem; min-height: 1rem; }
.tp-chatbot__escalation-done {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: #15803d;
  font-size: 0.85rem;
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .tp-chatbot__panel, .tp-chatbot__typing span { animation: none !important; }
}

@media (max-width: 575.98px) {
  .tp-chatbot {
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }
  .tp-chatbot__panel {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(4.75rem + env(safe-area-inset-bottom));
    width: auto;
    height: min(76vh, 620px);
    border-radius: 0.9rem;
  }
  .tp-chatbot__msg { max-width: 90%; }
  .tp-chatbot__suggestions {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.65rem;
  }
  .tp-chatbot__chip { flex: 0 0 auto; }
}
