/* ================================================================
   HFR DESIGNER — assistant.css
   Page autonome (n'utilise PAS les 5 thèmes du reste du site : un
   simple mode clair/sombre dédié, plus simple et plus lisible pour
   une interface de chat). Structure inspirée d'une référence fournie
   par le client, adaptée aux couleurs de marque HFR Designer.
   ================================================================ */

:root {
  --navy:          #0a0f1e;
  --navy-mid:      #101a30;
  --navy-light:    #16233f;
  --brand:         #3B82F6;
  --brand-mid:     #2563eb;
  --brand-light:   #60a5fa;
  --accent:        #06b6d4;
  --slate:         #334155;
  --slate-light:   #64748b;
  --warm-grey:     #94a3b8;

  --bg-primary:    #f4f7fb;
  --bg-secondary:  #ffffff;
  --bg-card:       #ffffff;
  --text-primary:  #0f172a;
  --text-secondary:#334155;
  --text-muted:    #64748b;
  --border:        rgba(51, 65, 85, 0.14);
  --card-shadow:   0 2px 20px rgba(15, 23, 42, 0.08);
  --nav-bg:        rgba(255, 255, 255, 0.96);
  --input-bg:      #f4f7fb;
  --input-border:  rgba(51, 65, 85, 0.18);
  --bubble-user:   #3B82F6;
  --bubble-bot:    #ffffff;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body:    'Inter', sans-serif;
}

[data-assistant-theme="dark"] {
  --bg-primary:    #0a0f1e;
  --bg-secondary:  #101a30;
  --bg-card:       #16233f;
  --text-primary:  #f4f7fb;
  --text-secondary:#b8c8de;
  --text-muted:    #6a7f9e;
  --border:        rgba(255, 255, 255, 0.08);
  --card-shadow:   0 2px 20px rgba(0, 0, 0, 0.35);
  --nav-bg:        rgba(10, 15, 30, 0.97);
  --input-bg:      #16233f;
  --input-border:  rgba(255, 255, 255, 0.12);
  --bubble-user:   #3B82F6;
  --bubble-bot:    #16233f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body.assistant-body {
  font-family: var(--font-body), system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: var(--app-height, 100vh); /* voir assistant.js : contourne les bugs de vh mobile */
  overflow: hidden;
  transition: background-color 0.3s, color 0.3s;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-family: var(--font-display), sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

a { color: inherit; text-decoration: none; }

/* ═══════════════ HEADER ═══════════════ */
.chat-header {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
  z-index: 10;
}

.chat-header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0; /* permet au texte de se réduire plutôt que de déborder */
}

.chat-brand img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.chat-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.chat-brand-text .name {
  font-family: var(--font-display), sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-brand-text .status {
  font-size: 0.7rem;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-light);
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); }
  50%      { opacity: 0.6; box-shadow: 0 0 0 4px rgba(59, 130, 246, 0); }
}

/* État hors-ligne : détecté par assistant.js (navigator.onLine +
   événements online/offline). Le point passe au rouge et cesse de
   pulser, pour bien distinguer "actif" de "problème de connexion". */
.chat-brand-text .status.offline { color: #dc2626; }
.chat-brand-text .status.offline .status-dot {
  background: #dc2626;
  animation: none;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all 0.2s;
  text-decoration: none;
  flex-shrink: 0;
}

.icon-btn:hover { background: rgba(59, 130, 246, 0.08); color: var(--brand); }

/* Bouton "effacer" : caché par défaut, affiché uniquement une fois la
   conversation commencée (piloté par assistant.js, voir showClearBtn). */
.icon-btn.danger {
  display: none;
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.25);
}
.icon-btn.danger:hover { background: rgba(220, 38, 38, 0.08); }
.icon-btn.danger.visible { display: flex; }

/* ═══════════════ CHAT AREA ═══════════════ */
.chat-window {
  flex: 1 1 auto;
  min-height: 0; /* essentiel : permet au flex-child de scroller au lieu de pousser le layout */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chat-scroll {
  width: 100%;
  max-width: 900px;
  padding: 1.5rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  flex: 1;
}

#messages-container {
  display: flex;
  flex-direction: column;
  gap: 0.9rem; /* espacement cohérent entre CHAQUE message et carte projet */
}

/* Bloc d'accueil */
.chat-intro {
  text-align: center;
  padding: 1.5rem 0 0.5rem;
}

.chat-intro-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 14px;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.chat-intro-icon::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(59, 130, 246, 0.4), transparent 60%);
}

.chat-intro-icon i {
  color: var(--brand-light);
  font-size: 1.4rem;
  position: relative;
  z-index: 1;
}

.chat-intro h1 {
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.chat-intro p {
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.7;
}

/* ═══════════════ SUGGESTIONS ═══════════════ */
.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  line-height: 1.5;
  font-family: var(--font-body);
}

.chip:hover {
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(59, 130, 246, 0.05);
  transform: translateY(-1px);
}

.chip i {
  color: var(--brand);
  margin-top: 0.15rem;
  flex-shrink: 0;
  font-size: 0.85rem;
}

/* ═══════════════ BULLES DE MESSAGE ═══════════════ */
.chat-msg {
  display: flex;
  gap: 0.65rem;
  max-width: 100%;
  animation: msgIn 0.3s ease;
  position: relative;
}

.chat-msg.removing {
  animation: msgOut 0.18s ease forwards;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes msgOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.96); }
}

.chat-msg.user { flex-direction: row-reverse; }

.chat-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  overflow: hidden;
}

