/* ============================================================
   微信风格样式
   ============================================================ */

:root {
  --wx-nav: #ededed;
  --wx-nav-border: #d6d6d6;
  --wx-bg: #f5f5f5;
  --wx-bubble-in: #ffffff;
  --wx-bubble-out: #95ec69;
  --wx-text: #191919;
  --wx-text-dim: #888888;
  --wx-text-time: #b2b2b2;
  --wx-green: #07c160;
  --wx-line: #e5e5e5;
  --wx-danger: #fa5151;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--wx-bg);
  color: var(--wx-text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* 只在桌面端限制宽度，手机上铺满 */
body { background: var(--wx-bg); }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--wx-bg);
  z-index: 1;
}
.screen.overlay {
  z-index: 3;
  transform: translateX(100%);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1), visibility .26s;
  visibility: hidden;
}
.screen.overlay.show { transform: translateX(0); visibility: visible; }

/* ---------------- 顶栏 ---------------- */

.wx-navbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  height: calc(var(--safe-top) + 48px);
  padding: var(--safe-top) 4px 0;
  background: var(--wx-nav);
  border-bottom: 1px solid var(--wx-nav-border);
  position: relative;
  z-index: 6;
}
.wx-navbar.light { background: var(--wx-nav); }

.wx-back {
  flex: 0 0 auto;
  width: 52px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: #191919;
  cursor: pointer;
  position: relative;
}
.wx-back svg { width: 24px; height: 24px; }
.wx-back:active { opacity: .5; }

.wx-badge {
  position: absolute;
  top: 6px;
  left: 26px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--wx-danger);
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
}

.wx-navbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.wx-navbar-title strong {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .2px;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wx-navbar-sub {
  font-size: 12px;
  color: var(--wx-text-dim);
  height: 14px;
  line-height: 14px;
  opacity: 0;
  transition: opacity .2s;
}
.wx-navbar-sub.on { opacity: 1; }

.wx-navbar-btn {
  flex: 0 0 auto;
  width: 52px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: #191919;
  cursor: pointer;
}
.wx-navbar-btn svg { width: 23px; height: 23px; }
.wx-navbar-btn:active { opacity: .5; }

/* ---------------- 消息区 ---------------- */

.wx-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 0 16px;
  display: flex;
  flex-direction: column;
}

/* 时间分隔 */
.wx-time {
  align-self: center;
  margin: 14px 0 8px;
  font-size: 12.5px;
  color: var(--wx-text-time);
  background: rgba(0, 0, 0, .06);
  border-radius: 4px;
  padding: 3px 9px;
}

/* 一行消息 = 头像 + 气泡 */
.wx-row {
  display: flex;
  align-items: flex-start;
  padding: 5px 12px;
  gap: 10px;
  animation: wxIn .18s ease-out;
  max-width: 100%;
}
@keyframes wxIn { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }

.wx-row.out { flex-direction: row-reverse; }

