/* ── Chat Page ─────────────────────────────────────────────────────────────── */

/* Container: fills the viewport height minus header + footer */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  min-height: 420px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.chat-header-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.3;
}

.chat-header-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* ── Messages area ─────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.chat-message.user      { align-self: flex-end; }
.chat-message.assistant { align-self: flex-start; }

.chat-bubble {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  line-height: 1.65;
  word-break: break-word;
}

.chat-bubble.user {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown rendering inside assistant bubbles */
.chat-bubble.assistant p { margin: 0 0 0.5rem; }
.chat-bubble.assistant p:last-child { margin-bottom: 0; }
.chat-bubble.assistant ul,
.chat-bubble.assistant ol {
  padding-left: 1.25rem;
  margin: 0.25rem 0 0.5rem;
}
.chat-bubble.assistant li { margin-bottom: 0.15rem; }
.chat-bubble.assistant strong { font-weight: 600; }
.chat-bubble.assistant em { font-style: italic; }
.chat-bubble.assistant a {
  color: var(--accent);
  text-decoration: underline;
}
.chat-bubble.assistant code {
  font-family: var(--font-mono);
  font-size: 0.83em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  color: #b5460c;
}
.chat-bubble.assistant pre {
  background: #1e1e2e;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}
.chat-bubble.assistant pre code {
  background: none;
  border: none;
  padding: 0;
  color: #cdd6f4;
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ── Typing indicator ──────────────────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.6rem 0.85rem;
  height: 2.4rem;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.4s infinite both;
  display: block;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.32s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.55); opacity: 0.35; }
  40%            { transform: scale(1);    opacity: 1; }
}

/* ── Input area ────────────────────────────────────────────────────────────── */
.chat-input-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-width: 0;
}

.chat-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 95, 196, 0.12);
}

.chat-input:disabled { opacity: 0.6; }

.chat-input::placeholder { color: var(--text-faint); }

.chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.chat-send-btn:hover:not(:disabled) { background: #2450a8; }
.chat-send-btn:active:not(:disabled) { transform: scale(0.95); }
.chat-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Error bubble ──────────────────────────────────────────────────────────── */
.chat-bubble.error {
  background: #fdf0f0;
  border-color: #e9c4c4;
  color: var(--danger);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .chat-container {
    height: calc(100vh - 130px);
    border-radius: 0;
    border-left: none;
    border-right: none;
    margin: 0 -1.25rem; /* bleed to edges */
  }
  .chat-message { max-width: 92%; }
}
