/* 智能客服聊天 UI —— 移动端优先，桌面浏览时居中显示成手机外观 */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --primary: #4f6ef7;
  --primary-dark: #3d5bd9;
  --bg: #ededed;
  --bubble-me: #95ec69;
  --bubble-agent: #ffffff;
  --text: #1a1a1a;
  --text-sub: #8a8a8a;
  --topbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
}
body { display: flex; justify-content: center; }

/* 手机容器：手机上满屏；PC 上居中手机框 */
.app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
@media (min-width: 520px) {
  body { background: #d9dde6; align-items: center; }
  .app {
    height: min(92vh, 900px);
    border-radius: 18px;
    box-shadow: 0 18px 60px rgba(0,0,0,.25);
  }
}

/* 顶栏 */
.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top, 0px);
  z-index: 5;
}
.agent-avatar { position: relative; width: 40px; height: 40px; flex: 0 0 auto; }
.agent-avatar img { border-radius: 50%; display: block; background: #fff; }
.online-dot {
  position: absolute; right: 0; bottom: 0;
  width: 11px; height: 11px; border-radius: 50%;
  background: #2ecc71; border: 2px solid var(--primary);
}
.agent-meta { flex: 1; min-width: 0; }
.agent-name { font-size: 16px; font-weight: 600; line-height: 1.25; }
.agent-status { font-size: 12px; opacity: .85; }
.install-btn {
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.7);
  background: rgba(255,255,255,.15);
  color: #fff; border-radius: 14px;
  font-size: 12px; padding: 5px 10px;
}

/* 消息区 */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.time-tip, .sys-tip {
  align-self: center;
  font-size: 12px;
  color: var(--text-sub);
  background: rgba(0,0,0,.08);
  padding: 3px 9px;
  border-radius: 8px;
  max-width: 80%;
  text-align: center;
}
.row { display: flex; width: 100%; gap: 8px; }
.row.me { flex-direction: row-reverse; }
.row .avatar {
  width: 36px; height: 36px; border-radius: 6px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff; overflow: hidden;
}
.row.agent .avatar { background: var(--primary); }
.row.agent .avatar img { width: 100%; height: 100%; }
.row.me .avatar { background: #5fa93f; }
.bubble {
  position: relative;
  max-width: calc(100% - 90px);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}
.bubble-agent { background: var(--bubble-agent); border-top-left-radius: 2px; }
.bubble-me { background: var(--bubble-me); border-top-right-radius: 2px; }
.bubble a { color: var(--primary-dark); word-break: break-all; }
.bubble.error { background: #fff1f0; color: #cf1322; border: 1px solid #ffccc7; }
.msg-meta { font-size: 11px; color: var(--text-sub); margin-top: 3px; }
.row.me .msg-meta { text-align: right; }

/* 正在输入 */
.typing { flex: 0 0 auto; padding: 0 12px 6px; }
.dots { display: inline-flex; gap: 5px; padding: 2px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: #b0b0b0; animation: blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* 输入区 */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: #f7f7f7;
  border-top: 1px solid #e0e0e0;
}
#input {
  flex: 1;
  resize: none;
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 16px; /* >=16px 防止 iOS 聚焦缩放 */
  line-height: 1.4;
  max-height: 120px;
  background: #fff;
  outline: none;
  font-family: inherit;
}
.send-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border: none; border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, background .15s;
}
.send-btn:disabled { opacity: .45; }
.send-btn:active { background: var(--primary-dark); }

