/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Microsoft YaHei', sans-serif;
}

body {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* 毛玻璃效果 */
.glass-effect {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

/* 聊天室容器 */
.chat-container {
    width: 100%;
    max-width: 1200px;
    height: 85vh;
    display: flex;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* 侧边栏 */
.sidebar {
    width: 280px;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-right: 1px solid rgba(255, 255, 255, 0.18);
    display: flex;
    flex-direction: column;
}

.user-info {
    padding: 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #4a89dc;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
    margin-right: 10px;
}

.username {
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

.online-users {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
}

.online-users h3 {
    color: #4a89dc;
    margin-bottom: 15px;
    font-size: 16px;
}

#users-list {
    list-style: none;
}

#users-list li {
    padding: 8px 10px;
    border-radius: 5px;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    transition: background-color 0.3s;
}

#users-list li:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

.refresh-btn {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 15px;
    background-color: #4a89dc;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.refresh-btn:hover {
    background-color: #3b7dd8;
}

#users-list .user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #4a89dc;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    margin-right: 10px;
}

.logout-btn {
    display: inline-block;
    text-align: center;
    padding: 8px 16px;
    background-color: #4a89dc;
    color: white;
    border-radius: 5px;
    text-decoration: none;
    transition: background-color 0.3s;
    font-size: 14px;
}

.logout-btn:hover {
    background-color: #3b7dd8;
}

/* 聊天区域 */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow:hidden;
}

.chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.chat-header h2 {
    color: #4a89dc;
    font-size: 18px;
}

.messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 15px;
    margin-bottom: 15px;
    position: relative;
    word-wrap: break-word;
}

.message-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 15px;
}

.message-wrapper .message {
    margin-bottom: 0;
}

.copy-btn {
    background: rgba(255, 255, 255, 0.3);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    flex-shrink: 0;
    margin-top: 5px;
    opacity: 0.7;
}

.copy-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.copy-btn:active {
    transform: scale(0.95);
}

.message-wrapper.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-wrapper.received {
    align-self: flex-start;
    flex-direction: row;
}

.message-time {
    font-size: 12px;
    color: #888;
    margin-top: 5px;
}

.message.sent {
    align-self: flex-end;
    background-color: #4a89dc;
    color: white;
    border-bottom-right-radius: 5px;
}

.message.received {
    align-self: flex-start;
    background-color: rgba(255, 255, 255, 0.7);
    color: #333;
    border-bottom-left-radius: 5px;
}

.message-sender {
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 5px;
}

.message-input {
    padding: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.18);
    display: flex;
}

#message-form {
    display: flex;
    width: 100%;
    gap: 8px;
    align-items: center;
}

.file-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    background-color: #5cb85c;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    transition: background-color 0.3s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-btn:hover {
    background-color: #4cae4c;
}

#message {
    flex: 1;
    min-width: 0;
    padding: 12px 15px;
    border: none;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    outline: none;
    transition: box-shadow 0.3s;
}

#message:focus {
    box-shadow: 0 0 0 2px rgba(74, 137, 220, 0.3);
}

#message-form button[type="submit"] {
    width: 70px;
    height: 44px;
    padding: 0;
    background-color: #4a89dc;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: background-color 0.3s;
    flex-shrink: 0;
    font-size: 14px;
}

#message-form button[type="submit"]:hover {
    background-color: #3b7dd8;
}

/* 认证页面样式 */
.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.auth-box {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

.auth-box h2 {
    color: #4a89dc;
    text-align: center;
    margin-bottom: 25px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 15px;
    border: none;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.7);
    outline: none;
    transition: box-shadow 0.3s;
}

.form-group input:focus {
    box-shadow: 0 0 0 2px rgba(74, 137, 220, 0.3);
}

.form-actions {
    margin-top: 25px;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background-color: #4a89dc;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.btn-primary:hover {
    background-color: #3b7dd8;
}

.auth-links {
    text-align: center;
    margin-top: 20px;
}

.auth-links a {
    color: #4a89dc;
    text-decoration: none;
}

.auth-links a:hover {
    text-decoration: underline;
}

.error-message {
    background-color: rgba(255, 99, 71, 0.2);
    color: #d9534f;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    text-align: center;
}

.success-message {
    background-color: rgba(144, 238, 144, 0.2);
    color: #5cb85c;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 20px;
    text-align: center;
}


/* 文件预览 */
#file-preview {
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    margin-top: 10px;
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-preview-item .file-icon {
    font-size: 24px;
}

.file-preview-item .file-name {
    flex: 1;
    font-size: 14px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-preview-item .file-size {
    font-size: 12px;
    color: #888;
}

.file-preview-item .remove-file {
    background-color: #d9534f;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: background-color 0.3s;
}

.file-preview-item .remove-file:hover {
    background-color: #c9302c;
}

/* 消息中的文件显示 */
.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    margin-top: 5px;
}

