/* =========================================================================
   portfolio-chat — widget de chat IA
   Depend de css/style.css pour les variables de theme.
   ========================================================================= */

/* ---------- Bouton flottant ---------- */

.chat-fab {
  position: fixed;
  /* Decalage vertical obligatoire : .back-to-top (premium.css) occupe
     bottom: 2rem / right: 2rem. Sans ce decalage, les 2 se chevauchent. */
  bottom: 6.5rem;
  right: 2rem;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9000;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
  padding: 0;
}

.chat-fab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.chat-fab[hidden] {
  display: none;
}

/* ---------- Robot Animé Interactif ---------- */

.chat-robot {
  position: relative;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
}

/* Ombre dynamique de lévitation au sol */
.chat-robot__shadow {
  position: absolute;
  bottom: -6px;
  width: 44px;
  height: 9px;
  background: radial-gradient(ellipse at center, rgba(34, 211, 238, 0.35) 0%, rgba(0, 0, 0, 0.45) 45%, transparent 75%);
  border-radius: 50%;
  animation: robotShadow 3.5s ease-in-out infinite;
  pointer-events: none;
}

/* Corps / Figurine flottante */
.chat-robot__figure {
  position: relative;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: robotFloat 3.5s ease-in-out infinite;
  transform-origin: center bottom;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.45));
  transition: transform 0.25s ease;
}

.chat-fab:hover .chat-robot__figure {
  animation-duration: 2s;
  transform: translateY(-4px) scale(1.08);
}

/* Antenne cybernétique */
.chat-robot__antenna {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 4;
}

.chat-robot__antenna-light {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #22d3ee;
  box-shadow: 0 0 10px #22d3ee, 0 0 18px #06b6d4;
  animation: antennaPulse 2s ease-in-out infinite;
}

