* { margin: 0; padding: 0; box-sizing: border-box; }
:root{
  --primary:#2563eb; --primary-d:#1d4ed8; --bg:#f0f2f5; --panel:#fff;
  --line:#e5e7eb; --text:#1f2937; --muted:#9ca3af; --bubble:#e5e7eb;
}
html,body{height:100%;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Microsoft YaHei",sans-serif;color:var(--text)}
body{background:var(--bg)}
a{text-decoration:none;color:inherit}

/* ============ 登录注册页 ============ */
.auth-wrap{min-height:100vh;display:flex;align-items:center;justify-content:center;
  background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);padding:20px}
.auth-card{background:#fff;border-radius:18px;box-shadow:0 20px 60px rgba(0,0,0,.2);
  width:100%;max-width:400px;padding:40px 36px}
.auth-card h1{font-size:26px;text-align:center;margin-bottom:6px;color:#111827}
.auth-card .sub{text-align:center;color:var(--muted);margin-bottom:28px;font-size:14px}
.tabs{display:flex;border-bottom:2px solid var(--line);margin-bottom:24px}
.tabs button{flex:1;background:none;border:0;padding:12px;font-size:16px;cursor:pointer;color:var(--muted);
  border-bottom:2px solid transparent;margin-bottom:-2px;transition:.2s}
.tabs button.active{color:var(--primary);border-bottom-color:var(--primary);font-weight:600}
.field{margin-bottom:18px;position:relative}
.field label{display:block;font-size:13px;color:#4b5563;margin-bottom:6px}
.field input{width:100%;padding:12px 14px;border:1px solid #d1d5db;border-radius:9px;font-size:15px;
  outline:none;transition:.2s}
.field input:focus{border-color:var(--primary);box-shadow:0 0 0 3px rgba(37,99,235,.12)}
.btn{width:100%;background:var(--primary);color:#fff;border:0;padding:13px;border-radius:9px;
  font-size:16px;cursor:pointer;transition:.2s;font-weight:600}
.btn:hover{background:var(--primary-d)}
.btn:disabled{opacity:.6;cursor:not-allowed}
.msg{min-height:20px;margin-top:12px;font-size:13px;text-align:center}
.msg.err{color:#dc2626}.msg.ok{color:#16a34a}

/* ============ 聊天主界面 ============ */
.chat-app{height:100vh;display:flex;background:var(--panel);overflow:hidden}
.sidebar{width:300px;display:flex;flex-direction:column;border-right:1px solid var(--line);background:#fafafa;flex-shrink:0}
.side-head{padding:18px 20px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line)}
.me{display:flex;align-items:center;gap:10px}
.avatar{width:40px;height:40px;border-radius:10px;background:linear-gradient(135deg,#667eea,#764ba2);
  color:#fff;display:flex;align-items:center;justify-content:center;font-weight:600;flex-shrink:0;font-size:16px}
.me-info .name{font-weight:600;font-size:15px}
.me-info .status{font-size:12px;color:#16a34a}
.icon-btn{background:none;border:0;cursor:pointer;color:var(--muted);font-size:18px;padding:6px;border-radius:6px}
.icon-btn:hover{background:#e5e7eb;color:var(--text)}
.side-title{padding:16px 20px 8px;font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.5px;
  display:flex;justify-content:space-between;align-items:center}
.side-title button{background:var(--primary);color:#fff;border:0;border-radius:6px;width:24px;height:24px;
  cursor:pointer;font-size:18px;line-height:1}
.group-list{overflow-y:auto;flex:1}
.group-item{padding:12px 20px;display:flex;gap:12px;align-items:center;cursor:pointer;transition:.15s}
.group-item:hover{background:#f0f2f5}
.group-item.active{background:#e8f0fe;border-left:3px solid var(--primary);padding-left:17px}
.group-item .gavatar{width:44px;height:44px;border-radius:10px;background:linear-gradient(135deg,#36d1dc,#5b86e5);
  color:#fff;display:flex;align-items:center;justify-content:center;font-weight:600;flex-shrink:0}
.group-item .ginfo{flex:1;min-width:0}
.group-item .gname{font-weight:600;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.group-item .glast{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:3px}
.group-item .gtime{font-size:11px;color:var(--muted);align-self:flex-start}

.main{flex:1;display:flex;flex-direction:column;min-width:0}
.chat-head{padding:16px 24px;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between}
.chat-head .title{font-size:18px;font-weight:600}
.chat-head .sub{font-size:12px;color:var(--muted);margin-top:2px}
.messages{flex:1;overflow-y:auto;padding:24px;background:#f5f6f8}
.msg-row{display:flex;gap:10px;margin-bottom:18px;align-items:flex-start}
.msg-row.mine{flex-direction:row-reverse}
.msg-row .avatar{width:36px;height:36px;border-radius:9px;font-size:14px}
.msg-body{max-width:60%;min-width:0}
.msg-meta{font-size:12px;color:var(--muted);margin-bottom:4px}
.msg-row.mine .msg-meta{text-align:right}
.bubble{background:#fff;padding:10px 14px;border-radius:4px 12px 12px 12px;box-shadow:0 1px 2px rgba(0,0,0,.05);
  line-height:1.6;font-size:14px;word-break:break-word;white-space:pre-wrap;display:inline-block}
.msg-row.mine .bubble{background:#dbeafe;border-radius:12px 4px 12px 12px}
.bubble img{max-width:100%;border-radius:8px;cursor:pointer}
.system-msg{text-align:center;color:var(--muted);font-size:12px;margin:12px 0}
.system-msg span{background:#e5e7eb;padding:4px 12px;border-radius:20px}
.recalled{font-style:italic;color:var(--muted);font-size:13px}
.composer{border-top:1px solid var(--line);padding:14px 20px;display:flex;gap:10px;align-items:flex-end;background:#fff}
.composer textarea{flex:1;resize:none;border:1px solid #d1d5db;border-radius:10px;padding:12px 14px;
  font-size:14px;font-family:inherit;outline:none;max-height:120px;min-height:44px;height:44px;line-height:1.5}
.composer textarea:focus{border-color:var(--primary);box-shadow:0 0 0 3px rgba(37,99,235,.1)}
.composer button{background:var(--primary);color:#fff;border:0;border-radius:10px;padding:0 22px;height:44px;
  cursor:pointer;font-size:15px;font-weight:600}
.composer button:hover{background:var(--primary-d)}
.hint{font-size:12px;color:var(--muted);text-align:center;padding:8px}

.empty{flex:1;display:flex;align-items:center;justify-content:center;flex-direction:column;color:var(--muted)}
.empty .big{font-size:60px;margin-bottom:12px}

/* 弹窗 */
.modal-mask{position:fixed;inset:0;background:rgba(0,0,0,.4);display:flex;align-items:center;justify-content:center;z-index:50}
.modal{background:#fff;border-radius:14px;padding:26px;width:90%;max-width:400px;box-shadow:0 20px 60px rgba(0,0,0,.2)}
.modal h3{margin-bottom:18px}
.modal .field{margin-bottom:14px}
.modal-btns{display:flex;gap:10px;margin-top:8px}
.modal-btns .btn{flex:1}
.btn-ghost{background:#e5e7eb;color:#374151}
.btn-ghost:hover{background:#d1d5db}

/* 侧栏账号显示 */
.me-info .account{font-size:11px;color:#60a5fa;cursor:pointer;margin-top:1px;max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.me-info .account:hover{text-decoration:underline}

/* 群成员管理 */
.member-manage{cursor:default!important;align-items:center}
.member-ops{display:flex;flex-wrap:wrap;gap:4px;justify-content:flex-end;max-width:210px}
.mop{border:1px solid var(--line);background:#fff;color:#4b5563;font-size:11px;padding:3px 7px;border-radius:5px;cursor:pointer;white-space:nowrap}
.mop:hover{border-color:var(--primary);color:var(--primary)}
.mop.warn:hover{border-color:#f59e0b;color:#f59e0b}
.mop.danger:hover{border-color:#dc2626;color:#dc2626}
.role-owner{color:#dc2626;font-weight:600}
.role-admin{color:#2563eb;font-weight:600}
.btn-danger{width:100%;background:#dc2626;color:#fff;border:0;padding:10px;border-radius:8px;font-size:14px;cursor:pointer;font-weight:600}
.btn-danger:hover{background:#b91c1c}

/* 未读红点徽章 */
.tab-badge{display:none;background:#ef4444;color:#fff;font-size:11px;line-height:16px;min-width:16px;height:16px;padding:0 4px;border-radius:8px;margin-left:5px;text-align:center;vertical-align:middle}
.badge{background:#ef4444;color:#fff;font-size:11px;line-height:18px;min-width:18px;height:18px;padding:0 5px;border-radius:9px;text-align:center;box-shadow:0 1px 3px rgba(239,68,68,.4)}
.badge.muted{background:#9ca3af;box-shadow:none}

/* 带文字的工具按钮 */
.composer .tool-btn{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;width:40px;height:46px;font-size:18px;line-height:1}
.composer .tool-btn span{font-size:10px;color:var(--muted)}

/* 设置开关 */
.setting-row{display:flex;align-items:center;justify-content:space-between;padding:14px 0;border-bottom:1px solid #f0f0f0}
.switch{position:relative;width:44px;height:24px;border-radius:12px;background:#d1d5db;border:0;cursor:pointer;transition:.2s;flex-shrink:0}
.switch span{position:absolute;top:2px;left:2px;width:20px;height:20px;border-radius:50%;background:#fff;transition:.2s;box-shadow:0 1px 3px rgba(0,0,0,.2)}
.switch.on{background:var(--primary)}
.switch.on span{left:22px}

/* 头像内图片 */
.avatar img,.gavatar img,.avatar-preview img{width:100%;height:100%;object-fit:cover;border-radius:inherit;display:block}
.avatar.clickable{cursor:pointer}
.avatar.small{width:34px;height:34px;font-size:13px}

/* 侧栏 Tab */
.side-tabs{display:flex;border-bottom:1px solid var(--line)}
.side-tab{flex:1;background:none;border:0;padding:12px;cursor:pointer;color:var(--muted);font-size:14px;border-bottom:2px solid transparent;margin-bottom:-1px}
.side-tab.active{color:var(--primary);border-bottom-color:var(--primary);font-weight:600}

/* 表情面板 */
.emoji-panel{display:none;flex-wrap:wrap;gap:2px;padding:10px 14px;background:#fff;border-top:1px solid var(--line);max-height:150px;overflow-y:auto}
.emoji{font-size:20px;cursor:pointer;padding:3px;border-radius:5px;line-height:1}
.emoji:hover{background:#f0f2f5}

/* 工具栏按钮 */
.composer .tool-btn{background:none;color:inherit;border:0;font-size:20px;padding:0 8px;height:44px;cursor:pointer;flex-shrink:0}
.composer .tool-btn:hover{opacity:.7}
.composer .send-btn{flex-shrink:0}

/* 图片消息 */
.chat-img{max-width:240px;max-height:240px;border-radius:8px;cursor:zoom-in;display:block}

/* 操作菜单 */
.action-menu{background:#fff;border-radius:14px;padding:18px;width:90%;max-width:280px;box-shadow:0 20px 60px rgba(0,0,0,.25)}
.action-menu h3{font-size:15px;margin-bottom:14px;text-align:center;color:#4b5563}
.menu-item,.action-menu .menu-item{display:block;width:100%;background:none;border:0;padding:13px;text-align:center;font-size:15px;cursor:pointer;border-radius:8px;color:#374151}
.menu-item:hover{background:#f0f2f5}
.avatar-preview{width:100px;height:100px;border-radius:50%;background:linear-gradient(135deg,#667eea,#764ba2);color:#fff;display:flex;align-items:center;justify-content:center;font-size:36px;margin:0 auto;overflow:hidden}
#avatarModal .btn{margin-top:6px}
.member-row{display:flex;gap:10px;align-items:center;padding:9px 6px;border-bottom:1px solid #f0f0f0;cursor:pointer;border-radius:6px}
.member-row:hover{background:#f5f7fa}
.system-msg[data-mid]{user-select:none}

@media(max-width:700px){
  .sidebar{width:74px}
  .side-head,.group-item{padding-left:12px;padding-right:12px}
  .me-info,.group-item .ginfo,.group-item .gtime,.side-title span{display:none}
  .side-title{justify-content:center}
  .msg-body{max-width:78%}
}
