/* ============================================================
   WP Knowledge Chat v2 — Widget CSS
   Design : clean, moderne, accessible, mobile-first
   ============================================================ */

/* Variables */
:root {
  --wpkc-primary:     #0f172a;
  --wpkc-accent:      #3b82f6;
  --wpkc-accent-dark: #1d4ed8;
  --wpkc-bg:          #ffffff;
  --wpkc-bg-body:     #f8fafc;
  --wpkc-border:      #e2e8f0;
  --wpkc-text:        #1e293b;
  --wpkc-text-light:  #64748b;
  --wpkc-user-bg:     #0f172a;
  --wpkc-user-text:   #ffffff;
  --wpkc-bot-bg:      #ffffff;
  --wpkc-bot-text:    #1e293b;
  --wpkc-radius:      16px;
  --wpkc-shadow:      0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.10);
  --wpkc-z:           9999990;
}

/* ——— Pulse animation ——— */
@keyframes wpkc-pulse-ring {
  0%   { transform: scale(1);   opacity: .6; }
  100% { transform: scale(1.9); opacity: 0;  }
}
@keyframes wpkc-pulse-ring2 {
  0%   { transform: scale(1);   opacity: .4; }
  100% { transform: scale(2.4); opacity: 0;  }
}

/* ——— FAB Button ——— */
.wpkc-fab {
  position: fixed;
  bottom: 20px;   /* surchargé dynamiquement par JS */
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--wpkc-accent) 0%, var(--wpkc-accent-dark) 100%);
  color: var(--wpkc-fab-icon, #fff);
  z-index: var(--wpkc-z);
  box-shadow: 0 6px 24px rgba(59,130,246,.5), 0 2px 8px rgba(0,0,0,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, box-shadow .2s;
  outline: none;
  /* Anneaux de pulse */
  isolation: isolate;
}
.wpkc-fab::before,
.wpkc-fab::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--wpkc-accent);
  z-index: -1;
  animation: wpkc-pulse-ring 2.2s ease-out infinite;
}
.wpkc-fab::after {
  animation: wpkc-pulse-ring2 2.2s ease-out .6s infinite;
}
/* Stopper le pulse quand le panel est ouvert */
.wpkc-fab.is-open::before,
.wpkc-fab.is-open::after {
  animation: none;
  opacity: 0;
}
.wpkc-fab:hover,
.wpkc-fab:focus-visible {
  transform: scale(1.1);
  box-shadow: 0 10px 36px rgba(59,130,246,.6), 0 4px 12px rgba(0,0,0,.25);
}
.wpkc-fab:active { transform: scale(0.94); }

/* SVG icône dans le FAB */
.wpkc-fab svg {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

/* Badge non-lu */
.wpkc-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  opacity: 0;
  transform: scale(0);
  transition: opacity .2s, transform .2s;
}
.wpkc-fab-badge.is-visible {
  opacity: 1;
  transform: scale(1);
}

/* ——— Panel ——— */
.wpkc-panel {
  position: fixed;
  bottom: 90px;
  width: 380px;
  max-width: calc(100vw - 24px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--wpkc-bg);
  border-radius: var(--wpkc-radius);
  box-shadow: var(--wpkc-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
  z-index: var(--wpkc-z);
  border: 1px solid rgba(255,255,255,.2);
}
.wpkc-panel.is-right { right: 20px; }
.wpkc-panel.is-left  { left: 20px;  }
.wpkc-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ——— Header ——— */
.wpkc-header {
  padding: 16px 16px 14px;
  background: linear-gradient(135deg, var(--wpkc-primary) 0%, #1e3a5f 100%);
  color: #fff;
  position: relative;
  flex-shrink: 0;
}
.wpkc-header-inner {
  display: flex;
  align-items: center;
  gap: 10px;
}
.wpkc-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.wpkc-header-text { flex: 1; min-width: 0; }
.wpkc-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wpkc-subtitle {
  font-size: 11px;
  opacity: .75;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wpkc-status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  animation: wpkc-pulse 2.5s infinite;
}
@keyframes wpkc-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}
.wpkc-close {
  position: absolute;
  right: 12px;
  top: 12px;
  width: 28px;
  height: 28px;
  background: rgba(255,255,255,.12);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  outline: none;
}
.wpkc-close:hover { background: rgba(255,255,255,.25); }

/* ——— Corps des messages ——— */
.wpkc-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--wpkc-bg-body);
  scroll-behavior: smooth;
}
.wpkc-body::-webkit-scrollbar { width: 4px; }
.wpkc-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ——— Messages ——— */
.wpkc-msg {
  display: flex;
  margin-bottom: 10px;
  animation: wpkc-fadein .2s ease;
}
@keyframes wpkc-fadein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wpkc-msg.is-user { justify-content: flex-end; }
.wpkc-msg.is-bot  { justify-content: flex-start; align-items: flex-end; gap: 6px; }

.wpkc-bot-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--wpkc-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.wpkc-bubble {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
}
.wpkc-msg.is-user .wpkc-bubble {
  background: var(--wpkc-user-bg);
  color: var(--wpkc-user-text);
  border-bottom-right-radius: 4px;
}
.wpkc-msg.is-bot .wpkc-bubble {
  background: var(--wpkc-bot-bg);
  color: var(--wpkc-bot-text);
  border: 1px solid var(--wpkc-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

/* Contenu bot */
.wpkc-answer { white-space: pre-wrap; }
.wpkc-answer strong { font-weight: 600; }

/* Sources */
.wpkc-sources-block {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--wpkc-border);
}
.wpkc-sources-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--wpkc-text-light);
  margin-bottom: 5px;
  font-weight: 600;
}
.wpkc-sources-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.wpkc-sources-list a {
  font-size: 12px;
  color: var(--wpkc-accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.wpkc-sources-list a:before { content: '↗'; font-size: 10px; }
.wpkc-sources-list a:hover { text-decoration: underline; color: var(--wpkc-accent-dark); }

/* Handoff suggestion */
.wpkc-handoff-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--wpkc-text-light);
  font-style: italic;
}

