/* ===============================
   1. 全局重置与基础样式
   =============================== */
* { box-sizing: border-box; margin: 0; padding: 0; outline: none; }

body {
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    /* 背景渐变 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* 工具类：隐藏元素 */
.hidden { display: none !important; }

/* ===============================
   2. 全局提示框 (Toast)
   =============================== */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: white;
    padding: 12px 24px;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    animation: slideDown 0.3s ease-out forwards;
}
.toast.success { border-left: 4px solid #00c853; color: #00c853; }
.toast.error { border-left: 4px solid #ff3d00; color: #ff3d00; }
.toast.info { border-left: 4px solid #2979ff; color: #2979ff; }

@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeOut { to { transform: translateY(-20px); opacity: 0; } }

/* ===============================
   3. 登录/注册卡片样式
   =============================== */
#auth-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.auth-card {
    background: rgba(255, 255, 255, 0.9);
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    text-align: center;
    width: 380px;
    backdrop-filter: blur(12px); /* 毛玻璃效果 */
    transition: all 0.4s ease;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.avatar-container img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    background: white;
    padding: 5px;
    margin-bottom: 15px;
}

h2 { margin-bottom: 5px; color: #333; font-weight: 600; }
.subtitle { color: #888; font-size: 13px; margin-bottom: 30px; }

/* 浮动标签输入框 */
.input-group { position: relative; margin-bottom: 20px; text-align: left; }

.input-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #eee;
    border-radius: 12px;
    background: #f9f9f9;
    font-size: 15px;
    transition: 0.3s;
}
.input-group input:focus { border-color: #764ba2; background: white; }

.input-group label {
    position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
    color: #aaa; pointer-events: none; transition: 0.3s; font-size: 14px;
    background: transparent; padding: 0 5px;
}
/* 标签上浮动画 */
.input-group input:focus + label,
.input-group input:not(:placeholder-shown) + label {
    top: 0; font-size: 12px; color: #764ba2; background: white;
}

/* 按钮 */
.btn-primary {
    width: 100%; padding: 12px;
    background: linear-gradient(to right, #667eea, #764ba2);
    color: white; border: none; border-radius: 12px;
    font-size: 16px; cursor: pointer; font-weight: bold;
    box-shadow: 0 5px 15px rgba(118, 75, 162, 0.3);
    transition: 0.3s; margin-top: 10px;
}
.btn-primary:hover { box-shadow: 0 8px 25px rgba(118, 75, 162, 0.5); transform: translateY(-2px); }

.btn-register { background: linear-gradient(to right, #00c6ff, #0072ff); box-shadow: 0 5px 15px rgba(0, 114, 255, 0.3); }
.btn-register:hover { box-shadow: 0 8px 25px rgba(0, 114, 255, 0.5); }

/* 切换链接 */
.switch-link { margin-top: 20px; font-size: 14px; color: #666; }
.switch-link span { color: #764ba2; cursor: pointer; font-weight: bold; margin-left: 5px; }
.switch-link span:hover { text-decoration: underline; }


/* ===============================
   4. 主界面布局 (响应式核心)
   =============================== */
#app-container {
    display: none; /* JS 控制显示 */
    
    /* 使用百分比适配平板/手机 */
    width: 95vw;
    max-width: 950px;
    height: 90vh;
    max-height: 800px;
    
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    flex-direction: row;
}

/* --- 左侧侧边栏 --- */
.sidebar {
    width: 260px;
    background: #f7f8fc;
    border-right: 1px solid #ebedf0;
    display: flex;
    flex-direction: column;
    transition: width 0.3s; /* 平滑过渡 */
}

.my-profile {
    padding: 20px;
    background: white;
    border-bottom: 1px solid #ebedf0;
    display: flex;
    align-items: center;
    height: 80px;
    flex-shrink: 0;
}
.my-profile img {
    width: 45px; height: 45px; border-radius: 50%; margin-right: 12px;
}
.profile-info { 
    display: flex; 
    flex-direction: column; 
    justify-content: center;
}
#my-username { 
    font-weight: bold; 
    font-size: 16px; 
    margin-bottom: 4px;
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
    max-width: 140px; 
}
/* 操作按钮容器 */
.action-btns {
    display: flex;
    gap: 10px;
    font-size: 12px;
}

.logout-btn { 
    color: #ff4757; 
    cursor: pointer; 
}
.logout-btn:hover { text-decoration: underline; }

.add-friend-btn {
    color: #667eea;
    cursor: pointer;
    font-weight: bold;
}
.add-friend-btn:hover { text-decoration: underline; }

.user-list { flex: 1; overflow-y: auto; }

/* 好友列表项 */
.user-item {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: 0.2s;
    height: 70px; /* 固定高度，视觉整齐 */
}
.user-item:hover { background: #eaeaea; }
.user-item.active { background: #dedede; }

.user-item img {
    width: 40px;  /* 固定头像大小 */
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px; height: 8px; background: #ccc; border-radius: 50%; margin-left: auto;
}
.status-dot.online { background: #00c853; }


/* --- 右侧聊天区 --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    min-width: 0; /* 防止子元素撑开布局 */
}

.chat-header {
    height: 60px;
    border-bottom: 1px solid #ebedf0;
    display: flex;
    align-items: center;
    padding: 0 25px;
    font-weight: bold;
    font-size: 17px;
    background: white;
    flex-shrink: 0;
}

.chat-window {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #fdfdfd;
    display: flex;
    flex-direction: column;
}

.empty-tip { text-align: center; color: #999; margin-top: 50px; }


/* --- 底部输入区 (修复按钮消失问题) --- */
.input-area {
    height: 140px; /* 减小高度，给移动端腾空间 */
    border-top: 1px solid #ebedf0;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    background: white;
    flex-shrink: 0; /* 关键：禁止输入区被压缩 */
}

.input-area textarea {
    font-family: inherit;
    font-size: 14px;
    border: none;
    resize: none;
    flex: 1;
    margin-bottom: 5px;
}

.input-area div { text-align: right; } /* 按钮容器 */

.input-area button {
    padding: 8px 24px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: 0.2s;
}
.input-area button:hover { background: #5a6fd6; }


/* ===============================
   5. 消息气泡样式 (含红点/时间戳)
   =============================== */
.message { 
    display: flex; 
    max-width: 80%; /* 稍微加宽气泡限制 */
    margin-bottom: 15px;
}
.message.sent { align-self: flex-end; flex-direction: row-reverse; }
.message.received { align-self: flex-start; }

/* 聊天中的头像 */
.message img { 
    width: 36px; height: 36px; border-radius: 50%; margin: 0 10px; flex-shrink: 0; 
}

/* 气泡包裹层 (修复红点位置) */
.bubble-container {
    display: flex;
    align-items: flex-start;
    max-width: 100%;
}
.message.sent .bubble-container { flex-direction: row-reverse; }

/* 气泡本体 */
.message .bubble {
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.5;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    min-width: 60px;
}
.message.sent .bubble { 
    background: linear-gradient(to right, #667eea, #764ba2); 
    color: white; 
    border-bottom-right-radius: 2px; 
}
.message.received .bubble { 
    background: white; 
    border: 1px solid #ebedf0; 
    color: #333; 
    border-bottom-left-radius: 2px; 
}

/* 时间戳 */
.msg-time { font-size: 10px; margin-top: 4px; text-align: right; opacity: 0.7; }
.message.sent .msg-time { color: #e0e0e0; }
.message.received .msg-time { color: #999; }

/* 未读红点 */
.unread-dot { 
    width: 8px; height: 8px; background-color: #f44336; border-radius: 50%; 
    margin-top: 12px; margin-left: 8px; 
    flex-shrink: 0; /* 防止被挤没 */
}

/* 状态文字 (已读/未读) */
.msg-status { font-size: 10px; margin-top: 15px; margin-right: 8px; flex-shrink: 0; }
.msg-status.unread { color: #f44336; }
.msg-status.read { color: #bbb; }


/* ===============================
   6. 平板与移动端强制适配
   =============================== */
@media screen and (max-width: 850px) {
    /* 1. 全屏铺满 */
    #app-container {
        width: 100vw !important;
        height: 100vh !important;
        border-radius: 0;
        max-width: none;
        max-height: none;
    }

    /* 2. 侧边栏变成窄条 */
    .sidebar {
        width: 70px !important;
        min-width: 70px;
    }

    /* 3. 隐藏名字和文字，只留头像 */
    .profile-info, 
    #my-username, 
    .logout-btn,
    .user-item div:not(.status-dot) { 
        display: none !important; 
    }

    /* 4. 居中头像 */
    .my-profile, .user-item {
        justify-content: center;
        padding: 0;
    }
    .my-profile img, .user-item img {
        margin: 0 !important;
        width: 40px; height: 40px;
    }

    /* 5. 调整小绿点位置 */
    .status-dot {
        position: absolute;
        bottom: 15px;
        right: 12px;
        border: 2px solid white;
    }
    .user-item { position: relative; }
    
    /* 6. 移动端输入框调整 */
    .input-area { height: 120px; }
    /* 确保移动端也隐藏这个新加的按钮容器 */
    .action-btns {
        display: none !important;
    }
}

/* ===============================
   自定义弹窗 (Modal) 样式
   =============================== */

/* 全屏遮罩背景 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5); /* 半透明黑底 */
    backdrop-filter: blur(5px);      /* 背景模糊 */
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s;
}

/* 隐藏状态 */
.modal-overlay.hidden {
    display: none !important;
    opacity: 0;
}

/* 弹窗主体 */
.modal-box {
    background: white;
    width: 320px;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    text-align: center;
    animation: scaleUp 0.3s ease-out;
}

@keyframes scaleUp {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-box h3 { margin-bottom: 10px; color: #333; }
.modal-desc { color: #888; font-size: 13px; margin-bottom: 10px; }

/* 按钮组 */
.modal-buttons {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

.modal-buttons button {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: 0.2s;
}

.btn-cancel {
    background: #f0f2f5;
    color: #666;
}
.btn-cancel:hover { background: #e4e6eb; }

.btn-confirm {
    background: linear-gradient(to right, #667eea, #764ba2);
    color: white;
}
.btn-confirm:hover { opacity: 0.9; transform: translateY(-1px); }

/* --- 新增：通知按钮与列表样式 --- */
.notice-btn {
    color: #667eea;
    cursor: pointer;
    font-weight: bold;
    position: relative;
    margin-right: 5px;
}
.notice-btn:hover { text-decoration: underline; }

/* 强提醒小红点 */
#notice-dot {
    position: absolute;
    top: -2px;
    right: -6px;
    width: 6px;
    height: 6px;
    background: #f44336;
    border-radius: 50%;
}

/* 请求列表容器 */
.request-list {
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
    margin-top: 15px;
}

.empty-req { text-align: center; color: #999; font-size: 13px; margin: 20px 0; }

/* 单个请求项 */
.req-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #f0f0f0;
}
.req-item:last-child { border-bottom: none; }

.req-item img {
    width: 36px; height: 36px; border-radius: 50%; margin-right: 10px;
}
.req-info { flex: 1; }
.req-name { font-size: 14px; font-weight: bold; }

/* 同意/拒绝按钮 */
.req-actions { display: flex; gap: 5px; }
.btn-mini {
    padding: 5px 10px;
    font-size: 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}
.btn-accept { background: #00c853; color: white; }
.btn-reject { background: #ff4757; color: white; }

/* ===============================
   底部版权信息样式
   =============================== */
.app-footer {
    position: fixed;
    bottom: 15px;
    left: 0;
    width: 100%;
    text-align: center;
    z-index: 0; /* 放在最底层，不要挡住弹窗 */
    pointer-events: none; /* 让鼠标点击穿透，防止挡住底部按钮 */
}

.app-footer p {
    color: rgba(255, 255, 255, 0.5); /* 半透明白色 */
    font-size: 12px;
    margin: -3px 0;
    font-weight: 300;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* 移动端适配：当屏幕高度太小时隐藏，避免挡住输入法或按钮 */
@media screen and (max-height: 500px) {
    .app-footer {
        display: none;
    }
}