:root {
  color-scheme: light;
  --ink: #16202a;
  --muted: #687683;
  --line: #dfe5e8;
  --surface: #ffffff;
  --soft: #f4f6f7;
  --orange: #ef780d;
  --orange-soft: #fff4e8;
  --green: #0f8a6a;
  --green-soft: #eaf8f3;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: #eef1f2;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  letter-spacing: 0;
}

button, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .62; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 2026-09-11 老板要求：头部固定在顶部，不随聊天长度滚动。
   做法：整个应用锁定为视口高度（height:100%，body 已是 100%），
   三行 grid（头部/内容/输入）里只有消息列表内部滚动 —— 头部和输入框永远焊在顶/底。 */
.public-shell {
  width: min(100%, 1040px);
  /* 键盘弹起时 JS 会把 --kb-pad 设为被挡高度，整体收缩 → 输入框贴在键盘上方 */
  height: calc(100% - var(--kb-pad, 0px));
  margin: 0 auto;
  background: var(--surface);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  box-shadow: 0 0 32px rgba(28, 42, 52, .09);
}

.public-header {
  min-height: 78px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.public-brand,
.public-header-actions,
.public-quick-actions,
.public-composer {
  display: flex;
  align-items: center;
}

.public-brand { gap: 12px; min-width: 0; }

/* 头像 = 大商严选 logo（2026-09-11 老板提供）。
   logo 本身是白底紫标：白底 + 细边框 + 轻投影，46px 与头部高度协调。 */
.public-brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(28, 42, 52, .10);
}

.public-brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
}

.public-brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.public-header-actions { gap: 10px; }

.public-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.public-status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.public-quiet-button,
.public-quick-actions button,
.public-starters button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #3e4b55;
}

.public-quiet-button { padding: 0 14px; }

