/* ==========================================================================
   SYSTÈME DE DESIGN DE L'ÉTAT (DSFR) - Widget de Chat
   Inspiré du style info.gouv.fr - Interface épurée et moderne
   ========================================================================== */

/* ==========================================================================
   1. POLICES MARIANNE - Import depuis CDN officiel
   ========================================================================== */

@import url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Light.woff2");
@import url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Regular.woff2");
@import url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Medium.woff2");
@import url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Bold.woff2");

/* Déclarations @font-face pour la police Marianne */

@font-face {
  font-family: "Marianne";
  font-weight: 300;
  font-style: normal;
  src: url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Light.woff2")
    format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Marianne";
  font-weight: 400;
  font-style: normal;
  src: url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Regular.woff2")
    format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Marianne";
  font-weight: 500;
  font-style: normal;
  src: url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Medium.woff2")
    format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Marianne";
  font-weight: 700;
  font-style: normal;
  src: url("https: //cdn.jsdelivr.net/npm/@gouvfr/dsfr@1.11/dist/fonts/Marianne-Bold.woff2")
    format("woff2");
  font-display: swap;
}

/* ==========================================================================
         2. VARIABLES CSS - Palette de couleurs et tokens de design
         ========================================================================== */

:root {
  /* --- Couleurs primaires de l'État --- */
  --blue-france-975: #000091;
  --blue-france-950: #1212ff;
  --blue-france-925: #2323ff;
  --blue-france-main-525: #6a6af4;
  --blue-france-main: #000091;
  --blue-france-sun-113: #e3e3fd;
  /* --- Couleurs d'accent --- */
  --red-marianne-425: #c9191e;
  --red-marianne-main: #c9191e;
  --red-marianne-975: #ffe9e9;
  /* --- Couleurs neutres (échelle de gris) --- */
  --grey-1000: #ffffff;
  --grey-975: #f6f6f6;
  --grey-950: #eeeeee;
  --grey-925: #e5e5e5;
  --grey-900: #dddddd;
  --grey-850: #cccccc;
  --grey-800: #bbbbbb;
  --grey-700: #929292;
  --grey-625: #666666;
  --grey-425: #3a3a3a;
  --grey-200: #1e1e1e;
  --grey-50: #161616;
  /* --- Couleurs système et feedback --- */
  --green-tilleul-verveine-950: #fcf8e3;
  --green-tilleul-verveine-main: #b7a73f;
  --green-emeraude-975: #c3fad5;
  --green-emeraude-main: #00a95f;
  --orange-terre-battue-950: #feebd0;
  --orange-terre-battue-main: #e4794a;
  --blue-cumulus-950: #e6f6ff;
  --blue-cumulus-main: #417dc4;
  --info-main-525: #0078f3;
  /* --- Couleurs personnalisées pour composants --- */
  --button-ter-hover: #eeeeee;
  --colors-hover: #ececfe;
  --tooltip-bg: #ffffff;
  --tooltip-color: #3a3a3a;
  --tooltip-shadow: #e5e7eb;
  --source-color: #3a3a3a;
  /* --- Espacements (basés sur le système 4px) --- */
  --spacing-1x: 0.25rem;
  /* 4px */
  --spacing-2x: 0.5rem;
  /* 8px */
  --spacing-3x: 0.75rem;
  /* 12px */
  --spacing-4x: 1rem;
  /* 16px */
  --spacing-5x: 1.25rem;
  /* 20px */
  --spacing-6x: 1.5rem;
  /* 24px */
  --spacing-8x: 2rem;
  /* 32px */
  --spacing-10x: 2.5rem;
  /* 40px */
  --spacing-12x: 3rem;
  /* 48px */
  /* --- Typographie --- */
  --font-family: "Marianne", arial, sans-serif;
  --font-size-xs: 0.75rem;
  /* 12px */
  --font-size-sm: 0.875rem;
  /* 14px */
  --font-size-md: 1rem;
  /* 16px */
  --font-size-lg: 1.125rem;
  /* 18px */
  --font-size-xl: 1.375rem;
  /* 22px */
  --line-height-sm: 1.25rem;
  /* 20px */
  --line-height-md: 1.5rem;
  /* 24px */
  --line-height-lg: 1.75rem;
  /* 28px */
  /* --- Rayons de bordure --- */
  --border-radius-sm: 0.25rem;
  --border-radius-md: 0.5rem;
}

/* --- Mode sombre - Adaptation des couleurs --- */

html[data-color-mode="dark"] {
  --blue-france-sun-113: #8585f6;
  --blue-france-main: #8585f6;
  --colors-hover: #8585f6;
  --button-ter-hover: #343434;
  --tooltip-bg: #343434;
  --tooltip-color: #cecece;
  --tooltip-shadow: #353535;
  --source-color: #cecece;
}