/* ——— Indicateur de frappe (3 points) ——— */
.wpkc-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 13px;
  background: var(--wpkc-bot-bg);
  border: 1px solid var(--wpkc-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  width: fit-content;
}
.wpkc-dot {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: wpkc-bounce .9s ease infinite;
}
.wpkc-dot:nth-child(2) { animation-delay: .15s; }
.wpkc-dot:nth-child(3) { animation-delay: .30s; }
@keyframes wpkc-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* ——— Suggestions ——— */
.wpkc-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 12px;
  background: var(--wpkc-bg-body);
}
.wpkc-suggestion-chip {
  padding: 5px 12px;
  border: 1px solid var(--wpkc-border);
  border-radius: 20px;
  background: #fff;
  font-size: 12px;
  color: var(--wpkc-text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wpkc-suggestion-chip:hover {
  background: var(--wpkc-primary);
  color: #fff;
  border-color: var(--wpkc-primary);
}

/* ——— Footer ——— */
.wpkc-footer {
  flex-shrink: 0;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--wpkc-border);
  background: var(--wpkc-bg);
}

/* Zone de saisie */
.wpkc-inputrow {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.wpkc-input-wrap {
  flex: 1;
  position: relative;
}
.wpkc-input {
  width: 100%;
  padding: 10px 40px 10px 12px;
  border: 1.5px solid var(--wpkc-border);
  border-radius: 12px;
  font-size: 13.5px;
  color: var(--wpkc-text);
  background: var(--wpkc-bg-body);
  resize: none;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
  box-sizing: border-box;
  display: block;
}
.wpkc-input:focus { border-color: var(--wpkc-accent); background: #fff; }
.wpkc-input::placeholder { color: #94a3b8; }
.wpkc-char-count {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 10px;
  color: #94a3b8;
}
.wpkc-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--wpkc-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
  outline: none;
}
.wpkc-send:hover:not(:disabled) { background: #1e293b; }
.wpkc-send:active:not(:disabled) { transform: scale(0.94); }
.wpkc-send:disabled { opacity: .45; cursor: not-allowed; }

/* Bouton callback */
.wpkc-footer-actions {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}
.wpkc-callback-btn {
  padding: 6px 14px;
  border: 1.5px solid var(--wpkc-border);
  border-radius: 20px;
  background: transparent;
  color: var(--wpkc-text-light);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.wpkc-callback-btn:hover {
  border-color: var(--wpkc-accent);
  color: var(--wpkc-accent);
  background: #eff6ff;
}

/* Mention RGPD */
.wpkc-privacy {
  text-align: center;
  font-size: 10.5px;
  color: #94a3b8;
  margin-top: 6px;
  line-height: 1.4;
}

/* ——— Formulaire callback ——— */
.wpkc-callback-form {
  margin-top: 10px;
  background: #f8fafc;
  border: 1px solid var(--wpkc-border);
  border-radius: 12px;
  padding: 14px;
  display: none;
}
.wpkc-callback-form.is-open { display: block; animation: wpkc-fadein .2s ease; }
.wpkc-callback-form h4 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--wpkc-text);
}
.wpkc-field {
  margin-bottom: 8px;
}
.wpkc-field-input {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--wpkc-border);
  border-radius: 9px;
  font-size: 13px;
  background: #fff;
  outline: none;
  transition: border-color .15s;
  box-sizing: border-box;
  font-family: inherit;
}
.wpkc-field-input:focus { border-color: var(--wpkc-accent); }
.wpkc-field-input::placeholder { color: #94a3b8; }
.wpkc-callback-actions { display: flex; gap: 8px; margin-top: 10px; }
.wpkc-callback-submit {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 9px;
  background: var(--wpkc-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.wpkc-callback-submit:hover { background: #1e293b; }
.wpkc-callback-cancel {
  padding: 9px 12px;
  border: 1px solid var(--wpkc-border);
  border-radius: 9px;
  background: transparent;
  font-size: 13px;
  color: var(--wpkc-text-light);
  cursor: pointer;
  transition: background .15s;
}
.wpkc-callback-cancel:hover { background: #f1f5f9; }

/* ——— État chargement du panel ——— */
.wpkc-panel.wpkc-busy .wpkc-send { opacity: .4; cursor: not-allowed; }
.wpkc-panel.wpkc-busy .wpkc-input { background: #f1f5f9; }

/* ——— Erreur ——— */
.wpkc-error-bubble .wpkc-bubble {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #be123c;
}

/* ——— Mobile ——— */
@media (max-width: 480px) {
  .wpkc-panel {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    border-radius: 0;
  }
  .wpkc-fab {
    bottom: 16px;
  }
}

/* ——— Accessibilité ——— */
.wpkc-fab:focus-visible,
.wpkc-close:focus-visible,
.wpkc-send:focus-visible,
.wpkc-input:focus-visible {
  outline: 2px solid var(--wpkc-accent);
  outline-offset: 2px;
}

/* ——— Reduced motion ——— */
@media (prefers-reduced-motion: reduce) {
  .wpkc-panel,
  .wpkc-msg,
  .wpkc-dot,
  .wpkc-status-dot { animation: none !important; transition: none !important; }
}
