.messages { flex: 1; overflow-y: auto; padding: var(--space-6) var(--space-5); }
.messages__empty { height: 100%; display: flex; align-items: center; justify-content: center; font-size: var(--text-2xl); color: var(--color-text-muted); }
.messages__col { max-width: var(--chat-max-width); margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-5); }
.message { display: flex; }
.message--user { justify-content: flex-end; }
.message__body { max-width: 85%; overflow-wrap: anywhere; line-height: var(--leading-relaxed); }
.message--user .message__body { white-space: pre-wrap; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); background: var(--color-accent-soft); color: var(--color-accent-soft-text); }
.message--assistant .message__body { max-width: 100%; }
.message__typing { color: var(--color-text-subtle); animation: message-blink 1s infinite; }
@keyframes message-blink { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .message__typing { animation: none; } }

/* ---- Beautify (m0-beautify) -------------------------------------------
   QUOI : illustrated empty state (violet sparkle floating in a soft glow,
   gradient greeting); messages rise in; user bubble with a "tail" corner and
   lit edge; thinking = three breathing dots; a violet caret blinks at the end
   of the answer while it streams.
   POURQUOI : the empty screen is the hero of the demo; motion on arrival
   and during streaming says "alive" without any spinner.
   COMMENT :
   - sparkle = ::before filled with --gradient-accent through an SVG MASK
     (data URI, ~300 B) so the colour follows the theme tokens;
   - greeting gradient ends are text-strong → accent-2, both AA on bg
     (and 36 px text only needs 3:1);
   - caret + spinning mark key off .message--streaming, set by the Dart on
     the answer being streamed (m1 — replaced the m0 :has(stop) workaround);
   - keyed messages (ValueKey) are inserted once, so nx-msg-in plays on
     arrival only, not on every streamed token. */
.messages__empty {
  height: auto; min-height: 100%; /* starters can outgrow a short viewport: grow, never clip */
  flex-direction: column; gap: var(--space-4); text-align: center; padding: var(--space-6) var(--space-5);
  font-size: var(--text-md); color: var(--color-text-muted);
  /* the glow stays on the box, behind sparkle + greeting */
  background: var(--gradient-glow) center 30% / min(560px, 90%) 420px no-repeat;
}
/* Greeting (m1: its own <h2>): gradient clipped to the glyphs. Ends
   text-strong → accent-2, both AA on bg (and 36 px text only needs 3:1). */
.messages__greeting {
  margin: 0; font-size: var(--text-2xl); font-weight: var(--weight-semibold); letter-spacing: -0.02em;
  line-height: var(--leading-tight); color: var(--color-text-strong);
  background: linear-gradient(100deg, var(--color-text-strong) 20%, var(--color-accent) 60%, var(--color-accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.messages__lead { margin: calc(var(--space-2) * -1) 0 var(--space-2); max-width: 46ch; }

/* Starters (mock-up empty.html): 4 cards, auto-fit grid → 4, 2×2, then 1
   column. Each card is a <button>: hover lifts it, keyboard focus uses the
   base ring; cards rise in one after the other (40 ms stagger). */
.starters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-2);
  width: min(100%, var(--chat-max-width)); text-align: start;
}
.starter {
  display: flex; flex-direction: column; gap: var(--space-1); min-height: var(--hit-target);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg);
  border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text);
  text-align: start; cursor: pointer;
  animation: nx-msg-in var(--duration-enter) var(--ease-standard) both;
  transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-base) var(--ease-standard), transform var(--duration-base) var(--ease-standard);
}
.starter:nth-child(2) { animation-delay: 40ms; }
.starter:nth-child(3) { animation-delay: 80ms; }
.starter:nth-child(4) { animation-delay: 120ms; }
.starter:hover { background: var(--color-surface-raised); border-color: var(--color-border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.starter:active { transform: scale(0.98); box-shadow: none; }
.starter__title { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-text-strong); }
.starter__title .nx-icon { color: var(--color-link); }
.starter__desc { font-size: var(--text-xs); color: var(--color-text-muted); }
.messages__empty::before { /* mask clips filters, so no drop-shadow: the glow layer of the box gives the halo */
  content: ""; width: 64px; height: 64px;
  background: var(--gradient-accent);
  -webkit-mask: var(--nx-sparkle) center / contain no-repeat;
          mask: var(--nx-sparkle) center / contain no-repeat;
  animation: nx-float 6s ease-in-out infinite;
}
.app, .messages__empty {
  --nx-sparkle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M28 4c1.4 13.6 10.4 22.6 24 24-13.6 1.4-22.6 10.4-24 24C26.6 38.4 17.6 29.4 4 28c13.6-1.4 22.6-10.4 24-24z'/%3E%3Cpath d='M51 38c.6 5.6 3.4 8.4 9 9-5.6.6-8.4 3.4-9 9-.6-5.6-3.4-8.4-9-9 5.6-.6 8.4-3.4 9-9z'/%3E%3Ccircle cx='52' cy='12' r='3'/%3E%3C/svg%3E");
}
.message { animation: nx-msg-in var(--duration-enter) var(--ease-standard) both; }
.message--user .message__body {
  border-bottom-right-radius: var(--radius-xs);
  box-shadow: var(--shadow-inset-highlight);
}
.message__typing {
  display: inline-block; width: 30px; height: 10px; position: relative;
  font-size: 0; color: var(--color-accent); animation: none;
}
.message__typing::before {
  content: ""; position: absolute; left: 2px; top: 2px; width: 6px; height: 6px; border-radius: 50%;
  animation: nx-dots 1.2s var(--ease-standard) infinite;
}
.message--streaming :is(.md > :last-child, .message__plain)::after {
  content: ""; display: inline-block; width: 2px; height: 1.1em; margin-left: 2px; vertical-align: text-bottom;
  border-radius: 1px; background: var(--color-accent); animation: nx-caret 1s steps(1) infinite;
}
.message__actions .icon-btn { transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard); }
.message__actions .icon-btn:active { transform: scale(0.94); }
@keyframes nx-msg-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes nx-float { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-6px) rotate(6deg); } }
@keyframes nx-caret { 50% { opacity: 0; } }
@keyframes nx-dots {
  0%, 100% { background: currentColor; box-shadow: 10px 0 0 rgb(from currentColor r g b / 0.35), 20px 0 0 rgb(from currentColor r g b / 0.35); }
  33%      { background: rgb(from currentColor r g b / 0.35); box-shadow: 10px 0 0 currentColor, 20px 0 0 rgb(from currentColor r g b / 0.35); }
  66%      { background: rgb(from currentColor r g b / 0.35); box-shadow: 10px 0 0 rgb(from currentColor r g b / 0.35), 20px 0 0 currentColor; }
}

