/**
 * "Ask the Docs" chat page styles.
 * Builds on styles.css (header, .app-content card, .app-button, colours).
 */

/* Active nav tab indicator (scoped to this page's stylesheet). */
.navigation .home-link.active {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Turn the content card into a fixed-height chat surface. */
.chat-content.app-content {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: 860px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 210px);
  min-height: 420px;
}

/* ── message list ─────────────────────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.chat-intro {
  color: #6b7280;
  text-align: center;
  margin: 2rem auto;
  max-width: 540px;
  padding: 1rem;
}

.chat-intro h2 {
  color: #144267;
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.chat-intro p {
  font-size: 0.92rem;
  line-height: 1.5;
}

.chat-msg {
  display: flex;
  margin-bottom: 1rem;
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-msg.assistant {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 82%;
  padding: 0.7rem 0.9rem;
  line-height: 1.5;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.chat-msg.user .chat-bubble {
  background: #144267;
  color: #fff;
  border-radius: 12px 12px 2px 12px;
  white-space: pre-wrap;
}

.chat-msg.assistant .chat-bubble {
  background: #f1f3f5;
  color: #1f2937;
  border-radius: 12px 12px 12px 2px;
}

.chat-msg.user.error .chat-bubble {
  opacity: 0.55;
}

.chat-bubble.error {
  background: #fdecec;
  color: #b02a37;
  border: 1px solid #f5c2c7;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-retry {
  background: #b02a37;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-retry:hover {
  opacity: 0.9;
}

/* ── typing indicator ─────────────────────────────────────────────────────── */

.chat-bubble.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.chat-bubble.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa3ad;
  animation: chat-dot 1.2s infinite ease-in-out both;
}

.chat-bubble.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-bubble.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── classification badge ─────────────────────────────────────────────────── */

.chat-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}

.chat-badge.badge-info   { background: #cfe2ff; color: #084298; }
.chat-badge.badge-warn   { background: #fff3cd; color: #664d03; }
.chat-badge.badge-muted  { background: #e2e3e5; color: #41464b; }
.chat-badge.badge-danger { background: #f8d7da; color: #842029; }

/* ── rendered markdown answer ─────────────────────────────────────────────── */

.chat-answer > *:first-child { margin-top: 0; }
.chat-answer > *:last-child { margin-bottom: 0; }

.chat-answer p { margin: 0 0 0.6rem; }

.chat-answer h1,
.chat-answer h2,
.chat-answer h3,
.chat-answer h4,
.chat-answer h5,
.chat-answer h6 {
  margin: 0.8rem 0 0.4rem;
  line-height: 1.25;
  color: #144267;
}

.chat-answer h1 { font-size: 1.25rem; }
.chat-answer h2 { font-size: 1.15rem; }
.chat-answer h3 { font-size: 1.05rem; }
.chat-answer h4,
.chat-answer h5,
.chat-answer h6 { font-size: 1rem; }

.chat-answer ul,
.chat-answer ol {
  margin: 0 0 0.6rem;
  padding-left: 1.4rem;
}

.chat-answer li { margin: 0.15rem 0; }

.chat-answer a {
  color: #0078d7;
  text-decoration: none;
}

.chat-answer a:hover { text-decoration: underline; }

.chat-answer code {
  background: rgba(0, 0, 0, 0.07);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.88em;
}

.chat-answer pre {
  background: #0d1117;
  color: #e6edf3;
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 0.6rem;
}

.chat-answer pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 0.85rem;
}

.chat-answer blockquote {
  margin: 0 0 0.6rem;
  padding: 0.1rem 0.9rem;
  border-left: 3px solid #cbd5e1;
  color: #52606d;
}

.chat-answer hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 0.8rem 0;
}

/* ── citations ────────────────────────────────────────────────────────────── */

.chat-citations {
  margin-top: 0.7rem;
  padding-top: 0.5rem;
  border-top: 1px solid #e2e5e9;
}

.chat-citations-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #6b7280;
  margin-bottom: 0.25rem;
}

.chat-citations ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.chat-citations li {
  margin: 0.2rem 0;
  font-size: 0.85rem;
}

.chat-citations a {
  color: #0078d7;
  text-decoration: none;
}

.chat-citations a:hover { text-decoration: underline; }

/* ── banner (turn limit / login) ──────────────────────────────────────────── */

.chat-banner {
  padding: 0.6rem 1rem;
  background: #fff3cd;
  color: #664d03;
  border-top: 1px solid #ffe69c;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
}

.chat-banner a { color: #0a58ca; }

/* ── input bar ────────────────────────────────────────────────────────────── */

.chat-inputbar {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding: 0.75rem 1rem 0.4rem;
  border-top: 1px solid #e5e7eb;
}

.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  max-height: 200px;
  overflow-y: auto;
}

.chat-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.15);
}

.chat-input:disabled {
  background: #f3f4f6;
  color: #9ca3af;
}

.chat-send {
  min-width: 80px;
  min-height: 40px;
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-hint {
  font-size: 0.75rem;
  color: #9ca3af;
  padding: 0 1rem 0.75rem;
}

/* ── responsive ───────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .chat-panel {
    height: calc(100vh - 260px);
  }
  .chat-bubble {
    max-width: 90%;
  }
  .navigation {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
  }
}
