/* ================================================================
   PURESYSTEM — ASSISTANT CONVERSATIONNEL
   Reprend les variables de style.css : aucune couleur en dur, aucune
   police en dur. Si la charte du site change, le widget suit.
   Les classes .terminal-dots, .dot et .terminal-title sont celles de
   style.css, réutilisées telles quelles pour l'en-tête.
   ================================================================ */

/* ----------------------------------------------------------------
   1. BOUTON D'OUVERTURE
   ---------------------------------------------------------------- */
.ps-chat-launcher {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 900;

  display: inline-flex;
  align-items: center;
  gap: 0.6rem;

  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-primary);

  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  border-radius: 100px;
  padding: 0.7rem 1.15rem;
  cursor: pointer;

  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 0 0 0 var(--purple-glow);
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease),
    border-color 0.25s, opacity 0.25s var(--ease);
}

.ps-chat-launcher:hover {
  transform: translateY(-3px);
  border-color: var(--purple);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5), 0 0 0 4px var(--purple-glow);
}

.ps-chat-launcher:focus-visible {
  outline: 2px solid var(--purple-light);
  outline-offset: 3px;
}

/* Le chevron du terminal, avec le curseur qui clignote comme dans le hero. */
.ps-chat-launcher-prompt {
  color: var(--green);
  font-weight: 600;
}
.ps-chat-launcher-caret {
  color: var(--purple);
  animation: blink 1.1s step-end infinite;
}

/* Pastille verte : l'assistant est en ligne. */
.ps-chat-launcher-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 var(--green-glow);
  animation: ps-chat-pulse 2.4s var(--ease) infinite;
}

@keyframes ps-chat-pulse {
  0%   { box-shadow: 0 0 0 0 var(--green-glow); }
  70%  { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Quand le panneau est ouvert, le bouton s'efface. */
.ps-chat-launcher[aria-expanded='true'] {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px) scale(0.94);
}

/* ----------------------------------------------------------------
   2. PANNEAU
   ---------------------------------------------------------------- */
.ps-chat-panel {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 950;

  width: min(390px, calc(100vw - 3rem));
  height: min(560px, calc(100vh - 3rem));
  display: flex;
  flex-direction: column;

  background: var(--bg-card);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius);
  overflow: hidden;

  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(139, 92, 246, 0.12);

  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease);
}

.ps-chat-panel--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* En-tête : le même bandeau terminal que le formulaire de devis. */
.ps-chat-head {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 1rem;
  background: var(--bg-card-alt);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ps-chat-head .terminal-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ps-chat-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 1.15rem;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}
.ps-chat-close:hover {
  color: var(--text-primary);
  background: rgba(139, 92, 246, 0.12);
}
.ps-chat-close:focus-visible {
  outline: 2px solid var(--purple-light);
  outline-offset: 1px;
}

/* ----------------------------------------------------------------
   3. FIL DE CONVERSATION
   ---------------------------------------------------------------- */
.ps-chat-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.15rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
}

.ps-chat-log::-webkit-scrollbar { width: 8px; }
.ps-chat-log::-webkit-scrollbar-track { background: transparent; }
.ps-chat-log::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 100px;
}
.ps-chat-log::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

.ps-chat-msg {
  max-width: 88%;
  font-size: 0.9rem;
  line-height: 1.65;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius);
  animation: ps-chat-in 0.35s var(--ease) both;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

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

.ps-chat-msg--bot {
  align-self: flex-start;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-top-left-radius: 4px;
}

.ps-chat-msg--moi {
  align-self: flex-end;
  background: rgba(139, 92, 246, 0.14);
  border: 1px solid var(--border-hover);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.ps-chat-msg--sys {
  align-self: center;
  max-width: 100%;
  text-align: center;
  background: none;
  border: none;
  padding: 0.2rem 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.ps-chat-msg p { margin: 0; }
.ps-chat-msg p + p,
.ps-chat-msg ul + p { margin-top: 0.55rem; }
.ps-chat-msg strong { color: var(--purple-light); font-weight: 600; }
.ps-chat-msg code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--green);
  background: rgba(34, 197, 94, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.ps-chat-msg ul {
  margin: 0.5rem 0 0;
  padding-left: 0;
  list-style: none;
}
.ps-chat-msg li {
  position: relative;
  padding-left: 1rem;
  margin-top: 0.3rem;
}
.ps-chat-msg li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--purple);
}