/* Assistant identity: a small gradient sparkle mark heads every answer
   (Sider shows the model mark above each reply). Pure ::before, decorative,
   so no accessible name is needed (the thread already says who speaks). */
.message--assistant { position: relative; padding-left: calc(28px + var(--space-3)); }
.message--assistant::before {
  content: ""; position: absolute; left: 0; top: 0; width: 28px; height: 28px;
  border-radius: var(--radius-sm); border: 1px solid var(--color-border);
  background: var(--color-surface-raised);
  box-shadow: var(--shadow-sm);
}
.message--assistant::after { /* the sparkle itself, masked so it follows the theme */
  content: ""; position: absolute; left: 6px; top: 6px; width: 16px; height: 16px;
  background: var(--gradient-accent);
  -webkit-mask: var(--nx-sparkle) center / contain no-repeat;
          mask: var(--nx-sparkle) center / contain no-repeat;
}
.message--assistant.message--streaming::after { animation: nx-spin-soft 2.4s var(--ease-standard) infinite; }
@keyframes nx-spin-soft { to { transform: rotate(360deg); } }
@media (max-width: 720px) { .message--assistant { padding-left: 0; padding-top: calc(28px + var(--space-2)); } }
/* Mobile (seen on the 390px capture): centring a column taller than the
   viewport cut the sparkle off the top → "safe center"; the 36px greeting
   broke inside "puis-je" → one step smaller. */
.messages__empty { justify-content: safe center; }
@media (max-width: 720px) { .messages__greeting { font-size: var(--text-xl); } }

/* m3-fix-css — user actions beside the bubble, not under it.
   QUOI : on a pointer device, copy/edit of a USER message sit to the LEFT of
   the bubble, bottom-aligned, instead of on a row below it.
   POURQUOI : the row below is invisible until hover (opacity 0) but still
   reserved 32 + 4 px, which, added to the 20 px column gap, left a ~56 px
   hole between every question and its answer (measured in the DOM on the
   m3-real captures, worst in the narrow multipane columns).
   COMMENT : the message becomes a ROW (flex-end), actions go first with
   order:-1; they now cost width only, and only once the bubble reaches its
   85 % cap (the bubble shrinks a little, the column never grows). Touch
   devices (hover: none) keep the visible row below — there it is a real,
   always-shown control, so its space is earned. The assistant row stays
   below: it closes the turn and holds regenerate. Doubled class: markdown.css
   (loaded later) sets .message to column at the same specificity. */
@media (hover: hover) {
  .message.message--user { flex-direction: row; align-items: flex-end; justify-content: flex-end; gap: var(--space-1); }
  .message.message--user .message__actions { order: -1; margin-top: 0; flex: none; }
}
