.chat-messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.chat-msg {
  max-width: 88%; padding: 12px 16px; border-radius: 12px;
  font-size: 14px; line-height: 1.7; word-wrap: break-word;
  white-space: normal;
}
.chat-msg code { background: var(--bg-hover); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.chat-msg strong { font-weight: 600; }
.chat-msg.chat-user {
  align-self: flex-end; background: var(--accent-gradient); color: white;
  border-bottom-right-radius: 4px;
}
.chat-msg.chat-ai {
  align-self: flex-start; background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.chat-persona-label {
  align-self: flex-start; font-size: 11px; color: var(--text-muted);
  font-weight: 500; padding: 2px 0; margin-top: 4px;
}
.chat-persona-joined {
  align-self: center; font-size: 12px; color: var(--text-muted);
  font-style: italic; padding: 6px 0; opacity: 0.7;
}
/* Markdown elements in chat messages */
.chat-h1 { font-size: 17px; font-weight: 700; margin: 14px 0 8px; font-family: var(--font-display); }
.chat-h1:first-child { margin-top: 0; }
.chat-h2 { font-size: 15px; font-weight: 600; margin: 12px 0 6px; font-family: var(--font-display); }
.chat-h2:first-child { margin-top: 0; }
.chat-h3 { font-size: 14px; font-weight: 600; margin: 10px 0 4px; color: var(--text-secondary); }
.chat-h3:first-child { margin-top: 0; }
.chat-para { margin: 0 0 10px 0; }
.chat-para:last-child { margin-bottom: 0; }
.chat-list { margin: 0 0 10px 0; padding-left: 20px; }
.chat-list:last-child { margin-bottom: 0; }
.chat-list li { margin-bottom: 4px; }
.chat-list li::marker { color: var(--accent); }
.chat-list .chat-list { margin: 4px 0 4px 0; }
.chat-code-block {
  background: var(--bg-primary); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px 14px; margin: 8px 0; overflow-x: auto;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px; line-height: 1.5; white-space: pre;
}
.chat-table-wrap { overflow-x: auto; margin: 8px 0; border-radius: 6px; }
.chat-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.chat-table th, .chat-table td {
  padding: 6px 10px; border: 1px solid var(--border); text-align: left;
}
.chat-table th {
  background: var(--bg-primary); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px;
}
.chat-table tr:nth-child(even) td { background: var(--bg-hover); }
.chat-callout {
  margin: 8px 0; padding: 10px 14px; border-radius: 8px;
  background: var(--bg-hover); border: 1px solid var(--border);
  font-size: 13px; line-height: 1.6;
}
.chat-blockquote {
  margin: 8px 0; padding: 8px 14px; border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0;
  background: var(--bg-hover); color: var(--text-secondary);
}
.chat-blockquote .chat-para { margin-bottom: 6px; }
.chat-blockquote .chat-para:last-child { margin-bottom: 0; }
.chat-hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.chat-msg a { color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.chat-msg a:hover { text-decoration-thickness: 2px; }
.chat-user a { color: #fff; text-decoration-color: rgba(255,255,255,0.6); }
.chat-msg em { font-style: italic; }
.chat-user .chat-para { margin-bottom: 4px; }
.chat-user .chat-list { margin-bottom: 4px; }
.chat-emf-hint { font-size: 12px; color: var(--text-secondary); margin-top: 10px; padding: 6px 10px; background: rgba(99, 102, 241, 0.05); border-left: 3px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; line-height: 1.5; }
.chat-emf-hint a { color: var(--accent); text-decoration: none; font-weight: 500; }
.chat-emf-hint a:hover { text-decoration: underline; }
.typing-indicator {
  display: inline-flex; gap: 4px; padding: 10px 14px;
  background: var(--bg-card); border-radius: 12px; border: 1px solid var(--border);
  align-self: flex-start;
}
.typing-indicator span {
  width: 6px; height: 6px; background: var(--text-muted); border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}
