/* ===== 全局重置 & 变量 ===== */
:root {
    --bg-primary: #f0f2f5;
    --bg-sidebar: #ffffff;
    --bg-main: #ffffff;
    --bg-input: #f0f2f5;
    --bg-hover: #f5f6f8;
    --text-primary: #1a1a2e;
    --text-secondary: #65676b;
    --text-muted: #999;
    --border-color: #e4e6eb;
    --msg-self-bg: #d9fdd3;
    --msg-self-text: #1a1a2e;
    --msg-other-bg: #ffffff;
    --msg-other-text: #1a1a2e;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd1;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
    --radius: 12px;
    --radius-lg: 18px;
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-sidebar: #16213e;
    --bg-main: #1a1a2e;
    --bg-input: #2a2a4a;
    --bg-hover: #2a2a4a;
    --text-primary: #e4e6eb;
    --text-secondary: #b0b3b8;
    --text-muted: #666;
    --border-color: #3a3b5c;
    --msg-self-bg: #2b5c2b;
    --msg-self-text: #e4e6eb;
    --msg-other-bg: #2a2a4a;
    --msg-other-text: #e4e6eb;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background var(--transition), color var(--transition);
}

/* ===== 应用容器 ===== */
.app {
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    max-height: 800px;
    display: flex;
    background: var(--bg-main);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin: 20px;
}

/* ===== 侧边栏 ===== */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: background var(--transition);
}

.sidebar-header {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
}

.sidebar-header h2 i {
    margin-right: 8px;
}

.theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background var(--transition);
}

.theme-toggle:hover {
    background: var(--bg-hover);
}

/* 用户资料 */
.user-profile {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

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

.username {
    font-weight: 600;
    font-size: 14px;
    display: block;
}

.status {
    font-size: 12px;
    color: var(--text-secondary);
}

.status i {
    font-size: 8px;
    color: #31a24c;
    margin-right: 4px;
    vertical-align: middle;
}

.switch-user-btn {
    background: none;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    transition: all var(--transition);
}

.switch-user-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(108, 92, 231, 0.08);
}

/* 搜索框 */
.search-box {
    padding: 12px 20px;
    position: relative;
}

.search-box i {
    position: absolute;
    left: 32px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border: none;
    border-radius: 24px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: background var(--transition);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

/* 聊天列表 */
.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
    margin-bottom: 2px;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: rgba(108, 92, 231, 0.1);
}

.chat-item.active .chat-name {
    color: var(--accent);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}

.chat-meta {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-weight: 600;
    font-size: 14px;
    display: block;
    margin-bottom: 3px;
}

.chat-preview {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* 在线人数 */
.online-count {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    color: var(--text-secondary);
}

.online-count i {
    margin-right: 6px;
    color: var(--accent);
}

/* ===== 主聊天区 ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    transition: background var(--transition);
}

/* 聊天头部 */
.chat-header {
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-main);
    transition: background var(--transition);
}

.chat-header-info h3 {
    font-size: 16px;
    font-weight: 600;
}

.room-status {
    font-size: 12px;
    color: #31a24c;
}

.room-status i {
    font-size: 8px;
    margin-right: 4px;
    vertical-align: middle;
}

.header-actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    font-size: 16px;
    transition: all var(--transition);
}

.header-actions button:hover {
    background: var(--bg-hover);
    color: #e74c3c;
}

/* ===== 消息区域 ===== */
.messages {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
    background: var(--bg-primary);
    transition: background var(--transition);
}

.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* 欢迎消息 */
.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.welcome-message h3 {
    font-size: 20px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
}

/* 消息气泡 */
.message {
    display: flex;
    gap: 10px;
    max-width: 75%;
    animation: messageIn 0.3s ease;
}

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

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

.message.other {
    align-self: flex-start;
}

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    margin-top: 4px;
}

.message-body {
    max-width: 100%;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    padding: 0 4px;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}

.message-time {
    font-size: 10px;
    color: var(--text-muted);
}

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.message.self .message-bubble {
    background: var(--msg-self-bg);
    color: var(--msg-self-text);
    border-bottom-right-radius: 4px;
}

.message.other .message-bubble {
    background: var(--msg-other-bg);
    color: var(--msg-other-text);
    border-bottom-left-radius: 4px;
}

.message-time-inline {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 4px;
    opacity: 0.7;
}

/* ===== 输入区域 ===== */
.input-area {
    padding: 16px 24px;
    background: var(--bg-main);
    border-top: 1px solid var(--border-color);
    transition: background var(--transition);
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border-radius: 28px;
    padding: 4px 4px 4px 16px;
    transition: background var(--transition);
}

.input-wrapper:focus-within {
    box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.3);
}

.input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    padding: 10px 0;
    outline: none;
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

.emoji-btn, .send-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px 12px;
    border-radius: 50%;
    font-size: 18px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.emoji-btn:hover {
    color: var(--accent);
    background: rgba(108, 92, 231, 0.1);
}

.send-btn {
    color: #fff;
    background: var(--accent);
    padding: 10px 18px;
    border-radius: 24px;
    font-size: 15px;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

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

/* ===== Emoji 选择器 ===== */
.emoji-picker {
    display: none;
    position: absolute;
    bottom: 90px;
    left: 24px;
    background: var(--bg-sidebar);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 12px;
    z-index: 100;
    border: 1px solid var(--border-color);
}

.emoji-picker.show {
    display: block;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    max-width: 280px;
}

.emoji-grid span {
    cursor: pointer;
    font-size: 24px;
    padding: 4px;
    border-radius: 6px;
    text-align: center;
    transition: background var(--transition);
}

.emoji-grid span:hover {
    background: var(--bg-hover);
    transform: scale(1.2);
}

/* ===== 通知样式 ===== */
.system-message {
    text-align: center;
    padding: 8px 16px;
    margin: 8px 0;
}

.system-message span {
    background: var(--bg-input);
    padding: 6px 16px;
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .app {
        max-height: none;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }

    .sidebar {
        width: 260px;
        min-width: 260px;
    }

    .message {
        max-width: 85%;
    }

    .chat-header {
        padding: 14px 16px;
    }

    .messages {
        padding: 16px;
    }

    .input-area {
        padding: 12px 16px;
    }
}

@media (max-width: 520px) {
    .sidebar {
        display: none;
    }

    .chat-main {
        width: 100%;
    }

    .message {
        max-width: 90%;
    }
}