.chat-robot__antenna-rod {
  width: 2.5px;
  height: 8px;
  background: linear-gradient(to bottom, #67e8f9, #0891b2);
  border-radius: 1px;
}

/* Oreilles mécaniques / Casque */
.chat-robot__ear {
  position: absolute;
  top: 50%;
  width: 7px;
  height: 16px;
  background: linear-gradient(135deg, #0e7490, #155e75);
  border: 1.5px solid #22d3ee;
  border-radius: 4px;
  transform: translateY(-50%);
  z-index: 1;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.35);
}

.chat-robot__ear--left {
  left: -3px;
}

.chat-robot__ear--right {
  right: -3px;
}

/* Tête & Visière cybernétique */
.chat-robot__head {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #1e293b 0%, #0a0e17 100%);
  border: 2px solid #22d3ee;
  box-shadow: 
    0 0 0 2px rgba(34, 211, 238, 0.2),
    0 0 18px rgba(34, 211, 238, 0.45),
    inset 0 0 12px rgba(34, 211, 238, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 2;
}

.chat-robot__visor {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #030712;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
}

/* 2 Yeux robotiques numériques LED */
.chat-robot__eyes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.chat-robot__eye {
  width: 9px;
  height: 15px;
  border-radius: 5px;
  background: linear-gradient(180deg, #e0f2fe 0%, #38bdf8 45%, #0284c7 100%);
  box-shadow: 
    0 0 8px #38bdf8,
    0 0 16px rgba(56, 189, 248, 0.8),
    inset 0 1px 2px #ffffff;
  animation: robotEyeBlink 3.8s ease-in-out infinite;
  transform-origin: center center;
  transition: border-radius 0.25s ease, height 0.25s ease, transform 0.25s ease, background 0.25s ease;
}

/* Expression joyeuse au survol (^ ^) */
.chat-fab:hover .chat-robot__eye {
  height: 10px;
  border-radius: 10px 10px 2px 2px;
  transform: translateY(-2px) scale(1.15);
  background: linear-gradient(180deg, #ffffff 0%, #67e8f9 50%, #06b6d4 100%);
  box-shadow: 
    0 0 12px #67e8f9,
    0 0 24px rgba(34, 211, 238, 0.9);
}

.chat-robot__scanline {
  position: absolute;
  top: -100%;
  left: 0;
  right: 0;
  height: 14px;
  background: linear-gradient(to bottom, transparent, rgba(34, 211, 238, 0.75), transparent);
  animation: visorScan 4s ease-in-out infinite;
  pointer-events: none;
  z-index: 3;
}

/* Bras robotique qui salue */
.chat-robot__arm {
  position: absolute;
  top: 12px;
  right: -16px;
  width: 28px;
  height: 34px;
  z-index: 5;
  transform-origin: 8px 8px;
  animation: robotWave 3.5s ease-in-out infinite;
  pointer-events: none;
}

.chat-fab:hover .chat-robot__arm {
  animation: robotWaveFast 0.8s ease-in-out infinite;
}

.chat-robot__arm-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

/* Propulseur sous le robot */
.chat-robot__thruster {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 7px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, #67e8f9 0%, #0891b2 50%, transparent 80%);
  filter: blur(2px);
  opacity: 0.85;
  animation: thrusterPulse 1.8s ease-in-out infinite alternate;
  pointer-events: none;
}

/* Bulle d'accroche interactive */
.chat-robot__bubble {
  position: absolute;
  bottom: calc(100% + 14px);
  right: 0;
  white-space: nowrap;
  background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%);
  color: var(--text);
  border: 1.5px solid var(--accent);
  padding: 0.45rem 0.85rem;
  border-radius: 14px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 
    0 8px 24px rgba(0, 0, 0, 0.35),
    0 0 14px var(--accent-glow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: auto;
  cursor: pointer;
  z-index: 9005;
  animation: bubbleFloat 3.5s ease-in-out infinite;
  transition: opacity 0.3s ease, transform 0.3s ease;
  user-select: none;
}

.chat-robot__bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 22px;
  width: 10px;
  height: 10px;
  background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%);
  border-right: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: rotate(45deg);
}

.chat-robot__bubble:hover {
  background: var(--surface-2);
  border-color: #67e8f9;
  transform: translateY(-2px);
}

.chat-robot__bubble.is-dismissed,
.chat-fab.is-open .chat-robot__bubble {
  opacity: 0;
  transform: translateY(6px) scale(0.9);
  pointer-events: none;
}

/* Icone de fermeture quand ouvert */
.chat-fab__close-icon {
  width: 50px;
  height: 50px;
  position: absolute;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 
    0 8px 24px rgba(0, 0, 0, 0.4),
    0 0 16px var(--accent-glow-strong);
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, background var(--transition), border-color var(--transition);
  pointer-events: none;
}

.chat-fab__close-icon svg {
  width: 22px;
  height: 22px;
}

.chat-fab.is-open .chat-robot {
  opacity: 0;
  transform: scale(0.3) rotate(-30deg);
  pointer-events: none;
}

.chat-fab.is-open .chat-fab__close-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  pointer-events: auto;
}

.chat-fab.is-open .chat-fab__close-icon:hover {
  background: var(--surface-2);
  border-color: #67e8f9;
  transform: rotate(90deg) scale(1.08);
}

/* ---------- Keyframes Animations Robot ---------- */

@keyframes robotFloat {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  25% {
    transform: translateY(-5px) rotate(1.5deg);
  }
  50% {
    transform: translateY(-9px) rotate(0deg);
  }
  75% {
    transform: translateY(-4px) rotate(-1.5deg);
  }
}

@keyframes robotShadow {
  0%, 100% {
    transform: scale(1);
    opacity: 0.45;
  }
  50% {
    transform: scale(0.65);
    opacity: 0.2;
  }
}

@keyframes robotWave {
  0%, 100% {
    transform: rotate(0deg);
  }
  15% {
    transform: rotate(-24deg);
  }
  30% {
    transform: rotate(12deg);
  }
  45% {
    transform: rotate(-20deg);
  }
  60% {
    transform: rotate(10deg);
  }
  75% {
    transform: rotate(-10deg);
  }
  90% {
    transform: rotate(0deg);
  }
}

@keyframes robotWaveFast {
  0%, 100% {
    transform: rotate(-6deg);
  }
  50% {
    transform: rotate(-28deg);
  }
}

@keyframes antennaPulse {
  0%, 100% {
    background-color: #22d3ee;
    box-shadow: 0 0 8px #22d3ee, 0 0 16px #06b6d4;
  }
  50% {
    background-color: #a5f3fc;
    box-shadow: 0 0 14px #67e8f9, 0 0 24px #22d3ee;
  }
}

@keyframes visorScan {
  0% {
    top: -100%;
    opacity: 0;
  }
  30% {
    opacity: 0.8;
  }
  60% {
    opacity: 0.8;
  }
  100% {
    top: 200%;
    opacity: 0;
  }
}

@keyframes thrusterPulse {
  0% {
    opacity: 0.6;
    transform: translateX(-50%) scaleX(0.85);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) scaleX(1.15);
  }
}

