:root {
  --bg: #e8f2ea;
  --bg-deep: #d5e8da;
  --surface: #f7fbf7;
  --ink: #14201a;
  --muted: #5a6f62;
  --line: rgba(20, 32, 26, 0.1);
  --brand: #1f6b45;
  --brand-2: #2f8f5b;
  --brand-soft: rgba(31, 107, 69, 0.12);
  --danger: #b42318;
  --danger-soft: rgba(180, 35, 24, 0.1);
  --visitor-bubble: #ffffff;
  --agent-bubble: #1f6b45;
  --system: #6b7c72;
  --shadow: 0 18px 50px rgba(20, 48, 32, 0.12);
  --radius: 18px;
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --display: "Outfit", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.7rem 1.2rem;
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-secondary {
  background: rgba(255,255,255,0.7);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.875rem; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
}
.brand-mark {
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 6px 18px rgba(20, 48, 32, 0.08);
  font-size: 1.1rem;
}
.brand-text {
  font-family: var(--display);
  letter-spacing: 0.02em;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.msg {
  max-width: min(78%, 420px);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  animation: rise 0.28s ease;
}
.msg-visitor { align-self: flex-end; align-items: flex-end; }
.msg-agent, .msg-system, .msg-bot { align-self: flex-start; align-items: flex-start; }
.msg-system { max-width: 90%; align-self: center; align-items: center; }

.bubble {
  padding: 0.7rem 0.95rem;
  border-radius: 16px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}
.msg-visitor .bubble {
  background: var(--agent-bubble);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg-agent .bubble,
.msg-bot .bubble {
  background: var(--visitor-bubble);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg-bot .bubble {
  border-color: rgba(31, 107, 69, 0.28);
  background: #f2faf5;
}
.msg-system .bubble {
  background: transparent;
  color: var(--system);
  box-shadow: none;
  font-size: 0.82rem;
  padding: 0.2rem 0.5rem;
  text-align: center;
}
.meta {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0 0.2rem;
}

.composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(8px);
}
.composer input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.75rem 1rem;
  font: inherit;
  background: #fff;
  outline: none;
}
.composer input:focus {
  border-color: rgba(31, 107, 69, 0.45);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.composer-icon {
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
}
.composer-icon:hover:not(:disabled) {
  border-color: rgba(31, 107, 69, 0.45);
  background: var(--brand-soft);
}
.composer-icon:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.bubble-image {
  padding: 0.35rem !important;
  background-clip: padding-box;
}
.bubble-image img {
  display: block;
  max-width: min(220px, 70vw);
  max-height: 280px;
  border-radius: 12px;
  cursor: zoom-in;
}
.msg-visitor .bubble-image img {
  border-bottom-right-radius: 4px;
}
.msg-agent .bubble-image img,
.msg-bot .bubble-image img {
  border-bottom-left-radius: 4px;
}
.img-caption {
  padding: 0.35rem 0.45rem 0.2rem;
  font-size: 0.85rem;
}

.typing-bar {
  padding: 0 1.1rem 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 720px) {
  .msg { max-width: 88%; }
}