/* 头像 */
.wx-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  letter-spacing: .5px;
  user-select: none;
  overflow: hidden;
}
.wx-avatar.her { background: linear-gradient(135deg, #ffb3c6 0%, #ff8fab 100%); }
.wx-avatar.me { background: linear-gradient(135deg, #7aa8ff 0%, #5b7cfa 100%); }

/* 气泡 */
.wx-bubble {
  position: relative;
  max-width: calc(100% - 130px);
  padding: 9px 13px;
  border-radius: 6px;
  font-size: 16.5px;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: bubbleIn .2s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes bubbleIn { from { transform: scale(.94); opacity: .6 } to { transform: none; opacity: 1 } }

/* 接收（她的）白色气泡，尾巴在左 */
.wx-row.in .wx-bubble {
  background: var(--wx-bubble-in);
  color: var(--wx-text);
}
.wx-row.in .wx-bubble::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 12px;
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 6px solid var(--wx-bubble-in);
}

/* 发送（我的）绿色气泡，尾巴在右 */
.wx-row.out .wx-bubble {
  background: var(--wx-bubble-out);
  color: var(--wx-text);
}
.wx-row.out .wx-bubble::before {
  content: '';
  position: absolute;
  right: -5px;
  top: 12px;
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid var(--wx-bubble-out);
}

/* 连续消息：中间的气泡不带尾巴，显得是"一串" */
.wx-row.mid .wx-bubble::before { display: none; }

/* 语音/表情类的大气泡 */
.wx-bubble.emoji-only {
  background: none !important;
  padding: 2px 4px;
  font-size: 40px;
  line-height: 1.1;
}
.wx-bubble.emoji-only::before { display: none !important; }

/* 错误提示 */
.wx-error {
  align-self: center;
  margin: 8px 20px;
  padding: 8px 14px;
  background: rgba(250, 81, 81, .09);
  border-radius: 6px;
  color: #c33;
  font-size: 13.5px;
  line-height: 1.5;
  text-align: center;
  max-width: 85%;
  white-space: pre-wrap;
}

/* 系统提示（小灰字） */
.wx-sys {
  align-self: center;
  margin: 10px 20px;
  font-size: 12.5px;
  color: var(--wx-text-time);
  text-align: center;
}

/* 正在输入 */
.wx-typing { display: inline-flex; gap: 4px; align-items: center; height: 22px; }
.wx-typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #b8b8b8;
  animation: wxBounce 1.2s infinite;
}
.wx-typing i:nth-child(2) { animation-delay: .15s; }
.wx-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes wxBounce { 0%,60%,100% { transform: translateY(0); opacity: .45 } 30% { transform: translateY(-5px); opacity: 1 } }

/* 回到最新按钮 */
.wx-scroll-bottom {
  position: absolute;
  right: 16px;
  bottom: calc(var(--safe-bottom) + 66px);
  width: 38px; height: 38px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .96);
  color: #666;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .14);
  z-index: 4;
  cursor: pointer;
}
.wx-scroll-bottom svg { width: 19px; height: 19px; }

/* ---------------- 底部输入栏 ---------------- */

.wx-toolbar {
  flex: 0 0 auto;
  background: var(--wx-nav);
  border-top: 1px solid var(--wx-nav-border);
  padding-bottom: var(--safe-bottom);
}

.wx-toolbar-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 7px 8px;
}

.wx-tool-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  margin-bottom: 3px;
  border: none;
  background: none;
  color: #444;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.wx-tool-btn svg { width: 26px; height: 26px; }
.wx-tool-btn:active { opacity: .5; }
.wx-tool-btn.off { opacity: .3; }

.wx-input-wrap {
  flex: 1;
  min-width: 0;
  background: #fff;
  border-radius: 5px;
  padding: 6px 10px;
  min-height: 34px;
  display: flex;
  align-items: center;
}
#input {
  width: 100%;
  border: none;
  outline: none;
  background: none;
  font-family: inherit;
  font-size: 16.5px; /* 16px+ 防 iOS 缩放 */
  line-height: 1.4;
  color: var(--wx-text);
  resize: none;
  max-height: 100px;
  padding: 0;
}
#input::placeholder { color: #b2b2b2; }

.wx-send-btn {
  flex: 0 0 auto;
  margin-bottom: 3px;
  padding: 0 14px;
  height: 32px;
  border: none;
  border-radius: 4px;
  background: var(--wx-green);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}
.wx-send-btn:active { background: #06ad56; }

/* 面板 */
.wx-panel {
  border-top: 1px solid var(--wx-line);
  background: #f7f7f7;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  max-height: 42vh;
  overflow-y: auto;
}

.wx-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.wx-emoji-grid button {
  border: none;
  background: none;
  font-size: 26px;
  line-height: 1;
  padding: 7px 0;
  border-radius: 6px;
  cursor: pointer;
}
.wx-emoji-grid button:active { background: #e6e6e6; }

.wx-plus-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  padding: 12px;
  font-family: inherit;
  font-size: 13px;
  color: #555;
  cursor: pointer;
}
.wx-plus-icon {
  width: 54px; height: 54px;
  border-radius: 12px;
  background: #fff;
  display: grid;
  place-items: center;
  font-size: 25px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}

/* ---------------- 设置页 ---------------- */

.wx-settings { background: var(--wx-bg); }
.wx-settings-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--safe-bottom) + 30px);
}

