/* ── Layout shell ──────────────────────────────────────────── */
html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;   /* prevent any child from widening the page */
  margin: 0;
  padding: 0;
}

.chat-shell {
  width: 100%;
  max-width: 100vw;     /* hard cap on mobile */
  box-sizing: border-box;
  height: 100dvh;       /* dynamic: shrinks when keyboard opens */
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

@media (min-width: 640px) {
  .chat-shell {
    max-width: 680px;
    height: 90vh;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
    overflow: hidden;
  }
}

/* ── Chat body ─────────────────────────────────────────────── */
.chat-body {
  flex: 1;
  min-height: 0;          /* critical: lets flex child shrink and scroll */
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8fafc;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Prevent iOS Safari from zooming on textarea focus (requires font-size >= 16px) */
@media (max-width: 639px) {
  #message { font-size: 16px; }
}

/* smooth scrollbar on desktop */
.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }
.chat-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }

/* ── Bubbles ───────────────────────────────────────────────── */
.bubble {
  width: 100%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 14.5px;
  word-break: break-word;
  animation: bubbleIn 0.18s ease-out both;
  box-sizing: border-box;
}

.bubble.agent {
  background: #ffffff;
  color: #1e293b;
  text-align: left;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(15,23,42,0.07);
}

.bubble.user {
  background: #4f46e5;
  color: #ffffff;
  text-align: right;
  border-bottom-right-radius: 4px;
}

/* ── Typing indicator ──────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.typing-bubble {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}

.typing-bubble span {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typingDot 1.2s ease-in-out infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

/* ── Animations ────────────────────────────────────────────── */
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1; }
}