/* Lien vers une page du site. Vert, comme les accents du site : c'est la couleur
   qui signale « c'est à toi de cliquer », le violet restant celui de la marque. */
.ps-chat-lien {
  color: var(--green);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: rgba(34, 197, 94, 0.4);
  border-radius: 3px;
  transition: text-decoration-color 0.2s, color 0.2s, background 0.2s;
}
.ps-chat-lien:hover {
  color: #4ade80;
  text-decoration-color: var(--green);
  background: rgba(34, 197, 94, 0.1);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}
.ps-chat-lien:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

/* Pendant la rédaction en flux : un curseur de terminal en fin de texte. */
.ps-chat-msg--flux > :last-child::after {
  content: '▋';
  display: inline-block;
  margin-left: 2px;
  color: var(--purple);
  animation: blink 1.1s step-end infinite;
  vertical-align: baseline;
}

/* Indicateur de frappe : trois points façon curseur de terminal. */
.ps-chat-typing {
  display: inline-flex;
  gap: 0.28rem;
  align-items: center;
  padding: 0.15rem 0;
}
.ps-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--purple-light);
  animation: ps-chat-bounce 1.3s var(--ease) infinite;
}
.ps-chat-typing span:nth-child(2) { animation-delay: 0.16s; }
.ps-chat-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes ps-chat-bounce {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-4px); }
}

/* ----------------------------------------------------------------
   4. SUGGESTIONS DE DÉPART
   ---------------------------------------------------------------- */
.ps-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.85rem;
  flex-shrink: 0;
}

.ps-chat-suggestion {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--purple-light);
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 100px;
  padding: 0.32rem 0.7rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s var(--ease);
}
.ps-chat-suggestion:hover {
  background: rgba(139, 92, 246, 0.16);
  border-color: var(--purple);
  color: var(--text-primary);
  transform: translateY(-2px);
}
.ps-chat-suggestion:focus-visible {
  outline: 2px solid var(--purple-light);
  outline-offset: 2px;
}

/* ----------------------------------------------------------------
   5. SAISIE
   ---------------------------------------------------------------- */
.ps-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.8rem 1rem 0.9rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card-alt);
  flex-shrink: 0;
}

.ps-chat-input {
  flex: 1;
  resize: none;
  max-height: 96px;
  min-height: 40px;

  font-family: var(--font-body);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-primary);

  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;

  transition: border-color 0.2s, box-shadow 0.2s;
}
.ps-chat-input::placeholder { color: var(--text-muted); }
.ps-chat-input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

.ps-chat-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;

  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;

  transition: transform 0.2s var(--ease), box-shadow 0.2s, opacity 0.2s, background 0.2s;
}
.ps-chat-send:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--purple-glow);
}
.ps-chat-send:focus-visible {
  outline: 2px solid var(--purple-light);
  outline-offset: 2px;
}
.ps-chat-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: var(--text-muted);
}

/* Mention légale sous la saisie. */
.ps-chat-pied {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0 1rem 0.7rem;
  background: var(--bg-card-alt);
  flex-shrink: 0;
  line-height: 1.5;
}
.ps-chat-pied a { color: var(--text-secondary); text-decoration: underline; }
.ps-chat-pied a:hover { color: var(--purple-light); }

/* ----------------------------------------------------------------
   6. MOBILE
   ---------------------------------------------------------------- */
@media (max-width: 560px) {
  .ps-chat-launcher {
    right: 1rem;
    bottom: 1rem;
    padding: 0.65rem 1rem;
    font-size: 0.78rem;
  }

  .ps-chat-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
}

/* Sur un écran bas, on rend la main à la hauteur disponible. */
@media (max-height: 620px) and (min-width: 561px) {
  .ps-chat-panel { height: calc(100vh - 3rem); }
}

/* ----------------------------------------------------------------
   7. ACCESSIBILITÉ — animations réduites
   ---------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ps-chat-launcher,
  .ps-chat-panel,
  .ps-chat-msg,
  .ps-chat-suggestion,
  .ps-chat-send {
    transition: none;
    animation: none;
  }
  .ps-chat-launcher-caret,
  .ps-chat-launcher-led,
  .ps-chat-typing span {
    animation: none;
  }
  .ps-chat-panel--open { transform: none; }
}

/* Masqué proprement pour les lecteurs d'écran comme pour l'affichage. */
.ps-chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
