* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #07c160;
    --primary-dark: #06ad56;
    --bg-dark: #2e2e2e;
    --bg-sidebar: #2e2e2e;
    --bg-middle: #e6e6e6;
    --bg-chat: #f5f5f5;
    --bg-white: #fff;
    --text-primary: #333;
    --text-secondary: #999;
    --text-light: #ccc;
    --border: #e0e0e0;
    --hover: #d9d9d9;
    --danger: #e74c3c;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: #f0f0f0;
    height: 100vh;
    overflow: hidden;
}

.page { display: none; height: 100vh; }
.page.active { display: flex; }

/* Auth Page */
#auth-page {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-container {
    background: white;
    border-radius: 12px;
    padding: 40px;
    width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.auth-header { text-align: center; margin-bottom: 30px; }
.auth-header h1 { color: var(--primary); font-size: 36px; }
.auth-header p { color: var(--text-secondary); margin-top: 8px; }

.auth-tabs { display: flex; margin-bottom: 20px; }
.tab-btn {
    flex: 1; padding: 10px; border: none; background: none;
    cursor: pointer; font-size: 16px; color: var(--text-secondary);
    border-bottom: 2px solid transparent; transition: all 0.3s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.auth-form { display: none; }
.auth-form.active { display: flex; flex-direction: column; gap: 12px; }

.auth-form input {
    padding: 12px 16px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; outline: none;
    transition: border-color 0.3s;
}
.auth-form input:focus { border-color: var(--primary); }

.btn-primary {
    padding: 12px; background: var(--primary); color: white;
    border: none; border-radius: 8px; font-size: 16px;
    cursor: pointer; transition: background 0.3s;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger {
    padding: 10px 20px; background: var(--danger); color: white;
    border: none; border-radius: 8px; cursor: pointer; width: 100%;
}

.btn-small {
    padding: 6px 12px; background: var(--primary); color: white;
    border: none; border-radius: 4px; cursor: pointer; font-size: 12px;
}

/* Main App */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 60px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 20px;
}

.sidebar-header {
    text-align: center;
    margin-bottom: 30px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 4px;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-name {
    font-size: 10px;
    color: var(--text-light);
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 8px; }

.nav-btn {
    width: 44px; height: 44px; border: none; background: none;
    border-radius: 8px; cursor: pointer; display: flex;
    align-items: center; justify-content: center; color: #aaa;
    transition: all 0.2s; position: relative;
}
.nav-btn:hover { color: white; background: rgba(255,255,255,0.1); }
.nav-btn.active { color: var(--primary); background: rgba(7,193,96,0.1); }

/* Navigation badge */
.nav-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    min-width: 18px;
    text-align: center;
}

/* Middle Panel */
.middle-panel {
    width: 280px;
    background: var(--bg-middle);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.panel { display: none; flex-direction: column; height: 100%; }
.panel.active { display: flex; }

.panel-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
}
.panel-header h3 { font-size: 16px; color: var(--text-primary); }

.btn-icon {
    width: 28px; height: 28px; border: none; background: var(--primary);
    color: white; border-radius: 50%; cursor: pointer; font-size: 18px;
    display: flex; align-items: center; justify-content: center;
    line-height: 1;
}

.search-box { padding: 8px 12px; }
.search-box input {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border);
    border-radius: 6px; outline: none; font-size: 13px;
}

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

