:root {
  --accent: #4a9cfe;
  --bg: #e8ecf1;
  --sb: #f5f6fa;
  --bubble: #fff;
  --my-bubble: #effdde;
  --text: #333;
  --text2: #666;
  --bubble-radius: 10px;
  --bubble-self: #effdde;
  --bubble-other: #ffffff;
  --bubble-text-self: #333;
  --bubble-text-other: #333;
}
* { margin: 0; padding: 0; box-sizing: border-box; font-family: -apple-system, sans-serif; }
body{display:flex;justify-content:center;align-items:center;height:100vh;background:#1a1a2e;overflow:hidden}
#app{width:100%;max-width:1200px;height:94vh;background:var(--bg);border-radius:16px;display:flex;overflow:hidden;box-shadow:0 20px 60px rgba(0,0,0,.5);color:var(--text)}
#authPanel{width:100%;height:100%;display:flex;align-items:center;justify-content:center;background:#f8f9fa}
#authPanel>div{background:#fff;padding:36px;border-radius:16px;width:360px;text-align:center;box-shadow:0 10px 40px rgba(0,0,0,.1)}
#authPanel input{width:100%;padding:12px;margin-bottom:10px;border:2px solid #e0e0e0;border-radius:10px;font-size:15px}
.btn{width:100%;padding:12px;border:none;border-radius:10px;font-size:15px;cursor:pointer;font-weight:600;margin-bottom:6px}
.btn-login{background:var(--accent);color:#fff}
.btn-test{background:#f0f0f0;color:#333;font-size:13px!important;padding:8px!important}
#authPanel .toggle{color:var(--accent);cursor:pointer;margin-top:8px;font-size:13px}
#authPanel .err{color:#e74c3c;font-size:13px;margin-bottom:8px}
#mainPanel{display:flex;width:100%;height:100%}
#sidebar{width:320px;min-width:320px;background:var(--sb);border-right:1px solid rgba(0,0,0,.08);display:flex;flex-direction:column}
#sidebar .head{padding:14px;background:var(--bubble);display:flex;align-items:center;gap:10px;cursor:pointer}
#sidebar .av{width:40px;height:40px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-weight:700;color:#fff;background:var(--accent)}
.srch{padding:8px 10px;position:relative}
.srch input{width:100%;padding:8px 12px;border:none;border-radius:16px;background:var(--bubble);outline:none;font-size:15px;color:var(--text)}
#srchWrap{position:relative}
.search-results{position:absolute;top:45px;left:10px;right:10px;background:#fff;border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,.2);z-index:50;max-height:300px;overflow-y:auto;display:none}
.search-results .r-item{padding:10px 16px;cursor:pointer;display:flex;align-items:center;gap:10px;font-size:14px}
.search-results .r-item:hover{background:#f5f5f5}
.chat-tabs{display:flex;gap:4px;padding:8px 10px 4px;border-bottom:1px solid rgba(0,0,0,.04)}
.tab{flex:1;text-align:center;padding:6px 0;border-radius:8px;font-size:13px;font-weight:500;color:var(--text2);cursor:pointer;transition:all 0.2s}
.tab:hover{background:rgba(0,0,0,.04)}
.tab.active{background:var(--accent);color:#fff}
#contacts{flex:1;overflow-y:auto;padding:6px 10px}
.c-item{display:flex;align-items:center;gap:12px;padding:8px 10px;cursor:pointer;border-radius:8px}
.c-item:hover{background:rgba(0,0,0,.04)}
.c-item.on{background:#3b8af7!important;color:#fff!important}
.c-item .avatar-box{width:56px;height:56px;border-radius:50%;flex-shrink:0;display:flex;align-items:center;justify-content:center;background:#7c8b9c}
.c-item .info{flex:1;overflow:hidden}
.c-item .name{font-weight:500;font-size:15px;color:#222;white-space:nowrap;overflow:hidden}
.c-item .last-msg{font-size:13px;color:#888;white-space:nowrap;overflow:hidden;flex:1}
.c-item .unread-badge{background:var(--accent);color:#fff;padding:2px 8px;border-radius:12px;display:none}
.c-item .unread-badge.show{display:inline-block}
#chatArea{flex:1;display:flex;flex-direction:column;background:#f0f2f5}
#chatHeader{padding:12px 18px;background:var(--bubble);font-weight:500;font-size:14px;display:flex;justify-content:space-between;align-items:center}
#msgs{flex:1;padding:16px 12px;overflow-y:auto;display:flex;flex-direction:column}
#inputBar{padding:8px 16px;background:#fff;display:flex;align-items:flex-end;gap:8px;border-top:1px solid rgba(0,0,0,.06)}
.icon-btn{background:none;border:none;font-size:22px;cursor:pointer;padding:6px;border-radius:50%;color:#707579}
#inputBar textarea{flex:1;width:100%;padding:8px 14px;border:none;background:#f5f6fa;outline:none;font-size:17px;color:#333;resize:none;min-height:38px;border-radius:20px}
.btn-sm{padding:7px 14px;border:none;border-radius:8px;cursor:pointer;font-size:12px}
.btn-primary{background:var(--accent);color:#fff}
.btn-outline{background:#fff;color:var(--accent);border:1px solid var(--accent)}
.btn-danger{background:#ffebee;color:#e74c3c}
.w-full{width:100%}
.hidden{display:none!important}
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.4);display:flex;align-items:center;justify-content:center;z-index:999}
.modal{background:#fff;border-radius:16px;width:360px;max-height:80vh;overflow-y:auto;box-shadow:0 20px 60px rgba(0,0,0,.2);padding:0 0 12px}
.modal-header{padding:16px 20px 0;display:flex;justify-content:space-between;align-items:center;position:sticky;top:0;z-index:10;background:#fff;border-radius:16px 16px 0 0}
.modal-header h3{font-size:16px;font-weight:500;margin:0}
.modal-close{background:none;border:none;font-size:22px;cursor:pointer;color:#999;padding:2px 6px;border-radius:50%}
.modal-close:hover{background:#f0f0f0}
.profile-top{text-align:center;padding:16px 20px 12px}
.profile-avatar-wrap{position:relative;display:inline-block;cursor:pointer}
.profile-avatar-wrap img,.profile-avatar-wrap .avatar-placeholder{width:80px;height:80px;border-radius:50%;object-fit:cover}
.avatar-placeholder{background:var(--accent);color:#fff;display:flex;align-items:center;justify-content:center;font-size:36px;font-weight:700}
.avatar-edit-badge{position:absolute;bottom:-2px;right:-2px;background:var(--accent);color:#fff;width:26px;height:26px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:13px;border:2px solid #fff}
.profile-name{font-size:17px;font-weight:500;margin-top:8px}
.profile-username{font-size:12px;color:#999}
.profile-bio{margin-top:4px;font-size:12px;color:#888;max-width:250px;margin:4px auto 0;word-break:break-all}
.profile-section{padding:0 20px 8px}
.profile-section h4{font-size:11px;color:#aaa;margin-bottom:4px;text-transform:uppercase}
.profile-row{display:flex;align-items:center;justify-content:space-between;padding:6px 10px;background:#f8f9fa;border-radius:8px;margin-bottom:4px;font-size:13px}
.profile-row .label{color:#666}
.profile-row select{font-size:12px;padding:4px 8px;border-radius:6px;border:1px solid #ddd}
.toggle-sw{width:40px;height:22px;background:#ddd;border-radius:11px;cursor:pointer;position:relative;transition:.2s}
.toggle-sw.on{background:var(--accent)}
.toggle-sw::after{content:'';position:absolute;width:18px;height:18px;background:#fff;border-radius:50%;top:2px;left:2px;transition:.2s}
.toggle-sw.on::after{left:20px}
.theme-grid{display:flex;gap:8px;flex-wrap:wrap}
.theme-card{width:44px;height:44px;border-radius:10px;cursor:pointer;border:2px solid transparent;overflow:hidden}
.theme-card.sel{border-color:var(--accent)}
.bubble-theme-grid{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px}
.bubble-card{width:30px;height:30px;border-radius:50%;cursor:pointer;border:2px solid transparent;display:flex}
.bubble-card.sel{border-color:var(--accent);border-width:3px}
.bubble-card .self-half{width:50%;height:100%;border-radius:50% 0 0 50%}
.bubble-card .other-half{width:50%;height:100%;border-radius:0 50% 50% 0}

/* =========================================
   🟢 群聊完美复刻 QQ 布局（核心修正）
   ========================================= */
/* 对方发的群消息 */
.msg-group-wrap.other {
    display: flex;
    align-items: flex-start;
    align-self: flex-start;
    width: 100%;
    max-width: 80%;
    padding: 2px 0;
    margin-bottom: 2px;
    gap: 8px;
}
.msg-group-wrap.other .g-av {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    background: #4a9cfe;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    margin-top: 2px;
    overflow: hidden;
}
.msg-group-wrap.other .bubble-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}
.msg-group-wrap.other .bubble-name {
    display: block;
    font-size: 13px;
    color: #888;
    margin-bottom: 2px;
    text-align: left;
    font-weight: 500;
}
/* 核心修正：气泡根据长短自适应，flex-wrap 让短消息和时间同行对齐 */
.msg-group-wrap.other .bubble {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: flex-start;
    width: fit-content;
    max-width: 100%;
    background: #fff;
    padding: 8px 14px;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.msg-group-wrap.other .bubble .text-content {
    width: auto;
    max-width: 100%;
    word-wrap: break-word;
    text-align: left;
}
.msg-group-wrap.other .bubble .meta {
    font-size: 12px;
    color: #999;
    flex-shrink: 0;
    margin-left: auto; /* 🟢 核心：将时间推到行的最右侧 */
    padding-left: 6px;
    white-space: nowrap;
    display: flex;
    align-items: flex-end;
}

/* 自己发的群消息 */
.msg-group-wrap.mine {
    display: flex;
    justify-content: flex-end;
    align-self: flex-end;
    width: 100%;
    max-width: 80%;
    padding: 2px 0;
    margin-bottom: 2px;
}
.msg-group-wrap.mine .bubble {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: flex-start;
    width: fit-content;
    max-width: 100%;
    background: #95ec69;
    padding: 8px 14px;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.msg-group-wrap.mine .bubble .text-content {
    width: auto;
    max-width: 100%;
    word-wrap: break-word;
    text-align: left;
}
.msg-group-wrap.mine .bubble .meta {
    font-size: 12px;
    color: #666;
    flex-shrink: 0;
    margin-left: auto; /* 🟢 核心：将时间推到行的最右侧 */
    padding-left: 6px;
    white-space: nowrap;
    display: flex;
    align-items: flex-end;
}

/* =========================================
   🟢 私聊布局 (保持不变)
   ========================================= */
.msg-date-divider{text-align:center;padding:16px 0 8px;font-size:13px;color:#999;font-weight:500}
.msg-row{display:flex;flex-direction:column;margin-bottom:6px;}
.msg-private-wrap{display:flex;width:100%;max-width:80%;padding:2px 0}
.msg-private-wrap.mine{flex-direction:row-reverse;align-self:flex-end}
.msg-private-wrap.other{flex-direction:row;align-self:flex-start}
.msg-private-wrap .bubble{max-width:100%;padding:8px 14px;border-radius:10px;word-break:break-word;white-space:pre-wrap;font-size:15px;line-height:1.6;box-shadow:0 1px 2px rgba(0,0,0,.06);position:relative;display:flex;flex-direction:column}
.msg-private-wrap .bubble.mine{background:#95ec69;color:#333}
.msg-private-wrap .bubble.other{background:#fff;color:#333}
.bubble .text-content{width:100%;word-wrap:break-word;text-align:left}
.bubble .meta{flex-shrink:0;font-size:12px;color:#999;margin-top:4px;white-space:nowrap;display:flex;align-items:center;justify-content:flex-end;gap:4px}
.bubble.mine .meta{color:#4d5c3b}
.status-icon{font-size:14px}

.context-menu { position:fixed; background:#fff; border-radius:12px; padding:6px 0; min-width:180px; max-width:220px; box-shadow:0 8px 30px rgba(0,0,0,0.15); z-index:9999; border:1px solid rgba(0,0,0,0.04); overflow:hidden; }
.context-menu div.menu-item { display:flex; align-items:center; gap:14px; padding:10px 16px; cursor:pointer; font-size:14px; color:#222; transition:background 0.1s; font-weight:450; line-height:1.2; }
.context-menu div.menu-item:hover { background:#f0f2f5; }
.context-menu .menu-item-danger { color:#e74c3c; }
.context-menu .menu-item-danger:hover { background:#ffebee; }
.context-menu .menu-item-desc { font-size:11px; color:#999; padding-left:44px; margin-top:-6px; margin-bottom:6px; cursor:default; pointer-events:none; }
.context-menu .menu-divider { height:1px; background:#eee; margin:4px 0; padding:0; pointer-events:none; }
.context-menu .menu-icon { font-size:18px; width:24px; text-align:center; }

#groupTopBar { padding:8px 16px; background:#fffbe6; border-bottom:1px solid #f0f0f0; display:none; flex-direction:column; gap:4px; max-height:120px; overflow-y:auto; font-size:13px; color:#333; }
#groupTopBar .tb-label { font-weight:bold; white-space:nowrap; color:#e74c3c; min-width:60px; }
#groupTopBar .tb-content { word-break:break-all; color:#333; line-height:1.5; }

@media (max-width: 768px) {
  #app { width:100vw; height:100vh; max-width:100%; border-radius:0; }
  #sidebar { width:75vw; min-width:unset; position:fixed; left:-100%; top:0; height:100vh; z-index:998; display:flex; transition:left 0.25s ease-in-out; box-shadow:0 0 20px rgba(0,0,0,0.3); background:var(--sb); }
  #sidebar.open { left:0; }
  #chatArea { width:100%; flex:1; }
  #authPanel>div { width:90%; padding:20px; }
  .modal { width:92vw; max-width:92vw; margin-top:20px;}
}