/* Tokiz Chatbot — les couleurs et la position sont injectées depuis les réglages (variables CSS). */
.tokiz-chatbot-root {
  --tcz-primary: #017eb0;
  --tcz-on-primary: #ffffff;
  --tcz-bot-bg: #eef0f3;
  --tcz-bottom: 20px;
  --tcz-side: 20px;
  --tcz-text: #1f2328;
  --tcz-muted: #6b7280;
  --tcz-border: #e5e7eb;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--tcz-text);
}

.tokiz-chatbot-root *,
.tokiz-chatbot-root *::before,
.tokiz-chatbot-root *::after {
  box-sizing: border-box;
}

.tokiz-chatbot-root .screen-reader-text {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}

/* ---------- Bulle ---------- */
.tokiz-chatbot-root .tcz-bubble {
  position: fixed;
  bottom: var(--tcz-bottom);
  right: var(--tcz-side);
  z-index: 99998;
  width: 58px;
  height: 58px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--tcz-primary);
  color: var(--tcz-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.tokiz-chatbot-root .tcz-bubble:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
}

.tokiz-chatbot-root .tcz-bubble:focus-visible,
.tokiz-chatbot-root .tcz-close:focus-visible,
.tokiz-chatbot-root .tcz-send:focus-visible {
  outline: 3px solid var(--tcz-primary);
  outline-offset: 3px;
}

.tokiz-chatbot-root .tcz-bubble svg {
  width: 26px;
  height: 26px;
}

.tokiz-chatbot-root .tcz-icon-close,
.tokiz-chatbot-root.is-open .tcz-icon-open {
  display: none;
}

.tokiz-chatbot-root.is-open .tcz-icon-close {
  display: block;
}

/* ---------- Fenêtre ---------- */
.tokiz-chatbot-root .tcz-window {
  position: fixed;
  bottom: calc(var(--tcz-bottom) + 72px);
  right: var(--tcz-side);
  z-index: 99999;
  width: 390px;
  max-width: calc(100vw - 2 * var(--tcz-side));
  height: 600px;
  max-height: calc(100vh - var(--tcz-bottom) - 96px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: tcz-in 0.18s ease-out;
}

.tokiz-chatbot-root .tcz-window[hidden] {
  display: none;
}

.tokiz-chatbot-root .tcz-box {
  flex: 1 1 0;
  min-height: 220px;
  background: #fff;
  border: 1px solid var(--tcz-border);
  border-radius: 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.16);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Mode intégré dans une page : [tokiz_chatbot affichage="integre"] */
.tokiz-chatbot-root.is-inline .tcz-window {
  position: relative;
  inset: auto;
  width: 100%;
  max-width: none;
  height: auto;
  max-height: none;
  z-index: auto;
  animation: none;
}

.tokiz-chatbot-root.is-inline .tcz-box {
  height: var(--tcz-inline-height);
  flex: 0 0 auto;
}

@keyframes tcz-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- En-tête ---------- */
.tokiz-chatbot-root .tcz-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--tcz-primary);
  color: var(--tcz-on-primary);
}

.tokiz-chatbot-root .tcz-header-id {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.tokiz-chatbot-root .tcz-header-avatar {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  margin: 0;
}

.tokiz-chatbot-root .tcz-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
}

.tokiz-chatbot-root .tcz-header-avatar.tcz-initial {
  background: color-mix(in srgb, var(--tcz-primary) 70%, #fff);
  color: var(--tcz-on-primary);
  border: 2px solid color-mix(in srgb, var(--tcz-on-primary) 35%, transparent);
}

.tokiz-chatbot-root .tcz-header-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
}

.tokiz-chatbot-root .tcz-header-text {
  font-size: 12.5px;
  opacity: 0.92;
  margin-top: 3px;
}

.tokiz-chatbot-root .tcz-header-text a {
  color: inherit;
  text-decoration: underline;
}