.wx-setup {
  margin: 14px 12px;
  padding: 14px;
  background: #fff3cd;
  border: 1px solid #ffe08a;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.wx-setup strong { font-size: 15px; }
.wx-setup span { font-size: 13px; color: #8a6d3b; }

.wx-group-title {
  font-size: 13.5px;
  color: var(--wx-text-dim);
  padding: 22px 16px 8px;
}

.wx-group {
  background: #fff;
  border-top: 1px solid var(--wx-line);
  border-bottom: 1px solid var(--wx-line);
}

.wx-cell {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--wx-line);
}
.wx-cell:last-child { border-bottom: none; }
.wx-cell.between {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.wx-cell label {
  font-size: 14px;
  color: #333;
}
.wx-cell-label { font-size: 16px; color: var(--wx-text); }

.wx-cell input,
.wx-cell select {
  width: 100%;
  padding: 10px 0;
  border: none;
  outline: none;
  background: none;
  font-family: inherit;
  font-size: 16.5px;
  color: var(--wx-text);
}
.wx-cell select { -webkit-appearance: none; appearance: none; }
.wx-cell input::placeholder { color: #c0c0c0; }

.wx-cell-note {
  padding: 10px 16px 14px;
  font-size: 12.5px;
  color: var(--wx-text-dim);
  line-height: 1.6;
  border-top: 1px solid var(--wx-line);
}

.wx-cell-cell { padding: 12px 16px; border-top: 1px solid var(--wx-line); }

.wx-btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 6px;
  background: var(--wx-green);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
}
.wx-btn-primary:active { background: #06ad56; }
.wx-btn-primary:disabled { opacity: .55; }

.wx-btn-text {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--wx-green);
  cursor: pointer;
  padding: 4px 0;
}
.wx-btn-text.danger { color: var(--wx-danger); }

.wx-test-result {
  margin: 0 16px 14px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  line-height: 1.6;
}
.wx-test-result.ok { background: #e8f8ee; color: #17883f; }
.wx-test-result.bad { background: #fdecec; color: #c33; }

.wx-seg {
  display: flex;
  background: #f0f0f0;
  border-radius: 6px;
  padding: 2px;
  flex: 0 0 auto;
}
.wx-seg button {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 13.5px;
  color: #666;
  padding: 6px 11px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.wx-seg button.on { background: var(--wx-green); color: #fff; }

.wx-settings-tip {
  padding: 20px 16px;
  font-size: 12.5px;
  color: var(--wx-text-dim);
  line-height: 1.8;
}

/* ---------------- 底部弹出菜单 ---------------- */

/* 默认隐藏。
   注意：这里只写 display:none，不要写成带 display:flex 的常驻规则——
   作者样式里的类选择器会盖过浏览器对 [hidden] 的默认处理，
   那样元素带着 hidden 属性仍然会显示，把底下的按钮挡住。
   实际的显示由 JS 用内联 display 控制（见 openMenu/closeMenu）。 */
.wx-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 20;
  align-items: flex-end;
  animation: wxFade .18s;
}
@keyframes wxFade { from { opacity: 0 } to { opacity: 1 } }

.wx-sheet {
  width: 100%;
  background: #f7f7f7;
  border-radius: 12px 12px 0 0;
  padding: 6px 0 calc(6px + var(--safe-bottom));
  animation: wxUp .22s cubic-bezier(.2,.9,.3,1);
  max-width: 640px;
  margin: 0 auto;
}
@keyframes wxUp { from { transform: translateY(100%) } to { transform: none } }

.wx-sheet button {
  width: 100%;
  padding: 15px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--wx-text);
  cursor: pointer;
  border-bottom: 1px solid var(--wx-line);
}
.wx-sheet button:active { background: #ececec; }
.wx-sheet button.cancel {
  margin-top: 6px;
  border-bottom: none;
  border-top: 6px solid #ececec;
  font-weight: 500;
  color: #555;
}

/* ---------------- Toast ---------------- */

.wx-toast {
  position: fixed;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(0, 0, 0, .78);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 30;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  max-width: 78vw;
  text-align: center;
  pointer-events: none;
  line-height: 1.5;
}
.wx-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 桌面端居中 */
@media (min-width: 640px) {
  .screen {
    max-width: 640px;
    margin: 0 auto;
    border-left: 1px solid var(--wx-line);
    border-right: 1px solid var(--wx-line);
  }
  .wx-bubble { max-width: 60%; }
}