/* ============ 视图切换 ============ */
.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }
.icon-btn {
  flex: 0 0 auto; width: 36px; height: 36px; border: none; border-radius: 50%;
  background: transparent; color: #fff; display: flex; align-items: center;
  justify-content: center; padding: 0;
}
.icon-btn:active { background: rgba(255,255,255,.2); }
.icon-btn.light { color: #fff; width: auto; padding: 0 8px; font-size: 15px; gap: 2px; }

/* ============ 注册视图 ============ */
.view-register { background: #f5f6fa; }
.reg-topbar {
  flex: 0 0 auto; height: 52px; background: var(--primary); color: #fff;
  display: flex; align-items: center; padding: 0 8px;
  padding-top: env(safe-area-inset-top, 0px);
  font-size: 17px; font-weight: 600;
}
.reg-topbar span { margin-left: 6px; }
.reg-scroll { flex: 1 1 auto; overflow-y: auto; padding: 0 22px 24px; }
.reg-head { text-align: center; padding: 26px 0 18px; }
.reg-logo { border-radius: 16px; box-shadow: 0 8px 24px rgba(79,110,247,.3); background:#fff; }
.reg-head h2 { font-size: 21px; margin: 12px 0 6px; color: #1a1a1a; }
.reg-head p { font-size: 13px; color: var(--text-sub); }
.switch-page {
  margin-top: 4px; border: none; background: transparent; padding: 8px;
  font-size: 14px; color: var(--text-sub); font-family: inherit; cursor: pointer;
  width: 100%; text-align: center;
}
.switch-page b { color: var(--primary); font-weight: 600; margin-left: 2px; }
.switch-page:active { opacity: .6; }
.reg-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 14px; color: #444; font-weight: 500; }
.field-label em { color: #f0483e; font-style: normal; }
.field input {
  height: 46px; border: 1px solid #dfe2ea; border-radius: 10px;
  padding: 0 13px; font-size: 16px; background: #fff; outline: none;
  font-family: inherit; width: 100%;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,.12); }
.addr-pick {
  min-height: 46px; border: 1px solid #dfe2ea; border-radius: 10px;
  background: #fff; padding: 10px 13px; display: flex; align-items: center;
  gap: 8px; text-align: left; font-family: inherit; width: 100%;
}
.addr-pick-text { flex: 1; font-size: 15px; color: #9aa0ad; line-height: 1.4; word-break: break-all; }
.addr-pick.filled .addr-pick-text { color: #1a1a1a; }
.addr-pick:active { border-color: var(--primary); }
.reg-err {
  background: #fff1f0; border: 1px solid #ffccc7; color: #cf1322;
  border-radius: 8px; padding: 9px 12px; font-size: 13px; line-height: 1.5;
}
.reg-submit {
  margin-top: 6px; height: 48px; border: none; border-radius: 24px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 600;
  font-family: inherit; width: 100%;
}
.reg-submit:active { background: var(--primary-dark); }
.reg-submit:disabled { opacity: .55; }
.reg-tip { text-align: center; font-size: 12px; color: var(--text-sub); margin-top: 2px; }

/* ============ 地图选点弹层 ============ */
.sheet {
  position: absolute; inset: 0; z-index: 50;
  background: #f5f6fa; display: flex; flex-direction: column;
}
.sheet[hidden] { display: none; }
.map-top {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: #fff; border-bottom: 1px solid #ececec;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  position: relative;
}
.map-back {
  flex: 0 0 auto; width: 36px; height: 36px; border: none; background: transparent;
  color: #333; display: flex; align-items: center; justify-content: center;
}
.map-search { flex: 1; position: relative; display: flex; align-items: center; }
.map-search-ic { position: absolute; left: 11px; flex: 0 0 auto; }
.map-search input {
  width: 100%; height: 38px; border: none; border-radius: 19px;
  background: #f0f1f5; padding: 0 38px 0 34px; font-size: 15px; outline: none;
  font-family: inherit;
}
.map-tips {
  position: absolute; top: 44px; left: 0; right: 0; z-index: 10;
  background: #fff; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15);
  max-height: 300px; overflow-y: auto;
}
.tip-item { padding: 10px 14px; border-bottom: 1px solid #f4f4f4; cursor: pointer; }
.tip-item:last-child { border-bottom: none; }
.tip-item .t-name { font-size: 14px; color: #1a1a1a; line-height: 1.4; }
.tip-item .t-addr { font-size: 12px; color: #909399; margin-top: 2px; line-height: 1.4; }
.tip-item:active, .tip-item.active { background: #f0f4ff; }
.map-body { flex: 1 1 auto; position: relative; min-height: 0; }
.map-canvas { position: absolute; inset: 0; }
.map-manual {
  position: absolute; inset: 0; padding: 20px 18px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.manual-title { font-size: 14px; color: #444; line-height: 1.6; }
.map-manual textarea {
  width: 100%; border: 1px solid #dfe2ea; border-radius: 10px; padding: 12px;
  font-size: 15px; font-family: inherit; resize: none; outline: none;
}
.map-manual textarea:focus { border-color: var(--primary); }
.manual-tip { font-size: 12px; color: var(--text-sub); line-height: 1.6; }
.map-foot {
  flex: 0 0 auto; background: #fff; border-top: 1px solid #ececec;
  padding: 10px 14px; display: flex; align-items: center; gap: 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
}
.map-addr { flex: 1; font-size: 13px; color: #444; line-height: 1.45; max-height: 56px; overflow-y: auto; }
.map-confirm {
  flex: 0 0 auto; min-width: 84px; height: 40px; border: none; border-radius: 20px;
  background: var(--primary); color: #fff; font-size: 15px; font-family: inherit;
}
.map-confirm:disabled { background: #c6cbd8; }
.amap-logo, .amap-copyright { opacity: .55; transform: scale(.85); transform-origin: bottom right; }
