/* 基础样式 */
:root {
    --primary-color: #0066ff;
    --primary-light: #3385ff;
    --primary-dark: #0052cc;
    --bg-color: #ffffff;
    --message-bg: #ffffff;
    --ai-message-bg: #f8f9fa;
    --text-color: #333333;
    --text-light: #666666;
    --error-color: #ff4d4f;
    --success-color: #52c41a;
    --border-color: #e5e5e5;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    background: #ffffff;
    color: var(--text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* 聊天容器 */
.chat-container {
    max-width: 768px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

/* 聊天头部 */
.chat-header {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background: #ffffff;
}

.chat-header h1 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
}

/* 设置按钮 */
.settings-button {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.5rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.settings-button:hover {
    opacity: 1;
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: #ffffff;
}

/* 消息气泡 */
.message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    font-size: 0.9375rem;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-message {
    align-self: flex-start;
    background: var(--ai-message-bg);
    color: var(--text-color);
}

.user-message {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
}

.error-message {
    align-self: center;
    background: #fff2f0;
    color: var(--error-color);
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #ffccc7;
}

/* 加载动画 */
.loading-message {
    align-self: flex-start;
    background: var(--ai-message-bg);
}

.loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.loading-dots span {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-light);
    opacity: 0;
    animation: pulse 1s infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

/* 输入区域 */
.chat-input {
    padding: 1rem;
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
    background: #ffffff;
}

.chat-input input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    outline: none;
    transition: all 0.2s;
    background: white;
}

.chat-input input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 102, 255, 0.1);
}

.chat-input button {
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    width: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.chat-input button:hover:not(:disabled) {
    background: var(--primary-dark);
}

.chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: #ffffff;
    width: 90%;
    max-width: 360px;
    margin: auto;
    border-radius: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
}

.close-button {
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.close-button:hover {
    opacity: 1;
}

.modal-body {
    padding: 1rem;
    background: #ffffff;
}

/* 表单样式 */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-light);
}

.api-key-input {
    position: relative;
}

.api-key-input input {
    width: 100%;
    padding-right: 2.5rem;
}

.toggle-password {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.toggle-password:hover {
    opacity: 1;
}

.primary-button {
    width: 100%;
    padding: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.primary-button:hover {
    background: var(--primary-dark);
}

.settings-message {
    margin-top: 0.75rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    display: none;
}

.settings-message.success {
    display: block;
    background: #f6ffed;
    color: var(--success-color);
    border: 1px solid #b7eb8f;
}

.settings-message.error {
    display: block;
    background: #fff2f0;
    color: var(--error-color);
    border: 1px solid #ffccc7;
}

/* 响应式设计 */
@media (max-width: 640px) {
    .chat-container {
        height: 100vh;
    }

    .message {
        max-width: 90%;
        font-size: 0.875rem;
    }

    .chat-input {
        padding: 0.75rem;
    }

    .chat-input input {
        padding: 0.625rem;
    }

    .chat-input button {
        padding: 0.625rem;
        width: 38px;
    }
}