:root {
  --bg-paper: #FAF8F5;
  --bg-card: #FFFFFF;
  --bg-subtle: #EFEAE2;
  --slate-dark: #1F2733;
  --slate-muted: #5C6778;
  --copper: #C75B26;
  --copper-bright: #E8834B;
  --border-light: #E2DBD0;
  --green-online: #22C55E;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-paper);
  color: var(--slate-dark);
  -webkit-font-smoothing: antialiased;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background-color: var(--bg-paper);
  border-left: 1px solid var(--border-light);
  border-right: 1px solid var(--border-light);
  overflow: hidden;
}

/* Chat Header */
.chat-header {
  flex-shrink: 0;
  background-color: var(--slate-dark);
  color: #FFFFFF;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
  flex-shrink: 0;
}

.back-link:hover {
  background: rgba(255, 255, 255, 0.2);
}

.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--copper-bright);
  flex-shrink: 0;
}

.chat-title-wrap {
  min-width: 0;
}

.chat-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--green-online);
  flex-shrink: 0;
}

/* Messages Scroll Area */
.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: var(--bg-paper);
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 84%;
}

.msg-row.bot {
  align-self: flex-start;
}

.msg-row.user {
  align-self: flex-end;
}

.msg-bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.48;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg-row.bot .msg-bubble {
  background-color: var(--bg-card);
  color: var(--slate-dark);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(31, 39, 51, 0.04);
}

.msg-row.user .msg-bubble {
  background-color: var(--copper);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}

.msg-bubble a {
  color: var(--copper);
  font-weight: 600;
  text-decoration: underline;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  font-size: 0.85rem;
  color: var(--slate-muted);
}

.typing-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--copper);
  animation: blink 1.2s infinite both;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* Bottom Area: Quick Chips + Composer */
.chat-footer {
  flex-shrink: 0;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-light);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
}

.quick-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}

.quick-chips::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  flex-shrink: 0;
  background-color: var(--bg-paper);
  color: var(--slate-dark);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  padding: 6px 13px;
  font-family: 'Inter', sans-serif;
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.chip-btn:hover {
  border-color: var(--copper);
  background-color: rgba(199, 91, 38, 0.06);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--border-light);
  border-radius: 20px;
  padding: 10px 15px;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--slate-dark);
  background-color: var(--bg-paper);
  min-height: 44px;
  max-height: 126px; /* ~5 lines */
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s ease;
}

.chat-textarea:focus {
  border-color: var(--copper);
  background-color: #FFFFFF;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background-color: var(--copper);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.send-btn:hover {
  background-color: var(--copper-bright);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 760px) {
  .chat-shell {
    border-left: none;
    border-right: none;
  }
}