.chat-msg.bot .chat-msg-avatar {
  background: var(--navy);
  color: var(--brand-light);
}
.chat-msg.bot .chat-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.chat-msg.user .chat-msg-avatar {
  background: rgba(59, 130, 246, 0.12);
  color: var(--brand);
}

.chat-msg-bubble {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.7;
  word-break: break-word;
}

.chat-msg.bot .chat-msg-bubble {
  background: var(--bubble-bot);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-top-left-radius: 4px;
  box-shadow: var(--card-shadow);
}

.chat-msg.user .chat-msg-bubble {
  background: var(--bubble-user);
  color: white;
  border-top-right-radius: 4px;
}

.chat-msg-bubble a { color: var(--brand); text-decoration: underline; font-weight: 600; }
.chat-msg.user .chat-msg-bubble a { color: rgba(255, 255, 255, 0.95); }

.chat-msg.error .chat-msg-bubble {
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: #dc2626;
}

/* Bouton d'options du message (desktop : survol ; mobile : appui long, voir assistant.js) */
.chat-msg-action {
  position: absolute;
  top: -6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.chat-msg.bot .chat-msg-action  { right: -6px; }
.chat-msg.user .chat-msg-action { left: -6px; }

.chat-msg:hover .chat-msg-action,
.chat-msg-action:focus-visible {
  opacity: 1;
}

/* Sur tactile, le bouton "..." reste discret : la suppression passe
   par l'appui long, pas par un bouton flottant intrusif. */
@media (hover: none) {
  .chat-msg-action { display: none; }
}

/* ═══════════════ CARTE PROJET ILLUSTRÉE (carrousel) ═══════════════ */
.chat-project-card {
  align-self: flex-start;
  max-width: 82%;
  margin-left: calc(32px + 0.65rem); /* aligné sous la bulle, pas sous l'avatar */
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-card);
  animation: msgIn 0.25s ease both;
}

.chat-project-carousel {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.chat-project-carousel::-webkit-scrollbar { height: 5px; }
.chat-project-carousel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.chat-project-carousel-item {
  flex-shrink: 0;
  scroll-snap-align: start;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  /* Petites vignettes, mais qui gardent la forme NATURELLE de l'image
     (pas de recadrage forcé) : hauteur fixe raisonnable, largeur libre
     calculée automatiquement par le navigateur selon le ratio réel. */
  height: 130px;
}

.chat-project-carousel-item img {
  display: block;
  height: 100%;
  width: auto;
  max-width: 220px;
  object-fit: contain; /* jamais rogné : la forme d'origine est respectée */
  background: var(--bg-secondary);
}

.chat-project-card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--brand);
  font-family: var(--font-body);
  border-top: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.15s;
}
.chat-project-card-label:hover { background: rgba(59, 130, 246, 0.06); }

/* ═══════════════ INDICATEUR DE FRAPPE ═══════════════ */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0.2rem;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ═══════════════ BAS D'ÉCRAN : suggestions + input (fixe) ═══════════════ */
.chat-bottom {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 1rem 1.25rem;
}

.chat-bottom-inner {
  max-width: 900px;
  margin: 0 auto;
}

.chat-suggestions-bottom {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.75rem;
  scrollbar-width: none;
}
.chat-suggestions-bottom::-webkit-scrollbar { display: none; }

.chat-suggestions-bottom .chip {
  flex-shrink: 0;
  white-space: nowrap;
  align-items: center;
}

.chat-input-form {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 14px;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-form:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-input-form input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--font-body), sans-serif;
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.5;
  padding: 0.45rem 0;
  min-width: 0;
}
.chat-input-form input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: var(--brand);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}
.send-btn:hover  { background: var(--brand-mid); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { background: var(--warm-grey); cursor: not-allowed; }

.chat-disclaimer {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}
.chat-disclaimer a { color: var(--brand); font-weight: 600; }

/* ═══════════════ MODALE DE CONFIRMATION ═══════════════ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.confirm-overlay.active { display: flex; }

.confirm-box {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 24px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  text-align: center;
}
.confirm-box p {
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 20px;
  line-height: 1.5;
}
.confirm-actions {
  display: flex;
  gap: 10px;
}
.btn-ghost, .btn-danger {
  flex: 1;
  padding: 11px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  font-family: var(--font-body);
}
.btn-ghost {
  background: var(--input-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* Menu contextuel (mobile : appui long sur un message) */
.msg-context-menu {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  z-index: 190;
  display: none;
  overflow: hidden;
}
.msg-context-menu.active { display: block; }
.msg-context-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: none;
  border: none;
  color: #dc2626;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font-body);
}
.msg-context-menu button:hover { background: rgba(220, 38, 38, 0.08); }

.msg-context-backdrop {
  position: fixed;
  inset: 0;
  z-index: 185;
  display: none;
}
.msg-context-backdrop.active { display: block; }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 600px) {
  .chat-suggestions       { grid-template-columns: 1fr; }
  .chat-msg-bubble        { max-width: 85%; }
  .chat-intro h1          { font-size: 1.15rem; }
  /* Le statut En ligne/Hors ligne reste TOUJOURS visible : sur un
     site web, savoir si on est connecté est important. Le nom de
     la marque se tronque proprement avec des points de suspension
     (text-overflow: ellipsis, voir .chat-brand-text .name) plutôt
     que de déborder ou de pousser le statut hors de vue. */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}

.chat-window::-webkit-scrollbar { width: 6px; }
.chat-window::-webkit-scrollbar-track { background: transparent; }
.chat-window::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