.public-chat {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.public-messages {
  min-height: 0;
  overflow-y: auto;
  padding: 30px max(24px, calc((100% - 820px) / 2));
  scroll-behavior: smooth;
}

/* 2026-09-11 老板要求：气泡宽度按实际文字长度自适应，不要固定占满。
   fit-content 让短句就是短气泡，长句撑到 max-width 再换行。 */
.public-message {
  width: fit-content;
  max-width: min(78%, 680px);
  margin-bottom: 22px;
}

.public-message > span {
  display: block;
  margin-bottom: 6px;
  color: #83909a;
  font-size: 12px;
  font-weight: 700;
}

.public-message > div {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  line-height: 1.75;
  word-break: break-word;
  box-shadow: 0 7px 20px rgba(30, 44, 54, .05);
}

.public-message.is-user {
  margin-left: auto;
}

.public-message.is-user > span { text-align: right; }
/* 客户气泡：微信绿（与微信聊天一致）。文字用深色保证对比度。 */
.public-message.is-user > div {
  border-color: #87d95f;
  background: #95ec69;
  color: #10240b;
}

.public-message.is-assistant > div { border-left: 3px solid #aab7bf; }
.public-message.is-greeting > div { border-left-color: var(--green); }

/* 常用语快捷栏（2026-09-11 老板要求：常驻显示，客户随时可点）。
   紧贴输入框上方、浅灰底与输入区连成一体，胶囊小按钮 —— 参考微信快捷回复样式。 */
.public-starters {
  padding: 8px max(12px, calc((100% - 860px) / 2)) 8px;
  border-top: 1px solid var(--line);
  background: #f7f7f7;
}

.public-starters[hidden] { display: none; }
.public-starters p { margin: 0 0 6px; color: var(--muted); font-size: 12px; }
.public-starters > div { display: flex; flex-wrap: wrap; gap: 8px; }
.public-starters button {
  padding: 0 14px;
  min-height: 32px;
  border-radius: 999px;
  border-color: #d9dde1;
  font-size: 13px;
}
.public-starters button:hover,
.public-quick-actions button:hover { border-color: #f2b370; color: #b84c00; }

.public-composer-wrap {
  padding: 8px max(12px, calc((100% - 860px) / 2)) 14px;
  border-top: 1px solid var(--line);
  background: #f7f7f7;
}

.public-quick-actions { margin-bottom: 8px; }
.public-quick-actions button { padding: 0 12px; color: var(--green); }

/* 输入栏参考微信原生样式（2026-09-11 老板要求）：
   浅灰底、白色圆角输入框、右侧微信绿(#07c160)发送按钮、白字。 */
.public-composer {
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  align-items: flex-end;
}

.public-composer textarea {
  width: 100%;
  min-height: 38px;
  max-height: 120px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 9px 12px;
  color: var(--ink);
  background: #fff;
  border-radius: 6px;
  line-height: 1.55;
  box-shadow: inset 0 0 0 0.5px #dcdfe3;
}

.public-composer textarea::placeholder { color: #9aa6ae; }

.public-composer button {
  min-width: 62px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: #07c160;
  font-size: 15px;
  font-weight: 500;
}

.public-composer button:disabled { background: #a5dbb8; }

.public-privacy {
  margin: 8px 2px 0;
  color: #8a969e;
  font-size: 11px;
  line-height: 1.5;
}

@media (max-width: 640px) {
  .public-header { min-height: 70px; padding: 11px 14px; }
  .public-brand-mark { width: 40px; height: 40px; flex-basis: 40px; font-size: 19px; }
  .public-brand h1 { font-size: 17px; }
  .public-brand p { font-size: 11px; }
  .public-status { display: none; }
  .public-quiet-button { min-height: 34px; padding: 0 10px; }
  .public-messages { padding: 18px 12px; }
  .public-message { max-width: 88%; margin-bottom: 16px; }
  .public-message > div { padding: 10px 12px; font-size: 14px; }
  .public-composer-wrap { padding: 6px 8px 10px; }
  .public-composer textarea { min-height: 34px; padding: 8px 10px; }
  .public-composer button { min-width: 54px; height: 34px; padding: 0 12px; font-size: 14px; }
  .public-starters { padding: 0 14px 16px; }
  .public-starters > div { display: grid; grid-template-columns: 1fr 1fr; }
  .public-composer-wrap { padding: 10px 10px 12px; }
  .public-composer { gap: 5px; padding: 6px; }
  .public-composer button { width: 64px; flex-basis: 64px; }
}

/* ============================================================
   大商小智 · 移动端/微信适配（2026-09-11）
   ============================================================ */

/* 返回箭头：只在浏览器直接打开时显示。
   微信 web-view 里微信自带原生导航栏（含返回 + 标题），
   再画一条就是双导航栏，所以 JS 会给 body 加 .in-webview 把它藏掉。 */
.public-back {
  display: none;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  margin-right: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  align-items: center;
  justify-content: center;
}
body:not(.in-webview) .public-back { display: inline-flex; }
.public-back:active { background: var(--soft); }

/* web-view 模式：整条自有头部藏掉（微信导航栏已显示"大商小智"），
   "新对话"入口挪到底部快捷区，功能不丢。 */
body.in-webview .public-header { display: none; }
body.in-webview #new-chat-webview { display: inline-flex; }
#new-chat-webview { display: none; }

/* 键盘弹起适配：JS 通过 visualViewport 计算 --kb-pad（键盘顶起的高度），
   现在作用于 .public-shell 的高度收缩（上面），输入区本身不再加 padding ——
   否则双重补偿会把输入框顶出屏幕外（2026-09-11 头部固定改造时一并调整）。 */
.public-composer-wrap {
  padding-bottom: 14px;
  transition: padding-bottom .12s ease-out;
}
/* 键盘弹起时把隐私提示藏掉，给内容区腾地方 */
body.keyboard-open .public-privacy { display: none; }
/* 安全区（全面屏底部横条），env() 不支持时回退 0 */
@supports (padding: env(safe-area-inset-bottom)) {
  .public-composer-wrap {
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }
}

/* 客户气泡绿底，发送者标签也随绿（保持品牌一致） */
.public-message.is-user > span { color: #4d7c3f; }
