/* 重置样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

.chat-container {
    display: grid;
    grid-template-areas:
        "header header"
        "sidebar main";
    grid-template-rows: 60px 1fr;
    grid-template-columns: 250px 1fr;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
}

/* 头部样式 */
.chat-header {
    grid-area: header;
    background: #2d3748;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid #4a5568;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-icon {
    font-size: 24px;
}

.header-title h1 {
    font-size: 18px;
    font-weight: 600;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 14px;
}

.status-online {
    color: #48bb78;
}

.status-offline {
    color: #f56565;
}

/* 侧边栏样式 */
.chat-sidebar {
    grid-area: sidebar;
    background: #f7fafc;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
}

.sidebar-section {
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
}

.sidebar-section h3 {
    font-size: 14px;
    color: #4a5568;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    font-size: 14px;
}

.user-avatar {
    width: 24px;
    height: 24px;
    background: #667eea;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
}

.no-users {
    text-align: center;
    color: #a0aec0;
    font-style: italic;
    padding: 20px 0;
}

.system-info {
    font-size: 12px;
    color: #718096;
    line-height: 1.5;
}

.system-info p {
    margin: 5px 0;
}

/* 主聊天区域样式 */
.chat-main {
    grid-area: main;
    display: flex;
    flex-direction: column;
    background: #edf2f7;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 70%;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 5px;
}

.user-message .message-avatar {
    background: #667eea;
    color: white;
}

.ai-message .message-avatar {
    background: #48bb78;
    color: white;
}

.message-content {
    background: white;
    padding: 12px 16px;
    border-radius: 18px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    line-height: 1.4;
    max-width: 100%;
    word-wrap: break-word;
}

.user-message .message-content {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message .message-content {
    border-bottom-left-radius: 4px;
    background: #ffffff;
}

.message-sender {
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 4px;
    opacity: 0.8;
}

.message-text {
    word-wrap: break-word;
    line-height: 1.5;
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.system-message {
    align-self: center;
    max-width: 80%;
    text-align: center;
}

.system-message .message-content {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
    font-size: 13px;
    text-align: center;
    padding: 10px 15px;
}

.system-message.welcome .message-content {
    background: #d1ecf1;
    border-color: #bee5eb;
    color: #0c5460;
}

.system-message.error .message-content {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.system-message.success .message-content {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

/* 输入区域样式 */
.chat-input-container {
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 15px 20px;
}

.input-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

.tool-btn {
    padding: 6px 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: #e9ecef;
}

.connection-status {
    font-size: 12px;
    color: #6c757d;
    margin-left: auto;
}

.input-area {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    min-height: 44px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

#messageInput:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.send-btn {
    background: #667eea;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    height: 44px;
    font-weight: 600;
}

.send-btn:hover:not(:disabled) {
    background: #5a6fd8;
    transform: translateY(-1px);
}

.send-btn:disabled {
    background: #a0aec0;
    cursor: not-allowed;
    transform: none;
}

.send-btn:active:not(:disabled) {
    transform: translateY(0);
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.chat-sidebar::-webkit-scrollbar {
    width: 4px;
}

.chat-sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-sidebar::-webkit-scrollbar-thumb {
    background: #d1d1d1;
    border-radius: 2px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .chat-container {
        grid-template-areas:
            "header"
            "main";
        grid-template-columns: 1fr;
        grid-template-rows: 60px 1fr;
    }

    .chat-sidebar {
        display: none;
    }

    .message {
        max-width: 90%;
    }

    .chat-input-container {
        padding: 10px 15px;
    }

    .input-toolbar {
        flex-wrap: wrap;
    }
}

/* 加载动画 */
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 16px;
    background: #f8f9fa;
    border-radius: 18px;
    align-self: flex-start;
    max-width: 60px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #6c757d;
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}