:root {
  --primary: #C8102E;
  --primary-dark: #9e0d24;
  --primary-soft: #fde8ec;
  --bg-page: #e8e8eb;
  --bg-widget: #ffffff;
  --bg-bubble-bot: #f4f4f6;
  --bg-bubble-card: #fff7e0;
  --bg-bubble-card-border: #fcd9a6;
  --text: #1f1f24;
  --muted: #8a8a93;
  --border: #ececee;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-widget);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

/* ===== Widget container (plein écran, responsive) ===== */

.widget {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-widget);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Header ===== */

.widget-header {
  background: var(--primary);
  color: white;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}
.widget-header > * { max-width: 100%; }
.widget-header {
  /* contenu interne centré sur grand écran */
  padding-left: max(1.25rem, calc((100vw - 880px) / 2));
  padding-right: max(1.25rem, calc((100vw - 880px) / 2));
}

.avatar {
  border-radius: 50%;
  background: white;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.avatar-header { width: 46px; height: 46px; border: 2px solid rgba(255,255,255,0.4); }

.header-text { flex: 1; min-width: 0; }
.header-text h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}
.header-subtitle {
  margin: 2px 0 0;
  font-size: 0.78rem;
  opacity: 0.92;
  line-height: 1.3;
}
.header-status {
  margin: 4px 0 0;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.95;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3ddc84;
  box-shadow: 0 0 0 2px rgba(61, 220, 132, 0.25);
}

/* ===== Main / chat ===== */

.widget-main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-widget);
  padding: 1.25rem max(1rem, calc((100vw - 880px) / 2));
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
}

/* Une "row" = avatar + bulle + timestamp */
.msg-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  max-width: 100%;
}
.msg-row.bot { justify-content: flex-start; }
.msg-row.user { justify-content: flex-end; }

.avatar-msg { width: 32px; height: 32px; align-self: flex-start; margin-top: 2px; }

.msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 640px);
  min-width: 0;
}
.msg-row.user .msg-wrap { align-items: flex-end; }
.msg-row.bot .msg-wrap { align-items: flex-start; }

.msg {
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg.bot {
  background: var(--bg-bubble-bot);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg.user {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.bot.censored {
  background: #fffbeb;
  border: 1px solid #fcd34d;
}

.msg-time {
  font-size: 0.68rem;
  color: var(--muted);
  margin: 4px 6px 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.msg-row.user .msg-time::after {
  content: "✓✓";
  color: var(--primary);
  font-size: 0.7rem;
  letter-spacing: -2px;
}

/* ===== Markdown rendu dans les bulles bot ===== */

.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }
.msg-content p { margin: 0.4rem 0; }
.msg-content h1, .msg-content h2, .msg-content h3 {
  margin: 0.8rem 0 0.4rem;
  font-weight: 700;
  line-height: 1.3;
}
.msg-content h1 { font-size: 1.05rem; }
.msg-content h2 { font-size: 1rem; }
.msg-content h3 { font-size: 0.95rem; }

.msg-content strong { font-weight: 700; }
.msg-content em { font-style: italic; }

.msg-content code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'SF Mono', Menlo, Consolas, monospace;
}
.msg-content pre {
  background: rgba(0,0,0,0.05);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 0.5rem 0;
}
.msg-content pre code { background: none; padding: 0; }

.msg-content blockquote {
  border-left: 3px solid rgba(0,0,0,0.1);
  padding-left: 0.8rem;
  margin: 0.4rem 0;
  color: var(--muted);
}

.msg-content a { color: var(--primary); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }

/* Listes simples (ul) */
.msg-content ul {
  margin: 0.5rem 0;
  padding-left: 1.2rem;
}
.msg-content ul li { margin: 0.2rem 0; }

/* Listes numérotées stylées : pastilles rouges */
.msg-content ol {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: 0.6rem 0;
}
.msg-content ol > li {
  counter-increment: step;
  position: relative;
  padding-left: 2rem;
  margin: 0.55rem 0;
  min-height: 1.4rem;
}
.msg-content ol > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.msg-content ol > li > p:first-child { margin-top: 0; }

/* Curseur de streaming */
.msg-content .cursor {
  display: inline-block;
  width: 6px;
  height: 0.95em;
  background: var(--muted);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ===== Sources ===== */

.sources { margin-top: 0.5rem; display: none; }
.sources.visible { display: block; }
.sources-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 0.3rem;
  font-weight: 600;
}
.sources-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.source-tag {
  background: white;
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.source-tag::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.7;
}

/* ===== Feedback ===== */

.feedback {
  margin-top: 0.55rem;
  display: none;
  flex-direction: column;
  gap: 6px;
}
.feedback.visible { display: flex; }

.feedback-label {
  font-size: 0.75rem;
  color: var(--muted);
}
.feedback-buttons { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.feedback-btn {
  background: white;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}
.feedback-btn:hover { border-color: var(--primary); color: var(--primary); }
.feedback-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.feedback-btn.active:hover { color: white; }
.feedback-latency {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.7rem;
}

/* ===== Hint (suggestions) ===== */

.hint {
  margin: 0.3rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.hint ul {
  list-style: none;
  padding: 0;
  margin: 0.3rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.hint li {
  background: white;
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.78rem;
}
.hint li:hover { border-color: var(--primary); color: var(--primary); }

/* ===== Footer / input ===== */

.widget-footer {
  background: white;
  border-top: 1px solid var(--border);
  padding: 0.75rem max(1rem, calc((100vw - 880px) / 2)) 0.5rem;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
}

.input-row input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 0.9rem;
  outline: none;
  background: #f6f6f8;
  transition: border-color 0.15s, background 0.15s;
}
.input-row input:focus {
  border-color: var(--primary);
  background: white;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.send-btn:hover:not(:disabled) { background: var(--primary-dark); }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.send-btn svg { transform: translateX(-1px); }

.widget-credits {
  text-align: center;
  font-size: 0.65rem;
  color: var(--muted);
  margin: 0.4rem 0 0;
  letter-spacing: 0.2px;
}

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

@media (max-width: 600px) {
  .header-text h1 { font-size: 0.95rem; }
  .header-subtitle, .header-status { font-size: 0.72rem; }
  .avatar-header { width: 40px; height: 40px; }
  .msg-wrap { max-width: 85%; }
  .widget-credits { display: none; }
}
