/* ===== H5 访客端 · 亮白主色 / 四套主题 ===== */
:root,
[data-theme="light"] {
  --bg: #eef3fa;
  --bg-2: #e8eefa;
  --panel: #ffffff;
  --panel-2: #f6f9fd;
  --line: rgba(20, 32, 56, 0.08);
  --line-2: rgba(20, 32, 56, 0.15);
  --text: #16203a;
  --text-2: #2b3a57;
  --muted: #66748c;
  --muted-2: #9aa6ba;
  --accent: #4f6ef7;
  --accent-2: #0ea5a4;
  --accent-soft: rgba(79, 110, 247, 0.09);
  --grad: linear-gradient(135deg, #4f6ef7, #6f8bff 55%, #0ea5a4);
  --bubble-in: #f3f7fd;
  --bubble-out: linear-gradient(135deg, #4f6ef7, #6480f8);
  --bubble-out-text: #fff;
  --ok: #12a150;
  --danger: #e5484d;
  --shadow: 0 22px 60px rgba(23, 42, 84, 0.14);
  --head-bg: rgba(255, 255, 255, 0.92);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
[data-theme="dark"] {
  --bg: #0b1120;
  --bg-2: #0e1526;
  --panel: #111a2b;
  --panel-2: #17223a;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #e9eefb;
  --text-2: #cdd8ee;
  --muted: #94a3bd;
  --muted-2: #64748b;
  --accent: #7c93ff;
  --accent-2: #2dd4bf;
  --accent-soft: rgba(124, 147, 255, 0.14);
  --grad: linear-gradient(135deg, #6d8dff, #2fd6c4);
  --bubble-in: #1b2540;
  --bubble-out: linear-gradient(135deg, #4f6ef7, #3f5ee0);
  --bubble-out-text: #f6f9ff;
  --ok: #34d399;
  --danger: #f87171;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  --head-bg: rgba(17, 26, 43, 0.92);
}
[data-theme="blue"] {
  --bg: #e9f1ff;
  --bg-2: #dfeaff;
  --panel: #ffffff;
  --panel-2: #f0f5ff;
  --line: rgba(28, 58, 120, 0.1);
  --line-2: rgba(28, 58, 120, 0.18);
  --text: #10214a;
  --text-2: #23386b;
  --muted: #5570a0;
  --muted-2: #8298bd;
  --accent: #2f6bff;
  --accent-2: #0e8ce0;
  --accent-soft: rgba(47, 107, 255, 0.1);
  --grad: linear-gradient(135deg, #2f6bff, #4c8dff 55%, #0e8ce0);
  --bubble-in: #eaf1ff;
  --bubble-out: linear-gradient(135deg, #2f6bff, #4c8dff);
  --bubble-out-text: #fff;
  --ok: #0f9d58;
  --shadow: 0 22px 60px rgba(24, 58, 130, 0.16);
  --head-bg: rgba(255, 255, 255, 0.92);
}
[data-theme="warm"] {
  --bg: #fbf3e9;
  --bg-2: #f7ecdc;
  --panel: #ffffff;
  --panel-2: #fdf8f1;
  --line: rgba(84, 56, 24, 0.09);
  --line-2: rgba(84, 56, 24, 0.16);
  --text: #352417;
  --text-2: #4d3625;
  --muted: #7d6450;
  --muted-2: #a8917c;
  --accent: #e2683c;
  --accent-2: #c99a2e;
  --accent-soft: rgba(226, 104, 60, 0.1);
  --grad: linear-gradient(135deg, #e2683c, #ec8a4e 55%, #c99a2e);
  --bubble-in: #f9efe2;
  --bubble-out: linear-gradient(135deg, #e2683c, #ec8a4e);
  --bubble-out-text: #fff;
  --ok: #4f9d2f;
  --shadow: 0 22px 60px rgba(96, 62, 28, 0.16);
  --head-bg: rgba(255, 255, 255, 0.92);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(760px 420px at 10% -6%, var(--accent-soft), transparent 62%), var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s ease, color 0.3s ease;
  overflow: hidden;
}

/* ---------- 引导页 ---------- */
.gate { height: 100%; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 24px; box-shadow: var(--shadow); text-align: center;
}
.gate-logo {
  width: 54px; height: 54px; border-radius: 16px; margin: 0 auto 16px;
  background: var(--grad); color: #fff; display: grid; place-items: center;
  font-size: 22px; font-weight: 800;
}
.gate-card h2 { font-size: 17px; margin: 0 0 8px; }
.gate-card p { font-size: 12.5px; color: var(--muted); line-height: 1.8; margin: 0 0 18px; }
.gate-card code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 11.5px; }
.gate-card input {
  width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text); padding: 0 14px; font-size: 14px; margin-bottom: 12px;
  outline: none; font-family: inherit;
}
.gate-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-primary {
  background: var(--grad); color: #fff; border: none; height: 44px; border-radius: 12px;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; width: 100%;
  box-shadow: 0 10px 24px rgba(79, 110, 247, 0.28);
}
.btn-block { display: block; }

/* ---------- 主容器 ---------- */
.shell {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: auto;
}
.chat-card {
  position: relative;
  width: 420px;
  min-width: 320px;
  max-width: 100%;
  height: calc(100vh - 36px);
  max-height: 860px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.24s ease, height 0.24s ease, border-radius 0.2s;
}
.chat-card.wide { width: 760px; }
.chat-card.full { width: calc(100vw - 36px); height: calc(100vh - 36px); max-height: none; }

.h5-head {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  background: var(--head-bg); backdrop-filter: blur(14px); position: relative; z-index: 3;
  padding-top: max(13px, env(safe-area-inset-top));
}
.shop { display: flex; align-items: center; gap: 10px; min-width: 0; }
.shop-logo {
  width: 38px; height: 38px; border-radius: 12px; flex: 0 0 auto;
  background: var(--grad); color: #fff; display: grid; place-items: center;
  font-weight: 800; font-size: 16px; box-shadow: 0 8px 18px rgba(79, 110, 247, 0.28);
}
.shop-txt { min-width: 0; }
.shop-txt b { display: block; font-size: 14.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px; }
.shop-txt span { font-size: 11px; color: var(--muted-2); display: inline-flex; align-items: center; gap: 5px; margin-top: 2px; }
.shop-txt span i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); }
.shop-txt span.on i { background: var(--ok); box-shadow: 0 0 0 3px rgba(18, 161, 80, 0.16); }
.shop-txt span.on { color: var(--ok); }
.head-acts { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  position: relative; width: 34px; height: 34px; border-radius: 10px; border: none;
  background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center;
  transition: 0.16s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.sm { width: 34px; height: 34px; }
.icon-btn .red {
  position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); border: 2px solid var(--panel);
}

/* ---------- 公告条 ---------- */
.ann-bar {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px;
  background: var(--accent-soft); border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--text-2); flex: 0 0 auto;
}
.ann-ic { font-size: 13px; flex: 0 0 auto; }
.ann-scroll { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ann-more { border: none; background: none; color: var(--accent); font-size: 11.5px; cursor: pointer; font-family: inherit; flex: 0 0 auto; }

/* ---------- 消息区 ---------- */
.h5-body {
  flex: 1; overflow-y: auto; padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 13px;
  scroll-behavior: smooth;
}
.h5-body::-webkit-scrollbar { width: 6px; }
.h5-body::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; }

.welcome { text-align: center; padding: 26px 14px 10px; }
.welcome .wlogo {
  width: 52px; height: 52px; border-radius: 16px; margin: 0 auto 12px;
  background: var(--grad); color: #fff; display: grid; place-items: center; font-size: 21px; font-weight: 800;
  box-shadow: 0 10px 24px rgba(79, 110, 247, 0.3);
}
.welcome h3 { margin: 0 0 6px; font-size: 15px; }
.welcome p { margin: 0 auto; font-size: 12.5px; color: var(--muted); line-height: 1.85; max-width: 300px; }
.welcome .quick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.welcome .quick button {
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2);
  font-size: 12px; padding: 7px 12px; border-radius: 20px; cursor: pointer; font-family: inherit;
}
.welcome .quick button:hover { border-color: var(--accent); color: var(--accent); }

.msg { display: flex; gap: 9px; max-width: 84%; animation: rise 0.24s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } }
.bubble {
  padding: 9px 13px; border-radius: 4px 15px 15px 15px;
  background: var(--bubble-in); border: 1px solid var(--line);
  font-size: 13.8px; line-height: 1.62; word-break: break-word; white-space: pre-wrap;
}
.meta { font-size: 10px; color: var(--muted-2); margin-top: 4px; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.me .bubble { background: var(--bubble-out); color: var(--bubble-out-text); border: none; border-radius: 15px 4px 15px 15px; box-shadow: 0 6px 16px rgba(79, 110, 247, 0.2); }
.msg.me .meta { text-align: right; }
.msg.sys { align-self: center; max-width: 92%; }
.msg.sys .bubble {
  background: var(--panel-2); border: 1px dashed var(--line-2); color: var(--muted);
  font-size: 12px; border-radius: 18px; padding: 7px 14px; text-align: center;
}
.msg.sys .ava, .msg.sys .meta { display: none; }
.msg.ai .bubble { border-color: rgba(14, 165, 164, 0.28); background: var(--accent-soft); }
.ava {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  background: var(--accent-soft); color: var(--accent); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.msg.ai .ava { color: var(--accent-2); background: rgba(14, 165, 164, 0.12); }
.day-sep { align-self: center; font-size: 10.5px; color: var(--muted-2); background: var(--panel-2); padding: 3px 11px; border-radius: 20px; }
.bubble .pic { display: block; max-width: 180px; max-height: 230px; border-radius: 10px; cursor: zoom-in; }

.typing { height: 16px; padding: 0 18px; font-size: 11px; color: var(--muted-2); flex: 0 0 auto; }

/* ---------- 输入区 ---------- */
.h5-foot {
  flex: 0 0 auto; border-top: 1px solid var(--line); background: var(--panel);
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
}
.composer { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; min-height: 42px; max-height: 130px; resize: none; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 11px 14px; font-size: 13.8px; line-height: 1.5; font-family: inherit; outline: none;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.send {
  width: 42px; height: 42px; border-radius: 13px; border: none; cursor: pointer;
  background: var(--grad); color: #fff; display: grid; place-items: center; flex: 0 0 auto;
  box-shadow: 0 8px 18px rgba(79, 110, 247, 0.3); transition: 0.16s;
}
.send svg { width: 18px; height: 18px; }
.send:disabled { opacity: 0.5; cursor: not-allowed; }
.h5-foot-note {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 10.5px; color: var(--muted-2); margin-top: 8px; min-height: 14px;
}
.h5-foot-note a { color: var(--accent); }

/* ---------- 拖拽缩放 ---------- */
.resizer {
  position: absolute; right: 0; top: 72px; bottom: 72px; width: 8px;
  cursor: ew-resize; z-index: 4;
}
.resizer::after {
  content: ""; position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 42px; border-radius: 3px; background: var(--line-2); opacity: 0;
  transition: 0.2s;
}
.chat-card:hover .resizer::after { opacity: 1; }

/* ---------- Lightbox ---------- */
#lightbox { position: fixed; inset: 0; background: rgba(10, 16, 30, 0.88); display: none; align-items: center; justify-content: center; z-index: 99; padding: 20px; }
#lightbox.on { display: flex; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }

/* ---------- 公告弹层 ---------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(16, 26, 46, 0.4); backdrop-filter: blur(4px);
  display: none; align-items: flex-end; justify-content: center; z-index: 80;
}
.sheet-mask.on { display: flex; }
.sheet {
  width: 100%; max-width: 520px; background: var(--panel); border-radius: 20px 20px 0 0;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom)); max-height: 76vh; overflow: auto;
  animation: up 0.24s ease;
}
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet h3 { margin: 0 0 14px; font-size: 15px; display: flex; align-items: center; justify-content: space-between; }
.sheet h3 button { border: none; background: none; font-size: 20px; color: var(--muted-2); cursor: pointer; line-height: 1; }
.ann-item { border: 1px solid var(--line); border-radius: 13px; padding: 14px; margin-bottom: 10px; background: var(--panel-2); }
.ann-item h4 { margin: 0 0 6px; font-size: 13.5px; display: flex; gap: 7px; align-items: center; }
.ann-item p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.8; white-space: pre-wrap; }
.ann-item .t { font-size: 10.5px; color: var(--muted-2); margin-top: 8px; }

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  .shell { padding: 0; align-items: stretch; }
  .chat-card, .chat-card.wide, .chat-card.full {
    width: 100% !important; max-width: 100%; height: 100% !important; max-height: none;
    border-radius: 0; border: none; box-shadow: none;
  }
  .resizer { display: none; }
  .shop-txt b { max-width: 150px; }
}

/* ---------- 嵌入模式（iframe: /h5/?code=xxx&embed=1） ---------- */
body.embed { background: transparent; }
body.embed .shell { padding: 0; align-items: stretch; }
body.embed .chat-card,
body.embed .chat-card.wide,
body.embed .chat-card.full {
  width: 100% !important; max-width: 100%; height: 100% !important; max-height: none;
  border-radius: 0; border: none; box-shadow: none; margin: 0;
}
body.embed .resizer { display: none; }
body.embed .h5-foot-note #poweredBy { display: none; }
