/* Widget chatbot DPB-Easy — palette SNI : orange #ED7D31 + bleu #1E40AF
 * Toutes les classes sont préfixées .dpb-chat-* pour éviter les collisions
 * avec les styles de la page hôte (Scan présence digitale).
 *
 * Customisable via CSS variables sur :root ou sur le wrapper .dpb-chat.
 */

.dpb-chat {
  /* Palette (overridable) */
  --dpb-chat-orange:        #ED7D31;
  --dpb-chat-orange-dark:   #D86C20;
  --dpb-chat-orange-soft:   #FEF3E7;
  --dpb-chat-orange-border: #FCD2B0;
  --dpb-chat-blue:          #1E40AF;
  --dpb-chat-blue-dark:     #1E3A8A;
  --dpb-chat-bg:            #FFFFFF;
  --dpb-chat-bg-soft:       #F1F3F6;
  --dpb-chat-text:          #1a1a1a;
  --dpb-chat-muted:         #666666;
  --dpb-chat-border:        #E5E7EB;
  --dpb-chat-shadow:        0 10px 40px rgba(0,0,0,.18);

  /* Sizing */
  --dpb-chat-radius:        16px;
  --dpb-chat-radius-sm:     10px;
  --dpb-chat-launcher-size: 56px;

  /* Typography (hérite par défaut, sinon fallback) */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--dpb-chat-text);

  /* Position */
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2147483000; /* sous le niveau max pour ne pas masquer modales système */
  pointer-events: none; /* le wrapper ne capture pas les clics, seuls les enfants */
}

.dpb-chat *,
.dpb-chat *::before,
.dpb-chat *::after {
  box-sizing: border-box;
}

/* ─────────────── Bouton flottant (launcher) ─────────────── */

.dpb-chat__launcher {
  pointer-events: auto;
  width: var(--dpb-chat-launcher-size);
  height: var(--dpb-chat-launcher-size);
  border: none;
  border-radius: 50%;
  background: var(--dpb-chat-orange);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--dpb-chat-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, background .15s ease;
}
.dpb-chat__launcher:hover { background: var(--dpb-chat-orange-dark); transform: scale(1.05); }
.dpb-chat__launcher:focus-visible {
  outline: 3px solid var(--dpb-chat-blue);
  outline-offset: 3px;
}
.dpb-chat__launcher svg { width: 26px; height: 26px; fill: currentColor; }

.dpb-chat[data-state="open"] .dpb-chat__launcher,
.dpb-chat[data-state="sending"] .dpb-chat__launcher {
  display: none;
}

/* ─────────────── Panel ─────────────── */

.dpb-chat__panel {
  pointer-events: auto;
  display: none;
  flex-direction: column;
  width: 380px;
  height: min(620px, calc(100vh - 40px));
  background: var(--dpb-chat-bg);
  border-radius: var(--dpb-chat-radius);
  box-shadow: var(--dpb-chat-shadow);
  overflow: hidden;
  animation: dpb-chat-pop .2s ease-out;
}
@keyframes dpb-chat-pop {
  from { opacity: 0; transform: translateY(20px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
.dpb-chat[data-state="open"] .dpb-chat__panel,
.dpb-chat[data-state="sending"] .dpb-chat__panel {
  display: flex;
}

/* ─────────────── Header ─────────────── */

.dpb-chat__header {
  background: linear-gradient(135deg, var(--dpb-chat-blue) 0%, var(--dpb-chat-blue-dark) 100%);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.dpb-chat__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dpb-chat__title svg {
  width: 22px;
  height: 22px;
  fill: var(--dpb-chat-orange);
  background: #fff;
  border-radius: 50%;
  padding: 4px;
}
.dpb-chat__close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.dpb-chat__close:hover { background: rgba(255,255,255,.15); }
.dpb-chat__close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.dpb-chat__close svg { width: 18px; height: 18px; fill: currentColor; }

/* ─────────────── Body / messages ─────────────── */

.dpb-chat__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--dpb-chat-bg-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.dpb-chat__msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: var(--dpb-chat-radius-sm);
  word-wrap: break-word;
  font-size: 14px;
}
.dpb-chat__msg p { margin: 0 0 6px; }
.dpb-chat__msg p:last-child { margin-bottom: 0; }
.dpb-chat__msg strong { font-weight: 600; }
.dpb-chat__msg em { font-style: italic; color: var(--dpb-chat-muted); }

.dpb-chat__msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--dpb-chat-border);
  border-bottom-left-radius: 4px;
}
.dpb-chat__msg--user {
  align-self: flex-end;
  background: var(--dpb-chat-orange-soft);
  border: 1px solid var(--dpb-chat-orange-border);
  border-bottom-right-radius: 4px;
  color: var(--dpb-chat-text);
}
.dpb-chat__msg--error {
  align-self: stretch;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  color: #991B1B;
  text-align: center;
  font-size: 13px;
}

.dpb-chat__sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--dpb-chat-border);
  font-size: 12px;
  color: var(--dpb-chat-muted);
}
.dpb-chat__sources-label {
  font-weight: 600;
  color: var(--dpb-chat-text);
  display: block;
  margin-bottom: 4px;
}
.dpb-chat__source {
  display: block;
  padding: 3px 0;
}
.dpb-chat__source-title { color: var(--dpb-chat-text); font-weight: 500; }
.dpb-chat__source-cat { color: var(--dpb-chat-blue); font-size: 11px; margin-left: 4px; }

