/* ===== CSS 变量定义 ===== */
:root {
    /* 主题色 */
    --primary-color: #4A90E2;
    --primary-hover: #357ABD;
    --secondary-color: #6C757D;
    --secondary-hover: #545B62;
    --success-color: #28A745;
    --danger-color: #DC3545;
    --warning-color: #FFC107;
    
    /* 背景色 */
    --bg-color: #E8ECF1;
    --card-bg: #FFFFFF;
    
    /* 文本色 */
    --text-color: #333333;
    --text-light: #666666;
    --text-muted: #999999;
    
    /* 边框 */
    --border-color: #D0D0D0;
    --border-radius: 6px;
    
    /* A4纸尺寸 */
    --a4-width: 210mm;
    --a4-height: 297mm;
}

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

body {
    font-family: 'Microsoft YaHei', '微软雅黑', 'Segoe UI', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.4;
    min-height: 100vh;
}

/* ===== 屏幕顶部标题 ===== */
.screen-header {
    background: #2C3E50;
    color: white;
    text-align: center;
    padding: 12px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.screen-header h1 {
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 1px;
}

/* ===== 主容器布局 ===== */
.app-container {
    display: flex;
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
    align-items: flex-start;
}

/* ===== 左侧配置面板 ===== */
.config-panel {
    width: 280px;
    flex-shrink: 0;
    position: sticky;
    top: 60px;
}

.config-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.config-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary-color);
}

/* ===== 表单样式 ===== */
.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-color);
}

.form-control {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    transition: border-color 0.2s;
    background-color: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 0.9em;
    padding-right: 24px;
}

/* ===== 复选框组 ===== */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 3px 4px;
    border-radius: 3px;
    font-size: 0.8rem;
    transition: background-color 0.15s;
}

.checkbox-label:hover {
    background-color: #F0F4F8;
}

.checkbox-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* 子选项缩进 */
.sub-option {
    margin-left: 20px;
    margin-top: 4px;
    margin-bottom: 4px;
}

.sub-option label {
    font-size: 0.78rem;
    margin-bottom: 2px;
}

.form-control-sm {
    padding: 4px 6px;
    font-size: 0.78rem;
}

/* ===== 范围输入 ===== */
.range-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
}

.range-inputs .form-control {
    width: 100%;
}

.range-separator {
    color: var(--text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

/* ===== 按钮样式 ===== */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 14px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: var(--secondary-hover);
}

.btn-small {
    padding: 4px 10px;
    font-size: 0.75rem;
}

.btn-icon {
    font-size: 1em;
}

.config-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #eee;
    font-size: 0.8rem;
    color: var(--text-light);
}

/* ===== 右侧A4纸预览区 ===== */
.preview-area {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 10px 0;
}

/* ===== A4纸样式 ===== */
.a4-paper {
    width: var(--a4-width);
    height: var(--a4-height);
    background: white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 10mm 10mm 15mm 10mm;
    position: relative;
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
    overflow: hidden;
}

.a4-paper:last-child {
    margin-bottom: 0;
}

/* 纸张内容区域 */
.paper-body {
    flex: 1;
    overflow: hidden;
}

/* A4纸头部 */
.paper-header {
    border-bottom: 2px solid #000;
    padding-bottom: 4mm;
    margin-bottom: 4mm;
}

.paper-title {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 2px;
    margin-bottom: 3mm;
    text-align: center;
}

.paper-info {
    font-size: 11px;
    color: #333;
    display: flex;
    flex-wrap: wrap;
    gap: 2mm 4mm;
}

.info-item {
    white-space: nowrap;
}

/* A4纸题目区域 */
.paper-body {
    flex: 1;
}

/* ===== 题目网格 ===== */
.problem-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3mm 5mm;
    min-height: 150mm;
}

.problem-item {
    padding: 2mm 1mm;
    font-size: 14px;
    display: flex;
    align-items: baseline;
    border-bottom: 1px solid #eee;
    animation: none;
    white-space: nowrap;
}

.problem-item:hover {
    background-color: #F8F9FA;
}

.problem-number {
    font-style: italic;
    color: #666;
    margin-right: 2mm;
    font-size: 10px;
}

.problem-expression {
    font-size: 15px;
    letter-spacing: 0.5px;
}

.problem-answer {
    color: var(--success-color);
    font-weight: 500;
    font-size: 14px;
}

.problem-answer.hidden {
    display: none;
}

.problem-answer-input {
    color: #999;
    font-size: 13px;
}

/* ===== 空状态 ===== */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20mm;
    color: var(--text-muted);
    text-align: center;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 4mm;
}

.empty-state p {
    font-size: 0.95rem;
}

/* ===== A4纸答案区域 ===== */
.paper-answer {
    margin-top: 5mm;
    padding-top: 3mm;
    border-top: 2px solid #000;
}

.answer-title {
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 2mm;
}

.answer-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1.5mm 3mm;
    font-size: 11px;
    line-height: 1.8;
}

.answer-item {
    padding: 0.5mm 0;
    border-bottom: 1px dotted #ccc;
}

.answer-num {
    color: #666;
}

.answer-val {
    font-weight: bold;
    color: #000;
}

/* 简单答案网格样式（题号. 答案） */
.answer-grid-simple {
    display: flex;
    flex-wrap: wrap;
    gap: 2mm 5mm;
    font-size: 13px;
    line-height: 1.8;
}

.answer-item-simple {
    white-space: nowrap;
}

.answer-item-simple .answer-num {
    font-style: italic;
    color: #666;
    font-size: 11px;
}

.answer-item-simple .answer-val {
    font-weight: bold;
    color: #000;
    font-size: 14px;
}

/* ===== A4纸页脚 ===== */
.paper-footer {
    text-align: center;
    font-size: 10px;
    color: #999;
    margin-top: auto;
    padding-top: 3mm;
    border-top: 0.5px solid #ccc;
}

/* ===== 加载状态 ===== */
.loading {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20mm;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== 提示信息 ===== */
.toast {
    position: fixed;
    top: 60px;
    right: 20px;
    padding: 10px 18px;
    background: var(--success-color);
    color: white;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    z-index: 1000;
    font-size: 0.85rem;
}

.toast.show {
    transform: translateX(0);
}

.toast.error {
    background: var(--danger-color);
}

.toast.warning {
    background: var(--warning-color);
    color: var(--text-color);
}

/* ===== 响应式设计 ===== */
@media (max-width: 1100px) {
    .app-container {
        flex-direction: column;
        align-items: center;
    }
    
    .config-panel {
        width: 100%;
        max-width: var(--a4-width);
        position: static;
    }
    
    .config-card {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .config-title {
        width: 100%;
    }
    
    .form-group {
        flex: 1;
        min-width: 120px;
    }
    
    .button-group {
        flex-direction: row;
    }
    
    .config-info {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .screen-header h1 {
        font-size: 1.1rem;
    }
    
    .a4-paper {
        width: 100%;
        min-height: auto;
        padding: 5mm;
    }
    
    .problem-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .answer-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 10px;
    }
    
    .problem-grid {
        grid-template-columns: 1fr;
    }
    
    .answer-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}