/* ============================================================
   H5 IM 聊天系统样式
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif; font-size: 14px; color: #333; background: #f5f5f5; overflow: hidden; }
#app { height: 100%; }
a { text-decoration: none; color: inherit; }
input, textarea, button { outline: none; border: none; font-family: inherit; font-size: inherit; }
ul, li { list-style: none; }

/* ========== 通用组件 ========== */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 20px; border-radius: 8px; font-size: 15px; cursor: pointer; transition: all .2s; border: none; }
.btn-primary { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: #fff; }
.btn-primary:active { opacity: .8; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-default { background: #fff; color: #333; border: 1px solid #ddd; }
.btn-danger { background: #ff4d4f; color: #fff; }
.btn-block { width: 100%; }

.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; }
.input-group input { width: 100%; height: 44px; padding: 0 14px; border: 1px solid #e0e0e0; border-radius: 8px; font-size: 15px; background: #fafafa; transition: border-color .2s; }
.input-group input:focus { border-color: #4facfe; background: #fff; }
.input-group .code-row { display: flex; gap: 10px; }
.input-group .code-row input { flex: 1; }
.input-group .code-row .btn { flex-shrink: 0; padding: 0 16px; height: 44px; font-size: 13px; }

/* Toast */
.toast { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,.75); color: #fff; padding: 12px 24px; border-radius: 8px; font-size: 14px; z-index: 9999; max-width: 80%; text-align: center; animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -40%); } to { opacity: 1; transform: translate(-50%, -50%); } }

/* Loading */
.loading-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.8); display: flex; align-items: center; justify-content: center; z-index: 9998; }
.loading-spinner { width: 36px; height: 36px; border: 3px solid #e0e0e0; border-top-color: #4facfe; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal */
.modal-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.5); z-index: 9000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-box { background: #fff; border-radius: 12px; width: 100%; max-width: 360px; max-height: 80vh; overflow: hidden; display: flex; flex-direction: column; }
.modal-header { padding: 16px; border-bottom: 1px solid #f0f0f0; font-size: 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal-close { font-size: 20px; color: #999; cursor: pointer; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 16px; border-top: 1px solid #f0f0f0; display: flex; gap: 10px; }
.modal-footer .btn { flex: 1; }

/* ========== 登录注册页 ========== */
.auth-page { min-height: 100%; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; flex-direction: column; padding: 60px 24px 24px; }
.auth-logo { text-align: center; margin-bottom: 40px; }
.auth-logo .logo-icon { width: 72px; height: 72px; background: #fff; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; font-size: 36px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.auth-logo h1 { color: #fff; font-size: 24px; margin-top: 16px; font-weight: 600; }
.auth-logo p { color: rgba(255,255,255,.7); font-size: 13px; margin-top: 6px; }
.auth-card { background: #fff; border-radius: 16px; padding: 28px 24px; box-shadow: 0 8px 32px rgba(0,0,0,.1); }
.auth-tabs { display: flex; margin-bottom: 24px; border-bottom: 1px solid #f0f0f0; }
.auth-tab { flex: 1; text-align: center; padding: 10px 0; font-size: 15px; color: #999; cursor: pointer; position: relative; }
.auth-tab.active { color: #4facfe; font-weight: 600; }
.auth-tab.active::after { content: ''; position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%); width: 30px; height: 2px; background: #4facfe; border-radius: 2px; }
.auth-sub-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.auth-sub-tab { flex: 1; text-align: center; padding: 8px; border-radius: 6px; font-size: 13px; color: #666; background: #f5f5f5; cursor: pointer; }
.auth-sub-tab.active { background: #e6f7ff; color: #4facfe; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 12px; color: #999; }

/* ========== 主界面布局 ========== */
.main-app { height: 100%; display: flex; flex-direction: column; background: #fff; }

/* 顶部导航 */
.top-nav { height: 50px; background: #fff; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; padding: 0 16px; flex-shrink: 0; position: relative; }
.top-nav .nav-title { flex: 1; text-align: center; font-size: 17px; font-weight: 600; }
.top-nav .nav-btn { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; color: #333; }
.top-nav .nav-btn.right { position: absolute; right: 16px; }

/* 主内容区 */
.main-content { flex: 1; overflow: hidden; position: relative; }

/* 底部Tab栏 */
.bottom-tab { height: 56px; background: #fff; border-top: 1px solid #f0f0f0; display: flex; flex-shrink: 0; }
.bottom-tab .tab-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.bottom-tab .tab-item .tab-icon { font-size: 22px; color: #999; }
.bottom-tab .tab-item .tab-label { font-size: 11px; color: #999; margin-top: 2px; }
.bottom-tab .tab-item.active .tab-icon, .bottom-tab .tab-item.active .tab-label { color: #4facfe; }
.bottom-tab .tab-badge { position: absolute; top: 6px; right: 50%; margin-right: -18px; background: #ff4d4f; color: #fff; font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

/* ========== 会话列表页 ========== */
.conv-list { height: 100%; overflow-y: auto; }
.conv-item { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid #f5f5f5; cursor: pointer; transition: background .15s; }
.conv-item:active { background: #f5f5f5; }
.conv-avatar { width: 48px; height: 48px; border-radius: 10px; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; font-weight: 600; flex-shrink: 0; position: relative; }
.conv-avatar.group { background: linear-gradient(135deg, #f093fb, #f5576c); }
.conv-info { flex: 1; margin-left: 12px; min-width: 0; }
.conv-name { font-size: 15px; font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.conv-time { font-size: 11px; color: #bbb; font-weight: normal; }
.conv-last { font-size: 13px; color: #999; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-unread { position: absolute; top: -4px; right: -4px; background: #ff4d4f; color: #fff; font-size: 10px; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.conv-empty { text-align: center; padding: 80px 20px; color: #bbb; }
.conv-empty .empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ========== 聊天窗口 ========== */
.chat-page { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #f5f5f5; display: flex; flex-direction: column; z-index: 100; }
.chat-header { height: 50px; background: #fff; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; padding: 0 12px; flex-shrink: 0; }
.chat-back { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer; color: #333; }
.chat-title { flex: 1; text-align: center; font-size: 16px; font-weight: 600; }
.chat-title .sub { font-size: 11px; color: #999; font-weight: normal; margin-top: 2px; }
.chat-more { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; font-size: 20px; cursor: pointer; }

.chat-messages { flex: 1; overflow-y: auto; padding: 12px; }
.chat-msg { display: flex; margin-bottom: 16px; align-items: flex-start; }
.chat-msg.self { flex-direction: row-reverse; }
.msg-avatar { width: 38px; height: 38px; border-radius: 8px; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.msg-body { max-width: 70%; margin: 0 10px; }
.msg-sender { font-size: 11px; color: #999; margin-bottom: 4px; }
.chat-msg.self .msg-sender { text-align: right; }
.msg-bubble { padding: 10px 14px; border-radius: 12px; font-size: 15px; line-height: 1.5; word-break: break-word; position: relative; }
.chat-msg:not(.self) .msg-bubble { background: #fff; border-top-left-radius: 4px; }
.chat-msg.self .msg-bubble { background: #4facfe; color: #fff; border-top-right-radius: 4px; }
.msg-time { font-size: 10px; color: #bbb; margin-top: 4px; }
.chat-msg.self .msg-time { text-align: right; }

/* 消息消失动画 */
.msg-fade-out { animation: msgFadeOut .5s ease forwards; }
@keyframes msgFadeOut { to { opacity: 0; transform: translateY(-10px); height: 0; margin: 0; padding: 0; overflow: hidden; } }

/* 系统消息 */
.msg-system { text-align: center; margin: 12px 0; }
.msg-system span { background: rgba(0,0,0,.1); color: #666; font-size: 12px; padding: 4px 12px; border-radius: 10px; }

/* 正在输入 */
.typing-indicator { display: flex; align-items: center; padding: 10px 14px; }
.typing-indicator .dot { width: 6px; height: 6px; background: #999; border-radius: 50%; margin: 0 2px; animation: typingBounce 1.4s infinite; }
.typing-indicator .dot:nth-child(2) { animation-delay: .2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* 底部输入栏 */
.chat-input-bar { background: #fff; border-top: 1px solid #f0f0f0; padding: 8px 12px; display: flex; align-items: flex-end; gap: 8px; flex-shrink: 0; }
.chat-input-bar textarea { flex: 1; min-height: 38px; max-height: 100px; padding: 9px 12px; border: 1px solid #e8e8e8; border-radius: 8px; font-size: 15px; resize: none; background: #f8f8f8; line-height: 1.4; }
.chat-input-bar textarea:focus { border-color: #4facfe; background: #fff; }
.chat-input-bar .send-btn { background: #4facfe; color: #fff; border: none; border-radius: 8px; padding: 0 18px; height: 38px; font-size: 14px; cursor: pointer; flex-shrink: 0; }
.chat-input-bar .send-btn:disabled { background: #ccc; cursor: not-allowed; }
.chat-input-bar .icon-btn { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; font-size: 22px; cursor: pointer; color: #666; flex-shrink: 0; }

/* ========== 通讯录/好友页 ========== */
.contacts-page { height: 100%; overflow-y: auto; }
.contact-section-title { padding: 10px 16px; font-size: 12px; color: #999; background: #f5f5f5; }
.contact-item { display: flex; align-items: center; padding: 12px 16px; background: #fff; border-bottom: 1px solid #f5f5f5; cursor: pointer; }
.contact-item:active { background: #f9f9f9; }
.contact-avatar { width: 42px; height: 42px; border-radius: 8px; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; font-weight: 600; flex-shrink: 0; position: relative; }
.contact-avatar .online-dot { position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; background: #52c41a; border-radius: 50%; border: 2px solid #fff; }
.contact-info { flex: 1; margin-left: 12px; min-width: 0; }
.contact-name { font-size: 15px; font-weight: 500; }
.contact-desc { font-size: 12px; color: #999; margin-top: 2px; }
.contact-action { flex-shrink: 0; }
.badge-dot { display: inline-block; width: 8px; height: 8px; background: #ff4d4f; border-radius: 50%; margin-left: 6px; }

/* 搜索栏 */
.search-bar { padding: 10px 16px; background: #fff; border-bottom: 1px solid #f0f0f0; }
.search-bar input { width: 100%; height: 36px; padding: 0 14px; background: #f5f5f5; border-radius: 18px; font-size: 14px; }

/* ========== 发现/群聊页 ========== */
.discover-page { height: 100%; overflow-y: auto; }
.discover-card { margin: 12px; background: #fff; border-radius: 12px; overflow: hidden; }
.discover-item { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid #f5f5f5; cursor: pointer; }
.discover-item:last-child { border-bottom: none; }
.discover-item:active { background: #f9f9f9; }
.discover-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.discover-icon.blue { background: #e6f7ff; }
.discover-icon.green { background: #f6ffed; }
.discover-icon.orange { background: #fff7e6; }
.discover-icon.purple { background: #f9f0ff; }
.discover-text { flex: 1; margin-left: 12px; }
.discover-text .title { font-size: 15px; font-weight: 500; }
.discover-text .desc { font-size: 12px; color: #999; margin-top: 2px; }
.discover-arrow { color: #ccc; font-size: 18px; }

/* 群列表 */
.group-list-item { display: flex; align-items: center; padding: 12px 16px; background: #fff; border-bottom: 1px solid #f5f5f5; cursor: pointer; }
.group-avatar { width: 44px; height: 44px; border-radius: 10px; background: linear-gradient(135deg, #f093fb, #f5576c); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; flex-shrink: 0; }
.group-info { flex: 1; margin-left: 12px; min-width: 0; }
.group-name { font-size: 15px; font-weight: 500; }
.group-desc { font-size: 12px; color: #999; margin-top: 2px; }

/* ========== 我的页 ========== */
.profile-page { height: 100%; overflow-y: auto; background: #f5f5f5; }
.profile-header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 30px 20px; display: flex; align-items: center; }
.profile-avatar { width: 64px; height: 64px; border-radius: 14px; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 28px; font-weight: 600; flex-shrink: 0; }
.profile-info { margin-left: 16px; color: #fff; }
.profile-name { font-size: 20px; font-weight: 600; }
.profile-phone { font-size: 13px; opacity: .8; margin-top: 4px; }
.profile-id { font-size: 11px; opacity: .6; margin-top: 2px; }
.profile-menu { margin: 12px; background: #fff; border-radius: 12px; overflow: hidden; }
.profile-menu-item { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid #f5f5f5; cursor: pointer; }
.profile-menu-item:last-child { border-bottom: none; }
.profile-menu-item:active { background: #f9f9f9; }
.profile-menu-icon { width: 28px; height: 28px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.profile-menu-text { flex: 1; margin-left: 12px; font-size: 15px; }
.profile-menu-value { font-size: 13px; color: #999; }
.profile-menu-arrow { color: #ccc; font-size: 16px; margin-left: 6px; }
.wallet-balance { font-size: 24px; font-weight: 700; color: #ff6b35; }

/* ========== 群详情页 ========== */
.group-detail-page { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #f5f5f5; z-index: 200; overflow-y: auto; }
.group-detail-header { height: 50px; background: #fff; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; padding: 0 12px; position: sticky; top: 0; z-index: 10; }
.group-detail-content { padding: 12px; }
.member-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; padding: 16px; background: #fff; border-radius: 12px; }
.member-cell { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.member-cell .avatar { width: 44px; height: 44px; border-radius: 10px; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; font-weight: 600; }
.member-cell .name { font-size: 11px; color: #666; margin-top: 6px; text-align: center; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-cell.add-btn .avatar { background: #f5f5f5; color: #999; font-size: 24px; }

/* ========== 邀请列表 ========== */
.invite-item { display: flex; align-items: center; padding: 12px 16px; background: #fff; border-bottom: 1px solid #f5f5f5; }
.invite-info { flex: 1; min-width: 0; }
.invite-title { font-size: 14px; font-weight: 500; }
.invite-desc { font-size: 12px; color: #999; margin-top: 2px; }
.invite-actions { display: flex; gap: 8px; flex-shrink: 0; }
.invite-actions .btn { padding: 6px 14px; font-size: 13px; height: auto; }

/* 空状态 */
.empty-state { text-align: center; padding: 60px 20px; color: #bbb; }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .text { font-size: 14px; }

/* 消息已读状态 */
.msg-read-status { font-size: 10px; color: #52c41a; margin-top: 2px; text-align: right; }

/* TTL倒计时提示 */
.ttl-timer { font-size: 10px; color: #ff8c00; margin-top: 2px; }

/* 图片消息气泡 */
.msg-image-bubble { padding: 4px; background: transparent !important; }
.chat-msg.self .msg-image-bubble { background: transparent !important; }

/* 语音消息气泡 */
.msg-voice-bubble { display: flex; align-items: center; min-width: 80px; cursor: pointer; }
.msg-voice-bubble:active { opacity: .8; }

/* 语音录制提示 */
.voice-recording-tip {
    position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,.75); color: #fff; padding: 12px 20px; border-radius: 10px;
    display: flex; align-items: center; gap: 12px; font-size: 13px; z-index: 50;
}
.voice-wave { display: flex; align-items: center; gap: 3px; height: 24px; }
.voice-wave span { width: 3px; background: #fff; border-radius: 2px; animation: voiceWave 1s ease-in-out infinite; }
.voice-wave span:nth-child(1) { height: 8px; animation-delay: 0s; }
.voice-wave span:nth-child(2) { height: 16px; animation-delay: .1s; }
.voice-wave span:nth-child(3) { height: 24px; animation-delay: .2s; }
.voice-wave span:nth-child(4) { height: 16px; animation-delay: .3s; }
.voice-wave span:nth-child(5) { height: 8px; animation-delay: .4s; }
@keyframes voiceWave { 0%, 100% { transform: scaleY(.5); } 50% { transform: scaleY(1); } }

/* 图片预览 */
.image-preview-mask {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.9);
    z-index: 9999; display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.image-preview-mask img { max-width: 90%; max-height: 90%; object-fit: contain; }
