/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部样式 */
header {
    background: white;
    padding: 2rem;
    border-radius: 15px 15px 0 0;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    color: #2d3748;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: #718096;
    font-size: 1.1rem;
}

/* 主布局 */
main {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 20px;
    min-height: calc(100vh - 200px);
}

/* 侧边栏 */
.sidebar {
    background: white;
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* 密钥管理 */
.key-manager, .chat-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.key-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.key-input-group input {
    padding: 0.75rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.key-input-group input:focus {
    outline: none;
    border-color: #667eea;
}

.key-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.key-buttons button {
    padding: 0.5rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s;
}

.key-buttons button:hover {
    background: #5a67d8;
}

.key-info {
    background: #f7fafc;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

/* 聊天列表 */
.btn-new-chat {
    width: 100%;
    padding: 0.75rem;
    background: #48bb78;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-new-chat:hover {
    background: #38a169;
}

#chat-list-container {
    flex: 1;
    overflow-y: auto;
    max-height: 500px;
}

.chat-item {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-item:hover {
    background: #f7fafc;
}

.chat-item.active {
    background: #ebf4ff;
    border-left: 4px solid #667eea;
}

.chat-title {
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.25rem;
}

.chat-meta {
    font-size: 0.85rem;
    color: #718096;
    display: flex;
    justify-content: space-between;
}

/* 聊天容器 */
.chat-container {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 1.5rem;
    background: #f7fafc;
    display: flex;
    gap: 1rem;
    align-items: center;
    border-bottom: 2px solid #e2e8f0;
}

#chat-title {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 500;
}

.chat-actions {
    display: flex;
    gap: 0.5rem;
}

.chat-actions button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s;
}

.chat-actions button:not(.danger) {
    background: #667eea;
    color: white;
}

.chat-actions button:not(.danger):hover {
    background: #5a67d8;
}

.chat-actions button.danger {
    background: #fc8181;
    color: white;
}

.chat-actions button.danger:hover {
    background: #f56565;
}

/* 消息容器 */
.messages-container {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    min-height: 400px;
    background: #f8f9fa;
}

.empty-state {
    text-align: center;
    color: #718096;
    padding: 3rem;
}

.message {
    margin-bottom: 1.5rem;
    animation: slideIn 0.3s ease;
}

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

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.sender-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.sender-badge.user {
    background: #bee3f8;
    color: #2c5282;
}

.sender-badge.ai {
    background: #c6f6d5;
    color: #22543d;
}

.message-time {
    font-size: 0.85rem;
    color: #718096;
}

.message-content {
    padding: 1rem;
    border-radius: 10px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-content.user {
    background: white;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #4299e1;
}

.message-content.ai {
    background: white;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #48bb78;
}

/* 消息输入区域 */
.message-input-area {
    padding: 1.5rem;
    border-top: 2px solid #e2e8f0;
    background: #f7fafc;
}

.input-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.sender-toggle {
    display: flex;
    gap: 0.5rem;
    background: #e2e8f0;
    padding: 0.25rem;
    border-radius: 8px;
}

.sender-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #718096;
    cursor: pointer;
    transition: all 0.3s;
}

.sender-btn.active {
    background: white;
    color: #2d3748;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.time-input {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

.time-input label {
    color: #718096;
    font-size: 0.9rem;
}

.time-input input {
    padding: 0.5rem;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
}

.time-input button {
    padding: 0.5rem 0.75rem;
    background: #a0aec0;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}

.input-main {
    position: relative;
}

#message-input {
    width: 100%;
    padding: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 1rem;
    resize: vertical;
    min-height: 100px;
    max-height: 300px;
}

#message-input:focus {
    outline: none;
    border-color: #667eea;
}

.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}

#send-btn {
    padding: 0.75rem 2rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

#send-btn:hover {
    background: #5a67d8;
}

.char-count {
    color: #718096;
    font-size: 0.9rem;
}

/* 页脚 */
footer {
    margin-top: 20px;
    padding: 1.5rem;
    background: white;
    border-radius: 0 0 15px 15px;
    text-align: center;
    color: #718096;
    font-size: 0.9rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 25px rgba(0, 0, 0, 0.1);
}

.modal-content h3 {
    margin-bottom: 1rem;
    color: #2d3748;
}

.modal-content input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
}

.modal-content input[type="file"] {
    padding: 0.5rem;
}

.or-separator {
    text-align: center;
    margin: 1rem 0;
    color: #718096;
    position: relative;
}

.or-separator::before,
.or-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 45%;
    height: 1px;
    background: #e2e8f0;
}

.or-separator::before {
    left: 0;
}

.or-separator::after {
    right: 0;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.modal-buttons button {
    flex: 1;
    padding: 0.75rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
}

.modal-buttons button:not(.secondary) {
    background: #667eea;
    color: white;
}

.modal-buttons button.secondary {
    background: #e2e8f0;
    color: #4a5568;
}

/* 加载状态 */
.loading {
    text-align: center;
    color: #718096;
    padding: 2rem;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        order: 2;
    }
    
    .chat-container {
        order: 1;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .chat-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .chat-actions {
        width: 100%;
    }
    
    .input-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .time-input {
        margin-left: 0;
        justify-content: space-between;
    }
}