/* AI chat widget (JS/chat.js): launcher, panel, bubbles. Full screen on phones. */
.chat-launcher {
  position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 90;
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 52px; padding: 0 var(--space-5) 0 var(--space-4);
  border: 0; border-radius: var(--radius-full); background: var(--color-primary); color: #fff;
  font-weight: var(--weight-semibold); font-size: var(--text-sm); cursor: pointer;
  box-shadow: 0 2px 4px rgba(27, 36, 48, .12), 0 8px 24px rgba(27, 36, 48, .18);
}
.chat-launcher:hover { background: var(--color-primary-hover); }
.chat-launcher:focus-visible { box-shadow: var(--focus-ring), 0 8px 24px rgba(27, 36, 48, .18); border-radius: var(--radius-full); }
.chat-launcher[aria-expanded="true"] { background: var(--color-primary-hover); }

.chat-panel {
  position: fixed; right: var(--space-5); bottom: calc(var(--space-5) + 64px); z-index: 95;
  display: flex; flex-direction: column;
  width: 380px; height: min(620px, calc(100vh - var(--header-h) - 104px)); min-height: 360px;
  background: var(--color-surface); border: 1px solid var(--color-line); border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(27, 36, 48, .10), 0 16px 40px rgba(27, 36, 48, .16);
  overflow: hidden;
}
.chat-panel__header {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-line);
}
.chat-panel__avatar {
  display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0;
  border-radius: var(--radius-full); background: var(--color-primary-tint); color: var(--color-primary);
}
.chat-panel__title { flex: 1; min-width: 0; }
.chat-panel__title h2 { font-size: var(--text-base); }
.chat-panel__title span { display: block; font-size: var(--text-xs); color: var(--color-ink-3); }

.chat-context {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
  background: var(--color-surface-2); border-bottom: 1px solid var(--color-line);
  font-size: var(--text-xs); color: var(--color-ink-2);
}
.chat-context span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-context a { font-weight: var(--weight-semibold); }

.chat-log {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-4); background: var(--color-bg); overscroll-behavior: contain;
}
.chat-log:focus-visible { box-shadow: inset var(--focus-ring); border-radius: 0; }
.chat-msg {
  max-width: 86%; padding: var(--space-2) var(--space-3); border-radius: var(--radius);
  font-size: var(--text-sm); line-height: 1.5; overflow-wrap: anywhere;
}
.chat-msg p + p, .chat-msg p + ul, .chat-msg ul + p { margin-top: var(--space-2); }
.chat-msg ul { margin: var(--space-1) 0 0; padding-left: var(--space-5); }
.chat-msg li + li { margin-top: 2px; }
.chat-msg--bot { align-self: flex-start; background: var(--color-surface); border: 1px solid var(--color-line); color: var(--color-ink); }
.chat-msg--bot a { font-weight: var(--weight-semibold); text-decoration: underline; text-underline-offset: 2px; }
.chat-msg--user { align-self: flex-end; background: var(--color-primary); color: #fff; }
.chat-msg--error { background: var(--color-warning-tint); border-color: #f0d6ad; }
.chat-msg--error .btn { margin-top: var(--space-2); }

.chat-typing { display: inline-flex; gap: 4px; padding: var(--space-3); }
.chat-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--color-ink-3); animation: chat-dot 1.2s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.chat-suggest { flex-wrap: wrap; overflow: visible; padding: var(--space-2) var(--space-4) 0; background: var(--color-bg); }
.chat-suggest .chip { font-size: var(--text-xs); }

.chat-form { display: flex; align-items: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-3) var(--space-2) var(--space-4); border-top: 1px solid var(--color-line); }
.chat-input { flex: 1; min-height: 40px; max-height: 120px; resize: none; padding-top: 9px; padding-bottom: 9px; line-height: 1.4; }
.chat-count { padding: 0 var(--space-4); font-size: var(--text-xs); color: var(--color-ink-3); }
.chat-count.is-over { color: var(--color-error); font-weight: var(--weight-semibold); }
.chat-note { padding: 0 var(--space-4) var(--space-3); font-size: var(--text-xs); color: var(--color-ink-3); }

/* Phones: the panel takes the whole screen, the page behind doesn't scroll. */
@media (max-width: 640px) {
  .chat-launcher { right: var(--space-4); bottom: var(--space-4); width: 52px; padding: 0; justify-content: center; }
  .chat-launcher__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .chat-panel { inset: 0; width: auto; height: auto; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
  .chat-msg { max-width: 90%; }
  .chat-input { font-size: var(--text-base); }   /* 16px: no zoom on iOS */
  body.chat-open-full { overflow: hidden; }
}
@media (pointer: coarse) {
  .chat-panel__header .btn--icon { width: var(--tap); min-height: var(--tap); }
}
