/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-tertiary: #64748b;
        --border-color: #334155;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

.app-container {
    display: flex;
    height: 100vh;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* 头部 */
.chat-header {
    height: 64px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.chat-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-title i {
    color: var(--primary-color);
    font-size: 22px;
}

.settings-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.settings-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.clear-chat-btn {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.clear-chat-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

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

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

/* 欢迎 */
.welcome-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    color: white;
    margin-bottom: 24px;
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.3);
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 8px 32px rgba(59, 130, 246, 0.3); }
    50% { box-shadow: 0 8px 40px rgba(59, 130, 246, 0.45); }
}

.welcome-container h2 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-container p {
    font-size: 16px;
    color: var(--text-secondary);
}

/* 消息 */
.message {
    display: flex;
    gap: 14px;
    padding: 16px 0;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.message-content {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 56px);
}

.message-text {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.7;
    word-wrap: break-word;
    text-align: left;
}

.message.user .message-text {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    margin-left: auto;
    display: block;
}

.message.assistant .message-text {
    /* 无背景，无边框 */
}

/* Markdown 样式 */
.message-text > p {
    margin: 12px 0;
}

.message-text > p:first-child {
    margin-top: 0;
}

.message-text > p:last-child {
    margin-bottom: 0;
}

.message-text h1 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 20px 0 12px 0;
    color: var(--text-primary);
}

.message-text h1:first-child {
    margin-top: 0;
}

.message-text h2 {
    font-size: 1.3em;
    font-weight: 600;
    margin: 18px 0 10px 0;
    color: var(--text-primary);
}

.message-text h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: var(--text-primary);
}

.message-text ul,
.message-text ol {
    margin: 10px 0;
    padding-left: 24px;
}

.message-text li {
    margin: 6px 0;
}

.message-text strong {
    font-weight: 600;
}

.message-text em {
    font-style: italic;
}

.message-text a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

.message-text blockquote {
    margin: 12px 0;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary-color);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
    font-style: italic;
}

.message-text hr {
    margin: 20px 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* 代码 */
.message-text code {
    background: var(--bg-tertiary);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', Consolas, monospace;
    font-size: 0.9em;
    color: var(--primary-color);
}

.message.user .message-text code {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message-text pre {
    margin: 12px 0;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.message-text pre code {
    display: block;
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 16px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
    border-radius: var(--radius-md);
}

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-sm);
    color: #d4d4d4;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.code-copy-btn.copied {
    color: #22c55e;
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
}

.typing-indicator .dot {
    width: 8px;
    height: 8px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(1) { animation-delay: 0s; }
.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* 输入区 */
.chat-input-area {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 12px 16px;
    transition: all 0.2s;
}

.input-container:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#chatInput {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 24px;
    font-family: inherit;
}

#chatInput::placeholder {
    color: var(--text-tertiary);
}

.send-btn {
    width: 46px;
    height: 46px;
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.send-btn.loading i {
    animation: pulse 0.8s infinite;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 24px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 1000;
    color: var(--text-primary);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    visibility: visible;
}

.toast.error {
    border-color: #ef4444;
    color: #ef4444;
}

.toast.success {
    border-color: #22c55e;
    color: #22c55e;
}

/* 设置弹窗 */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 999;
}

.settings-overlay.active {
    opacity: 1;
    visibility: visible;
}

.settings-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 90%;
    max-width: 420px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 1000;
}

.settings-modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.settings-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.settings-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-header h2 i {
    color: var(--primary-color);
}

.settings-body {
    padding: 24px;
}

.settings-body label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.settings-body input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: all 0.2s;
}

.settings-body input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.settings-body input::placeholder {
    color: var(--text-tertiary);
}

.settings-hint {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.settings-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.settings-footer button {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-cancel:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-save {
    background: var(--primary-color);
    border: none;
    color: white;
}

.btn-save:hover {
    background: var(--primary-hover);
}

/* 移动端 */
@media (max-width: 768px) {
    .chat-header {
        padding: 0 16px;
    }

    .settings-modal {
        width: 95%;
    }

    .chat-messages {
        padding: 16px;
    }

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

    .welcome-container h2 {
        font-size: 22px;
    }

    .welcome-icon {
        width: 64px;
        height: 64px;
        font-size: 28px;
    }

    .message-text {
        font-size: 14px;
        padding: 12px 14px;
    }
}
