/* Contact chat page — modern AI-chat UI.
   Reuses the design tokens from styles.css (:root vars + --font). No new
   design system, no build step. */

.chat-page {
  padding-top: 3rem;
  padding-bottom: 4rem;
  max-width: 820px;
}

.chat-head {
  margin-bottom: 1.75rem;
}
.chat-head h1 {
  margin: 0.25rem 0 0.75rem;
}

/* --- Chat surface --------------------------------------------------- */
.chat {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 60vh;
  max-height: 72vh;
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

/* --- Bubbles -------------------------------------------------------- */
.bubble {
  max-width: 80%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble-assistant {
  align-self: flex-start;
  background: var(--bg-alt);
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble-user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-error {
  align-self: flex-start;
  background: #fdecef;
  color: var(--pink);
  border: 1px solid #f3c6cf;
}

/* Rendered Markdown (assistant messages). Block layout instead of the plain
   pre-wrap used for user/error bubbles. */
.bubble-md {
  white-space: normal;
}
.bubble-md > :first-child {
  margin-top: 0;
}
.bubble-md > :last-child {
  margin-bottom: 0;
}
.bubble-md p {
  margin: 0 0 0.6rem;
}
.bubble-md ul,
.bubble-md ol {
  margin: 0 0 0.6rem;
  padding-left: 1.3rem;
}
.bubble-md li {
  margin: 0.15rem 0;
}
.bubble-md .md-h {
  font-weight: 700;
  margin: 0.5rem 0 0.3rem;
}
.bubble-md a {
  color: inherit;
  text-decoration: underline;
}
.bubble-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.bubble-md pre {
  margin: 0 0 0.6rem;
  padding: 0.6rem 0.8rem;
  background: rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.bubble-md pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  white-space: pre;
}

.chat-empty .bubble {
  opacity: 0.95;
}

/* --- Typing indicator ----------------------------------------------- */
.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* --- Capture-complete banner ---------------------------------------- */
.chat-captured {
  align-self: center;
  background: rgba(127, 200, 68, 0.14);
  color: var(--ink);
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
}

/* --- Composer (sticky bottom) --------------------------------------- */
.chat-composer {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  bottom: 0;
}
.chat-input {
  flex: 1 1 auto;
  resize: none;
  font: inherit;
  color: var(--ink);
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  max-height: 8rem;
  overflow-y: auto;
}
.chat-input:focus {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}
.chat-send {
  flex: 0 0 auto;
}
.chat-send[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* --- Fallback ------------------------------------------------------- */
.chat-fallback {
  margin-top: 2rem;
  padding: 1.25rem 1.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
}
.chat-fallback h2 { margin-top: 0; }

/* When JS boots the chat, it un-hides #chat and hides the fallback. */
.chat[hidden] { display: none; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

@media (max-width: 600px) {
  .bubble { max-width: 92%; }
  .chat { min-height: 64vh; }
}
