/* The AI chat: the chat page (templates/agent/chat.html) and the panel on
   public and portal pages (templates/agent/_chat_widget.html, drawn by
   static/js/chat.js). Only the site tokens from static/css/site.css are
   used, so light and dark follow the visitor's choice. The assistant's
   speech always carries its "AI assistant" label, in words. */

.chat-notice { margin: 0 0 1rem; }

.chat-log { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.75rem; }
.chat-msg {
  max-width: 42rem; padding: 0.6rem 0.85rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.chat-msg p { margin: 0.15rem 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-who { display: block; font-size: 0.85rem; font-weight: 700; color: var(--text-secondary); }
.chat-msg-user { justify-self: end; background: var(--surface-inset); border-color: var(--border-ink); }
.chat-msg-notice { background: var(--warning-bg); border-color: var(--warning-strong); color: var(--warning-fg); }
.chat-typing p { font-style: italic; color: var(--text-secondary); }

.chat-error {
  margin: 0 0 1rem; padding: 0.6rem 0.85rem; border: 2px solid var(--danger-border); border-radius: 8px;
  background: var(--danger-bg); color: var(--danger-fg); font-weight: 600;
}

.chat-form { display: grid; gap: 0.4rem; margin-bottom: 1rem; }
.chat-form label { font-weight: 600; }
.chat-form textarea { width: 100%; min-height: 4.5rem; font-size: 1rem; }
.chat-form .button { justify-self: start; min-width: 6rem; min-height: 2.75rem; }
.chat-handoff { border-top: 1px solid var(--border); padding-top: 0.75rem; }
.chat-handoff h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }

/* The panel */
.chat-widget { position: fixed; right: 1rem; bottom: 1rem; z-index: 40; max-width: calc(100vw - 2rem); }
.chat-widget-link { box-shadow: var(--shadow-card); }
.chat-panel {
  width: 24rem; max-width: calc(100vw - 2rem); max-height: min(36rem, calc(100vh - 2rem)); overflow-y: auto;
  padding: 0.85rem; background: var(--surface); color: var(--text); border: 2px solid var(--border-ink);
  border-radius: 12px; box-shadow: var(--shadow-pop);
}
.chat-panel[hidden], .chat-widget-link[hidden] { display: none; }
.chat-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.chat-panel-head h2 { margin: 0; font-size: 1.1rem; }
.chat-panel-notice { margin: 0.5rem 0; font-size: 0.9rem; color: var(--text-secondary); }
.chat-log-live { max-height: 16rem; overflow-y: auto; margin-bottom: 0.5rem; }
.chat-status { min-height: 1.25rem; margin: 0 0 0.4rem; font-size: 0.9rem; color: var(--text-secondary); }
.chat-panel-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.chat-panel-handoff { margin: 0.75rem 0 0; }

@media (max-width: 36rem) {
  .chat-widget { right: 0.5rem; bottom: 0.5rem; left: 0.5rem; max-width: none; }
  .chat-panel { width: 100%; max-width: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .chat-panel { transition: opacity 0.15s ease; }
}
@media print { .chat-widget { display: none; } }
