/* ===== 全局变量与重置 ===== */
:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #10b981;
    --accent: #f59e0b;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
}

/* ===== 布局 ===== */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.badge {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.header-right {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--border);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ===== 卡片 ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== 表单 ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-group.half {
    flex: 1;
}

.button-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.btn-primary,
.btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
    flex: 2;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border);
    flex: 1;
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-primary:disabled,
.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== 诊断结果 ===== */
.diagnosis-header {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.error-type-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* 错误类型颜色 */
.error-type-badge.概念混淆 { background: #fef3c7; color: #92400e; }
.error-type-badge.计算失误 { background: #fee2e2; color: #991b1b; }
.error-type-badge.审题不清 { background: #e0e7ff; color: #3730a3; }
.error-type-badge.公式记错 { background: #fce7f3; color: #9d174d; }
.error-type-badge.思路错误 { background: #d1fae5; color: #065f46; }

.knowledge-tag {
    background: #e2e8f0;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.diagnosis-body p {
    margin-bottom: 10px;
    line-height: 1.6;
}

.diagnosis-body strong {
    color: var(--primary-dark);
}

/* ===== 练习题卡片 ===== */
.practice-item {
    background: var(--bg-main);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 16px;
    border-left: 4px solid var(--primary);
}

.practice-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
}

.practice-number {
    font-weight: 700;
    color: var(--primary);
}

.practice-question {
    font-weight: 500;
    margin-bottom: 16px;
    padding: 8px;
    background: white;
    border-radius: var(--radius-sm);
}

.practice-hint,
.practice-answer {
    margin-top: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
}

.practice-hint {
    background: #fef9c3;
    border-left: 4px solid var(--accent);
}

.practice-answer {
    background: #dcfce7;
    border-left: 4px solid var(--secondary);
}

.practice-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.practice-actions button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.practice-actions button:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== 加载动画 ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.ai-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* ===== API Key 对话框 ===== */
.api-key-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.api-key-dialog {
    background: white;
    border-radius: 20px;
    padding: 28px;
    max-width: 450px;
    width: 90%;
    box-shadow: 0 25px 30px -12px rgba(0, 0, 0, 0.25);
    animation: dialogSlideIn 0.3s ease;
}

@keyframes dialogSlideIn {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dialog-header h3 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1.3rem;
}

.dialog-desc {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.dialog-desc a {
    color: var(--primary);
    text-decoration: none;
}

.dialog-body input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: monospace;
    margin-bottom: 8px;
}

.dialog-body input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-hint {
    font-size: 0.8rem;
    color: #94a3b8;
}

.dialog-footer {
    display: flex;
    gap: 12px;
    margin-top: 28px;
    justify-content: flex-end;
}

/* ===== 学情报告 ===== */
.stats-summary {
    display: flex;
    gap: 24px;
    margin-bottom: 24px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.chart-container {
    margin-top: 24px;
    height: 250px;
}

/* ===== 响应式 ===== */
@media (max-width: 640px) {
    .app-container {
        padding: 12px;
    }
    
    .header-left h1 {
        font-size: 1.4rem;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .btn-primary,
    .btn-secondary {
        width: 100%;
    }
    
    .card {
        padding: 16px;
    }
}

/* ===== 底部 ===== */
.app-footer {
    margin-top: 32px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 16px 0;
}

/* 题目输入框包装器（包含拍照按钮） */
.textarea-wrapper {
    position: relative;
    display: flex;
    align-items: flex-start;
}

.textarea-wrapper textarea {
    flex: 1;
    padding-right: 50px; /* 为拍照按钮留出空间 */
}

.camera-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.camera-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.camera-btn:active {
    transform: scale(0.95);
}

/* 设置对话框中凭证分组 */
.config-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.config-section:last-child {
    border-bottom: none;
}

.config-section h4 {
    margin-bottom: 12px;
    color: var(--primary-dark);
}

.config-section label {
    display: block;
    margin-top: 10px;
    margin-bottom: 4px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.config-section input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: monospace;
}