/* ==========================================================================
         3. STYLES DE BASE - Reset et configuration globale
         ========================================================================== */

body,
html {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  line-height: var(--line-height-md);
  color: var(--grey-50);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Reset du border-radius des boutons par défaut */

button {
  border-radius: 0;
}

/* ==========================================================================
         4. CONTAINER PRINCIPAL DU CHAT
         ========================================================================== */

div#core-widget {
  border-radius: 0;
}

.chat-widget,
.chat-container,
#chat-container {
  background-color: var(--grey-1000);
  border: none;
  border-radius: 0;
  font-family: var(--font-family);
  color: var(--grey-50);
  box-shadow: none;
  max-width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
         5. EN-TÊTE DU CHAT (HEADER)
         ========================================================================== */

.chat-header,
.header {
  background-color: var(--grey-1000);
  color: var(--grey-50);
  padding: var(--spacing-8x) var(--spacing-6x) var(--spacing-6x);
  border-bottom: 1px solid var(--grey-925);
  font-weight: 500;
}

/* Titre principal du chat */

.chat-title,
.title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--grey-50);
  margin: 0;
  line-height: 1.3;
}

/* Nom de l'assistant dans le header */

h1#genii-header-name {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--blue-france-main);
  margin: 0;
  padding: var(--spacing-2x) 0;
  line-height: 1.3;
}

h2#genii-header-name {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--blue-france-main);
  margin: 0;
  padding: var(--spacing-2x) 0;
  line-height: 1.3;
}

/* Sous-titre */

.chat-subtitle,
.subtitle {
  font-size: var(--font-size-sm);
  font-weight: 400;
  color: var(--grey-625);
  margin-top: var(--spacing-2x);
}

/* Texte de confidentialité / disclaimer */

p#genii-policy-privacy__label {
  font-size: 12px;
  line-height: normal;
  font-weight: normal;
}

/* Boutons du header */

header#genii-header button:hover {
  background-color: #00000033;
  border: none;
}

/* Désactivation de l'effet de scale au survol */

.hover\:trf_scale\(1\.2\):is(:hover, [data-hover]) {
  transform: none;
}

/* ==========================================================================
         6. ZONE DES MESSAGES
         ========================================================================== */

.messages-container,
.chat-messages,
.messages {
  padding: var(--spacing-6x) var(--spacing-6x);
  overflow-y: auto;
  flex: 1;
  background-color: var(--grey-1000);
}

/* --- Styles des messages individuels --- */

.message,
.chat-message {
  margin-bottom: var(--spacing-6x);
  padding: var(--spacing-4x) var(--spacing-5x);
  border-radius: 0;
  max-width: 85%;
  word-wrap: break-word;
  line-height: var(--line-height-lg);
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  font-size: var(--font-size-md);
}

/* Taille de police pour le contenu des messages Genii */

div.genii-message p {
  font-size: 14px;
}

/* Nom de l'utilisateur dans les messages */

html[data-color-mode="light"] h2.genii-message__name--user {
  color: var(--grey-425);
}

html[data-color-mode="dark"] h2.genii-message__name--user {
  color: #cecece;
}

html[data-color-mode="light"] h3.genii-message__name--user {
  color: var(--grey-425);
}

html[data-color-mode="dark"] h3.genii-message__name--user {
  color: #cecece;
}

/* Nom du bot dans les messages */

h2.genii-message__name--bot {
  color: var(--blue-france-main) !important;
}

h3.genii-message__name--bot {
  color: var(--blue-france-main) !important;
}

/* Lien powered by Genii */

a#genii-powered-by-link {
  color: var(--blue-france-main) !important;
}

/* --- Message utilisateur --- */

.message.user,
.user-message,
.message-user {
  background-color: var(--blue-france-sun-113);
  color: var(--grey-50);
  margin-left: auto;
  border-left: 3px solid var(--blue-france-main);
}

/* --- Message assistant/bot --- */

.message.assistant,
.message.bot,
.bot-message,
.assistant-message {
  background-color: var(--grey-975);
  color: var(--grey-50);
  margin-right: auto;
  border-left: 3px solid var(--grey-900);
}

/* --- Message système --- */

.message.system,
.system-message {
  background-color: var(--blue-cumulus-950);
  color: var(--grey-50);
  font-size: var(--font-size-sm);
  text-align: center;
  margin: var(--spacing-4x) auto;
  max-width: 70%;
  border: 1px solid var(--blue-cumulus-main);
  border-left: 3px solid var(--blue-cumulus-main);
}

/* --- Message d'erreur --- */

