/* ===== 基础重置 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; }
body { background: #f0f2f5; color: #1f2328; }

/* ===== 登录 ===== */
.login-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
.login-box {
  background: #fff; padding: 32px 40px; border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.15); min-width: 320px;
  text-align: center;
}
.login-box h2 { margin-bottom: 8px; font-size: 20px; }
.login-tip { color: #666; font-size: 13px; margin-bottom: 16px; }
.login-box input {
  width: 100%; padding: 10px 14px; border: 1px solid #d0d7de;
  border-radius: 8px; font-size: 14px; margin-bottom: 16px;
}
.login-box input:focus { outline: none; border-color: #1677ff; box-shadow: 0 0 0 2px rgba(22,119,255,.15); }
.login-box button {
  width: 100%; padding: 10px; background: #1677ff; color: #fff;
  border: none; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.login-box button:hover { background: #4096ff; }

/* ===== 应用布局 ===== */
#app { display: flex; flex-direction: column; height: 100vh; }

/* 顶部栏 */
.topbar {
  height: 48px; background: #fff; border-bottom: 1px solid #e5e7eb;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0;
}
.topbar .title { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.brand-icon { width: 22px; height: 22px; flex-shrink: 0; }
.status-row { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #666; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-online { background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,.5); }
.dot-starting { background: #f59e0b; animation: pulse 1s infinite; }
.dot-reconnecting { background: #f59e0b; animation: pulse 1s infinite; }
.dot-offline { background: #9ca3af; }
.dot-error { background: #ef4444; }
.dot-unknown { background: #9ca3af; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* 主区 */
.main { flex: 1; display: flex; overflow: hidden; }

/* 左侧会话 */
.sidebar {
  width: 280px; background: #fff; border-right: 1px solid #e5e7eb;
  display: flex; flex-direction: column; flex-shrink: 0;
}
.side-head { padding: 12px; border-bottom: 1px solid #f0f0f0; }
.side-head input {
  width: 100%; padding: 8px 12px; border: 1px solid #e5e7eb;
  border-radius: 6px; font-size: 13px; background: #f9fafb;
}
.side-head input:focus { outline: none; border-color: #1677ff; background: #fff; }
.session-list { flex: 1; overflow-y: auto; list-style: none; }
.session-item {
  padding: 12px 16px; border-bottom: 1px solid #f5f5f5;
  cursor: pointer; transition: background .15s;
}
.session-item:hover { background: #f9fafb; }
.session-item.active { background: #eff6ff; border-left: 3px solid #1677ff; padding-left: 13px; }
.session-title { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 6px; min-width: 0; }
.session-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-remark { color: #8a8f99; font-weight: normal; }
.session-type { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #e0e7ff; color: #4f46e5; font-weight: normal; flex-shrink: 0; }
.session-type.group { background: #fef3c7; color: #92400e; }
.session-type.pin { background: #e8f7ee; color: #15803d; }
.session-preview { font-size: 12px; color: #888; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.session-bottom .session-preview { flex: 1; min-width: 0; }
.session-time { font-size: 11px; color: #bbb; flex-shrink: 0; }
.session-item .badge {
  float: right; background: #ef4444; color: #fff; font-size: 11px;
  padding: 0 6px; border-radius: 10px; min-width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center; margin-top: -22px;
}

/* 侧栏 Tab：会话 / 通讯录 / 群 */
.side-tabs { display: flex; border-bottom: 1px solid #f0f0f0; flex-shrink: 0; }
.side-tab {
  flex: 1; padding: 10px 0; border: none; background: #fafafa;
  cursor: pointer; font-size: 13px; color: #666; transition: color .15s;
}
.side-tab:hover { color: #1677ff; }
.side-tab.active { background: #fff; color: #1677ff; font-weight: 600; box-shadow: inset 0 -2px 0 #1677ff; }

/* 通讯录 */
.dept-item {
  padding: 8px 12px; font-size: 13px; font-weight: 600; color: #444;
  background: #fafafa; border-bottom: 1px solid #f5f5f5; user-select: none;
}
.dept-count { float: right; font-weight: normal; font-size: 11px; color: #aaa; }
.member-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-bottom: 1px solid #f9f9f9; cursor: pointer; transition: background .15s;
}
.member-item:hover { background: #f9fafb; }
.member-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: #e0e7ff; color: #4f46e5;
  font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.member-name { font-size: 13px; color: #333; }
.member-title { font-size: 11px; color: #999; margin-left: auto; }
.list-hint { padding: 20px; color: #aaa; text-align: center; font-size: 13px; list-style: none; }
.list-error { padding: 20px; color: #dc2626; text-align: center; font-size: 13px; list-style: none; line-height: 1.6; }

/* 侧栏底部固定刷新区 */
.side-foot { padding: 10px 12px; border-top: 1px solid #f0f0f0; flex-shrink: 0; }
.side-refresh { width: 100%; }

/* 聊天区 */
.chat { flex: 1; display: flex; flex-direction: column; background: #f0f2f5; }
.chat-head {
  height: 52px; background: #fff; border-bottom: 1px solid #e5e7eb;
  padding: 0 20px; display: flex; flex-direction: column; justify-content: center;
  flex-shrink: 0;
}
.chat-title { font-size: 15px; font-weight: 600; }
.chat-meta { font-size: 12px; color: #888; margin-top: 2px; }

.chat-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.empty-hint { text-align: center; color: #aaa; margin: auto; }
.empty-hint .emoji { margin-bottom: 12px; }
.empty-hint .emoji svg { width: 56px; height: 56px; display: block; margin: 0 auto; }

/* 气泡 */
.msg { display: flex; max-width: 75%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; flex-direction: row-reverse; }
.msg-bubble { padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.msg.in .msg-bubble { background: #fff; border-top-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.msg.out .msg-bubble { background: #1677ff; color: #fff; border-top-right-radius: 4px; }
.msg-sender { font-size: 11px; color: #888; margin-bottom: 3px; }
.msg.out .msg-sender { text-align: right; }
.msg-time { font-size: 11px; color: #aaa; margin-top: 3px; }
.msg.out .msg-time { text-align: right; }

/* 媒体 */
.msg-img, .msg-file { max-width: 300px; border-radius: 8px; display: block; }
.msg.out .msg-img { max-width: 300px; }

/* 输入区（参考钉钉桌面端：整体圆角卡片 + 底部工具栏） */
.chat-input {
  background: #fff; border-top: 1px solid #f0f0f0;
  padding: 10px 16px 12px; flex-shrink: 0;
}
.composer {
  position: relative;
  border: 1px solid #e5e7eb; border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
/* 表情面板：浮于输入框上方 */
.emoji-panel {
  position: absolute; left: 8px; bottom: 46px; z-index: 999;
  display: grid; grid-template-columns: repeat(9, 28px); gap: 2px;
  padding: 8px; background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  max-height: 216px; overflow-y: auto;
}
.emoji-item {
  width: 28px; height: 28px; padding: 0; border: none; border-radius: 6px;
  background: transparent; font-size: 17px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.emoji-item:hover { background: #f2f3f5; }
/* 表情图片：跨平台一致的扁平样式 */
.emoji-img { width: 18px; height: 18px; vertical-align: -3px; display: inline-block; }
.msg-text .emoji-img { width: 20px; height: 20px; }
.session-preview .emoji-img { width: 16px; height: 16px; vertical-align: -2px; }
.emoji-item .emoji-img { width: 20px; height: 20px; vertical-align: middle; }
.composer:focus-within {
  border-color: #1677ff; box-shadow: 0 0 0 2px rgba(22,119,255,.12);
}
#msgInput {
  display: block; width: 100%; padding: 10px 14px 4px;
  border: none; outline: none; background: transparent;
  font-size: 14px; font-family: inherit; resize: none;
  min-height: 42px; max-height: 160px; line-height: 1.5;
}
.composer-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 8px 6px 10px;
}
.composer-tools { display: flex; gap: 2px; }
.tool-btn {
  height: 28px; padding: 0 10px; display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 6px; background: transparent;
  font-size: 13px; color: #4a4f56; cursor: pointer; line-height: 1;
  transition: background .15s, color .15s;
}
.tool-btn:hover { background: #f2f3f5; color: #1677ff; }
.composer-right { display: flex; align-items: center; gap: 10px; }
.input-hint { font-size: 11px; color: #b0b3b8; white-space: nowrap; }
.send-btn {
  padding: 5px 18px; border: none; border-radius: 6px;
  background: #1677ff; color: #fff; font-size: 13px; cursor: pointer;
  transition: background .15s;
}
.send-btn:hover { background: #4096ff; }
.send-btn:active { background: #0958d9; }
.btn {
  padding: 8px 16px; border: 1px solid #e5e7eb; border-radius: 6px;
  font-size: 13px; cursor: pointer; background: #fff; transition: all .15s;
}
.btn:hover { border-color: #1677ff; color: #1677ff; }
.btn-primary { background: #1677ff; color: #fff; border-color: #1677ff; }
.btn-primary:hover { background: #4096ff; color: #fff; }
.btn-ghost { background: transparent; }
@media (max-width: 620px) {
  .input-hint { display: none; }
}

/* 弹窗 */
.dialog-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 998;
}
.dialog-box {
  background: #fff; padding: 24px; border-radius: 10px; min-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.dialog-box h3 { margin-bottom: 16px; font-size: 16px; }
.dialog-box input {
  width: 100%; padding: 10px 12px; border: 1px solid #d0d7de; border-radius: 6px;
  font-size: 13px; margin-bottom: 16px;
}
.dialog-box input:focus { outline: none; border-color: #1677ff; }
.dialog-btns { display: flex; gap: 10px; justify-content: flex-end; }

/* Toast */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.8); color: #fff; padding: 10px 20px; border-radius: 6px;
  font-size: 13px; z-index: 1000; max-width: 80%;
}

.hidden { display: none !important; }

/* 滚动条美化 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* 图片预览 */
.preview-img { max-width: 100%; max-height: 200px; border-radius: 6px; }

/* 自定义右键菜单 */
.ctx-menu {
  position: fixed; z-index: 9999; min-width: 160px; padding: 4px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.12);
}
.ctx-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; font-size: 13px; color: #333;
  border-radius: 6px; cursor: pointer; user-select: none;
}
.ctx-item:hover { background: #eff6ff; color: #1677ff; }
.ctx-icon { width: 18px; text-align: center; }

/* 已读状态 / 撤回 */
.msg-time .recall-link { color: #1677ff; text-decoration: none; }
.msg-time .recall-link:hover { text-decoration: underline; }
.msg-time .read-status { color: #999; }
