/* ==================== 基础样式 ==================== */
:root {
    --primary-color: #007AFF;
    --success-color: #34C759;
    --bg-primary: #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-tertiary: #636366;
    --border-color: #38383A;
    --bubble-incoming: #262628;
    --bubble-outgoing: #007AFF;
    --danger-color: #FF3B30;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ==================== 页面切换 ==================== */
.page {
    display: none;
    height: 100vh;
}

.page.active {
    display: flex;
}

/* ==================== 登录页面 ==================== */
#login-page {
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, #1a1a2e 0%, #0f0f1a 100%);
}

.login-container {
    text-align: center;
    padding: 40px;
    max-width: 360px;
    width: 100%;
}

.login-icon {
    margin-bottom: 24px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.login-container h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 14px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#login-form input {
    padding: 16px 20px;
    border: none;
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    transition: all 0.2s;
}

#login-form input:focus {
    box-shadow: 0 0 0 2px var(--primary-color);
}

.btn-primary {
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    background: var(--success-color);
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    padding: 14px 24px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: transparent;
    color: var(--danger-color);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.btn-secondary:hover {
    background: rgba(255, 59, 48, 0.1);
}

.error-text {
    color: var(--danger-color);
    font-size: 14px;
    margin-top: 8px;
    min-height: 20px;
}

/* ==================== 主页面布局 ==================== */
#main-page {
    display: flex;
    height: 100vh;
}

.panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#conversations-panel {
    width: 380px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
}

#messages-panel {
    flex: 1;
    background: var(--bg-secondary);
}

/* ==================== 面板头部 ==================== */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    min-height: 64px;
}

.panel-header h1 {
    font-size: 32px;
    font-weight: 700;
}

.panel-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--border-color);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* ==================== 会话列表 ==================== */
.list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.15s;
}

.conversation-item:hover {
    background: var(--bg-secondary);
}

.conversation-item.active {
    background: var(--bg-tertiary);
}

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    margin-right: 14px;
    flex-shrink: 0;
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.conversation-name {
    font-size: 16px;
    font-weight: 500;
}

.conversation-time {
    font-size: 13px;
    color: var(--text-secondary);
}

.conversation-preview {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== 消息区域 ==================== */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message-bubble.incoming {
    background: var(--bubble-incoming);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-bubble.outgoing {
    background: var(--bubble-outgoing);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
    padding: 0 4px;
}

.message-time.outgoing {
    text-align: right;
}

/* ==================== 输入区域 ==================== */
.input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

.input-area.hidden {
    display: none;
}

#message-input {
    flex: 1;
    padding: 12px 18px;
    border: none;
    border-radius: 20px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
}

#message-input:focus {
    box-shadow: 0 0 0 2px var(--primary-color);
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--success-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.send-btn:hover {
    opacity: 0.9;
}

.send-btn:active {
    transform: scale(0.95);
}

/* ==================== 弹窗 ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 20px;
    font-weight: 600;
}

.modal form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal input, .modal textarea {
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    resize: none;
}

.modal input:focus, .modal textarea:focus {
    border-color: var(--primary-color);
}

.modal h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.modal hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 20px 0;
}

/* ==================== 移动端适配 ==================== */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    #main-page {
        flex-direction: column;
    }
    
    #conversations-panel {
        width: 100%;
        border-right: none;
    }
    
    #messages-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }
    
    #messages-panel.visible {
        transform: translateX(0);
    }
    
    .hidden-mobile {
        /* 在移动端隐藏，直到点击会话 */
    }
    
    .mobile-only {
        display: flex;
    }
    
    .panel-header h1 {
        font-size: 28px;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .contact-info {
        flex: 1;
        text-align: center;
    }
}

/* ==================== 滚动条美化 ==================== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ==================== 加载动画 ==================== */
.loading {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== Toast 提示 ==================== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 2000;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate(-50%, 10px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}
