:root {
    --green: #95ec69;
    --bg-gray: #ededed;
    --chat-bg: #f5f5f5;
    --border-color: #dcdcdc;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0; padding: 0;
    background-color: var(--bg-gray);
    height: 100vh; height: -webkit-fill-available;
    overflow: hidden; /* 禁止整体滚动 */
    user-select: none; -webkit-user-select: none;
    position: relative; /* 关键：作为定位基准 */
}

/* === 页面层级管理 === */
/* 所有屏幕都全屏绝对定位 */
.screen-container {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    overflow: hidden; background: white;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* 平滑动画 */
}

/* 1. 登录页 (最底层) */
#login-screen { z-index: 100; display: flex; flex-direction: column; justify-content: center; align-items: center; }

/* 2. 仪表盘 (中间层) */
#dashboard-screen { z-index: 20; background: white; }

/* 3. 聊天页 (最顶层 - 初始状态藏在右边) */
#chat-screen { 
    z-index: 30; 
    background-color: var(--chat-bg);
    transform: translateX(100%); /* 默认藏在屏幕右侧外 */
    display: flex; flex-direction: column; /* 必须是 flex 才能让 header/footer 固定 */
}

/* 当聊天页处于活动状态时 (通过JS添加此类) */
#chat-screen.active { transform: translateX(0); }

/* 添加阴影，让层级感更强 (仿iOS) */
#chat-screen::before {
    content: ''; position: absolute; top: 0; left: -10px; width: 10px; height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.1));
    z-index: 99;
}

/* === 以下样式保持不变，负责内部布局 === */

/* 登录样式 */
#login-screen input { width: 80%; padding: 12px; margin: 10px 0; border: 1px solid #ddd; border-radius: 8px; font-size: 16px; background: #f9f9f9; }
#login-screen button { width: 85%; padding: 12px; background: #07c160; color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; }

/* 列表样式 */
.scroll-view { flex: 1; overflow-y: auto; padding: 0; -webkit-overflow-scrolling: touch; }
.user-card, .group-entry { padding: 15px; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; background: white; }
.user-card:active, .group-entry:active { background-color: #d5d5d5; }

/* 聊天内部 */
header {
    height: 44px; flex-shrink: 0; background: var(--bg-gray); border-bottom: 1px solid #d0d0d0;
    display: flex; align-items: center; justify-content: space-between; padding: 0 15px; padding-top: env(safe-area-inset-top); z-index: 101;
}
header button { background: none; border: none; font-size: 16px; color: #111; font-weight: 500; display: flex; align-items: center; }
header span { font-weight: 600; font-size: 17px; }

#messages {
    flex: 1; overflow-y: auto; padding: 15px; margin: 0; list-style: none; display: flex; flex-direction: column; gap: 15px; -webkit-overflow-scrolling: touch;
}
#messages li { display: flex; max-width: 80%; align-items: flex-start; }
.me { align-self: flex-end; flex-direction: row-reverse; }
.other { align-self: flex-start; flex-direction: row; }

.avatar { width: 40px; height: 40px; border-radius: 6px; background: #ddd; color: #666; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 14px; flex-shrink: 0; }
.me .avatar { margin-left: 10px; background: #eee; }
.other .avatar { margin-right: 10px; }

.bubble-container { display: flex; flex-direction: column; }
.username-label { font-size: 12px; color: #999; margin-bottom: 3px; }
.me .username-label { display: none; }
.bubble { padding: 10px 12px; border-radius: 6px; font-size: 16px; line-height: 1.5; position: relative; word-wrap: break-word; min-height: 20px; }
.me .bubble { background-color: var(--green); color: black; }
.me .bubble::after { content: ''; position: absolute; right: -6px; top: 14px; border-width: 6px 0 6px 6px; border-style: solid; border-color: transparent transparent transparent var(--green); }
.other .bubble { background-color: white; border: 1px solid #e5e5e5; }
.other .bubble::after { content: ''; position: absolute; left: -6px; top: 14px; border-width: 6px 6px 6px 0; border-style: solid; border-color: transparent white transparent transparent; }

.voice-bubble { display: flex; align-items: center; cursor: pointer; min-width: 60px; }
.voice-icon { font-size: 16px; margin: 0 5px; }
.voice-duration { color: #666; font-size: 14px; margin: 0 8px; font-weight: normal; }
.me .voice-row { display: flex; align-items: center; flex-direction: row-reverse; }
.other .voice-row { display: flex; align-items: center; flex-direction: row; }
.media-msg { max-width: 150px; border-radius: 6px; border: 1px solid #ccc; background: black; }

#input-area {
    background: #f7f7f7; border-top: 1px solid var(--border-color); padding: 8px 10px;
    display: flex; align-items: center; gap: 10px; flex-shrink: 0; padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.icon-btn { width: 28px; height: 28px; font-size: 26px; border: none; background: none; color: #444; display: flex; align-items: center; justify-content: center; padding: 0; }
.input-wrapper { flex: 1; display: flex; height: 40px; }
#input { width: 100%; height: 100%; border: none; border-radius: 6px; padding: 0 10px; font-size: 16px; background: white; box-sizing: border-box; -webkit-appearance: none; }
#voice-hold-btn { width: 100%; height: 100%; border-radius: 6px; border: 1px solid #ddd; background: white; color: #333; font-weight: bold; font-size: 15px; display: flex; align-items: center; justify-content: center; touch-action: none; user-select: none; }
#voice-hold-btn.holding { background: #dcdcdc; color: #555; }
#send-btn { background: #07c160; color: white; border: none; border-radius: 4px; padding: 0 12px; height: 34px; font-size: 14px; font-weight: bold; }

#recording-overlay {
    position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%);
    width: 160px; height: 160px; background: rgba(0,0,0,0.6); border-radius: 10px;
    display: none; flex-direction: column; justify-content: center; align-items: center; color: white; z-index: 200; pointer-events: none;
}
.rec-icon { font-size: 60px; margin-bottom: 20px; }

/* 未读消息红点徽章 */
.badge {
    background-color: #ff3b30; /* 苹果红 */
    color: white;
    font-size: 12px;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 9px; /* 圆形 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-sizing: border-box;
    margin-left: auto; /* 自动推到最右边 */
}
/* 隐藏没有数字的徽章 */
.badge:empty {
    display: none;
}

/* === 时间显示样式 (WeChat Style) === */
.msg-time-box {
    width: 100%;
    text-align: center;
    margin-top: 20px; /* 消息之间的间距 */
    margin-bottom: 5px;
}

.msg-time-text {
    font-size: 12px;
    color: #b2b2b2; /* 浅灰色 */
    background-color: rgba(0,0,0,0.05); /* 极淡的背景 */
    padding: 3px 8px;
    border-radius: 4px;
    display: inline-block; /* 让背景只包裹文字 */
}