/* 基础样式：主题变量、重置、通用组件、消息气泡（电脑端/手机端共用） */

:root {
  --green: #07c160;
  --green-dark: #06ad56;
  --green-press: #059748;
  --red: #fa5151;
  --orange: #fa9d3b;
  --blue: #576b95;
  --yellow: #ffc300;

  --bg-app: #f7f7f7;
  --bg-panel: #ededed;
  --bg-chat: #f5f5f5;
  --bg-card: #ffffff;
  --bg-hover: #ececec;
  --bg-active: #d9d9d9;
  --bg-input: #ffffff;
  --rail: #2e2e2e;
  --rail-hover: #3d3d3d;

  --bubble-me: #95ec69;
  --bubble-me-arrow: #95ec69;
  --bubble-you: #ffffff;

  --text: #191919;
  --text-2: #7f7f7f;
  --text-3: #b2b2b2;
  --line: #e5e5e5;
  --line-2: #d9d9d9;

  --shadow: 0 8px 32px rgba(0, 0, 0, .18);
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg-app: #1e1e1e;
  --bg-panel: #262626;
  --bg-chat: #191919;
  --bg-card: #2c2c2c;
  --bg-hover: #303030;
  --bg-active: #3a3a3a;
  --bg-input: #2c2c2c;
  --rail: #1b1b1b;
  --rail-hover: #2a2a2a;

  --bubble-me: #3eb575;
  --bubble-me-arrow: #3eb575;
  --bubble-you: #2c2c2c;

  --text: #cfcfcf;
  --text-2: #8a8a8a;
  --text-3: #5c5c5c;
  --line: #2f2f2f;
  --line-2: #3a3a3a;
  --shadow: 0 8px 32px rgba(0, 0, 0, .5);
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-app);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body[data-size="small"] { font-size: 13px; }
body[data-size="large"] { font-size: 16px; }
body[data-size="huge"] { font-size: 18px; }

img { display: block; max-width: 100%; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
a { color: var(--blue); text-decoration: none; }
ul, li { margin: 0; padding: 0; list-style: none; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, .35); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, .55); }
::-webkit-scrollbar-track { background: transparent; }

.hide { display: none !important; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ell2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.avatar { border-radius: 4px; background: var(--bg-hover); flex: none; object-fit: cover; }

/* ---------- 通用组件层 ---------- */

#ui-layer { position: fixed; inset: 0; pointer-events: none; z-index: 9000; }
#ui-layer > * { pointer-events: auto; }

.wx-toast {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9);
  background: rgba(0, 0, 0, .82); color: #fff; padding: 14px 20px; border-radius: 8px;
  font-size: 14px; text-align: center; opacity: 0; transition: .18s; max-width: 70vw;
  z-index: 9500; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.wx-toast.in { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.wx-toast-icon { font-size: 30px; line-height: 1; }
.wx-spin {
  width: 26px; height: 26px; border: 2.5px solid rgba(255, 255, 255, .28);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.wx-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 9200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .2s;
}
.wx-mask.in { opacity: 1; }
.wx-mask.sheet { align-items: flex-end; }

.wx-dialog {
  width: 300px; background: var(--bg-card); border-radius: 10px; overflow: hidden;
  transform: scale(.92); transition: transform .2s;
}
.wx-mask.in .wx-dialog { transform: scale(1); }
.wx-dialog-title { padding: 22px 20px 0; font-size: 17px; font-weight: 500; text-align: center; }
.wx-dialog-body { padding: 12px 20px 22px; color: var(--text-2); text-align: center; font-size: 14px; }
.wx-dialog-body.notitle { padding-top: 26px; color: var(--text); font-size: 16px; }
.wx-dialog-tip { margin-top: 8px; font-size: 12px; color: var(--text-3); }
.wx-dialog-btns { display: flex; border-top: 1px solid var(--line); }
.wx-dialog-btns button {
  flex: 1; padding: 13px; font-size: 16px; color: var(--text);
  border-right: 1px solid var(--line);
}
.wx-dialog-btns button:last-child { border-right: none; }
.wx-dialog-btns button:hover { background: var(--bg-hover); }
.wx-dialog-btns .primary { color: var(--green); }
.wx-dialog-btns .danger { color: var(--red); }
.wx-input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line-2); border-radius: 4px;
  background: var(--bg-input); outline: none; text-align: left;
}
.wx-input:focus { border-color: var(--green); }

