:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --line: #e6e4dd;
  --text: #23231f;
  --muted: #77776f;
  --accent: #0f6e56;
  --accent-soft: #e1f5ee;
  --danger: #a32d2d;
  --bubble-in: #ffffff;
  --bubble-out: #dcf8c6;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 4px; }
h3 { font-size: 14px; margin: 0 0 8px; }

button { font: inherit; cursor: pointer; }
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f1efe9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0b5a46; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e8c9c9; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link { border: 0; background: none; color: var(--muted); text-decoration: underline; font-size: 12px; padding: 0; }

/* 登录 */
.login-wrap { height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.logo {
  width: 42px; height: 42px; border-radius: 12px; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-weight: 600; letter-spacing: .5px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.err { color: var(--danger); font-size: 13px; margin: 0; min-height: 18px; }

/* 布局 */
.app { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 14px 14px 8px; border-bottom: 1px solid var(--line); }
.side-title { display: flex; align-items: center; gap: 8px; justify-content: space-between; font-weight: 600; }
.me-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.me-name { font-size: 12px; color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell { border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; text-decoration: none; font-size: 11px; white-space: nowrap; }
.bell:hover { color: var(--text); background: rgba(18, 140, 126, 0.08); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.badge.on { background: var(--accent-soft); color: var(--accent); border-color: #b7e3d2; }
.badge.off { background: #faf1e6; color: #92500f; border-color: #f0dcc2; }
.tabs { display: flex; gap: 4px; margin: 10px 0 8px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 99px;
  color: var(--muted); white-space: nowrap; font-size: 13px;
}
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.search { width: 100%; }

.chat-list { overflow-y: auto; flex: 1; }
.chat-item {
  display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid #f2f0ea;
  cursor: pointer; align-items: flex-start;
}
.chat-item:hover { background: #faf9f5; }
.chat-item.active { background: var(--accent-soft); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 38px;
  display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 500;
}
.chat-item .info { flex: 1; min-width: 0; }
.chat-item .top { display: flex; justify-content: space-between; gap: 6px; }
.chat-item .nm { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .tm { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.chat-item .last { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.unread {
  background: var(--accent); color: #fff; border-radius: 99px; font-size: 11px;
  min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px;
}
.who { font-size: 11px; color: #8a8a80; margin-top: 3px; }

.main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.chat-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.empty { flex: 1; display: grid; place-content: center; gap: 6px; text-align: center; color: var(--muted); }
.empty-art { font-size: 34px; }

.chat-body { flex: 1; min-height: 0; display: flex; flex-direction: column; background: #efece4; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.chat-id { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-actions { display: flex; gap: 6px; }
.icon-btn { border: 0; background: transparent; font-size: 18px; padding: 4px 8px; color: var(--muted); }
.icon-btn.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 68%; display: flex; flex-direction: column; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble {
  background: var(--bubble-in); border-radius: 10px; padding: 8px 11px;
  line-height: 1.5; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.04);
}
.msg.out .bubble { background: var(--bubble-out); }
.msg .meta { font-size: 10.5px; color: #8a8a80; margin-top: 2px; }
.msg.pending { opacity: 0.65; }
.msg.pending .bubble img { filter: grayscale(0.15); }
.sending { font-size: 10.5px; color: #8a8a80; margin-top: 4px; }
.chat-body.drop-hover { outline: 2px dashed #128c7e; outline-offset: -8px; background: rgba(18, 140, 126, 0.04); }
.bubble img { max-width: 240px; border-radius: 8px; display: block; }
.bubble a { color: #0a6b52; }
.day-sep { align-self: center; font-size: 11px; color: #7d7d74; background: #e6e2d8; padding: 3px 10px; border-radius: 99px; margin: 8px 0; }

/* 待发送附件预览条（跟 WhatsApp 一样，先看清再发） */
.attach-bar { border-top: 1px solid var(--line); background: var(--surface); padding: 10px 14px 6px; }
.attach-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.attach-item {
  position: relative; flex: 0 0 auto; width: 118px;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg);
}
.attach-item img { width: 100%; height: 88px; object-fit: cover; display: block; }
.attach-doc {
  height: 88px; display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
}
.attach-meta { padding: 5px 7px; display: grid; gap: 1px; }
.attach-name { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-x {
  position: absolute; top: 4px; right: 4px; width: 21px; height: 21px;
  display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%;
  background: rgba(20, 20, 16, .6); color: #fff; font-size: 15px; line-height: 1;
}
.attach-x:hover { background: rgba(20, 20, 16, .88); }
.attach-hint { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 2px; }
.attach-bar + .composer { border-top: 0; }

/* 消息更多菜单 / 撤回 / 大图 / 表情 */
.msg .meta { position: relative; }
.msg-more {
  border: 0; background: transparent; color: var(--muted); font-size: 15px;
  line-height: 1; padding: 0 4px; margin-left: 4px; opacity: 0; transition: opacity .12s;
}
.msg:hover .msg-more, .msg-more:focus { opacity: 1; }
.msg-menu {
  position: fixed; z-index: 80; min-width: 168px; padding: 5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(20,20,16,.16);
}
.msg-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; border-radius: 7px; font-size: 13px; color: var(--text);
}
.msg-menu button:hover { background: var(--bg); }
.msg-menu button.danger { color: var(--danger); }
.revoked { color: var(--muted); font-style: italic; font-size: 12.5px; }

/* 删除 / 编辑弹窗 */
.del-opt {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.del-opt:hover { background: var(--bg); }
.del-opt input { margin-top: 3px; flex: 0 0 auto; }
.del-opt span { display: block; }
.del-opt strong { display: block; font-size: 13.5px; font-weight: 600; }
.del-opt .small { display: block; margin-top: 3px; line-height: 1.45; }
.del-opt:has(input:checked) { border-color: var(--brand); background: rgba(37,211,102,.07); }
.edit-area {
  width: 100%; margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; line-height: 1.5; resize: vertical;
}
.del-log { max-height: 52vh; overflow: auto; }
.del-log-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.del-log-row:last-child { border-bottom: 0; }
img.zoomable { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 90; background: rgba(12,12,10,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px;
}
.lightbox img { max-width: 94vw; max-height: 80vh; object-fit: contain; border-radius: 6px; }
.lightbox-bar { display: flex; gap: 8px; }
.lightbox-bar .btn { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.emoji-wrap { position: relative; flex: 0 0 auto; }
.emoji-panel {
  position: absolute; bottom: 46px; left: -6px; z-index: 70;
  width: min(340px, 78vw); max-height: 244px; overflow-y: auto;
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(20,20,16,.16);
}
.emoji-panel button {
  border: 0; background: transparent; font-size: 20px; line-height: 1;
  padding: 5px 0; border-radius: 6px; cursor: pointer;
}
.emoji-panel button:hover { background: var(--bg); }

.composer { display: flex; gap: 8px; padding: 10px 14px; background: var(--surface); border-top: 1px solid var(--line); align-items: flex-end; }
.composer .btn { flex: 0 0 auto; white-space: nowrap; }
.composer .icon-btn { flex: 0 0 auto; }
.composer textarea { resize: none; max-height: 120px; border-radius: 18px; }

/* 面板 */
.pane { padding: 20px; overflow-y: auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 14px 0; }
.card-list { display: grid; gap: 10px; }
.user-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.user-row .grow { flex: 1; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #c9c7bd; display: inline-block; }
.dot.on { background: #1d9e75; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.form-grid label, .pane label, .card > label {
  display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); margin-top: 8px;
}
.check { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
.check input { width: auto; }
.kw-list { display: grid; gap: 8px; margin-top: 8px; }
.kw-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; align-items: center; }
.qr-box { margin-top: 14px; text-align: center; }
.qr-box img { width: 240px; height: 240px; border: 1px solid var(--line); border-radius: 10px; }
.wa-state { font-size: 13px; color: var(--muted); line-height: 1.7; }
.add-box summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.card list { margin: 0; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #f1efe9; color: #6b6b62; }

/* 弹窗 */
.modal { position: absolute; inset: 0; background: rgba(20,20,16,.35); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal-card { background: #fff; border-radius: 14px; padding: 20px; width: 100%; max-width: 420px; max-height: 82vh; overflow: auto; }
.toast {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #23231f; color: #fff; padding: 9px 16px; border-radius: 99px; font-size: 13px; z-index: 60;
}

/* 手机 */
@media (max-width: 760px) {
  .msg-more { opacity: .55; }
  .emoji-panel { grid-template-columns: repeat(8, 1fr); }
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .main { position: absolute; inset: 0; background: var(--bg); z-index: 20; display: none; }
  .app.mobile-chat .main { display: flex; }
  .app.mobile-chat .sidebar { display: none; }
  .icon-btn.back { display: block; }
  .msg { max-width: 84%; }
  .chat-actions .btn { padding: 4px 8px; font-size: 12px; }
}
