/**
 * 核心样式文件
 * 特点：
 * 1. 使用CSS变量实现全局换肤
 * 2. 语义化命名，结构清晰
 * 3. 适配响应式布局
 */

/* ========== 全局CSS变量（一键换肤核心） ========== */
:root {
    /* 主色调 */
    --primary-color: #007bff;       /* 主色 */
    --primary-hover: #0056b3;       /* 主色hover */
    /* 辅助色 */
    --success-color: #28a745;       /* 成功色 */
    --danger-color: #dc3545;        /* 危险色 */
    --warning-color: #ffc107;       /* 警告色 */
    /* 中性色 */
    --bg-white: #ffffff;            /* 白色背景 */
    --bg-gray: #f5f5f5;             /* 灰色背景 */
    --text-black: #333333;          /* 黑色文字 */
    --text-gray: #666666;           /* 灰色文字 */
    --text-light: #999999;          /* 浅灰文字 */
    --border-gray: #dddddd;         /* 灰色边框 */
    /* 聊天样式 */
    --msg-self-bg: #007bff;         /* 自己消息气泡背景 */
    --msg-self-text: #ffffff;       /* 自己消息文字颜色 */
    --msg-other-bg: #ffffff;        /* 对方消息气泡背景 */
    --msg-other-text: #333333;      /* 对方消息文字颜色 */
    --msg-border: #eeeeee;          /* 消息气泡边框 */
    /* 布局尺寸 */
    --sidebar-width: 250px;         /* 侧边栏宽度 */
    --header-height: 60px;          /* 头部高度 */
    --input-height: 80px;           /* 输入框高度 */
}

/* ========== 重置样式（消除浏览器默认样式） ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Microsoft Yahei", Arial, sans-serif;
    background-color: var(--bg-gray);
    color: var(--text-black);
    overflow: hidden; /* 隐藏页面滚动条 */
}

/* ========== 通用样式 ========== */
a { text-decoration: none; color: var(--primary-color); }
button { cursor: pointer; }
ul, li { list-style: none; }
.hidden { display: none !important; }
.clearfix::after { content: ''; display: block; clear: both; }
.text-center { text-align: center; }
.pointer { cursor: pointer; }

/* 滚动条样式优化 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #cccccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #999; }

/* ========== 聊天主容器 ========== */
.chat-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* ========== 左侧侧边栏 ========== */
.chat-sidebar {
    width: var(--sidebar-width);
    height: 100%;
    background: var(--bg-white);
    border-right: 1px solid var(--border-gray);
    display: flex;
    flex-direction: column; /* 垂直布局 */
}

/* 侧边栏头部（用户信息+隐藏按钮） */
.sidebar-header {
    height: var(--header-height);
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-gray);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px; /* 间距 */
}

.avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%; /* 圆形头像 */
    object-fit: cover; /* 保持比例 */
}

.user-name {
    font-weight: bold;
    font-size: 16px;
}

.logout-btn {
    color: var(--danger-color);
    font-size: 14px;
}

/* 侧边栏标签（好友/群聊） */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-gray);
}

.tab-item {
    flex: 1; /* 平分宽度 */
    text-align: center;
    padding: 10px 0;
    cursor: pointer;
    border-bottom: 2px solid transparent; /* 选中下划线 */
}

.tab-item.active {
    border-bottom-color: var(--primary-color);
    color: var(--primary-color);
}

/* 联系人/群列表 */
.sidebar-list {
    flex: 1; /* 占满剩余高度 */
    overflow-y: auto; /* 垂直滚动 */
    padding: 10px;
}

.list-item {
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}

.list-item:hover {
    background-color: #f8f9fa; /* hover背景 */
}

.list-item.active {
    background-color: #e9f5ff; /* 选中背景 */
    color: var(--primary-color);
}

.item-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.item-info {
    flex: 1;
    overflow: hidden; /* 隐藏溢出 */
}

.item-name {
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap; /* 不换行 */
    overflow: hidden;
    text-overflow: ellipsis; /* 超出省略 */
}

