/* ---------- Messages ---------- */
.message {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 920px;
  animation: msgIn 0.2s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { justify-content: flex-end; }

/* User : bulle grise arrondie, propre, sans effet */
.message.user .bubble {
  background: var(--user-bg);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 15px;
  max-width: 620px;
  line-height: 1.5;
  font-size: 0.93rem;
  word-wrap: break-word;
}

/* IA : pas de bulle, juste le texte */
.message.ai {
  align-items: flex-start;
}

.message.ai .bubble {
  max-width: 780px;
  line-height: 1.65;
  font-size: 0.95rem;
  word-wrap: break-word;
  padding: 0;
}

.bubble code {
  background: #f0f1f6;
  padding: 2px 6px;
  border-radius: 5px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.85em;
}

.bubble pre {
  background: var(--code-bg);
  color: #e8eaf0;
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 0.85rem;
}

.bubble pre code { background: none; padding: 0; color: inherit; }

/* ---------- Blocs de code stylises ---------- */
.code-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin: 12px 0;
  background: #f6f7f9;
}

.code-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #eceef4;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.code-head .devicon { font-size: 1rem; }
.code-head i.far { color: var(--text-muted); }
.code-head span {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.code-copy {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s, background 0.2s;
}

.code-wrap:hover .code-copy { opacity: 1; }
.code-copy:hover { color: var(--text); background: rgba(0,0,0,0.06); }

.code-wrap pre {
  margin: 0;
  border-radius: 0;
  border: none;
  background: transparent;
  color: #24292f;
}

.code-wrap pre code { color: inherit; }

/* ---------- Rendu markdown propre ---------- */
.message.ai .bubble p { margin: 0 0 8px; }
.message.ai .bubble p:last-child { margin-bottom: 0; }

.md-gap { height: 8px; }

.md-hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}

.md-h {
  font-weight: 700;
  font-size: 1.05em;
  color: var(--text);
  margin: 12px 0 6px;
}
.md-h:first-child { margin-top: 0; }
.md-h strong { color: inherit; }

.message.ai .bubble ul,
.message.ai .bubble ol {
  margin: 4px 0 10px;
  padding-left: 22px;
}
.message.ai .bubble li { margin: 3px 0; }
.message.ai .bubble li strong { color: var(--text); }
.message.ai .bubble li::marker { color: var(--accent); }

.md-table-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  margin: 12px 0;
}

.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88em;
}

.md-table th,
.md-table td {
  padding: 10px 14px;
  text-align: left;
}

.md-table th {
  background: #eef3ff;
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.md-table td { border-top: 1px solid #eef0f6; }
.md-table tr:first-child td { border-top: none; }
.md-table tbody tr:hover td { background: #fafbfd; }

.message.ai .bubble a {
  color: var(--accent);
  text-decoration: none;
}
.message.ai .bubble a:hover { text-decoration: underline; }

.message.ai .bubble strong {
  color: var(--text);
}

.foxy-name {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  vertical-align: -2px;
}

.foxy-name img {
  width: 1.15em;
  height: 1.15em;
  border-radius: 4px;
  object-fit: cover;
}

.file-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.06);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.8rem;
  margin-bottom: 6px;
}

/* ---------- Reasoning ---------- */
.reasoning-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 6px 10px;
  background: #f6f7fb;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  user-select: none;
}

.reasoning-toggle:hover { background: #eef0f6; }
.reasoning-toggle i { color: var(--text-muted); }
.reasoning-toggle .arrow {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 0.65rem;
}
.reasoning-toggle.open .arrow { transform: rotate(90deg); }
.reasoning-toggle .r-time {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-style: normal;
  font-variant-numeric: tabular-nums;
}

.reasoning-body {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-bottom: 0;
  padding: 0 12px;
  background: #f6f7fb;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.83rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  font-style: italic;
  transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.3s ease, margin 0.3s ease;
}

.reasoning-wrap {
  max-width: 560px;
}

.reasoning-body.open {
  max-height: 80px;
  opacity: 1;
  padding: 10px 12px;
  margin-bottom: 12px;
  overflow-y: auto;
}

.reasoning-body.expanded.open {
  max-height: none;
  overflow: visible;
}

.stream-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
}

/* ---------- Typing ---------- */
.typing { display: flex; gap: 4px; padding: 14px 0; }

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.error { color: #d64545; font-size: 0.85rem; }

/* Avatar IA (icone du site, apparait en fin de generation) */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  transition: opacity 0.5s ease;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; }

.ai-body { flex: 1; min-width: 0; }

/* ---------- Case de generation d'image ---------- */
.gen-loading {
  position: relative;
  width: 340px;
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: 18px;
  background: #eef0f5;
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Fond floue progressif pendant la generation */
.gen-blob {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 60% at 35% 40%, rgba(37, 99, 235, 0.16) 0%, transparent 70%),
    radial-gradient(ellipse 60% 55% at 65% 60%, rgba(100, 116, 160, 0.18) 0%, transparent 70%),
    radial-gradient(ellipse 80% 70% at 50% 50%, rgba(28, 35, 51, 0.10) 0%, transparent 75%);
  filter: blur(30px);
  opacity: 0;
  animation: genBlobFade 2.4s ease-out forwards;
}

@keyframes genBlobFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- Images generees ---------- */
.gen-image {
  display: block;
  max-width: 460px;
  max-height: 340px;
  width: auto;
  border-radius: 14px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

/* Revelation : tres flou -> net progressivement */
.gen-image.gen-blur {
  filter: blur(26px) grayscale(1);
  opacity: 0.3;
}

.gen-image.gen-sharp {
  transition: filter 4.5s cubic-bezier(0.3, 0.6, 0.3, 1), opacity 3.5s ease;
  filter: blur(0) grayscale(0);
  opacity: 1;
}

.gen-caption {
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.55;
}

/* ---------- Visionneuse image ---------- */
.img-viewer {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(10, 15, 30, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 30px;
  animation: viewerIn 0.2s ease-out;
  cursor: zoom-out;
}

@keyframes viewerIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.img-viewer img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  cursor: default;
}

.img-viewer-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.img-viewer-close:hover { background: rgba(255,255,255,0.22); }

.img-viewer-download {
  position: absolute;
  top: 18px;
  left: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: background 0.15s;
}

.img-viewer-download:hover { background: rgba(255,255,255,0.22); }

.img-viewer-caption {
  color: rgba(255,255,255,0.75);
  font-size: 0.85rem;
  text-align: center;
  max-width: 600px;
}