.list-item {
    display: flex; align-items: center; padding: 12px 16px;
    cursor: pointer; transition: background 0.2s; gap: 12px;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.list-item:hover { background: var(--hover); }
.list-item.active { background: #c8c8c8; }

.list-item-avatar {
    width: 40px; height: 40px; border-radius: 6px;
    background: var(--primary); display: flex; align-items: center;
    justify-content: center; color: white; font-size: 16px;
    flex-shrink: 0; overflow: hidden;
}
.list-item-avatar img { width: 100%; height: 100%; object-fit: cover; }

.list-item-info { flex: 1; min-width: 0; }
.list-item-name {
    font-size: 14px; color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* 群聊名称样式 */
.list-item-name.group-chat {
    color: #2c3e50;
    font-weight: 500;
}
.list-item-preview {
    font-size: 12px; color: var(--text-secondary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    margin-top: 2px;
}
.list-item-meta {
    text-align: right; flex-shrink: 0;
}
.list-item-time {
    font-size: 11px; color: var(--text-secondary);
}
.list-item-badge {
    background: var(--danger); color: white; border-radius: 10px;
    padding: 1px 6px; font-size: 11px; margin-top: 4px;
    display: inline-block;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
}

/* Desktop: chat-window shown via inline style */
.chat-window {
    display: none;
    flex-direction: column;
    height: 100%;
}
.chat-window.active {
    display: flex;
}

.chat-placeholder {
    flex: 1; display: flex; align-items: center;
    justify-content: center; color: var(--text-secondary);
}
.chat-placeholder.hidden {
    display: none;
}

.chat-header {
    padding: 12px 20px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-title { font-size: 16px; font-weight: 500; }
.status-text { font-size: 12px; color: var(--text-secondary); margin-left: 8px; }

.chat-actions { display: flex; gap: 8px; }
.chat-actions .btn-icon {
    background: none; color: var(--text-secondary);
    width: 32px; height: 32px;
}
.chat-actions .btn-icon:hover { color: var(--primary); }

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

.message-bubble {
    display: flex; margin-bottom: 16px; gap: 10px;
}
.message-bubble.sent { flex-direction: row-reverse; }

.message-avatar {
    width: 36px; height: 36px; border-radius: 50%;  /* 圆形头像 */
    background: var(--primary); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 14px; overflow: hidden;
}
.message-avatar img { width: 100%; height: 100%; object-fit: cover; }

.message-content {
    max-width: 60%;
}
.message-sender {
    font-size: 12px; color: var(--text-secondary); margin-bottom: 4px;
}
.message-bubble.sent .message-sender { display: none; }

.message-text {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.message-bubble.received .message-text {
    background: var(--bg-white);
    border-top-left-radius: 2px;
}
.message-bubble.sent .message-text {
    background: #95ec69;
    border-top-right-radius: 2px;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
}

.message-file {
    padding: 10px 14px;
    background: var(--bg-white);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
}
.message-file-icon { font-size: 24px; }
.message-file-info { flex: 1; }
.message-file-name { font-size: 13px; word-break: break-all; }
.message-file-size { font-size: 11px; color: var(--text-secondary); }

.message-time {
    font-size: 11px; color: var(--text-secondary); margin-top: 4px;
}
.message-bubble.sent .message-time { text-align: right; }

.message-system {
    text-align: center; margin: 16px 0;
    font-size: 12px; color: var(--text-secondary);
    background: rgba(0,0,0,0.05);
    padding: 4px 12px;
    border-radius: 4px;
    display: inline-block;
    left: 50%;
    position: relative;
    transform: translateX(-50%);
}

/* Message Input */
.message-input-area {
    background: var(--bg-white);
    border-top: 1px solid var(--border);
    padding: 8px 16px 12px;
}

.input-toolbar {
    display: flex; gap: 8px; margin-bottom: 8px;
}
.toolbar-btn {
    border: none; background: none; cursor: pointer;
    color: var(--text-secondary); padding: 4px;
    border-radius: 4px;
}
.toolbar-btn:hover { color: var(--primary); background: rgba(0,0,0,0.05); }

.input-row {
    display: flex; gap: 8px;
}
.input-row textarea {
    flex: 1; border: 1px solid var(--border); border-radius: 6px;
    padding: 8px 12px; font-size: 14px; resize: none; outline: none;
    font-family: inherit;
}
.input-row textarea:focus { border-color: var(--primary); }

.btn-send {
    padding: 8px 20px; background: var(--primary); color: white;
    border: none; border-radius: 6px; cursor: pointer; font-size: 14px;
    align-self: flex-end;
}
.btn-send:hover { background: var(--primary-dark); }

/* Settings */
.settings-content {
    padding: 20px; overflow-y: auto; flex: 1;
}
.setting-section {
    margin-bottom: 24px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.setting-section h4 { margin-bottom: 12px; color: var(--text-primary); }
.setting-item {
    margin-bottom: 12px;
}
.setting-item label {
    display: block; font-size: 13px; color: var(--text-secondary);
    margin-bottom: 4px;
}
.setting-item input, .setting-item select {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 14px; outline: none;
}
.setting-item input:focus, .setting-item select:focus { border-color: var(--primary); }

.avatar-upload {
    display: flex; align-items: center; gap: 12px;
}
.avatar-upload img {
    width: 60px; height: 60px; border-radius: 8px; object-fit: cover;
}

/* Modal */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    justify-content: center; align-items: center;
}
.modal-overlay.active { display: flex; }

.modal {
    background: white; border-radius: 12px; width: 400px;
    max-height: 80vh; overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-close {
    border: none; background: none; font-size: 24px;
    cursor: pointer; color: var(--text-secondary);
}
.modal-body { padding: 20px; overflow-y: auto; max-height: 60vh; }

.modal-body input {
    width: 100%; padding: 10px; border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 10px; outline: none; font-size: 14px;
}
.modal-body input:focus { border-color: var(--primary); }

.modal-body .user-result {
    display: flex; align-items: center; gap: 10px;
    padding: 10px; border-radius: 6px; cursor: pointer;
}
.modal-body .user-result:hover { background: var(--bg-chat); }

/* Call Overlay */
.call-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9); z-index: 2000;
    display: flex; justify-content: center; align-items: center;
}

.call-container { text-align: center; }

.call-avatar {
    width: 100px; height: 100px; border-radius: 50%;
    background: var(--primary); margin: 0 auto 20px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 40px;
}

.call-name { color: white; font-size: 24px; margin-bottom: 8px; }
.call-status { color: #aaa; font-size: 14px; margin-bottom: 8px; }
.call-timer { color: #aaa; font-size: 16px; margin-bottom: 30px; }

.call-controls { display: flex; gap: 20px; justify-content: center; position: relative; z-index: 100; }
.call-btn {
    width: 50px; height: 50px; border-radius: 50%;
    border: none; background: rgba(255,255,255,0.2);
    color: white; font-size: 20px; cursor: pointer;
    position: relative;
    z-index: 100;
}
.call-btn-end { background: var(--danger); }
.call-btn:hover { opacity: 0.8; }

/* Call videos - ensure they don't cover buttons */
#local-video, #remote-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
    pointer-events: none;
}

/* Friend request item */
.friend-request-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.friend-request-item .request-info { flex: 1; }
.friend-request-item .request-actions { display: flex; gap: 6px; }

/* Section header in middle panel */
.section h4 {
    padding: 8px 16px; font-size: 12px;
    color: var(--text-secondary); background: var(--bg-middle);
}
.badge {
    background: var(--danger); color: white; border-radius: 10px;
    padding: 1px 6px; font-size: 11px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* Blacklist item */
.blacklist-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 0; border-bottom: 1px solid var(--border);
}
.blacklist-item .bl-info { flex: 1; }
.blacklist-item .bl-actions { display: flex; gap: 6px; }

/* ========== 移动端适配 ========== */
@media screen and (max-width: 768px) {
    body {
        overflow: auto;
    }

    .page.active {
        flex-direction: column;
    }

    /* Auth page mobile */
    #auth-page {
        padding: 20px;
    }
    .auth-container {
        width: 100%;
        max-width: 100%;
        padding: 24px;
        border-radius: 8px;
    }
    .auth-header h1 {
        font-size: 28px;
    }

    /* App container mobile */
    .app-container {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
    }

    /* Sidebar becomes bottom nav */
    .sidebar {
        width: 100%;
        height: 56px;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        padding: 0;
        order: 3;
        border-top: 1px solid rgba(255,255,255,0.1);
    }
    .sidebar-header {
        display: none;
    }
    .sidebar-nav {
        flex-direction: row;
        gap: 0;
        width: 100%;
        justify-content: space-around;
    }
    .nav-btn {
        width: 40px;
        height: 40px;
    }

    /* Middle panel takes full width */
    .middle-panel {
        width: 100%;
        flex: 1;
        order: 1;
        border-right: none;
    }
    .middle-panel.chat-open {
        display: none;
    }

    /* Chat area mobile */
    .chat-area {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 56px;
        z-index: 100;
        display: none;
    }
    .chat-area.mobile-visible {
        display: flex;
    }

    /* Chat header mobile */
    .chat-header {
        padding: 10px 12px;
    }
    .chat-title {
        font-size: 15px;
    }
    .chat-actions .btn-icon {
        width: 28px;
        height: 28px;
    }

    /* Messages mobile */
    .messages-container {
        padding: 12px;
    }
    .message-content {
        max-width: 75%;
    }
    .message-text {
        font-size: 14px;
        padding: 8px 12px;
    }
    .message-image {
        max-width: 180px;
        max-height: 180px;
    }
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    /* Input area mobile */
    .message-input-area {
        padding: 6px 10px 10px;
    }
    .input-row textarea {
        font-size: 14px;
        padding: 8px 10px;
    }
    .btn-send {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* List items mobile */
    .list-item {
        padding: 10px 12px;
    }
    .list-item-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    .list-item-name {
        font-size: 14px;
    }
    .list-item-preview {
        font-size: 12px;
    }

    /* Panel header mobile */
    .panel-header {
        padding: 12px;
    }
    .panel-header h3 {
        font-size: 15px;
    }

    /* Modal mobile */
    .modal {
        width: 90%;
        max-width: 90%;
        margin: 20px;
    }
    .modal-body {
        padding: 16px;
    }

    /* Settings mobile */
    .settings-content {
        padding: 16px;
    }

    /* Call overlay mobile */
    .call-avatar {
        width: 80px;
        height: 80px;
        font-size: 32px;
    }
    .call-name {
        font-size: 20px;
    }
    .call-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    /* Back button for mobile chat */
    .chat-back-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        border: none;
        background: none;
        color: var(--text-primary);
        cursor: pointer;
        font-size: 20px;
        margin-right: 8px;
    }
}

/* Desktop: hide back button */
.chat-back-btn {
    display: none;
}