/* ─── V2 : étapes pas-à-pas + deep link bouton ─── */

.dpb-chat__steps {
  margin: 10px 0 4px;
  padding-left: 22px;
  list-style: decimal;
  font-size: 13px;
}
.dpb-chat__step {
  margin-bottom: 8px;
  line-height: 1.45;
}
.dpb-chat__step::marker {
  color: var(--dpb-chat-orange);
  font-weight: 700;
}
.dpb-chat__step-title {
  display: block;
  font-weight: 600;
  color: var(--dpb-chat-text);
  margin-bottom: 2px;
}
.dpb-chat__step p {
  margin: 0;
}

.dpb-chat__deep-link {
  display: inline-block;
  margin-top: 12px;
  padding: 8px 14px;
  background: var(--dpb-chat-orange);
  color: #fff !important;
  text-decoration: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s ease;
}
.dpb-chat__deep-link:hover {
  background: var(--dpb-chat-orange-dark);
  text-decoration: none;
}
.dpb-chat__deep-link:focus-visible {
  outline: 2px solid var(--dpb-chat-blue);
  outline-offset: 2px;
}
.dpb-chat__deep-link::after {
  content: " →";
}

/* ─────────────── Quick replies ─────────────── */

.dpb-chat__quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 8px;
  align-self: flex-start;
  max-width: 100%;
}
.dpb-chat__qr {
  background: #fff;
  color: var(--dpb-chat-text);
  border: 1px solid var(--dpb-chat-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  font-family: inherit;
}
.dpb-chat__qr:hover {
  background: var(--dpb-chat-orange-soft);
  border-color: var(--dpb-chat-orange);
  color: var(--dpb-chat-orange-dark);
}
.dpb-chat__qr:focus-visible {
  outline: 2px solid var(--dpb-chat-orange);
  outline-offset: 2px;
}
.dpb-chat__qr:disabled { opacity: .5; cursor: not-allowed; }

/* Indicateur "typing" */
.dpb-chat__typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--dpb-chat-border);
  border-radius: var(--dpb-chat-radius-sm);
  border-bottom-left-radius: 4px;
}
.dpb-chat__typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dpb-chat-muted);
  animation: dpb-chat-typing 1.2s infinite ease-in-out;
}
.dpb-chat__typing span:nth-child(2) { animation-delay: .15s; }
.dpb-chat__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes dpb-chat-typing {
  0%, 60%, 100% { transform: scale(.7); opacity: .4; }
  30%           { transform: scale(1);  opacity: 1; }
}

/* ─────────────── Input ─────────────── */

.dpb-chat__input {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid var(--dpb-chat-border);
  flex-shrink: 0;
}
.dpb-chat__input input {
  flex: 1;
  border: 1px solid var(--dpb-chat-border);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  color: var(--dpb-chat-text);
  background: #fff;
}
.dpb-chat__input input:focus {
  border-color: var(--dpb-chat-orange);
  box-shadow: 0 0 0 2px var(--dpb-chat-orange-soft);
}
.dpb-chat__input input:disabled { background: #F9FAFB; color: var(--dpb-chat-muted); }

.dpb-chat__send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--dpb-chat-orange);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s ease;
}
.dpb-chat__send:hover { background: var(--dpb-chat-orange-dark); }
.dpb-chat__send:focus-visible { outline: 2px solid var(--dpb-chat-blue); outline-offset: 2px; }
.dpb-chat__send:disabled { background: #D1D5DB; cursor: not-allowed; }
.dpb-chat__send svg { width: 18px; height: 18px; fill: currentColor; }

/* ─────────────── Mobile ─────────────── */

@media (max-width: 600px) {
  .dpb-chat { bottom: 12px; right: 12px; left: 12px; }
  .dpb-chat__panel {
    width: auto;
    height: calc(100vh - 80px);
    height: calc(100dvh - 80px);
    max-height: none;
  }
  .dpb-chat__launcher { margin-left: auto; }
}

/* Reduce motion preferences */
@media (prefers-reduced-motion: reduce) {
  .dpb-chat__panel { animation: none; }
  .dpb-chat__typing span { animation: none; opacity: 1; }
  .dpb-chat__launcher { transition: none; }
  .dpb-chat__body { scroll-behavior: auto; }
}
