:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #7b8794;
  --line: #e4e7eb;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --user: #0f766e;
  --agent: #ffffff;
  --danger: #b91c1c;
  --composer-height: 68px;
  --keyboard-inset: 0px;
}
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
}
.app {
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  background: var(--card);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 0 1px var(--line);
  position: relative;
}
header {
  padding: 14px 16px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
header h1 { margin: 0; font-size: 16px; font-weight: 650; }
header p { margin: 2px 0 0; font-size: 12px; opacity: .85; }
.messages {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 12px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg);
}
body.manual-keyboard .messages {
  padding-bottom: calc(16px + var(--composer-height) + var(--keyboard-inset) + env(safe-area-inset-bottom, 0px));
}
.bubble {
  flex-shrink: 0;
  max-width: 82%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.agent {
  align-self: flex-start;
  background: var(--agent);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.bubble.user {
  align-self: flex-end;
  background: var(--user);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble img,
.bubble video {
  display: block; max-width: 220px; border-radius: 8px; margin-top: 6px;
}
.bubble video { max-height: 200px; background: #000; }
.meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.bubble.user .meta { color: rgba(255,255,255,.75); }
.status {
  flex-shrink: 0;
  align-self: center; font-size: 12px; color: var(--muted); padding: 4px 0;
}
.status.error { color: var(--danger); }
form.composer input[type="file"] {
  display: none !important;
  visibility: hidden !important;
  width: 0 !important;
  height: 0 !important;
  position: fixed !important;
  left: -9999px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
form.composer {
  flex-shrink: 0;
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line); background: #fff;
  min-width: 0;
  z-index: 20;
}
body.manual-keyboard form.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--keyboard-inset) + env(safe-area-inset-bottom, 0px));
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 14px;
}
textarea {
  flex: 1 1 auto; min-width: 0; width: 100%; max-width: 100%;
  resize: none; box-sizing: border-box;
  height: 44px; min-height: 44px; max-height: 120px;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font: inherit; font-size: 14px; line-height: 20px;
  overflow-y: auto; -webkit-appearance: none; appearance: none;
}
textarea:focus { outline: none; border-color: var(--brand); }
.attach-wrap {
  flex-shrink: 0;
  width: 40px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.attach-wrap.is-disabled { opacity: .5; pointer-events: none; cursor: not-allowed; }
.media-input-hidden {
  display: none !important;
  position: fixed;
  left: -9999px;
  top: 0;
  width: 0;
  height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}
.attach-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
}
.attach-icon img {
  display: block;
  width: 22px;
  height: 22px;
  object-fit: contain;
  filter: invert(1);
  opacity: 0.72;
}
button.send {
  flex-shrink: 0;
  height: 44px;
  border: none; background: var(--brand); color: #fff;
  border-radius: 10px; padding: 0 16px; font-size: 14px; line-height: 44px;
  white-space: nowrap; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button.send:disabled { opacity: .5; cursor: not-allowed; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 13px; }

.browser-guide {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  padding: 20px; background: rgba(15, 23, 42, 0.45);
}
.browser-guide.is-open { display: flex; }
.browser-guide-panel {
  width: 100%; max-width: 340px; background: #fff; border-radius: 14px;
  padding: 20px 18px 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.browser-guide-lead {
  margin: 0 0 16px; font-size: 15px; line-height: 1.55; color: var(--text);
  text-align: center;
}
.browser-guide-actions { display: flex; flex-direction: column; gap: 8px; }
.browser-guide-actions button {
  border: none; border-radius: 10px; padding: 11px 14px; font-size: 14px; cursor: pointer;
}
.browser-guide-actions .primary {
  background: var(--brand); color: #fff;
}
.browser-guide-tip {
  margin-top: 10px; font-size: 12px; color: var(--muted); text-align: center;
}

/* 主题色（:root 绿色为默认，与后台 green 一致） */
.app[data-webchat-theme="yellow"] { --brand: #ca8a04; --brand-dark: #a16207; --user: #ca8a04; }
.app[data-webchat-theme="red"] { --brand: #dc2626; --brand-dark: #b91c1c; --user: #dc2626; }
.app[data-webchat-theme="blue"] { --brand: #2563eb; --brand-dark: #1d4ed8; --user: #2563eb; }
.app[data-webchat-theme="black"] { --brand: #27272a; --brand-dark: #18181b; --user: #3f3f46; }
.app[data-webchat-theme="orange"] { --brand: #ea580c; --brand-dark: #c2410c; --user: #ea580c; }
.app[data-webchat-theme="gold"] { --brand: #ffa62b; --brand-dark: #e08a18; --user: #ffa62b; }
.app[data-webchat-theme="lemon"] { --brand: #ffde12; --brand-dark: #e6c800; --user: #ffde12; }
.app[data-webchat-theme="wine"] { --brand: #a81e32; --brand-dark: #8a1929; --user: #a81e32; }
.app[data-webchat-theme="lemon"] header {
  color: #1f2933;
}
.app[data-webchat-theme="lemon"] header p { opacity: 0.75; }
.app[data-webchat-theme="lemon"] .avatar { background: rgba(0, 0, 0, 0.08); color: #1f2933; }
.app[data-webchat-theme="lemon"] .bubble.user { color: #1f2933; }
.app[data-webchat-theme="lemon"] .bubble.user .meta { color: rgba(31, 41, 51, 0.65); }
.app[data-webchat-theme="lemon"] button.send { color: #1f2933; }
