* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif; color: #222; background: #ededed; }
button { font-family: inherit; }

#app {
  display: grid;
  grid-template-columns: 64px 280px 1fr;
  height: 100vh;
  background: #f7f7f7;
}

/* ---------- 左侧导航 ---------- */
.sidebar {
  background: #2e2e2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 16px;
  color: #b0b0b0;
}
.me { margin-bottom: 28px; }
.avatar {
  width: 40px; height: 40px; border-radius: 6px;
  background: #07c160; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px;
  user-select: none;
}
.nav { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.nav-item {
  width: 48px; height: 48px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 6px; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { color: #fff; }
.nav-item.active { color: #07c160; background: rgba(255,255,255,0.05); }
.nav-item span { font-size: 10px; margin-top: 2px; display: none; }
.logout { padding: 10px; cursor: pointer; color: #b0b0b0; }
.logout:hover { color: #fff; }

/* ---------- 中间栏 ---------- */
.middle {
  background: #ededed;
  border-right: 1px solid #d8d8d8;
  display: flex; flex-direction: column;
  min-width: 0;
}
.middle-header {
  display: flex; gap: 8px; padding: 12px;
  background: #ededed; border-bottom: 1px solid #d8d8d8;
}
.middle-header input {
  flex: 1; padding: 6px 10px; border: 1px solid #d8d8d8;
  border-radius: 4px; background: #fff; font-size: 13px; outline: none;
}
.middle-header input:focus { border-color: #07c160; }
.middle-header button {
  width: 32px; height: 32px; background: #fff; border: 1px solid #d8d8d8;
  border-radius: 4px; cursor: pointer; font-size: 18px; color: #555;
}
.middle-header button:hover { background: #f5f5f5; }
.middle-body { flex: 1; overflow-y: auto; }

.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; cursor: pointer; border-bottom: 1px solid #e8e8e8;
  transition: background .12s;
}
.conv-item:hover { background: #e0e0e0; }
.conv-item.active { background: #d0d0d0; }
.conv-item .avatar { width: 40px; height: 40px; flex-shrink: 0; font-size: 14px; }
.conv-item .info { flex: 1; min-width: 0; }
.conv-item .name {
  font-size: 14px; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .sub {
  font-size: 12px; color: #888; margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .right { font-size: 11px; color: #aaa; }

.section-title { padding: 10px 12px; font-size: 12px; color: #888; }

/* ---------- 主聊天区 ---------- */
.main { display: flex; flex-direction: column; background: #f5f5f5; min-width: 0; }
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #999; gap: 12px;
}
.empty-logo {
  width: 80px; height: 80px; border-radius: 20px;
  background: #07c160; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; opacity: .9;
}
.tiny { font-size: 12px; color: #bbb; }

#chatPanel { display: flex; flex-direction: column; height: 100%; }

.chat-header {
  padding: 14px 20px; background: #f5f5f5; border-bottom: 1px solid #e0e0e0;
}
.chat-title { font-size: 16px; font-weight: 500; color: #222; }
.chat-sub { font-size: 12px; color: #999; margin-top: 2px; }

.messages {
  flex: 1; overflow-y: auto; padding: 18px 20px;
  background: #f5f5f5;
}
.msg-row {
  display: flex; gap: 10px; margin-bottom: 18px;
}
.msg-row.me { flex-direction: row-reverse; }
.msg-row .avatar { width: 36px; height: 36px; font-size: 13px; flex-shrink: 0; border-radius: 4px; }
.msg-content { max-width: 60%; }
.msg-row.me .msg-content { display: flex; flex-direction: column; align-items: flex-end; }
.msg-author { font-size: 11px; color: #999; margin-bottom: 4px; }
.msg-row.me .msg-author { display: none; }
.bubble {
  padding: 9px 12px; border-radius: 6px; background: #fff;
  font-size: 14px; line-height: 1.5; word-wrap: break-word; word-break: break-word;
  position: relative; box-shadow: 0 1px 1px rgba(0,0,0,0.04);
  max-width: 100%;
}
.msg-row.me .bubble { background: #95ec69; }
.bubble.image-bubble { padding: 4px; background: #fff; }
.bubble.image-bubble img {
  max-width: 220px; max-height: 220px; border-radius: 4px; display: block; cursor: pointer;
}
.bubble.voice-bubble {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  min-width: 80px;
}
.voice-icon {
  width: 16px; height: 16px; display: inline-block;
}
.voice-bubble.playing .voice-icon { animation: voicePlay 1s infinite; }
@keyframes voicePlay {
  0%, 100% { opacity: .3; }
  50% { opacity: 1; }
}
.msg-time { font-size: 11px; color: #aaa; margin-top: 4px; }
.system-tip {
  text-align: center; color: #999; font-size: 12px; margin: 12px 0;
}
.system-tip span {
  background: rgba(0,0,0,0.08); padding: 3px 10px; border-radius: 3px;
}

/* ---------- 输入区 ---------- */
.composer {
  border-top: 1px solid #e0e0e0; background: #f5f5f5; padding: 8px 16px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.mobile-plus { display: none; }
.mobile-tools-panel { display: none; }

/* 弹出菜单文字颜色兜底（手机端浏览器有时会用默认浅色） */
.add-menu, .msg-menu { color: #222; }
.add-menu .mm-item, .msg-menu .mm-item { color: #222; }
.add-menu .mm-item:active, .msg-menu .mm-item:active { background: #ececec; }
.composer-tools { display: flex; gap: 8px; }
.tool {
  background: none; border: none; cursor: pointer; padding: 4px;
  color: #555; border-radius: 4px; display: flex; align-items: center;
}
.tool:hover { color: #07c160; background: #ececec; }
.tool input[type="file"] { display: none; }
#voiceBtn.recording { color: #e64340; background: #fee; }

#msgInput {
  width: 100%; border: none; outline: none; background: transparent;
  resize: none; font-size: 14px; padding: 4px 0; font-family: inherit;
  min-height: 50px;
}
.composer .send-btn {
  align-self: flex-end; background: #07c160; color: #fff;
  border: none; padding: 6px 18px; border-radius: 4px;
  cursor: pointer; font-size: 13px;
}
.composer .send-btn:hover { background: #06ad56; }
.composer .send-btn:disabled { background: #aaa; cursor: not-allowed; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  width: 420px; max-height: 80vh; background: #fff; border-radius: 8px;
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.modal-card h3 { font-size: 16px; }
.modal-card input {
  width: 100%; padding: 8px 10px; border: 1px solid #d8d8d8;
  border-radius: 4px; outline: none; font-size: 14px;
}
.modal-card input:focus { border-color: #07c160; }
.group-users {
  max-height: 280px; overflow-y: auto; border: 1px solid #eee; border-radius: 4px; padding: 4px;
}
.group-user {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  cursor: pointer; border-radius: 4px;
}
.group-user:hover { background: #f5f5f5; }
.group-user input { width: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions button {
  padding: 6px 16px; border: 1px solid #d8d8d8; background: #fff;
  border-radius: 4px; cursor: pointer; font-size: 13px;
}
.modal-actions button.primary { background: #07c160; color: #fff; border-color: #07c160; }
.modal-actions button.primary:hover { background: #06ad56; }

/* ---------- 图片预览 ---------- */
.image-viewer {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 200;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.image-viewer img { max-width: 92%; max-height: 92%; border-radius: 4px; }

/* ---------- 设置面板 ---------- */
.settings-panel { padding: 20px; }
.settings-panel h3 { font-size: 16px; margin-bottom: 12px; color: #333; }
.settings-row {
  padding: 14px 0; border-bottom: 1px solid #eee;
  display: flex; justify-content: space-between; align-items: center;
}
.settings-row .label { font-size: 14px; color: #333; }
.settings-row .value { font-size: 13px; color: #888; }
.settings-row .desc { font-size: 12px; color: #999; margin-top: 6px; }

/* 聊天头部右侧动作按钮 */
.chat-actions { display: flex; gap: 6px; align-items: center; }
.chat-action-btn {
  background: none; border: none; cursor: pointer;
  padding: 6px 10px; color: #555; border-radius: 4px; font-size: 13px;
}
.chat-action-btn:hover { background: #ececec; color: #07c160; }

/* 引用条 */
.reply-bar {
  display: flex; align-items: center; background: #fff;
  border-top: 1px solid #e0e0e0; border-bottom: 1px solid #e0e0e0;
  padding: 8px 14px; gap: 10px;
}
.reply-info { flex: 1; min-width: 0; border-left: 3px solid #07c160; padding-left: 8px; }
.reply-label { font-size: 12px; color: #07c160; }
.reply-preview { font-size: 13px; color: #555; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar button { background: none; border: none; font-size: 20px; color: #999; cursor: pointer; padding: 0 4px; }
.reply-bar button:hover { color: #333; }

/* 消息中的引用气泡 */
.reply-quote {
  background: rgba(0,0,0,0.04); border-left: 3px solid #07c160;
  padding: 6px 8px; margin-bottom: 6px; border-radius: 4px;
  font-size: 12px; color: #666; cursor: pointer; max-width: 100%;
}
.reply-quote.recalled { font-style: italic; color: #aaa; border-left-color: #ccc; }
.reply-quote-name { color: #07c160; font-size: 11px; margin-bottom: 2px; }

/* 文件消息 */
.bubble.file-bubble {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; min-width: 220px; max-width: 280px; cursor: pointer;
}
.file-icon {
  width: 36px; height: 36px; border-radius: 6px; background: #07c160; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 13px; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 11px; color: #999; margin-top: 2px; }

/* 高亮跳转 */
@keyframes msgHighlight {
  0%, 100% { background: transparent; }
  20% { background: #fff4b8; }
}
.msg-row.highlight { animation: msgHighlight 1.5s; border-radius: 6px; }

/* 设置面板的可点击项 */
.settings-row.clickable { cursor: pointer; }
.settings-row.clickable:hover { background: #fafafa; }
.settings-row .arrow { color: #ccc; }

/* 头像图片 */
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }

/* 群成员列表 */
.member-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 12px; max-height: 360px; overflow-y: auto; padding: 4px;
}
.member-item {
  display: flex; flex-direction: column; align-items: center;
  font-size: 12px; color: #555; gap: 4px; position: relative;
}
.member-item.kickable { cursor: pointer; }
.member-item .kick-x {
  position: absolute; top: -4px; right: 8px; background: #e64340; color: #fff;
  width: 18px; height: 18px; border-radius: 50%; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity .15s;
}
.member-item:hover .kick-x { opacity: 1; }
.member-owner-tag {
  background: #fa9d3b; color: #fff; font-size: 10px; padding: 1px 4px; border-radius: 2px; margin-left: 2px;
}

/* 搜索结果 */
.search-result-item {
  padding: 12px; border-bottom: 1px solid #eee; cursor: pointer;
}
.search-result-item:hover { background: #f5f5f5; }
.search-result-conv { font-size: 13px; color: #07c160; }
.search-result-snippet { font-size: 13px; color: #333; margin-top: 4px; }
.search-result-snippet mark { background: #ffe79b; color: inherit; padding: 0 1px; }
.search-result-time { font-size: 11px; color: #aaa; margin-top: 4px; }

/* ----------- 视频通话 ----------- */
.call-panel {
  position: fixed; right: 20px; bottom: 20px; width: 360px;
  background: #1c1c1c; color: #fff; border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5); z-index: 400;
  overflow: hidden; display: flex; flex-direction: column;
}
.call-panel.fullscreen {
  inset: 0; width: auto; right: 0; bottom: 0; border-radius: 0;
}
.call-header {
  padding: 10px 14px; background: rgba(0,0,0,0.4); display: flex; gap: 10px;
  align-items: center; font-size: 13px;
}
.call-header span:nth-child(1) { flex: 1; font-weight: 500; }
.call-videos { position: relative; background: #000; aspect-ratio: 4/3; }
.call-videos #remoteVideo { width: 100%; height: 100%; object-fit: cover; background: #000; }
.call-videos #localVideo {
  position: absolute; right: 8px; top: 8px; width: 90px; height: 120px;
  object-fit: cover; border-radius: 6px; background: #333;
  border: 2px solid rgba(255,255,255,0.3);
}
.call-controls {
  display: flex; justify-content: center; gap: 18px; padding: 14px; background: rgba(0,0,0,0.4);
}
.call-btn {
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.18); color: #fff; cursor: pointer;
  font-size: 12px; transition: transform .12s;
}
.call-btn:hover { transform: scale(1.06); }
.call-btn.hangup { background: #e64340; }
.call-btn.accept { background: #07c160; }
.call-btn.active { background: #07c160; }

.incoming-call {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
.incoming-card {
  background: #fff; padding: 32px 40px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center;
}

/* 在线状态小绿点 */
.presence-dot {
  position: absolute; right: -2px; bottom: -2px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #bbb; border: 2px solid #ededed;
}
.presence-dot.online { background: #07c160; }

/* 消息长按菜单项的 hover */
.msg-menu .mm-item:hover { background: #f5f5f5; }

/* 防止移动端长按选中文字 */
.bubble {
  -webkit-user-select: text;
  -webkit-touch-callout: none;
}

/* 移动端响应式 */
@media (max-width: 760px) {
  /* ========== 手机端整体布局 ========== */
  html, body { overscroll-behavior: none; }
  #app {
    display: block;
    position: fixed;
    inset: 0;
    overflow: hidden;
  }
  /* 底部导航栏 */
  .sidebar {
    position: fixed;
    left: 0;
    top: auto;
    bottom: 0;
    width: 100vw;
    height: calc(54px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    flex-direction: row;
    justify-content: space-around;
    align-items: stretch;
    z-index: 20;
    background: #f7f7f7;
    color: #888;
    border-top: 1px solid #e0e0e0;
  }
  .sidebar .me { display: none; }
  .sidebar .nav {
    display: flex; flex-direction: row; flex: 1; height: 100%; gap: 0; padding: 0; align-items: stretch;
  }
  .sidebar .nav-item {
    flex: 1; margin: 0; height: 100%; width: auto; border-radius: 0;
    color: #888;
  }
  .sidebar .nav-item.active { color: #07c160; background: transparent; }
  .sidebar .nav-item span { display: block; font-size: 10px; margin-top: 2px; }
  .sidebar .nav-item svg { width: 22px; height: 22px; }
  .sidebar .logout { display: none; }

  /* 中间栏（会话/通讯录列表）—— 满屏 */
  .middle {
    position: absolute;
    left: 0; top: 0; right: 0;
    bottom: calc(54px + env(safe-area-inset-bottom));
    width: 100vw;
    z-index: 5;
    background: #ededed;
  }
  .middle-header {
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  /* 聊天主区 —— 全屏 */
  .main {
    position: absolute;
    left: 100vw; top: 0; right: auto; bottom: 0;
    width: 100vw;
    height: 100dvh;        /* 动态视口高度，键盘弹出时自动收缩 */
    z-index: 30;
    background: #ededed;
    transition: left 0.25s ease;
  }
  #app.show-chat .main { left: 0; }
  #app.show-chat .middle { left: -100vw; }
  #app.show-chat .sidebar { display: none; }   /* 进入聊天后隐藏底部 nav */

  /* 聊天页结构 */
  #chatPanel { height: 100dvh; }
  .chat-header {
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    display: flex; align-items: center; gap: 6px;
    background: #ededed; border-bottom: 1px solid #d8d8d8;
    min-height: calc(48px + env(safe-area-inset-top));
  }
  .chat-title { font-size: 16px; font-weight: 500; text-align: center; }
  .chat-sub { font-size: 11px; text-align: center; }

  .messages {
    background: #ededed; padding: 10px 10px;
  }
  .msg-row { margin-bottom: 14px; gap: 8px; }
  .msg-row .avatar { width: 36px; height: 36px; }
  .msg-content { max-width: 72%; }
  .bubble { font-size: 15px; padding: 8px 11px; border-radius: 4px; }
  .msg-author { font-size: 11px; color: #888; margin-bottom: 2px; padding: 0 2px; }

  /* 输入区（仿微信） */
  .composer {
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: #f7f7f7;
    border-top: 1px solid #d8d8d8;
    display: flex; flex-direction: row; align-items: flex-end; gap: 6px;
    flex-wrap: nowrap;
  }
  .composer-tools {
    /* 手机端：工具栏改成右侧的"+"按钮展开 */
    display: contents;
  }
  .composer-tools .tool {
    order: 3; /* 主要工具放到输入框右边 */
    padding: 8px;
    width: 36px; height: 36px;
    justify-content: center;
    align-self: flex-end;
  }
  .composer-tools .tool svg { width: 22px; height: 22px; }
  /* 默认手机上：图片/文件/语音/视频图标都隐藏，由"+"按钮展开 */
  #imgInput, #fileInput { display: none; }
  .composer label.tool,
  #voiceBtn, #videoCallBtn { display: none; }
  /* "+"按钮展开后显示 */
  .composer.tools-open label.tool,
  .composer.tools-open #voiceBtn,
  .composer.tools-open #videoCallBtn { display: flex; }

  /* 加号按钮（手机端专属） */
  .composer .mobile-plus {
    display: flex !important;
    order: 4;
    background: none; border: none; cursor: pointer;
    padding: 6px; width: 36px; height: 36px;
    align-items: center; justify-content: center;
    color: #555; align-self: flex-end;
  }
  .composer .mobile-plus svg { width: 26px; height: 26px; }
  /* 手机端隐藏顶部的工具行内按钮（图片/文件/语音/视频）—— 改为通过 "+" 弹出 */
  .composer-tools { display: none !important; }

  #msgInput {
    order: 2;
    flex: 1; min-height: 36px; max-height: 96px;
    padding: 8px 10px; border-radius: 4px;
    background: #fff; border: 1px solid #d8d8d8;
    font-size: 15px;
  }
  .composer .send-btn {
    order: 5;
    padding: 0 14px; height: 36px;
    min-width: 56px;
    font-size: 14px;
    align-self: flex-end;
  }

  /* "+"按钮展开后多出的工具弹出栏（仿微信底部宫格） */
  .mobile-tools-panel {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 14px;
    background: #f7f7f7;
    border-top: 1px solid #e0e0e0;
  }
  .composer-bottom { background: #f7f7f7; }
  .composer-bottom.show-panel .mobile-tools-panel { display: grid; }
  .mobile-tool-item {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    cursor: pointer; color: #333; font-size: 12px;
  }
  .mobile-tool-item .icon-box {
    width: 56px; height: 56px;
    background: #fff;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  }
  .mobile-tool-item svg { width: 30px; height: 30px; color: #555; }

  /* 聊天页操作区按钮（… 菜单） */
  .chat-actions { gap: 4px; }
  .chat-actions button { font-size: 13px; padding: 4px 8px; }

  .empty-state { padding-top: 40vh; }

  /* 视频通话面板适配 */
  #videoCallPanel { padding: 0 !important; }
}

/* 滚动条美化 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #cfcfcf; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b0b0; }
::-webkit-scrollbar-track { background: transparent; }
