/* A viewport-sized chat, with one history scroller and an always-visible
   composer. Consent, pre-interview forms and the dashboard keep page scrolling. */
body.participant-mode.chat-active {
  position: fixed;
  inset-inline: 0;
  top: var(--chat-viewport-top, 0px);
  height: var(--chat-viewport-height, 100dvh);
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.chat-active .topbar { flex: 0 0 auto; min-height: 72px; padding-block: 8px; }
body.chat-active #participant.shell {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
body.chat-active #chat {
  flex: 1 1 0;
  height: 100%;
  min-height: 0;
  max-height: none;
}
#chat .chat-title { padding: 10px 16px; gap: 8px; }
.chat-history { position: relative; flex: 1 1 0; min-height: 0; }
#chat .messages {
  display: block;
  height: 100%;
  min-height: 0;
  padding: 16px;
  scroll-behavior: auto;
  overflow-anchor: none;
  scrollbar-gutter: stable;
}
.message-list { display: flex; flex-direction: column; gap: 12px; }
#chat .message { line-height: 1.8; }
#chat #choice-form.composer.choices {
  margin-top: 16px;
  padding: 0;
  max-height: none;
  overflow: visible;
  flex: none;
}
#chat #chat-controls {
  flex: 0 0 auto;
  flex-wrap: wrap;
  margin: 0;
  padding: 8px 12px;
  gap: 8px;
  border-top: 1px solid var(--line);
}
body.participant-mode #chat-controls .quiet { min-height: 44px; }
#chat #message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: end;
  gap: 4px 10px;
  padding: 8px 12px;
}
.composer-label { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); }
#chat #message-input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  max-height: min(144px, 24dvh);
  padding: 10px 12px;
  font-size: max(16px, 1rem);
  line-height: 1.65;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 10px;
}
#chat .send { width: 48px; height: 48px; min-height: 48px; }
#chat .message-length { flex: 0 0 auto; padding: 0 12px 8px; font-size: .75rem; }
body.participant-mode #chat .message-length,
body.participant-mode #chat .chat-title span,
body.participant-mode #chat #message-input::placeholder { color: var(--muted); }
body.participant-mode #chat .message-length.error { color: var(--danger); }
.latest-message {
  position: absolute;
  bottom: 8px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 24px;
  font: 600 .85rem Vazirmatn, Tahoma, sans-serif;
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 4px 16px #10243b22;
  cursor: pointer;
}
#chat button { touch-action: manipulation; }
#chat .network-note { flex-wrap: wrap; }
#chat .retry { min-height: 44px; }
@media (max-width: 600px) {
  body.chat-active #participant.shell { padding: 0; }
  body.chat-active #chat { border-radius: 0; border-inline: 0; }
  body.chat-active .topbar { min-height: 60px; padding: 6px 12px; }
  #chat .messages { padding: 12px; }
  #chat .chat-title { padding: 8px 12px; }
  #chat .message-length { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}
/* Compact only secondary spacing while a keyboard or landscape viewport
   leaves little room; all interview controls stay reachable. */
/* The chat's own title and exit button stay visible. Hide the redundant site
   masthead only in a short visual viewport to make room for the keyboard. */
body.chat-compact .topbar { display: none; }
body.chat-compact .top-brand span,
body.chat-compact .chat-title span,
body.chat-compact .composer-label { display: none; }
body.chat-compact .chat-title { padding-block: 4px; }
body.chat-compact #chat-controls { padding-block: 4px; }
body.chat-compact #message-form { padding-block: 4px; }
body.chat-compact #message-input { max-height: 80px; }
body.chat-compact .message-length { font-size: .75rem; line-height: 1.4; }