.message.sent .message-file {
    background: rgba(255, 255, 255, 0.2);
}

.message-file .file-icon {
    font-size: 32px;
}

.message-file .file-info {
    flex: 1;
    min-width: 0;
}

.message-file .file-name {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-file .file-size {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 2px;
}

.message-file .file-download {
    background-color: rgba(74, 137, 220, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 5px;
    text-decoration: none;
    font-size: 16px;
    transition: background-color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message.sent .message-file .file-download {
    background-color: rgba(255, 255, 255, 0.3);
}

.message-file .file-download:hover {
    background-color: rgba(74, 137, 220, 1);
}

.message.sent .message-file .file-download:hover {
    background-color: rgba(255, 255, 255, 0.5);
}

/* 上传进度条 */
.upload-progress {
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 10px;
    margin-top: 10px;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4a89dc, #5cb85c);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    font-size: 13px;
    color: #333;
    text-align: center;
}

#progress-percent {
    font-weight: bold;
    color: #4a89dc;
}

/* 消息中的媒体显示 */
.message-media {
    margin-top: 5px;
    max-width: 100%;
}

.message-image {
    max-width: 300px;
    max-height: 300px;
    width: 100%;
    height: auto;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
    display: block;
}

.message-image:hover {
    transform: scale(1.02);
}

.message-video {
    max-width: 400px;
    width: 100%;
    border-radius: 8px;
    display: block;
}

.media-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 5px;
    font-size: 12px;
    opacity: 0.8;
}

.media-info .file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 10px;
}

.media-info .file-size {
    white-space: nowrap;
}

/* 图片模态框 */
.image-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    justify-content: center;
    align-items: center;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    animation: zoomIn 0.3s;
}

@keyframes zoomIn {
    from {
        transform: scale(0.7);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.modal-close:hover {
    color: #ff4444;
}

/* 响应式设计 */
@media (max-width: 768px) {
    body {
        padding: 0;
        align-items: stretch;
    }
    
    .chat-container {
        flex-direction: column;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 30vh;
        min-height: auto;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.18);
        flex-shrink: 0;
    }
    
    .user-info {
        padding: 10px 15px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .user-info .user-details {
        display: flex;
        align-items: center;
        flex: 1;
    }
    
    .user-info .avatar {
        margin-right: 10px;
    }
    
    .user-info .logout-btn {
        padding: 6px 12px;
        font-size: 12px;
        margin: 0;
        display: inline-block;
        width: auto;
    }
    
    .online-users {
        padding: 10px;
        max-height: calc(30vh - 60px);
        overflow-y: auto;
    }
    
    .chat-area {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }
    
    .chat-header {
        padding: 12px 15px;
        flex-shrink: 0;
    }
    
    .messages {
        flex: 1;
        padding: 15px;
        overflow-y: auto;
        min-height: 0;
    }
    
    .message {
        max-width: 85%;
    }
    
    .message-wrapper {
        max-width: 90%;
    }
    
    .copy-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .message-input {
        padding: 8px;
        flex-shrink: 0;
        background: rgba(255, 255, 255, 0.9);
    }
    
    #message-form {
        gap: 6px;
    }
    
    .file-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    #message {
        flex: 1;
        min-width: 0;
        padding: 10px 12px;
        font-size: 16px;
    }
    
    #message-form button[type="submit"] {
        width: 60px;
        height: 40px;
        font-size: 13px;
    }
    
    .message-file {
        flex-wrap: wrap;
    }
    
    .file-preview-item .file-name {
        max-width: 150px;
    }
    
    .message-image {
        max-width: 200px;
        max-height: 200px;
    }
    
    .message-video {
        max-width: 100%;
    }
    
    .modal-close {
        top: -35px;
        font-size: 35px;
    }
    
    /* 确保在移动端键盘弹出时布局正常 */
    .chat-container.keyboard-open {
        height: 100vh;
    }
}

/* 小屏幕优化 */
@media (max-width: 480px) {
    .sidebar {
        max-height: 25vh;
    }
    
    .online-users {
        max-height: calc(25vh - 50px);
    }
    
    .online-users h3 {
        font-size: 14px;
        margin-bottom: 10px;
    }
    
    .refresh-btn {
        padding: 6px 10px;
        font-size: 12px;
        margin-bottom: 10px;
    }
    
    .message {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .message-wrapper {
        max-width: 95%;
    }
    
    .copy-btn {
        width: 26px;
        height: 26px;
        font-size: 13px;
    }
    
    .message-sender {
        font-size: 11px;
    }
    
    .message-time {
        font-size: 11px;
    }
    
    .file-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    #message {
        flex: 1;
        min-width: 0;
        font-size: 14px;
        padding: 8px 10px;
    }
    
    #message-form button[type="submit"] {
        width: 55px;
        height: 36px;
        font-size: 12px;
    }
}