/* HK668 在线客服（访客端）— 微信样式 v7 */
* { box-sizing: border-box; }
html, body { height: 100%; }
html, body { overflow: hidden; }
body {
  margin: 0;
  background: #ededed;
  color: #111;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; font-size: 16px; color: inherit; }
button { border: 0; background: transparent; cursor: pointer; }
[hidden] { display: none !important; }

.phone {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: 100dvh;
  margin: 0 auto;
  background: #ededed;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* 顶栏 */
.top {
  flex: none; display: flex; align-items: center; gap: 4px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: #f7f7f7; border-bottom: 1px solid #e3e3e3;
  position: relative; z-index: 3;
}
.heading { flex: 1 1 auto; min-width: 0; text-align: center; }
.home-btn {
  flex: none; padding: 6px 12px; border-radius: 14px;
  background: #fff; border: 1px solid #dcdcdc; color: #333;
  font-size: 14px; font-family: inherit; line-height: 1.2;
}
.home-btn:active { background: #eee; }
.heading h1 {
  margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub { margin: 2px 0 0; color: #9a9a9a; font-size: 11px; word-break: break-all; }
button.nav-back {
  flex: none; width: 44px; height: 40px; padding: 0;
  font-size: 28px; line-height: 1; color: #333;
}
#edit-nickname {
  flex: none; min-width: 44px; min-height: 40px; padding: 0 6px;
  color: #576b95; font-size: 14px;
}
.identity-id { padding: 4px 14px; background: #ededed; text-align: center; }

/* 微信内置浏览器兼容提示（低调版，不遮挡、不自动跳转） */
.wx-guide {
  position: fixed; inset: 0; z-index: 60;
  background: #fff;
  display: flex; flex-direction: column;
  padding: calc(18px + env(safe-area-inset-top)) 22px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.wx-guide-arrow {
  position: absolute;
  top: calc(2px + env(safe-area-inset-top));
  right: 14px;
  font-size: 64px;
  line-height: 1;
  color: #07c160;
  animation: wx-bounce 1.1s ease-in-out infinite;
}
@keyframes wx-bounce {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(6px, -6px); }
}
.wx-guide-card { margin: 92px 0 auto; width: 100%; max-width: 460px; align-self: center; }
.wx-guide h1 {
  margin: 0 0 10px; font-size: 28px; font-weight: 700;
  text-align: center; color: #111; letter-spacing: .5px;
}
.wx-guide-sub {
  margin: 0 0 26px; text-align: center; color: #777;
  font-size: 15px; line-height: 1.6;
}
.wx-guide-steps { margin: 0 0 22px; padding: 0; list-style: none; }
.wx-guide-steps li {
  display: flex; align-items: flex-start; gap: 12px;
  margin: 16px 0; font-size: 19px; line-height: 1.65; color: #222;
}
.wx-num {
  flex: none; width: 30px; height: 30px; margin-top: 3px;
  border-radius: 50%; background: #07c160; color: #fff;
  font-size: 17px; font-weight: 700; line-height: 30px; text-align: center;
}
.wx-guide-steps b { color: #07c160; font-weight: 700; }
.wx-dots { font-size: 26px; vertical-align: middle; }
.wx-copy {
  display: block; width: 100%; min-height: 56px;
  border-radius: 10px; background: #07c160; color: #fff;
  font-size: 19px; font-weight: 600;
}
.wx-copy:active { background: #06ad56; }
.wx-copied {
  margin: 10px 0 0; text-align: center;
  color: #07a352; font-size: 16px; font-weight: 600;
}
.wx-continue {
  display: block; width: 100%; margin-top: 14px; min-height: 46px;
  background: transparent; color: #999; font-size: 15px;
}
.wx-guide[hidden] { display: none !important; }

.browser-tip {
  flex: none;
  background: #fff8e6;
  border-bottom: 1px solid #f0e2bd;
  color: #6b5320;
  font-size: 12.5px;
  line-height: 1.5;
  padding: 7px 12px;
}
.browser-tip-row { display: flex; align-items: center; gap: 8px; }
.browser-tip-text { flex: 1 1 auto; min-width: 0; }
#browser-tip-help {
  flex: none; padding: 0; min-height: 0; color: #8a6a1f;
  font-size: 12.5px; text-decoration: underline;
}
#browser-tip-close {
  flex: none; width: 26px; height: 26px; padding: 0; min-height: 0;
  color: #9a8149; font-size: 17px; line-height: 1;
}
.browser-tip-steps {
  margin: 6px 0 0; padding-left: 18px;
  color: #6b5320; font-size: 12.5px;
}
.browser-tip-steps li { margin: 2px 0; }
.browser-tip-steps b { font-weight: 600; }

/* 昵称表单 */
.nickname-form {
  flex: none; display: grid; gap: 8px; padding: 12px 14px;
  background: #fff; border-bottom: 1px solid #eee;
}
.nickname-form label { font-size: 13px; color: #666; }
.nickname-form input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid #dedede; border-radius: 6px; background: #fff; outline: none;
}
.nickname-form input:focus { border-color: #07c160; }
.row { display: flex; gap: 8px; }
.row button {
  flex: 1; min-height: 42px; border-radius: 6px;
  background: #07c160; color: #fff; font-size: 15px;
}
.row button[type="button"] { background: #f2f2f2; color: #333; }
.form-error { margin: 0; min-height: 1.2em; color: #fa5151; font-size: 13px; }

/* 消息区 */
.thread-wrap { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.thread {
  flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 18px; display: flex; flex-direction: column;
}
.thread::-webkit-scrollbar { width: 6px; }
.thread::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }

.time-sep { align-self: center; margin: 6px 0 14px; color: #a9a9a9; font-size: 12px; }
.time-sep:first-child { margin-top: 0; }

.msg { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; max-width: 100%; }
.msg.mine { flex-direction: row-reverse; }
.msg-body { min-width: 0; display: flex; flex-direction: column; max-width: calc(100% - 50px); }
.msg.mine .msg-body { align-items: flex-end; }
.bubble {
  position: relative; max-width: 100%; padding: 9px 12px; border-radius: 5px; background: #fff;
  font-size: 16px; line-height: 1.45; color: #111;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
}
.bubble::before {
  content: ""; position: absolute; top: 11px; left: -6px;
  border-top: 6px solid transparent; border-bottom: 6px solid transparent;
  border-right: 6px solid #fff;
}
.msg.mine .bubble { background: #95ec69; }
.msg.mine .bubble::before {
  left: auto; right: -6px; border-right: 0; border-left: 6px solid #95ec69;
}
.bubble p { margin: 0; }
.bubble.image { padding: 0; background: transparent; box-shadow: none; }
.bubble.image::before { display: none; }
button.thumb { display: block; padding: 0; border-radius: 5px; overflow: hidden; background: #ddd; }
.bubble img { display: block; width: auto; max-width: min(220px, 62vw); height: auto; max-height: 280px; object-fit: cover; }

.msg.pending .bubble { opacity: .5; }
.spin {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1.5px solid #bdbdbd; border-top-color: transparent;
  display: inline-block; animation: rot .7s linear infinite;
}
@keyframes rot { to { transform: rotate(360deg); } }

.empty { margin: auto; padding: 40px 20px; color: #aaa; text-align: center; font-size: 14px; }

.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 600; user-select: none;
  background: #7d8b99; overflow: hidden;
}
.avatar.agent { background: linear-gradient(135deg, #07c160, #059e4e); }

.notice {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4;
  padding: 8px 15px; border-radius: 16px; background: #fff; color: #07c160;
  font-size: 13px; box-shadow: 0 2px 10px rgba(0, 0, 0, .14);
}

/* 输入区 */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
  background: #f7f7f7; border-top: 1px solid #e3e3e3;
}
.composer textarea {
  flex: 1 1 auto; width: 100%; height: 38px; min-height: 38px; max-height: 110px;
  padding: 8px 12px; border: 0; border-radius: 6px; background: #fff;
  line-height: 22px; resize: none; overflow-y: hidden; outline: none;
}
.composer input[type="file"] { display: none; }
.icon-btn {
  flex: none; width: 38px; height: 38px; min-width: 38px; padding: 0;
  font-size: 21px; line-height: 1; color: #3a3a3a;
  display: flex; align-items: center; justify-content: center;
}
#emoji-btn, #plus-btn { font-size: 22px; }
#plus-btn { font-size: 25px; font-weight: 300; }
.send-btn {
  flex: none; min-width: 62px; height: 34px; margin-bottom: 2px; padding: 0 14px;
  border-radius: 5px; background: #07c160; color: #fff; font-size: 15px; font-weight: 500;
}
.send-btn:disabled { background: #d6d6d6; color: #fff; cursor: default; }
button:disabled { opacity: .5; }
button:not(:disabled):active { filter: brightness(.94); }

.status { flex: none; margin: 0; padding: 4px 16px; color: #999; font-size: 12px; text-align: center; }
.status:empty { display: none; }
.notify {
  flex: none; margin: 8px 14px 0; padding: 9px 12px; border-radius: 8px;
  background: #e8f7ee; color: #07a352; font-size: 13px; text-align: center;
}

/* 表情 / 更多功能面板（微信式） */
.panel {
  flex: none;
  background: #f7f7f7;
  border-top: 1px solid #e3e3e3;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  max-height: 44dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.emoji-grid button {
  height: 40px;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 24px;
  line-height: 40px;
  text-align: center;
}
.emoji-grid button:active { background: #e4e4e4; }
.emoji-grid button.del { font-size: 19px; color: #666; }
.plus-grid { display: flex; flex-wrap: wrap; gap: 14px; padding: 4px 2px 8px; }
.plus-item {
  width: 68px; padding: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.plus-icon {
  width: 56px; height: 56px; border-radius: 12px; background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.plus-label { font-size: 12px; color: #666; }

/* 大图 */
dialog[open] {
  z-index: 30; position: fixed; inset: 0; width: 100%; height: 100%; margin: 0; border: 0;
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  max-width: none; max-height: none; background: rgba(0, 0, 0, .94);
  display: flex; align-items: center; justify-content: center;
}
dialog img {
  display: block; width: auto; max-width: 100%;
  max-height: calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  object-fit: contain;
}
#viewer-close {
  position: absolute; top: calc(8px + env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left));
  width: 44px; height: 44px; color: #fff; font-size: 30px; background: transparent; line-height: 1;
}

@media (min-width: 560px) {
  body { background: #e6e6e6; }
  .phone { height: 100dvh; box-shadow: 0 0 24px rgba(0,0,0,.08); }
}
