:root {
  --bg-a: #0f2f2c;
  --bg-b: #1a4a45;
  --bg-c: #e8f3f1;
  --panel: #ffffff;
  --ink: #14312e;
  --muted: #5f7a76;
  --line: #d5e6e2;
  --accent: #0f8a75;
  --accent-dark: #0a6b5b;
  --visitor: #0f8a75;
  --agent: #f3f8f7;
  --system: #eef4f3;
  --shadow: 0 18px 50px rgba(15, 47, 44, 0.18);
  --radius: 18px;
  --font: "Noto Sans SC", "DM Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a7a6e 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #c9ebe3 0%, transparent 45%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b) 40%, var(--bg-c));
}

.page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}

.chat-shell {
  width: min(440px, 100%);
  height: min(780px, calc(100vh - 32px));
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: rise 0.45s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.chat-header {
  padding: 16px 18px;
  background: linear-gradient(135deg, #0f8a75, #146f63);
  color: #fff;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.35), transparent),
    #0a5f51;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 11px 10px 10px 11px;
  border: 2.5px solid #fff; border-radius: 50%;
  border-right-color: transparent; transform: rotate(-20deg);
}
.chat-header h1 { margin: 0; font-size: 1.1rem; font-weight: 700; letter-spacing: .02em; }
.chat-header p { margin: 2px 0 0; font-size: .8rem; opacity: .88; }

.welcome-banner {
  margin: 12px 12px 0;
  padding: 12px 36px 12px 14px;
  background: linear-gradient(180deg, #f4fbf9, #eaf6f3);
  border: 1px solid var(--line);
  border-radius: 12px;
  position: relative;
  animation: fadeIn .35s ease both;
}
.welcome-banner p { margin: 0; font-size: .92rem; line-height: 1.5; color: var(--ink); }
.welcome-close {
  position: absolute; right: 8px; top: 6px;
  border: 0; background: transparent; font-size: 1.2rem;
  color: var(--muted); cursor: pointer;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px);} to { opacity: 1; transform: none;} }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    linear-gradient(180deg, rgba(232,243,241,.55), transparent 80px),
    #f7fbfa;
}

.msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: bubble .25s ease both;
}
@keyframes bubble {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.msg.visitor { align-self: flex-end; }
.msg.agent, .msg.system { align-self: flex-start; }
.msg .meta { font-size: .72rem; color: var(--muted); padding: 0 4px; }
.msg .bubble {
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  font-size: .95rem;
}
.msg.visitor .bubble {
  background: var(--visitor);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.agent .bubble {
  background: var(--agent);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg.system .bubble {
  background: var(--system);
  color: var(--muted);
  font-size: .85rem;
  border-radius: 10px;
}
.msg .bubble img {
  display: block;
  max-width: min(240px, 70vw);
  border-radius: 10px;
  cursor: zoom-in;
}
.msg .emoji-only { font-size: 1.7rem; line-height: 1.2; }

.emoji-panel {
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 8px 10px;
  max-height: 150px;
  overflow-y: auto;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.emoji-grid button {
  border: 0; background: transparent; font-size: 1.35rem;
  padding: 6px; border-radius: 8px; cursor: pointer;
}
.emoji-grid button:hover { background: #eef6f4; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: #f7fbfa;
  cursor: pointer; font-size: 1.1rem; color: var(--ink);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; font: inherit;
  min-height: 40px; max-height: 110px; outline: none;
  background: #fafcfb;
}
.composer textarea:focus { border-color: var(--accent); }
.send-btn {
  border: 0; background: var(--accent); color: #fff;
  border-radius: 12px; padding: 0 16px; height: 40px;
  font-weight: 600; cursor: pointer;
}
.send-btn:hover { background: var(--accent-dark); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 520px) {
  .page { padding: 0; }
  .chat-shell {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
}

/* iframe 嵌入模式 */
body.embed {
  background: #fff;
}
body.embed .page {
  padding: 0;
  min-height: 100%;
}
body.embed .chat-shell {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  border-radius: 0;
  box-shadow: none;
}
