.chat-launcher { position: fixed; z-index: 20; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); min-height: 52px; padding: 12px 22px; border: 1px solid var(--accent); border-radius: 999px; background: var(--accent-soft); color: var(--on-accent-soft); font: 600 16px "Source Sans 3", sans-serif; box-shadow: var(--elevation); cursor: pointer; }
.chat-dialog { position: fixed; inset: auto 20px 20px auto; margin: 0; padding: 0; width: min(460px, calc(100vw - 40px)); max-width: none; height: min(720px, calc(100dvh - 40px)); max-height: none; border: 1px solid var(--line); border-radius: 24px; background: var(--bg); color: var(--text); box-shadow: var(--elevation); overflow: hidden; }
.chat-dialog[open] { display: flex; flex-direction: column; }
.chat-dialog::backdrop { background: rgb(0 0 0 / .35); }
html.chat-open { overflow: hidden; }
.chat-header { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; padding: 16px 16px 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-header h2 { margin: 0; font-size: 23px; }
.chat-header p { margin: 3px 0 0; font-size: 14px; color: var(--muted); }
.chat-dialog button, .chat-dialog textarea { font: inherit; }
.chat-dialog button { cursor: pointer; }
.chat-close { flex-shrink: 0; width: 48px; height: 48px; border: 0; border-radius: 50%; background: transparent; color: var(--text); font-size: 30px !important; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px 20px; }
.chat-notice { color: var(--muted); font-size: 14px; line-height: 1.5; }
.chat-message { margin-top: 16px; padding: 12px 14px; border-radius: 18px; background: var(--surface); overflow-wrap: anywhere; }
.chat-message strong { display: block; font-size: 13px; color: var(--muted); }
.chat-message p { margin: 4px 0 0; white-space: pre-wrap; line-height: 1.5; }
.chat-user { background: var(--accent-soft); color: var(--on-accent-soft); }
.chat-user strong { color: inherit; }
.chat-sources { padding-left: 18px; margin: 10px 0 0; font-size: 14px; }
.chat-sources li { margin-top: 8px; }
.chat-sources a { color: var(--accent); }
.chat-status { margin: 12px 0 0; color: var(--muted); font-size: 14px; }
.chat-status:empty { display: none; }
.chat-form { padding: 12px 20px 16px; border-top: 1px solid var(--line); flex-shrink: 0; }
.chat-form label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.chat-input-row { display: flex; gap: 8px; align-items: stretch; }
.chat-input-row textarea { width: 100%; min-width: 0; min-height: 56px; max-height: 140px; resize: vertical; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface); color: var(--text); font-size: 16px; line-height: 1.4; }
.chat-input-row button { border: 0; border-radius: 12px; padding: 10px 14px; background: var(--accent-soft); color: var(--on-accent-soft); font-weight: 600; }
.chat-dialog button:disabled { cursor: wait; opacity: .6; }
.chat-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; }
.chat-clear { min-height: 44px; padding: 8px 0; border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.chat-memory { margin: 0; font-size: 12px; color: var(--muted); }
/* Leave room to reach footer links behind the fixed launcher. */
.site-footer { padding-bottom: 90px; }
@media (max-width: 599px) {
  .chat-dialog { inset: auto 8px max(8px, env(safe-area-inset-bottom)) 8px; width: calc(100vw - 16px); height: calc(100dvh - 24px - env(safe-area-inset-bottom)); border-radius: 20px; }
  .chat-launcher { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .chat-header, .chat-scroll, .chat-form { padding-left: 16px; padding-right: 16px; }
}
@media print { .chat-launcher, .chat-dialog { display: none !important; } }
