/* ---------- Message list (I3, I5) ---------- */
.messages {
  flex: 1; min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.messages-inner {
  max-width: var(--content-w);
  min-height: 100%;
  margin: 0 auto;
  padding: 8px calc(20px + var(--safe-right)) 32px calc(20px + var(--safe-left));
}
.msg { margin: 0 0 28px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  background: var(--bubble);
  padding: 10px 18px;
  border-radius: 22px;
  max-width: min(85%, 640px);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user .msg-attachments { justify-content: flex-end; margin-bottom: 8px; max-width: 85%; }
.msg.assistant .body { min-height: 1.6em; overflow-wrap: anywhere; }

.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text-2); font-size: 13px; }
.avatar {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #b85c3f); color: #fff;
}
.msg.streaming .avatar { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* Generation activity stays in the header, never after the last word. */

/* Typing indicator (before first token) */
.typing { display: inline-flex; gap: 6px; padding: 8px 0; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); animation: wave 2.4s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .28s; }
.typing i:nth-child(3) { animation-delay: .56s; }
@keyframes wave { 0%, 60%, 100% { transform: translateY(0) scale(.8); opacity: .45; } 30% { transform: translateY(-4px) scale(1); opacity: 1; } }

/* Thinking / reasoning block (E10) */
.thinking { margin: 0 0 12px; }
.thinking > summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px; border-radius: 999px;
  font-size: 13.5px; color: var(--text-2);
  border: 1px solid var(--border);
  transition: background .15s;
  user-select: none;
}
.thinking > summary::-webkit-details-marker { display: none; }
.thinking > summary:hover { background: var(--bg-hover); }
.thinking > summary .chev { transition: transform .2s; }
.thinking[open] > summary .chev { transform: rotate(180deg); }
.thinking.live > summary .label {
  background: linear-gradient(90deg, var(--text-3) 0%, var(--text) 50%, var(--text-3) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.thinking-body {
  margin: 10px 0 4px 8px; padding: 2px 0 2px 16px;
  border-left: 2px solid var(--border);
  color: var(--text-2); font-size: 14.5px;
  max-height: 420px; overflow-y: auto;
}

/* Images returned by the model (E13) */
.gen-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.gen-images img { max-width: min(100%, 420px); border-radius: 12px; cursor: zoom-in; border: 1px solid var(--border); }
.artifacts { display: grid; gap: 8px; margin-top: 12px; }
.artifact-card, .artifact-preparing { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 10px; border-radius: 14px; background: var(--bg-soft); }
.artifact-preparing { width: fit-content; color: var(--text-2); font-size: 13px; }
.artifact-spinner { width: 15px; height: 15px; border: 2px solid var(--border-strong); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.artifact-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: #fff; background: #64748b; }
.artifact-icon.spreadsheet { background: #16834b; }.artifact-icon.word { background: #2563a8; }.artifact-icon.pdf { background: #c43b32; }.artifact-icon.code { background: #7c5bb8; }
.artifact-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.artifact-type { color: var(--text-3); font-size: 11px; margin-right: auto; }

/* Error card (D7) */
.msg-error {
  display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;
  margin-top: 8px; padding: 12px 14px;
  border-radius: 12px;
  background: var(--danger-bg); color: var(--danger);
  font-size: 14px; line-height: 1.5;
  overflow-wrap: anywhere;
}
.msg-error .err-text { flex: 1; min-width: 200px; }
.msg-error .btn { color: var(--text); background: var(--bg); }