@keyframes bubbleFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@keyframes robotEyeBlink {
  0%, 86%, 92%, 100% {
    transform: scaleY(1);
    opacity: 1;
  }
  88%, 90% {
    transform: scaleY(0.08);
    opacity: 0.8;
  }
}

/* Pastille "nouveau message" / indisponible */
.chat-fab__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--bg);
  z-index: 1;
}

.chat-fab__badge[hidden] {
  display: none;
}

/* ---------- Region live pour lecteurs d'ecran ---------- */

.chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- Panneau ---------- */

.chat-panel {
  position: fixed;
  bottom: 6.5rem;
  right: 2rem;
  width: min(440px, calc(100vw - 2rem));
  height: min(640px, calc(100vh - 10rem));
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow:
    0 32px 80px rgba(0, 0, 0, 0.55),
    0 0 0 1px var(--accent-glow);
  z-index: 9001;
  overflow: hidden;
  transform-origin: bottom right;
  animation: chatPanelIn 0.24s cubic-bezier(0.34, 1.3, 0.64, 1);
}

/* ---------- Vitrine : bordure degradee + barre de tete ---------- */

.chat-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(
    from 0deg,
    var(--accent) 0deg,
    var(--accent-strong) 110deg,
    #a855f7 190deg,
    var(--accent) 270deg,
    var(--accent) 360deg
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask-composite: exclude;
  pointer-events: none;
  z-index: 4;
}

.chat-panel::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--accent) 30%,
    #a855f7 60%,
    transparent
  );
  pointer-events: none;
  z-index: 5;
}

.chat-panel[hidden] {
  display: none;
}

@keyframes chatPanelIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- En-tete ---------- */

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  flex-shrink: 0;
}

.chat-header__avatar {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, var(--surface-2) 0%, #0a0e1a 100%);
  border: 2px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow:
    0 0 0 2px var(--accent-glow),
    0 0 16px var(--accent-glow-strong);
  overflow: visible;
}

.chat-header__avatar-img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

.chat-header__dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  border: 2px solid var(--surface-2);
  transition: background var(--transition);
  z-index: 2;
}

.chat-header__dot.is-online {
  background: var(--success);
}

.chat-header__dot.is-offline {
  background: var(--danger);
}

.chat-header__text {
  flex: 1;
  min-width: 0;
}

.chat-header__title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__status {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin: 0.1rem 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}

.chat-header__btn:hover {
  background: var(--surface);
  color: var(--accent);
}

.chat-header__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chat-header__btn svg {
  width: 17px;
  height: 17px;
}

/* ---------- Liste de messages ---------- */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.chat-msg {
  max-width: 86%;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  font-size: 0.885rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.chat-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #04121a;
  border-bottom-right-radius: 4px;
  box-shadow: 0 6px 18px var(--accent-glow-strong);
}