.tokiz-chatbot-root .tcz-close {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.tokiz-chatbot-root .tcz-close:hover {
  background: rgba(255, 255, 255, 0.18);
}

.tokiz-chatbot-root .tcz-close svg {
  width: 100%;
  height: 100%;
}

.tokiz-chatbot-root .tcz-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tokiz-chatbot-root .tcz-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px color-mix(in srgb, #22c55e 30%, transparent);
}

.tokiz-chatbot-root .tcz-intro {
  margin: 0 0 4px;
  font-size: 12.5px;
  color: var(--tcz-muted);
}

.tokiz-chatbot-root .tcz-intro a {
  color: inherit;
  text-decoration: underline;
}

.tokiz-chatbot-root .tcz-msg-avatar.tcz-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tcz-primary);
  color: var(--tcz-on-primary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ---------- Messages ---------- */
.tokiz-chatbot-root .tcz-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fff;
  overscroll-behavior: contain;
}

.tokiz-chatbot-root .tcz-msg {
  display: flex;
  gap: 8px;
  max-width: 100%;
}

.tokiz-chatbot-root .tcz-msg-user {
  justify-content: flex-end;
}

.tokiz-chatbot-root .tcz-msg-avatar {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0;
}

.tokiz-chatbot-root .tcz-text {
  padding: 9px 13px;
  border-radius: 14px;
  max-width: 82%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.tokiz-chatbot-root .tcz-msg-bot .tcz-text {
  background: var(--tcz-bot-bg);
  border: 1px solid rgba(0, 0, 0, 0.06);
  color: var(--tcz-text);
  border-top-left-radius: 4px;
}

.tokiz-chatbot-root .tcz-msg-user .tcz-text {
  background: var(--tcz-user-bg, var(--tcz-primary));
  color: var(--tcz-user-text, var(--tcz-on-primary));
  border-top-right-radius: 4px;
}

.tokiz-chatbot-root .tcz-text p {
  margin: 0 0 6px;
}

.tokiz-chatbot-root .tcz-text p:last-child,
.tokiz-chatbot-root .tcz-text ul:last-child {
  margin-bottom: 0;
}

.tokiz-chatbot-root .tcz-text ul {
  margin: 4px 0 6px;
  padding-left: 18px;
}

.tokiz-chatbot-root .tcz-text li {
  margin: 2px 0;
}

.tokiz-chatbot-root .tcz-text a {
  color: inherit;
  text-decoration: underline;
}

.tokiz-chatbot-root .tcz-msg-error .tcz-text {
  background: #fef2f2;
  color: #991b1b;
}

/* Indicateur de saisie */
.tokiz-chatbot-root .tcz-typing .tcz-text {
  display: flex;
  gap: 4px;
  padding: 13px 14px;
}

.tokiz-chatbot-root .tcz-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tcz-muted);
  animation: tcz-blink 1.4s infinite both;
}

.tokiz-chatbot-root .tcz-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.tokiz-chatbot-root .tcz-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes tcz-blink {
  0%,
  100% {
    opacity: 0.25;
  }
  20% {
    opacity: 1;
  }
}

/* ---------- Saisie ---------- */
.tokiz-chatbot-root .tcz-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border-top: 1px solid var(--tcz-border);
  background: #fff;
}

.tokiz-chatbot-root .tcz-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  color: var(--tcz-text);
  font: inherit;
  font-size: 16px; /* évite le zoom automatique sur iPhone */
  line-height: 1.35;
  resize: none;
  box-shadow: none;
}

.tokiz-chatbot-root .tcz-input:focus {
  outline: none;
  border-color: var(--tcz-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--tcz-primary) 25%, transparent);
}

.tokiz-chatbot-root .tcz-send {
  flex: 0 0 auto;
  height: 40px;
  margin: 0;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--tcz-primary);
  color: var(--tcz-on-primary);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  line-height: 40px;
  text-transform: none;
  letter-spacing: normal;
}

.tokiz-chatbot-root .tcz-send:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ---------- Mobile : plein écran ---------- */
@media (max-width: 600px) {
  .tokiz-chatbot-root:not(.is-inline) .tcz-window {
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    gap: 0;
    background: #fff;
  }

  .tokiz-chatbot-root:not(.is-inline) .tcz-box {
    border-radius: 0;
    border: 0;
    box-shadow: none;
    min-height: 0;
  }

  .tokiz-chatbot-root.is-open:not(.is-inline) .tcz-bubble {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tokiz-chatbot-root .tcz-window,
  .tokiz-chatbot-root .tcz-dot,
  .tokiz-chatbot-root .tcz-bubble {
    animation: none;
    transition: none;
  }
}
