/* 重置样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* 登录页面 */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    height: 100%;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.login-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    padding: 30px;
    width: 100%;
    max-width: 400px;
    animation: slideUp 0.5s ease;
    margin: auto;
    position: relative;
    z-index: 1;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-header {
    text-align: center;
    margin-bottom: 25px;
}

.avatar-large {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    margin: 0 auto 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 35px;
    color: white;
}

.login-header h1 {
    color: #333;
    font-size: 22px;
    margin-bottom: 8px;
    font-weight: 600;
}

.login-header p {
    color: #666;
    font-size: 14px;
    line-height: 1.4;
}

.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    text-align: center;
    animation: shake 0.5s ease;
    font-size: 14px;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.login-form .input-group {
    position: relative;
    margin-bottom: 15px;
}

.input-group i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #667eea;
    font-size: 16px;
}

.input-group input {
    width: 100%;
    padding: 14px 15px 14px 45px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    background: #fff;
    line-height: 1.4;
    height: 50px;
}

.input-group input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.btn-login {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.btn-login:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-login:active {
    transform: translateY(0);
}

.login-footer {
    margin-top: 20px;
    text-align: center;
    color: #666;
    font-size: 12px;
    line-height: 1.5;
    padding: 0 10px;
}

/* 聊天应用容器 */
.chat-app {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #f0f2f5;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: 280px;
    background: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e0e0e0;
    transition: transform 0.3s ease;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar.active {
    transform: translateX(0);
}

.sidebar-header {
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 70px;
    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-details h3 {
    font-size: 16px;
    color: #333;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.status {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 10px;
    display: inline-block;
    font-weight: 500;
}

.status.online {
    background: #e8f5e9;
    color: #4caf50;
}

.status.offline {
    background: #f5f5f5;
    color: #9e9e9e;
}

.btn-toggle {
    background: none;
    border: none;
    font-size: 18px;
    color: #666;
    cursor: pointer;
    padding: 8px;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.btn-toggle:hover {
    background: #f5f5f5;
}

.sidebar-menu {
    padding: 15px 20px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.menu-item {
    padding: 12px 15px;
    border: none;
    background: none;
    text-align: left;
    border-radius: 10px;
    cursor: pointer;
    font-size: 15px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    font-weight: 500;
}

.menu-item:hover {
    background: #f8f9fa;
}

.menu-item.active {
    background: #e3f2fd;
    color: #1976d2;
}

.menu-item i {
    width: 22px;
    text-align: center;
    font-size: 16px;
}

.user-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px 20px;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s ease;
    margin-bottom: 8px;
    border: 1px solid transparent;
}

.user-item:hover {
    background: #f8f9fa;
    border-color: #e9ecef;
}

.user-item.active {
    background: #e3f2fd;
    border-color: #bbdefb;
}

.user-item .avatar {
    width: 42px;
    height: 42px;
    font-size: 17px;
}

.user-item .user-details {
    flex: 1;
    min-width: 0;
}

.user-item .user-details h3 {
    font-size: 15px;
    margin-bottom: 3px;
    font-weight: 500;
}

.user-status-info {
    font-size: 12px;
    color: #6c757d;
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.user-status.online {
    background: #28a745;
}

.user-status.offline {
    background: #6c757d;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
    background: white;
    position: sticky;
    bottom: 0;
}

.btn-logout {
    width: 100%;
    padding: 12px 15px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    color: #495057;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    font-weight: 500;
}

.btn-logout:hover {
    background: #e9ecef;
    border-color: #ced4da;
}

/* 主聊天布局 */
.chat-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* 聊天头部 */
.chat-header {
    background: white;
    padding: 0 15px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    height: 56px;
    min-height: 56px;
    width: 100%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.btn-menu {
    background: none;
    border: none;
    font-size: 20px;
    color: #333;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.btn-menu:hover {
    background: #f5f5f5;
}

.chat-header h2 {
    flex: 1;
    font-size: 18px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    padding-right: 10px;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-action {
    background: none;
    border: none;
    font-size: 18px;
    color: #666;
    cursor: pointer;
    padding: 8px;
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.btn-action:hover {
    background: #f5f5f5;
    color: #333;
}

/* 消息容器 */
.messages-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
    min-height: 0;
    width: 100%;
    background: #f0f2f5;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 消息布局 */
.message {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 自己发送的消息：靠右对齐 */
.message.own {
    justify-content: flex-end;
}

/* 消息内容区域 */
.message-content {
    max-width: 75%;
    position: relative;
}

/* 消息气泡 */
.message-text {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    position: relative;
    max-width: 100%;
}

/* 别人发送的消息气泡（浅灰色，在左侧） */
.message:not(.own) .message-text {
    background: white;
    border-top-left-radius: 4px;
    margin-left: 5px;
}

/* 自己发送的消息气泡（绿色，在右侧） */
.message.own .message-text {
    background: #95ec69;
    border-top-right-radius: 4px;
    margin-right: 5px;
}

/* 消息信息（用户名和时间） */
.message-info {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    font-size: 12px;
    color: #666;
    min-height: 20px;
    padding: 0 4px;
}

/* 别人发送的消息：用户名和时间都在左边 */
.message:not(.own) .message-info {
    justify-content: flex-start;
    margin-left: 5px;
}

/* 自己发送的消息：只显示时间，右对齐 */
.message.own .message-info {
    justify-content: flex-end;
    margin-right: 5px;
}

/* 用户名样式 */
.username {
    font-weight: 600;
    color: #333;
    margin-right: 8px;
    font-size: 13px;
}

/* 时间样式 */
.time {
    color: #888;
    font-size: 11px;
    opacity: 0.8;
}

/* 头像样式 */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 24px;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.3s ease;
    display: block;
    width: auto;
    height: auto;
}

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

/* 输入区域 */
.input-area-wrapper {
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 100%;
    position: sticky;
    bottom: 0;
    z-index: 100;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1);
    padding-bottom: env(safe-area-inset-bottom);
}

.input-tools {
    padding: 10px 15px 0;
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.btn-tool {
    background: none;
    border: none;
    font-size: 20px;
    color: #666;
    cursor: pointer;
    padding: 8px;
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.btn-tool:hover {
    color: #1976d2;
    background: #f0f7ff;
}

.input-main {
    display: flex;
    gap: 10px;
    padding: 10px 15px 15px;
    align-items: flex-end;
    flex-shrink: 0;
    width: 100%;
}

.input-main input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    background: #f8f9fa;
    line-height: 1.4;
    min-height: 44px;
    max-height: 100px;
    resize: none;
}

.input-main input:focus {
    border-color: #1976d2;
    background: white;
    box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

.btn-send {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
    margin-bottom: 2px;
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.4);
}

.btn-send:active {
    transform: scale(0.98);
}

/* Emoji选择器 */
.emoji-picker {
    position: fixed;
    bottom: calc(60px + env(safe-area-inset-bottom));
    right: 15px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    width: 300px;
    max-height: 300px;
    overflow: hidden;
    display: none;
    z-index: 1000;
    border: 1px solid #e0e0e0;
}

.emoji-picker.show {
    display: block;
    animation: slideUp 0.3s ease;
}

.emoji-header {
    padding: 15px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    color: #333;
    font-weight: 600;
    background: #f8f9fa;
    flex-shrink: 0;
}

.emoji-header button {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 5px;
    -webkit-appearance: none;
    appearance: none;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.emoji-header button:hover {
    background: #e9ecef;
}

.emoji-grid {
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    max-height: 240px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.emoji {
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    text-align: center;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
}

.emoji:hover {
    background: #f0f7ff;
    transform: scale(1.1);
}

/* 管理面板 */
.admin-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 20px;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    overflow: hidden;
    display: none;
    z-index: 2000;
    max-height: 80vh;
    border: 1px solid #e0e0e0;
}

.admin-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.admin-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.admin-header button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    -webkit-appearance: none;
    appearance: none;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.admin-header button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.admin-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
    -webkit-overflow-scrolling: touch;
}

.btn-admin {
    padding: 16px 20px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    color: #333;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    font-weight: 500;
    text-align: left;
}

.btn-admin:hover {
    background: #e9ecef;
    border-color: #dee2e6;
    transform: translateY(-2px);
}

.btn-admin i {
    color: #1976d2;
    font-size: 18px;
    width: 24px;
}

/* 消息菜单 */
.message-menu {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    min-width: 160px;
    z-index: 3000;
    border: 1px solid #e0e0e0;
    overflow: hidden;
}

.message-menu button {
    width: 100%;
    padding: 14px 20px;
    border: none;
    background: none;
    text-align: left;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 1px solid #f5f5f5;
}

.message-menu button:last-child {
    border-bottom: none;
}

.message-menu button:hover {
    background: #f8f9fa;
}

.message-menu button i {
    color: #f44336;
    width: 18px;
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .btn-menu {
        display: flex;
    }
    
    .message-content {
        max-width: 80%;
    }
    
    .emoji-picker {
        width: 280px;
        right: 10px;
        bottom: calc(60px + env(safe-area-inset-bottom));
    }
    
    .chat-header {
        height: 56px;
        min-height: 56px;
    }
    
    .messages-container {
        padding: 12px 15px;
    }
    
    .input-area-wrapper {
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
    
    .input-main {
        padding: 10px 15px;
    }
    
    .input-main input {
        min-height: 44px;
        font-size: 16px;
    }
    
    .btn-send {
        width: 44px;
        height: 44px;
    }
}

/* 横屏模式 */
@media (orientation: landscape) and (max-height: 500px) {
    .chat-header {
        height: 50px;
        min-height: 50px;
        padding: 0 10px;
    }
    
    .messages-container {
        padding: 8px 10px;
        max-height: calc(100vh - 110px);
    }
    
    .input-area-wrapper {
        padding-bottom: 5px;
    }
    
    .input-main {
        padding: 6px 10px;
    }
    
    .input-main input {
        min-height: 38px;
        padding: 8px 12px;
        font-size: 14px;
    }
    
    .btn-send {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
    
    .message-text {
        padding: 6px 10px;
        font-size: 14px;
    }
    
    .avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
        margin-top: 20px;
    }
    
    .emoji-picker {
        bottom: calc(55px + env(safe-area-inset-bottom));
        max-height: 200px;
    }
}

/* 超小屏幕 */
@media (max-width: 360px) {
    .message-content {
        max-width: 85%;
    }
    
    .emoji-picker {
        width: 260px;
        right: 10px;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(7, 1fr);
        gap: 6px;
        padding: 12px;
    }
    
    .chat-header {
        height: 52px;
        min-height: 52px;
        padding: 0 12px;
    }
    
    .messages-container {
        padding: 10px 12px;
    }
    
    .input-main input {
        min-height: 42px;
        padding: 10px 14px;
    }
    
    .btn-send {
        width: 42px;
        height: 42px;
    }
}

/* 防止iOS输入框缩放 */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    input, textarea {
        font-size: 16px !important;
    }
}

/* 修复iOS Safari的滚动问题 */
.messages-container {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* 安全区域适配 */
@supports (padding: max(0px)) {
    .input-area-wrapper {
        padding-bottom: max(15px, env(safe-area-inset-bottom));
    }
}