.chat-msg--bot {
  position: relative;
  align-self: flex-start;
  margin-inline-start: 34px;
  max-width: calc(86% - 34px);
  background: color-mix(in srgb, var(--surface-2) 92%, var(--accent) 8%);
  border: 1px solid var(--border);
  border-inline-start: 2px solid var(--accent);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-msg--bot::before {
  content: "";
  position: absolute;
  inset-inline-start: -34px;
  top: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: var(--surface-2);
  background-image: url("../assets/img/sif_avatar_sansbackgroud.png");
  background-size: cover;
  background-position: top center;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.chat-msg--error {
  align-self: flex-start;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: var(--text);
}

.chat-msg a {
  color: var(--accent);
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.chat-msg strong {
  font-weight: 700;
}

.chat-msg ul {
  margin: 0.35rem 0;
  padding-inline-start: 1.1rem;
}

.chat-msg--user strong,
.chat-msg--user a {
  color: #04121a;
}

/* ---------- Indicateur d'ecriture ---------- */

.chat-typing {
  position: relative;
  align-self: flex-start;
  margin: 0.35rem 1rem;
  margin-inline-start: calc(1rem + 34px);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.8rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.chat-typing::before {
  content: "";
  position: absolute;
  inset-inline-start: -34px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: var(--surface-2);
  background-image: url("../assets/img/sif_avatar_sansbackgroud.png");
  background-size: cover;
  background-position: top center;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chatTyping 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chatTyping {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.chat-typing[hidden] {
  display: none;
}

/* ---------- Bandeau de quota ---------- */

/* Deux usages : etat informatif (questions restantes) et blocage (compte a
   rebours, message d'erreur). La couleur porte le sens, pas seulement la
   decoration, pour rester lisible sans dependre de la teinte. */

.chat-notice {
  flex-shrink: 0;
  padding: 0.5rem 1rem;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--surface-2) 80%, var(--accent) 4%);
  border-top: 1px solid var(--border);
  border-inline-start: 2px solid var(--accent);
  font-variant-numeric: tabular-nums;
}

.chat-notice[hidden] {
  display: none;
}

.chat-notice.is-warn {
  color: var(--text);
  border-inline-start-color: var(--accent-strong);
  background: color-mix(in srgb, var(--surface-2) 80%, var(--accent) 12%);
}

.chat-notice.is-error {
  color: var(--text);
  border-inline-start-color: var(--danger);
  background: color-mix(in srgb, var(--surface-2) 88%, var(--danger) 12%);
}

/* Bouton envoyer bloque : on garde la forme, on retire l'apparence active. */

.chat-send.is-blocked {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: not-allowed;
  opacity: 0.6;
}

/* ---------- Suggestions ---------- */

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.7rem;
  flex-shrink: 0;
}

.chat-suggestions[hidden] {
  display: none;
}

.chat-chip {
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition),
    background var(--transition);
}

.chat-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Mention IA ---------- */

.chat-disclaimer {
  margin: 0;
  padding: 0.35rem 1rem;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--text-muted);
  text-align: center;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---------- Repli quand l'IA est indisponible ---------- */

.chat-fallback {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.chat-fallback[hidden] {
  display: none;
}

.chat-fallback p {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.chat-fallback__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chat-fallback__link {
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  font-size: 0.79rem;
  text-decoration: none;
  transition: border-color var(--transition), background var(--transition);
}

.chat-fallback__link:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.chat-fallback__link--primary {
  background: var(--accent);
  color: #04121a;
  border-color: var(--accent);
  font-weight: 600;
}

/* ---------- Zone de saisie ---------- */

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.45;
  resize: none;
  max-height: 96px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.chat-send {
  width: 40px;
  height: 40px;
  align-self: flex-end;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #04121a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity var(--transition), transform var(--transition);
}

.chat-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-send svg {
  width: 18px;
  height: 18px;
}

/* ---------- Bouton "arreter" pendant le streaming ---------- */

.chat-send.is-streaming svg {
  display: none;
}

.chat-send.is-streaming::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 2px;
  animation: chatSpin 0.7s linear infinite;
}

@keyframes chatSpin {
  to {
    transform: rotate(360deg);
  }
}

/* =========================================================================
   RTL
   ========================================================================= */

[dir="rtl"] .chat-panel {
  transform-origin: bottom left;
}

[dir="rtl"] .chat-msg {
  border-radius: 14px;
}

[dir="rtl"] .chat-msg--user {
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 14px;
}

[dir="rtl"] .chat-msg--bot {
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 14px;
}

[dir="rtl"] .chat-typing {
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .chat-msg ul {
  padding-inline-start: 1.1rem;
}

[dir="rtl"] .chat-fab,
[dir="rtl"] .chat-panel {
  right: auto;
  left: 2rem;
}

[dir="rtl"] .chat-fab__badge {
  right: auto;
  left: -2px;
}

[dir="rtl"] .chat-robot__arm {
  right: auto;
  left: -16px;
  transform: scaleX(-1);
  transform-origin: 8px 8px;
}

[dir="rtl"] .chat-robot__bubble {
  right: auto;
  left: 0;
}

[dir="rtl"] .chat-robot__bubble::after {
  right: auto;
  left: 22px;
  border-right: none;
  border-left: 1.5px solid var(--accent);
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (pointer: coarse) {
  .chat-fab,
  .chat-panel {
    bottom: 5.5rem;
    right: 1rem;
  }
  [dir="rtl"] .chat-fab,
  [dir="rtl"] .chat-panel {
    left: 1rem;
  }
}

@media (max-width: 520px) {
  .chat-fab {
    width: 56px;
    height: 56px;
    bottom: 5.25rem;
    right: 1rem;
  }
  .chat-robot {
    width: 52px;
    height: 52px;
  }
  .chat-robot__figure {
    width: 48px;
    height: 48px;
  }
  .chat-robot__head {
    width: 48px;
    height: 48px;
  }
  .chat-robot__visor {
    width: 38px;
    height: 38px;
  }
  .chat-robot__eyes {
    gap: 6px;
  }
  .chat-robot__eye {
    width: 8px;
    height: 13px;
  }
  .chat-robot__arm {
    top: 10px;
    right: -13px;
    width: 24px;
    height: 30px;
  }
  .chat-robot__bubble {
    font-size: 0.76rem;
    padding: 0.35rem 0.65rem;
    bottom: calc(100% + 10px);
  }
  .chat-fab__close-icon {
    width: 46px;
    height: 46px;
  }
  .chat-panel {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    bottom: 0.5rem;
    height: min(78vh, 560px);
  }
  [dir="rtl"] .chat-fab {
    left: 1rem;
  }
  [dir="rtl"] .chat-robot__arm {
    left: -13px;
    right: auto;
  }
  .chat-msg {
    max-width: 92%;
  }
  .chat-msg--bot {
    margin-inline-start: 30px;
    max-width: calc(92% - 30px);
  }
  .chat-msg--bot::before {
    inset-inline-start: -30px;
    width: 24px;
    height: 24px;
  }
  .chat-typing {
    margin-inline-start: calc(1rem + 30px);
  }
  .chat-typing::before {
    inset-inline-start: -30px;
    width: 24px;
    height: 24px;
  }
}

/* Sur petit ecran, le back-to-top est masque quand le chat est ouvert */
@media (max-width: 520px) {
  .chat-open ~ .back-to-top {
    opacity: 0;
    visibility: hidden;
  }
}

/* =========================================================================
   Theme clair
   L'ombre 0.55 et l'opacite du halo sont calibres pour le fond sombre.
   ========================================================================= */

[data-theme="light"] .chat-panel {
  box-shadow:
    0 24px 64px rgba(15, 23, 42, 0.18),
    0 0 0 1px var(--accent-glow-strong);
}

[data-theme="light"] .chat-fab::after {
  border-color: var(--accent-strong);
  animation-duration: 3.4s;
}

[data-theme="light"] .chat-fab {
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

/* =========================================================================
   Preferences de mouvement reduit
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  .chat-panel {
    animation: none;
  }
  .chat-fab::after {
    animation: none;
    opacity: 0.3;
    transform: scale(1.1);
  }
  .chat-robot__figure,
  .chat-robot__shadow,
  .chat-robot__arm,
  .chat-robot__antenna-light,
  .chat-robot__eye,
  .chat-robot__scanline,
  .chat-robot__thruster,
  .chat-robot__bubble {
    animation: none !important;
  }
  .chat-typing span {
    animation: none;
    opacity: 0.7;
  }
  .chat-send.is-streaming::before {
    animation: none;
  }
  .chat-fab {
    transition: none;
  }
}

/* =========================================================================
   Impression
   ========================================================================= */

/* ---------- Faux message système (hors widget) ---------- */

.chat-messages--static {
  overflow: visible;
  max-height: none;
  padding: 0;
}

.chat-msg--system {
  align-self: flex-start;
  max-width: min(820px, 92%);
  background: color-mix(in srgb, var(--surface-2) 92%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  border-inline-start: 2px solid var(--text-muted);
  box-shadow: none;
  padding: 0.85rem 1rem 1rem;
}

.chat-msg__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.chat-msg__avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 70%, var(--text-muted) 30%);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.chat-msg__label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
}

.chat-msg__content {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: var(--text);
  max-height: min(320px, 60vh);
  overflow-y: auto;
  padding-right: 0.25rem;
  scrollbar-width: thin;
}

[dir="rtl"] .chat-msg--system {
  border-inline-start: none;
  border-inline-end: 2px solid var(--text-muted);
}

[dir="rtl"] .chat-msg__content {
  padding-right: 0;
  padding-left: 0.25rem;
}

@media print {
  .chat-fab,
  .chat-panel {
    display: none !important;
  }
}
