.chat { display: flex; justify-content: flex-end; align-items: center; min-height: 76px; padding-block: .75rem; }
.chat[hidden] { display: none; }

.chat-launcher {
  display: inline-flex; align-items: center; gap: .6rem;
  min-height: 44px; padding: .25rem .75rem .25rem .35rem;
  font: 700 .9375rem/1.25 var(--f-text, sans-serif); color: var(--ink, #0e1a3a);
  background: transparent; border: 1px solid var(--line); border-radius: var(--r, 3px);
  cursor: pointer;
}
.chat-launcher img { width: 32px; height: 32px; border-radius: 2px; object-fit: cover; }
.chat-launcher:hover { background: var(--sky, #e8eef9); }
.chat-launcher:focus-visible { outline: 3px solid transparent; outline-offset: 2px; box-shadow: var(--focus); }
.chat.is-open .chat-launcher { display: none; }

.chat-panel {
  position: fixed; right: var(--s2, 1rem); bottom: var(--s2, 1rem); z-index: 80;
  display: flex; flex-direction: column;
  width: min(27rem, calc(100vw - 2rem)); height: min(42rem, calc(100vh - 2rem));
  background: var(--paper, #fff); color: var(--ink, #0e1a3a);
  border: 2px solid var(--ink, #0e1a3a); border-radius: var(--r, 3px);
  box-shadow: 0 10px 40px rgba(14, 26, 58, .28);
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }
@media (max-width: 40rem) {
  .chat-panel { inset: 0; right: 0; bottom: 0; width: 100%; height: 100%; height: 100dvh; border: 0; border-radius: 0; }
}

.chat-head { display: flex; align-items: flex-start; gap: .75rem; padding: .75rem .75rem .75rem 1rem; background: var(--blue, #244ca4); color: #fff; }
.chat-head img { width: 48px; height: 48px; border-radius: 2px; border: 2px solid #fff; object-fit: cover; flex: none; }
.chat-head__text { flex: 1; min-width: 0; }
.chat-title { font-family: var(--f-display, sans-serif); font-weight: 800; font-size: 1.35rem; line-height: 1.1; margin: 0; }
.chat-intro { margin: .25rem 0 0; font-size: .875rem; line-height: 1.4; }
.chat-close {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  font-size: 1.75rem; line-height: 1; color: #fff; background: transparent;
  border: 2px solid transparent; border-radius: var(--r, 3px); cursor: pointer;
}
.chat-close:hover { border-color: #fff; }
.chat-close:focus-visible { outline: 3px solid var(--star, #ffd52e); outline-offset: 0; }

.chat-notice { margin: 0; padding: .5rem 1rem; font-size: .875rem; background: var(--warn-bg, #fff4d1); color: var(--warn, #7a4f00); border-bottom: 1px solid var(--line, #c6cfe2); }
.chat-notice[hidden] { display: none; }

.chat-log { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 1rem; display: flex; flex-direction: column; gap: .75rem; overscroll-behavior: contain; }
.chat-msg { max-width: 90%; padding: .6rem .8rem; border-radius: var(--r, 3px); font-size: 1rem; line-height: 1.5; }
.chat-msg p { margin: 0; }
.chat-msg p + p { margin-top: .6em; }
.chat-msg--bot { align-self: flex-start; background: var(--sky, #e8eef9); }
.chat-msg--user { align-self: flex-end; background: var(--blue, #244ca4); color: #fff; }
.chat-msg--user a { color: #fff; }
.chat-msg--error { background: var(--err-bg, #fdebed); color: var(--err, #a8182b); }
.chat-msg--crisis { background: var(--err-bg, #fdebed); border-left: 4px solid var(--err, #a8182b); max-width: 100%; }
.chat-msg__sources { margin: .5rem 0 0; padding: 0; list-style: none; font-size: .9rem; }
.chat-msg__sources li + li { margin-top: .2rem; }
.chat-msg__handoff { margin-top: .5rem; }
.chat-msg__handoff .btn { min-height: 44px; padding: .4rem .8rem; font-size: .95rem; }
.chat-thinking { color: var(--muted, #4d5875); font-style: italic; }
@media (prefers-reduced-motion: no-preference) {
  .chat-thinking::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: chat-dots 1.2s steps(4, end) 3; }
  @keyframes chat-dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
}

.chat-form { display: grid; grid-template-columns: 1fr auto; gap: .5rem; align-items: end; padding: .75rem 1rem .25rem; border-top: 1px solid var(--line, #c6cfe2); margin: 0; }
.chat-form textarea { min-height: 48px; max-height: 8rem; resize: none; width: 100%; font: inherit; }
.chat-send { min-height: 48px; }
.chat-privacy { margin: 0; padding: .1rem 1rem .25rem; font-size: .8rem; color: var(--muted, #4d5875); }
.chat-actions { display: flex; flex-wrap: wrap; gap: .25rem 1rem; padding: 0 .75rem .5rem; }
.chat-actions .btn { min-height: 44px; font-size: .95rem; }

.chat-handoff { padding: 1rem; overflow-y: auto; border-top: 1px solid var(--line, #c6cfe2); }
.chat-handoff[hidden] { display: none; }
.chat-handoff > * + * { margin-top: .75rem; }
.chat-handoff h3 { margin: 0; }
.chat-handoff input, .chat-handoff textarea { width: 100%; }
.chat-handoff textarea { min-height: 4rem; }
.chat-handoff__status:empty { display: none; }
.chat-handoff__status.is-error { color: var(--err, #a8182b); font-weight: 700; }
.chat.is-handoff .chat-form, .chat.is-handoff .chat-privacy, .chat.is-handoff .chat-actions, .chat.is-handoff .chat-log { display: none; }

@media print { .chat { display: none !important; } }
.chat-msg__rate { display: flex; gap: .25rem; margin-top: .4rem; font-size: .85rem; color: var(--muted); }
.chat-rate { min-width: 36px; min-height: 36px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); cursor: pointer; font-size: 1rem; line-height: 1; }
.chat-rate:hover { border-color: var(--blue); }