.message.error,
.error-message {
  background-color: var(--red-marianne-975);
  color: var(--red-marianne-425);
  border-left: 3px solid var(--red-marianne-425);
}

/* --- Contenu des messages (typographie) --- */

.message p {
  margin: 0 0 var(--spacing-3x) 0;
}

.message p:last-child {
  margin-bottom: 0;
}

.message strong {
  font-weight: 700;
}

.message code {
  background-color: rgba(0, 0, 0, 0.05);
  padding: 0.125rem 0.375rem;
  border-radius: 0;
  font-family: "Courier New", monospace;
  font-size: 0.9em;
}

/* ==========================================================================
         7. INDICATEUR DE FRAPPE (TYPING INDICATOR)
         ========================================================================== */

.typing-indicator,
.is-typing {
  background-color: var(--grey-975);
  color: var(--grey-625);
  font-style: italic;
  font-size: var(--font-size-sm);
  padding: var(--spacing-3x) var(--spacing-5x);
  border-radius: var(--border-radius-md);
  margin-right: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-2x);
  border-left: 3px solid var(--grey-900);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.typing-indicator::after {
  content: "...";
  animation: dots 1.5s infinite;
}

@keyframes dots {
  0%,
  20% {
    content: ".";
  }
  40% {
    content: "..";
  }
  60%,
  100% {
    content: "...";
  }
}

/* ==========================================================================
         8. AVATARS
         ========================================================================== */

.avatar,
.user-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--blue-france-main) 0%,
    var(--blue-france-main-525) 100%
  );
  color: var(--grey-1000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 145, 0.2);
}

.bot-avatar {
  background: linear-gradient(135deg, var(--grey-700) 0%, var(--grey-625) 100%);
}

/* ==========================================================================
         9. ZONE DE SAISIE (INPUT)
         ========================================================================== */

.input-container,
.chat-input-container {
  padding: var(--spacing-5x) var(--spacing-6x);
  border-top: 1px solid var(--grey-925);
  background-color: var(--grey-1000);
  display: flex;
  gap: var(--spacing-3x);
  align-items: flex-end;
}

/* --- Champ de saisie --- */

.message-input,
.chat-input,
input[type="text"],
textarea {
  flex: 1;
  padding: var(--spacing-3x) var(--spacing-4x);
  border: none;
  border-radius: 0.25rem 0 0 0;
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  background-color: var(--grey-950);
  color: var(--grey-50);
  resize: none;
  transition: all 0.2s ease;
  line-height: var(--line-height-md);
  min-height: 2.5rem;
  margin-right: 0;
  box-shadow: inset 0 -2px 0 0 var(--grey-625);
}

.message-input::placeholder,
.chat-input::placeholder,
input[type="text"]::placeholder,
textarea::placeholder {
  color: var(--grey-625);
}

.message-input:focus,
.chat-input:focus,
input[type="text"]:focus,
textarea:focus {
  outline: 2px solid var(--grey-425);
  border-bottom-color: var(--grey-425);
  box-shadow: inset 0 -2px 0 0 var(--grey-425);
}

/* ==========================================================================
         10. BOUTONS
         ========================================================================== */

/* --- Bouton principal (envoi) --- */

.send-button,
.chat-send-button,
button[type="submit"],
.btn {
  background-color: var(--blue-france-main);
  color: var(--grey-1000);
  border: none;
  border-radius: 0;
  padding: var(--spacing-4x) var(--spacing-8x);
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: auto;
  height: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px var(--grey-425);
}

.send-button:hover:not(:disabled),
.chat-send-button:hover:not(:disabled),
button[type="submit"]:hover:not(:disabled),
.btn:hover:not(:disabled) {
  background-color: var(--blue-france-main-525);
  box-shadow: 0 4px 8px rgba(0, 0, 145, 0.2);
  transform: translateY(-1px);
}

.send-button:active:not(:disabled),
.chat-send-button:active:not(:disabled),
button[type="submit"]:active:not(:disabled),
.btn:active:not(:disabled) {
  background-color: var(--blue-france-975);
  transform: translateY(0);
}

.send-button:disabled,
.chat-send-button:disabled,
button[type="submit"]:disabled,
.btn:disabled {
  background-color: var(--grey-950) !important;
  box-shadow: inset 0 -2px 0 0 var(--grey-625);
  cursor: not-allowed;
}

button[type="submit"]:disabled svg {
  stroke: var(--grey-50);
}

/* --- Bouton secondaire --- */

.btn-secondary {
  background-color: var(--grey-1000);
  color: var(--blue-france-main);
  border: 2px solid var(--blue-france-main);
  box-shadow: none;
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--blue-france-sun-113);
  border-color: var(--blue-france-main);
}

