:root { --primary: #007bff; --white: #fff; }
* { box-sizing: border-box; font-family: 'Segoe UI', -apple-system, sans-serif; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent;}

body { background: linear-gradient(135deg, #a1c4fd, #c2e9fb); height: 100vh; width: 100vw; display: flex; justify-content: center; align-items: center; overflow: hidden;}
.msg-bubble, .chat-item, .avatar, .list-btn, .nav-item, .tool-icon { -webkit-touch-callout: none; user-select: none; }
input, textarea { -webkit-touch-callout: default; user-select: auto; }

#auth-box { display: none; background: white; padding: 30px; border-radius: 15px; width: 350px; max-width: 90%; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,0.15); position: relative; z-index: 100;}
#app { display: none; width: 1100px; height: 90vh; max-height: 850px; background: var(--white); border-radius: 12px; box-shadow: 0 25px 50px rgba(0,0,0,0.15); overflow: hidden; flex-direction: column; position: relative; z-index: 10;}
.layout { display: flex; height: 100%; width: 100%; flex-direction: row; }
#sidebar { width: 280px; min-width: 280px; background: #fafafa; border-right: 1px solid #eee; display: flex; flex-direction: column; height: 100%; overflow: hidden;}
#chat-area { flex: 1; display: flex; flex-direction: column; background: #fff; overflow: hidden; height: 100%; position: relative; min-width: 0; }

.user-card { padding: 20px; border-bottom: 1px solid #eee; display: flex; align-items: center; cursor: pointer; flex-shrink: 0;}
.avatar { width: 45px; height: 45px; border-radius: 50%; color: white; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: bold; margin-right: 15px; background-size: cover; background-position: center; flex-shrink: 0; overflow: hidden; background-color: transparent;}

.sidebar-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar-nav { display: flex; height: 50px; border-top: 1px solid #eee; background: #fafafa; flex-shrink: 0; }
.nav-item { flex: 1; display: flex; justify-content: center; align-items: center; cursor: pointer; font-size: 14px; color: #666; transition: 0.2s; position: relative;}
.nav-item.active { color: var(--primary); font-weight: bold; background: #eaf3ff; border-top: 3px solid var(--primary);}
.nav-badge { position: absolute; top: 6px; right: 25px; background: #ff3b30; color: white; font-size: 10px; padding: 2px 6px; border-radius: 10px; font-weight: bold; line-height: 1; pointer-events: none; box-shadow: 0 1px 3px rgba(0,0,0,0.2);}

.chat-list { flex: 1; overflow-y: auto; }
.list-title { padding: 15px 20px 5px; font-size: 12px; color: #888; display: flex; justify-content: space-between; font-weight: bold;}
.list-btn { color: var(--primary); cursor: pointer; background: #eaf3ff; padding: 2px 6px; border-radius: 4px; }

.chat-item { padding: 12px 15px; display: flex; align-items: center; cursor: pointer; position: relative; transition: 0.2s;}
.chat-item:hover { background: #f0f2f5; }
.chat-item.active { background: #eaf3ff; border-left: 4px solid var(--primary); padding-left: 11px;}
.chat-item img { width: 40px; height: 40px; border-radius: 50%; margin-right: 12px; object-fit: cover; flex-shrink: 0; background-color: transparent;}
.chat-item-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; justify-content: center; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.chat-item-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #333; font-weight: 500;}
.chat-item-time { font-size: 11px; color: #aaa; white-space: nowrap; margin-left: 8px; flex-shrink: 0;}
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; }
.chat-preview { font-size: 12px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

.badge { color: white; font-size: 11px; padding: 2px 6px; border-radius: 10px; font-weight: bold; margin-left: 5px; flex-shrink: 0;}
.badge-red { background: #ff3b30; } .badge-grey { background: #adb5bd; }

#chat-header { width: 100%; min-height: 60px; border-bottom: 1px solid #eee; display: flex; align-items: center; justify-content: space-between; padding: 0 15px; background: #fff; z-index: 10; flex-shrink: 0;}
#msg-list { width: 100%; flex: 1; min-height: 0; overflow-y: auto; padding: 15px; background: #f8f9fa; scroll-behavior: smooth;}
.load-more { display: flex; justify-content: center; align-items: center; width: 100%; font-size: 12px; color: var(--primary); cursor: pointer; margin-bottom: 15px; padding: 5px; }

#input-box { width: 100%; display: flex; flex-direction: column; border-top: 1px solid #eee; background: #fff; padding: 10px 15px; flex-shrink: 0; position: relative; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
#staging-area { display: none; background:#f0f8ff; border:1px dashed #007bff; border-radius:6px; padding:8px; margin-bottom:8px; gap:10px; flex-wrap:wrap; max-height:100px; overflow-y:auto;}
.staged-file { background: white; padding: 4px 8px; border-radius: 4px; font-size: 11px; border: 1px solid #ddd; display: flex; align-items: center; gap: 5px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);}
.staged-file span.del { color: red; cursor: pointer; font-weight: bold; }

.toolbar { height: 35px; display: flex; align-items: center; gap: 15px; margin-bottom: 5px;}
.tool-icon { font-size: 20px; cursor: pointer; color: #666; position: relative;}
.emo-panel { display: none; position: absolute; bottom: 35px; left: -5px; width: 280px; height: 220px; background: white; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 -5px 15px rgba(0,0,0,0.1); padding: 10px; overflow-y: auto; z-index: 100;}
.emo-item { width: 45px; height: 45px; display: inline-block; cursor: pointer; padding: 5px; border-radius: 5px;}
.emo-item img { width: 100%; height: 100%; object-fit: contain; }

.btn-send { background: var(--primary); color: white; border: none; padding: 6px 15px; border-radius: 4px; cursor: pointer; font-size: 13px; flex-shrink: 0; white-space: nowrap; transition: 0.2s;}
.btn-send:hover { filter: brightness(0.9); }
.btn-header { background: #f0f2f5; color: #333; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: bold; transition: 0.2s; display: flex; align-items: center; justify-content: center;}
.btn-header:hover { background: #e4e6e9; }

.msg-input-container { display: flex; align-items: flex-end; width: 100%; gap: 10px; margin-top: 5px; }
#msg-text { flex: 1; min-width: 0; height: 70px; border: none; outline: none; resize: none; font-size: 14px; background: transparent; }
#btn-send-msg { flex-shrink: 0; width: 75px; height: 36px; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: bold; transition: 0.2s;}
#btn-send-msg:hover { background: #0056b3; }

.msg-row { display: flex; margin-bottom: 15px; width: 100%; }
.msg-row.me { justify-content: flex-end; }
.msg-content-box { display: flex; max-width: 80%; align-items: flex-start; }
.msg-row.me .msg-content-box { flex-direction: row-reverse; }
.msg-bubble { padding: 10px 14px; border-radius: 8px; font-size: 14px; word-break: break-all; margin: 0 10px; background: white; box-shadow: 0 1px 3px rgba(0,0,0,0.05); transition: box-shadow 0.3s;}
.msg-row.me .msg-bubble { background: #95ec69; color: #000; }
.msg-nick { font-size: 11px; color: #999; margin: 0 10px 5px; }
.msg-row.me .msg-nick { text-align: right; }

.msg-multi-file { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 5px; }
.msg-media { max-width: 100%; max-height: 200px; border-radius: 5px; cursor: pointer; border: 1px solid #eee; background: #fafafa;}
.msg-doc-box { display: flex; align-items: center; background: rgba(0,0,0,0.04); padding: 8px 12px; border-radius: 6px; cursor: pointer; border: 1px solid #ebebeb; transition: 0.2s;}
.msg-doc-box:hover { background: rgba(0,0,0,0.08); }

.msg-audio-card { display: flex; align-items: center; background: #f8f9fa; border: 1px solid #e4e6e9; border-radius: 8px; padding: 8px 12px; min-width: 260px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); overflow: hidden; }
.msg-audio-card .audio-icon { font-size: 24px; margin-right: 12px; color: var(--primary); }
.msg-audio-card .audio-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.msg-audio-card .audio-name { font-size: 12px; font-weight: bold; color: #333; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-audio-card audio { width: 100%; height: 30px; outline: none; }
.msg-row.me .msg-audio-card { background: rgba(255,255,255,0.9); border-color: #79d64f; }

.read-tag { font-size: 10px; margin: 2px 10px 0; cursor: pointer; user-select: none; flex-shrink: 0;}
.read-tag.unread { color: var(--primary); } .read-tag.read { color: #aaa; }

.modal { display:none; position:fixed; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.5); z-index:10001; justify-content:center; align-items:center; }
.modal-content { background:white; padding:25px; border-radius:12px; width:450px; max-width: 90%; max-height: 85vh; overflow-y: auto;}
.form-control { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ddd; border-radius: 6px; outline: none; font-size:14px;}

.admin-toolbar { font-size: 10px; margin-top: 5px; text-align: right; padding-right: 50px; }
.admin-toolbar.left { text-align: left; padding-left: 50px; padding-right: 0; }
.btn-admin { background: #ff4d4f; color: white; border: none; padding: 2px 6px; border-radius: 3px; cursor: pointer; margin-left: 5px; font-size: 10px;}
.member-li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px dashed #eee; font-size: 13px;}
.grp-title { font-size: 10px; padding: 1px 4px; border-radius: 3px; margin-left: 5px; color: white; display: inline-block; vertical-align: middle;}
.grp-title.owner { background: #ff9800; } 
.grp-title.admin { background: #8bc34a; color: #333; }
.grp-title.custom { background: #9c27b0; }

/* 🌟 核心修复 1：拔高右键菜单层级到 10005 */
.ctx-menu { position: absolute; background: #fff; border: 1px solid #ddd; box-shadow: 0 5px 15px rgba(0,0,0,0.15); border-radius: 6px; z-index: 10005; display: none; min-width: 130px; overflow: hidden; }
.ctx-menu li { padding: 10px 15px; cursor: pointer; font-size: 13px; list-style: none; color: #333; border-bottom: 1px solid #f0f0f0; transition: background 0.2s;}
.ctx-menu li:last-child { border-bottom: none; }
.ctx-menu li:hover { background: #f0f2f5; color: var(--primary);}
.ctx-menu li.danger { color: #dc3545; }

#quote-preview { display: none; background: #f0f2f5; border-left: 3px solid #ccc; padding: 5px 10px; font-size: 12px; color: #666; margin-bottom: 5px; border-radius: 0 4px 4px 0; position: relative; }
.close-quote { position: absolute; right: 5px; top: 5px; cursor: pointer; color: #999; font-weight: bold; }
#at-popup { display: none; position: absolute; bottom: 85px; left: 15px; background: white; border: 1px solid #ddd; border-radius: 8px; box-shadow: 0 -2px 10px rgba(0,0,0,0.1); width: 200px; max-height: 200px; overflow-y: auto; z-index: 100; }
.at-member-li { padding: 8px 10px; border-bottom: 1px solid #eee; cursor: pointer; display: flex; align-items: center; font-size: 13px; }
.at-member-li:hover { background: #f0f2f5; }
.at-member-li img { width: 24px; height: 24px; border-radius: 50%; margin-right: 8px; background-color: transparent;}
#at-floating-bar { display: none; position: absolute; top: 70px; right: 20px; background: #fff; color: var(--primary); padding: 8px 15px; border-radius: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); cursor: pointer; font-size: 13px; z-index: 20; font-weight: bold; border: 1px solid #eaf3ff;}

/* 🌟 核心修复 2：拔高多媒体播放器层级到 10005，确保手机端绝对在最上层 */
#media-viewer { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 10005; justify-content: center; align-items: center; flex-direction: column; }
.media-tools { position: absolute; top: 20px; right: 20px; display: flex; gap: 20px; color: white; font-size: 24px; z-index: 10006; }
.media-tools span, .media-tools a { cursor: pointer; text-decoration: none; color: white; transition: 0.2s;}
.media-tools span:hover, .media-tools a:hover { opacity: 0.7; }
#media-obj { max-width: 90vw; max-height: 80vh; transition: transform 0.2s; box-shadow: 0 5px 30px rgba(0,0,0,0.5);}

@media (max-width: 768px) {
    body { align-items: flex-start; padding-top: 10vh; overflow-y: auto; background: var(--bg-main); }
    #auth-box { margin: 0 auto 50px; position: static; transform: none; width: 92%; padding: 25px 20px; }
    #app { position: fixed; top: 0; left: 0; width: 100%; height: 100%; max-height: none; border-radius: 0; box-shadow: none; z-index: 9999; background: var(--white); }
    
    .layout { flex-direction: row; }
    #sidebar { width: 100%; min-width: 100%; display: flex; }
    #chat-area { display: none; width: 100%; min-width: 100%; }
    .layout.show-chat #sidebar { display: none; }
    .layout.show-chat #chat-area { display: flex; }
    
    #chat-header h3 { font-size: 15px; }
    #input-box { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    .mobile-back { display: inline-flex !important; align-items: center; margin-right: 10px; color: var(--primary); font-weight: bold; cursor: pointer; font-size: 14px;}
    .nav-badge { right: 20%; top: 4px; }
    
    .list-btn { padding: 8px 12px !important; font-size: 16px !important; display: inline-flex; align-items: center; justify-content: center; margin-left: 10px; }

    /* 🌟 核心修复 3：强行提权移动端底部菜单的层级到 10005 */
    .ctx-menu { position: fixed !important; top: auto !important; left: 0 !important; bottom: 0 !important; width: 100% !important; border-radius: 18px 18px 0 0; box-shadow: 0 -5px 25px rgba(0,0,0,0.15); padding-bottom: env(safe-area-inset-bottom); animation: slideUp 0.25s cubic-bezier(0.1, 0.8, 0.2, 1); border: none; z-index: 10005 !important; }
    .ctx-menu li { padding: 18px 15px; font-size: 15px; text-align: center; border-bottom: 1px solid #f5f5f5; }
    .ctx-menu li:last-child { border-bottom: none; }
    @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
}
.mobile-back { display: none; }