.item-msg {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.item-time {
    font-size: 12px;
    color: var(--text-light);
}

.item-badge {
    background-color: var(--danger-color);
    color: white;
    font-size: 12px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
}

/* ========== 右侧聊天区域 ========== */
.chat-main {
    flex: 1; /* 占满剩余宽度 */
    display: flex;
    flex-direction: column;
    background: var(--bg-white);
}

/* 聊天头部（标题） */
.chat-header {
    height: var(--header-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-gray);
    font-weight: bold;
    font-size: 16px;
}

/* 聊天内容区 */
.chat-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f8f9fa;
}

/* 消息项 */
.msg-item {
    margin-bottom: 15px;
    display: flex;
}

.msg-item.self {
    justify-content: flex-end; /* 自己消息右对齐 */
}

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0; /* 不压缩 */
}

.msg-item.other .msg-avatar {
    margin-right: 10px; /* 对方消息头像间距 */
}

.msg-item.self .msg-avatar {
    margin-left: 10px; /* 自己消息头像间距 */
}

.msg-content {
    max-width: 70%; /* 最大宽度70% */
    padding: 10px 15px;
    border-radius: 8px;
    position: relative;
}

/* 对方消息样式 */
.msg-item.other .msg-content {
    background-color: var(--msg-other-bg);
    color: var(--msg-other-text);
    border: 1px solid var(--msg-border);
    border-bottom-left-radius: 0; /* 左下角直角 */
}

/* 自己消息样式 */
.msg-item.self .msg-content {
    background-color: var(--msg-self-bg);
    color: var(--msg-self-text);
    border-bottom-right-radius: 0; /* 右下角直角 */
}

.msg-time {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 5px;
    text-align: right;
}

.msg-item.other .msg-time {
    text-align: left;
    padding-left: 15px;
}

.msg-revoke {
    color: var(--text-light);
    font-style: italic; /* 斜体 */
}

/* 聊天输入区 */
.chat-input-area {
    height: var(--input-height);
    padding: 10px 20px;
    border-top: 1px solid var(--border-gray);
    display: flex;
    gap: 10px;
    align-items: center;
}

.msg-input {
    flex: 1;
    height: 100%;
    padding: 10px;
    border: 1px solid var(--border-gray);
    border-radius: 4px;
    resize: none; /* 禁止调整大小 */
    font-size: 14px;
    outline: none; /* 去掉聚焦边框 */
}

.msg-input:focus {
    border-color: var(--primary-color); /* 聚焦边框颜色 */
}

.send-btn {
    width: 80px;
    height: 40px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
}

.send-btn:hover {
    background-color: var(--primary-hover);
}

.send-btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

/* 功能按钮（表情/图片） */
.func-btn {
    display: flex;
    gap: 10px;
    margin-bottom: 5px;
}

.func-item {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    background-color: #f5f5f5;
}

.func-item:hover {
    background-color: #e9e9e9;
}

/* 模态框样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0,0,0,0.5); /* 半透明背景 */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999; /* 最高层级 */
}

.modal-content {
    width: 400px;
    background-color: var(--bg-white);
    border-radius: 8px;
    padding: 20px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.modal-title {
    font-size: 18px;
    font-weight: bold;
}

.modal-close {
    cursor: pointer;
    font-size: 20px;
    color: var(--text-light);
}

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-btn {
    padding: 8px 15px;
    border-radius: 4px;
    border: none;
    font-size: 14px;
}

.modal-btn.primary {
    background-color: var(--primary-color);
    color: white;
}

.modal-btn.default {
    background-color: #e9e9e9;
    color: var(--text-black);
}

/* ========== 个人中心样式 ========== */
.personal-container {
    max-width: 800px;
    margin: 50px auto;
    padding: 30px;
    background: var(--bg-white);
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.personal-title {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-gray);
}

.personal-form {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
    align-items: center;
}

.form-label {
    font-weight: 500;
    text-align: right;
}

.form-control {
    padding: 10px;
    border: 1px solid var(--border-gray);
    border-radius: 4px;
    font-size: 14px;
}

.avatar-upload {
    display: flex;
    align-items: center;
    gap: 20px;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-gray);
}

.submit-btn {
    grid-column: 2; /* 跨列 */
    width: 120px;
    padding: 10px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.submit-btn:hover {
    background-color: var(--primary-hover);
}