/* --- Boutons dans la section messages --- */

section#genii-messages button {
  border: 1px solid #475569;
  background-color: transparent;
  box-shadow: none;
  color: var(--blue-france-main);
}

section#genii-messages button:not(:disabled):hover {
  background-color: var(--button-ter-hover);
}

/* --- Bouton des sources --- */

section#genii-messages button.genii-sources-button {
  border-left: 0;
  border-right: 0;
}

section#genii-messages button.genii-sources-button:not(:disabled):hover {
  background: none;
}

section#genii-messages button.genii-sources-button span svg {
  stroke: var(--blue-france-main);
}

/* --- Groupe d'actions --- */

.action-buttons {
  display: flex;
  gap: var(--spacing-3x);
  margin-top: var(--spacing-4x);
}

/* ==========================================================================
         11. SOURCES ET RÉFÉRENCES
         ========================================================================== */

div.genii-sources-container div.genii-source {
  border-radius: 0px;
  border: 1px solid var(--info-main-525);
  background: transparent;
  padding: 0;
}

div.genii-sources-container div.genii-source span:first-child {
  background-color: var(--info-main-525);
}

div.genii-sources-container div.genii-source span {
  color: var(--source-color);
  padding: 6px;
}

div.genii-sources-container div.genii-source span svg {
  stroke: white;
}

/* ==========================================================================
         12. TOOLTIPS
         ========================================================================== */

.bg_tooltip {
  background-color: var(--tooltip-bg);
  color: var(--tooltip-color);
  box-shadow: 0px 2.5px 5px 0px var(--tooltip-shadow);
  border-radius: 0px !important;
  border: 1px solid var(--tooltip-shadow);
}

/* ==========================================================================
         13. ÉLÉMENTS DIVERS
         ========================================================================== */

/* --- Horodatage --- */

.timestamp {
  font-size: var(--font-size-xs);
  color: var(--grey-700);
  margin-top: var(--spacing-2x);
  font-weight: 400;
}

/* --- Badge ou étiquette --- */

.badge {
  display: inline-block;
  padding: var(--spacing-1x) var(--spacing-3x);
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
  font-weight: 500;
  background-color: var(--blue-france-sun-113);
  color: var(--blue-france-main);
}

/* --- Séparateur visuel --- */

.divider {
  height: 1px;
  background-color: var(--grey-925);
  margin: var(--spacing-6x) 0;
}

/* --- État de chargement --- */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-3x);
  color: var(--grey-625);
  padding: var(--spacing-6x);
}

.spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--grey-925);
  border-top: 3px solid var(--blue-france-main);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
         14. LIENS
         ========================================================================== */

a {
  color: var(--blue-france-main);
  text-decoration: underline;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--blue-france-main-525);
}

a:focus {
  outline: 2px solid var(--blue-france-main);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ==========================================================================
         15. SCROLLBAR PERSONNALISÉE
         ========================================================================== */

::-webkit-scrollbar {
  width: 0.5rem;
}

::-webkit-scrollbar-track {
  background-color: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: var(--grey-900);
  border-radius: 0.25rem;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--grey-800);
}

/* ==========================================================================
         16. ACCESSIBILITÉ
         ========================================================================== */

/* Focus visible renforcé pour navigation au clavier */

*:focus-visible {
  outline: 2px solid var(--blue-france-main);
  outline-offset: 2px;
}

/* Réduction des animations pour les utilisateurs sensibles au mouvement */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
         17. RESPONSIVE DESIGN
         ========================================================================== */

/* --- Tablettes et petits écrans (max-width: 768px) --- */

@media (max-width: 768px) {
  .chat-widget,
  .chat-container {
    border-radius: 0;
    height: 100vh;
  }
  .chat-header,
  .header {
    padding: var(--spacing-4x);
  }
  .messages-container,
  .chat-messages,
  .messages {
    padding: var(--spacing-4x);
  }
  .message,
  .chat-message {
    max-width: 95%;
    margin-bottom: var(--spacing-4x);
  }
  .input-container,
  .chat-input-container {
    padding: var(--spacing-4x);
    flex-direction: column;
    gap: var(--spacing-3x);
  }
  .send-button,
  .chat-send-button {
    width: 100%;
  }
  .chat-title,
  .title {
    font-size: var(--font-size-lg);
  }
}

/* --- Mobiles (max-width: 480px) --- */

@media (max-width: 480px) {
  .messages-container,
  .chat-messages,
  .messages {
    padding: var(--spacing-3x);
  }
  .input-container,
  .chat-input-container {
    padding: var(--spacing-3x);
  }
  .message,
  .chat-message {
    padding: var(--spacing-3x) var(--spacing-4x);
  }
}