.wx-sheet {
  width: 100%; max-width: 480px; margin: 0 auto; background: var(--bg-panel);
  border-radius: 12px 12px 0 0; overflow: hidden;
  transform: translateY(100%); transition: transform .24s cubic-bezier(.2, .8, .3, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.wx-mask.in .wx-sheet { transform: translateY(0); }
.wx-sheet-title { padding: 14px; text-align: center; color: var(--text-2); font-size: 13px; background: var(--bg-card); }
.wx-sheet-item {
  display: block; width: 100%; padding: 15px; text-align: center; font-size: 17px;
  background: var(--bg-card); border-bottom: 1px solid var(--line);
}
.wx-sheet-item:active { background: var(--bg-active); }
.wx-sheet-item.danger { color: var(--red); }
.wx-sheet-gap { height: 8px; background: var(--bg-panel); }

.wx-menu {
  position: fixed; z-index: 9400; background: var(--bg-card); border-radius: 6px;
  box-shadow: var(--shadow); padding: 4px 0; min-width: 130px; font-size: 13px;
  border: 1px solid var(--line);
}
.wx-menu-item { padding: 7px 16px; cursor: pointer; white-space: nowrap; }
.wx-menu-item:hover { background: var(--bg-hover); }
.wx-menu-item.danger { color: var(--red); }
.wx-menu-sep { height: 1px; background: var(--line); margin: 4px 0; }

.wx-viewer {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 9600;
  display: flex; align-items: center; justify-content: center;
}
.wx-viewer-img { max-width: 92vw; max-height: 92vh; transition: transform .15s; object-fit: contain; }
.wx-viewer-close, .wx-viewer-save {
  position: absolute; top: 20px; color: #fff; font-size: 15px; opacity: .8;
  background: rgba(255, 255, 255, .12); border-radius: 20px; padding: 6px 14px;
}
.wx-viewer-close { right: 20px; }
.wx-viewer-save { right: 90px; }
.wx-viewer-nav {
  position: absolute; bottom: 30px; display: flex; align-items: center; gap: 20px;
  color: #fff; background: rgba(255, 255, 255, .12); border-radius: 20px; padding: 4px 16px;
}
.wx-viewer-nav button { color: #fff; font-size: 26px; line-height: 1; padding: 0 6px; }

.wx-modal {
  background: var(--bg-card); border-radius: 10px; overflow: hidden;
  transform: scale(.94); transition: transform .2s; max-height: 90vh;
}
.wx-mask.in .wx-modal { transform: scale(1); }

.btn-green {
  background: var(--green); color: #fff; border-radius: 4px; padding: 8px 22px;
  font-size: 14px; transition: .15s;
}
.btn-green:hover { background: var(--green-dark); }
.btn-green:active { background: var(--green-press); }
.btn-green:disabled { opacity: .5; cursor: not-allowed; }
.btn-plain {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--line-2);
  border-radius: 4px; padding: 8px 22px;
}
.btn-plain:hover { background: var(--bg-hover); }

/* ---------- 消息气泡（共用） ---------- */

.msg-time { text-align: center; color: var(--text-3); font-size: 12px; margin: 14px 0 8px; }
.msg-sys {
  text-align: center; color: var(--text-2); font-size: 12px; margin: 10px auto;
  background: rgba(125, 125, 125, .12); padding: 3px 10px; border-radius: 4px;
  width: fit-content; max-width: 80%; line-height: 1.6;
}
.msg-sys a { color: var(--blue); cursor: pointer; }

.msg { display: flex; margin: 4px 0 12px; padding: 0 6px; align-items: flex-start; }
.msg.mine { flex-direction: row-reverse; }
.msg-avatar { width: 36px; height: 36px; border-radius: 4px; flex: none; cursor: pointer; background: var(--bg-hover); }
.msg-main { margin: 0 10px; max-width: min(560px, 62%); display: flex; flex-direction: column; }
.msg.mine .msg-main { align-items: flex-end; }
.msg-name { font-size: 11px; color: var(--text-2); margin: 0 0 3px 2px; }
.msg-bubble-row { display: flex; }

.bubble {
  position: relative; padding: 9px 12px; border-radius: 4px; background: var(--bubble-you);
  word-break: break-word; white-space: normal; max-width: 100%; font-size: 14px; line-height: 1.55;
}
.msg.mine .bubble { background: var(--bubble-me); color: #191919; }
:root[data-theme="dark"] .msg.mine .bubble { color: #e8f5ee; }
.bubble::after {
  content: ''; position: absolute; top: 12px; width: 0; height: 0;
  border: 5px solid transparent;
}
.msg:not(.mine) .bubble::after { left: -9px; border-right-color: var(--bubble-you); }
.msg.mine .bubble::after { right: -9px; border-left-color: var(--bubble-me-arrow); }
.bubble.img::after, .bubble.sticker::after, .bubble.video::after { display: none; }

.bubble .at { color: var(--blue); }
.bubble.big-emoji { font-size: 32px; line-height: 1.2; background: transparent; padding: 0; }
.bubble.big-emoji::after { display: none; }
.emo { font-size: 1.18em; vertical-align: -.12em; }

.bubble.img { padding: 0; overflow: hidden; border-radius: 4px; cursor: pointer; background: none; }
.bubble.img img { max-width: 220px; max-height: 280px; border-radius: 4px; object-fit: cover; }
.bubble.sticker { padding: 0; background: none; }
.bubble.sticker img { width: 110px; height: 110px; object-fit: contain; }
.sticker-emo { font-size: 60px; line-height: 1.1; }

.voice-wrap { display: flex; flex-direction: column; }
.msg.mine .voice-wrap { align-items: flex-end; }
.bubble.voice { cursor: pointer; display: flex; align-items: center; gap: 8px; min-width: 60px; }
.msg.mine .bubble.voice { flex-direction: row-reverse; }
.voice-ico { display: flex; align-items: flex-end; gap: 2px; height: 15px; }
.voice-ico i { width: 3px; background: currentColor; border-radius: 2px; opacity: .75; }
.voice-ico i:nth-child(1) { height: 5px; }
.voice-ico i:nth-child(2) { height: 10px; }
.voice-ico i:nth-child(3) { height: 15px; }
.bubble.voice.playing .voice-ico i { animation: vwave .9s infinite; }
.bubble.voice.playing .voice-ico i:nth-child(2) { animation-delay: .15s; }
.bubble.voice.playing .voice-ico i:nth-child(3) { animation-delay: .3s; }
@keyframes vwave { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
.voice-dur { font-size: 13px; color: var(--text-2); }
.msg.mine .voice-dur { color: rgba(0, 0, 0, .5); }
.voice-text {
  margin-top: 4px; background: var(--bubble-you); padding: 7px 10px; border-radius: 4px;
  font-size: 13px; color: var(--text-2); max-width: 260px;
}

.bubble.video { padding: 0; position: relative; cursor: pointer; background: none; }
.bubble.video img { width: 180px; border-radius: 4px; }
.bubble.video .play {
  position: absolute; inset: 0; margin: auto; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0, 0, 0, .45); color: #fff; display: flex; align-items: center;
  justify-content: center; font-size: 16px; padding-left: 3px;
}
.bubble.video .vdur { position: absolute; right: 6px; bottom: 6px; color: #fff; font-size: 11px; text-shadow: 0 1px 2px #000; }

.bubble.file { width: 230px; display: flex; justify-content: space-between; gap: 10px; cursor: pointer; }
.file-name { font-size: 14px; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.file-size { font-size: 11px; color: var(--text-2); margin-top: 8px; }
.file-ico {
  width: 40px; height: 40px; border-radius: 4px; flex: none; display: flex;
  align-items: center; justify-content: center; font-size: 22px;
}

.bubble.chatlog { width: 230px; cursor: pointer; }
.cl-title { font-size: 14px; margin-bottom: 6px; }
.cl-line { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-foot { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 11px; color: var(--text-3); }

.bubble.loc { width: 240px; padding: 10px 10px 0; cursor: pointer; overflow: hidden; }
.loc-name { font-size: 14px; }
.loc-addr { font-size: 11px; color: var(--text-2); margin: 2px 0 8px; }
.loc-map { width: 100%; border-radius: 0 0 4px 4px; margin: 0 -10px; width: calc(100% + 20px); }

.bubble.link { width: 240px; cursor: pointer; display: flex; flex-wrap: wrap; gap: 8px; }
.link-main { flex: 1; min-width: 0; }
.link-title { font-size: 14px; margin-bottom: 4px; }
.link-digest { font-size: 12px; color: var(--text-2); max-height: 3em; overflow: hidden; }
.link-cover { width: 44px; height: 44px; border-radius: 3px; object-fit: cover; }
.link-src { width: 100%; border-top: 1px solid var(--line); padding-top: 5px; font-size: 11px; color: var(--text-3); }

.bubble.card { width: 220px; cursor: pointer; }
.card-top { display: flex; gap: 10px; align-items: center; }
.card-top img { width: 42px; height: 42px; border-radius: 4px; }
.card-name { font-size: 15px; }
.card-wxid { font-size: 11px; color: var(--text-2); margin-top: 3px; }
.card-foot { margin-top: 8px; padding-top: 5px; border-top: 1px solid var(--line); font-size: 11px; color: var(--text-3); }

.bubble.rp, .bubble.tf {
  width: 220px; padding: 0; overflow: hidden; cursor: pointer; color: #fff;
  background: linear-gradient(160deg, #fa9d3b, #f76b1c);
}
.msg.mine .bubble.rp, .msg.mine .bubble.tf { background: linear-gradient(160deg, #fa9d3b, #f76b1c); color: #fff; }
.bubble.rp::after { border-right-color: #fa9d3b !important; border-left-color: #fa9d3b !important; }
.bubble.tf::after { border-right-color: #fa9d3b !important; border-left-color: #fa9d3b !important; }
.bubble.rp.opened, .bubble.tf.done { background: linear-gradient(160deg, #f7c99a, #eda877); }
.msg.mine .bubble.rp.opened, .msg.mine .bubble.tf.done { background: linear-gradient(160deg, #f7c99a, #eda877); }
.bubble.rp.opened::after, .bubble.tf.done::after { border-right-color: #f7c99a !important; border-left-color: #f7c99a !important; }
.rp-top, .tf-top { display: flex; align-items: center; gap: 10px; padding: 12px; }
.rp-icon, .tf-icon {
  width: 34px; height: 34px; flex: none; border-radius: 4px; background: rgba(255, 255, 255, .22);
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.rp-memo, .tf-amount { font-size: 15px; line-height: 1.3; }
.tf-amount { font-weight: 500; }
.rp-sub, .tf-sub { font-size: 11px; opacity: .85; margin-top: 3px; }
.rp-foot, .tf-foot {
  padding: 5px 12px; font-size: 11px; background: rgba(0, 0, 0, .1);
}
.bubble.call { display: flex; align-items: center; gap: 8px; }

.quote {
  margin-top: 5px; background: rgba(125, 125, 125, .13); border-radius: 3px;
  padding: 5px 8px; font-size: 12px; color: var(--text-2); cursor: pointer;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i {
  width: 4px; height: 4px; border-radius: 50%; background: currentColor;
  animation: tdot 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes tdot { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* 九宫格图片（朋友圈 / 聊天记录） */
.grid { display: grid; gap: 4px; }
.grid.g1 { grid-template-columns: 1fr; max-width: 190px; }
.grid.g2 { grid-template-columns: repeat(2, 1fr); max-width: 234px; }
.grid.g3 { grid-template-columns: repeat(3, 1fr); max-width: 234px; }
.grid.g4 { grid-template-columns: repeat(2, 1fr); max-width: 234px; }
.grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 3px; cursor: pointer; background: var(--bg-hover); }
.grid.g1 img { aspect-ratio: auto; max-height: 240px; width: auto; object-fit: contain; }

.badge {
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--red);
  color: #fff; font-size: 11px; line-height: 17px; text-align: center; flex: none;
}
.badge.dot { min-width: 8px; width: 8px; height: 8px; padding: 0; }
