/* 组卷页面样式 */

/* 步骤导航 */
.breadcrumb {
    display: flex;
    gap: 16px;
    margin: 24px 0;
    padding: 16px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

.breadcrumb span {
    color: #6c757d;
    font-size: 14px;
}

.breadcrumb span.active {
    color: #0d6efd;
    font-weight: 600;
}

/* 组卷容器 */
.paper-create-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 24px;
}

/* 科目列表 */
.subject-list {
    display: grid;
    gap: 12px;
    margin: 24px 0;
}

.subject-card {
    display: flex;
    align-items: center;
    padding: 16px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 150ms;
}

.subject-card:hover {
    border-color: #0d6efd;
    background-color: #f8f9fa;
}

.subject-card input[type="radio"] {
    margin-right: 12px;
}

.subject-card input[type="radio"]:checked + .subject-name {
    color: #0d6efd;
}

.subject-name {
    font-size: 18px;
    font-weight: 500;
    flex: 1;
}

.subject-count {
    color: #6c757d;
    font-size: 14px;
}

/* 表单组 */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #212529;
}

.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 16px;
}

/* 范围选项 */
.range-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.range-option {
    display: flex;
    align-items: center;
    padding: 12px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
}

.range-option input[type="radio"] {
    margin-right: 8px;
}

.time-selector,
.knowledge-selector {
    margin-left: 32px;
    margin-top: 8px;
}

.time-selector {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.time-selector[hidden],
.knowledge-selector[hidden] {
    display: none;
}

.time-mode-option,
.date-range-inputs,
.date-range-inputs label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-selector input[type="number"] {
    width: 80px;
}

.time-selector input[type="date"] {
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 16px;
}

@media (max-width: 640px) {
    .date-range-inputs {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* 知识点树 */
.knowledge-outline,
.knowledge-option-children {
    list-style: none;
    margin: 8px 0;
    padding-left: 20px;
}

.knowledge-outline {
    padding-left: 0;
}

.knowledge-option-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-weight: 400;
}

.knowledge-option-name {
    flex: 1;
}

.knowledge-option-count {
    color: #6c757d;
    font-size: 13px;
    white-space: nowrap;
}

/* 预览结果 */
.preview-result {
    margin-top: 32px;
    padding: 24px;
    background-color: #f8f9fa;
    border-radius: 8px;
}

.preview-result h3 {
    margin-top: 0;
}

.preview-questions {
    display: grid;
    gap: 12px;
    margin: 16px 0;
}

.preview-question-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background-color: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

.preview-number {
    font-weight: 600;
    min-width: 60px;
}

.preview-thumbnail {
    max-width: 120px;
    max-height: 80px;
    object-fit: contain;
}

/* 试卷展示 */
.paper-view-container {
    max-width: 210mm; /* A4 宽度 */
    margin: 0 auto;
    padding: 24px;
}

.paper-header {
    text-align: center;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 2px solid #dee2e6;
}

.paper-header-title-row {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 24px;
}

.paper-header-title-row h1,
.paper-header-title-row .paper-meta {
    margin: 0;
}

.paper-meta {
    color: #6c757d;
    font-size: 14px;
    margin-top: 8px;
}

.paper-questions {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.paper-question {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 16px;
    padding: 16px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
}

.question-content {
    min-width: 0;
}

.question-number {
    font-size: 24px;
    font-weight: 600;
    color: #0d6efd;
    padding: 8px;
}

/* 图片缩放容器：inline-block 使容器贴合图片实际宽度 */
.image-resize-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
    /* 屏幕上显示虚线轮廓，提示此区域可拖拽缩放 */
    outline: 1.5px dashed var(--border, #dee2e6);
    outline-offset: 3px;
}

.image-resize-wrap img {
    display: block;
    max-width: 100%;
    height: auto; /* 宽度改变时高度按比例自动跟随 */
}

/* 缩放控制点，复用 mistakes.css 中 resize-handle 的视觉语言 */
.img-resize-handle {
    position: absolute;
    background: var(--brand, #0d6efd);
    border: 2px solid white;
    box-shadow: 0 1px 4px rgb(0 0 0 / 25%);
    z-index: 2;
    touch-action: none; /* 阻止触摸时浏览器滚动，让拖拽事件正常触发 */
}

/* 右侧边缘手柄：左右拖动 */
.img-resize-e {
    width: 8px;
    height: 40px;
    top: 50%;
    right: -4px;
    transform: translateY(-50%);
    cursor: ew-resize;
    border-radius: 4px;
}

/* 右下角手柄 */
.img-resize-se {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    bottom: -6px;
    right: -6px;
    cursor: nwse-resize;
}

/* 左下角手柄 */
.img-resize-sw {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    bottom: -6px;
    left: -6px;
    cursor: nesw-resize;
}

.img-resize-handle:hover {
    background: #0b5ed7;
}

/* 打印时去掉轮廓；控制点本身用 no-print 隐藏，图片尺寸保留用户调整结果 */
@media print {
    .image-resize-wrap {
        outline: none;
    }
}

.question-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.question-tags .tag {
    display: inline-block;
    padding: 4px 8px;
    background-color: #f8f9fa;
    border-radius: 4px;
    font-size: 14px;
    color: #495057;
}

.paper-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 32px;
}

/* 试卷列表 */
.papers-list-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.actions {
    margin-bottom: 24px;
}

.papers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.paper-card {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

.paper-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.paper-card-header h3 {
    margin: 0;
    font-size: 18px;
}

.btn-icon-delete {
    background: none;
    border: none;
    color: #dc3545;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

.btn-icon-delete:hover {
    color: #c82333;
}

.paper-card-body {
    padding: 16px;
}

.paper-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.filter-tag {
    display: inline-block;
    padding: 4px 8px;
    background-color: #e7f3ff;
    color: #0d6efd;
    border-radius: 4px;
    font-size: 12px;
}

.paper-card-footer {
    padding: 16px;
    border-top: 1px solid #dee2e6;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state p {
    color: #6c757d;
    margin-bottom: 16px;
}

/* 按钮样式 */
.btn-primary,
.btn-secondary {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    border: none;
    font-size: 16px;
}

.btn-primary {
    background-color: #0d6efd;
    color: white;
}

.btn-primary:hover {
    background-color: #0b5ed7;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5c636a;
}

/* 独立试卷预览 */
.paper-preview-page {
    min-height: 100vh;
    padding: 24px;
    background-color: #eef1f4;
}

.preview-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    max-width: 210mm;
    margin: 0 auto 20px;
}

.preview-toolbar h1,
.preview-toolbar p {
    margin: 0;
}

.preview-toolbar p {
    margin-top: 6px;
    color: #6c757d;
}

.paper-sheet {
    box-sizing: border-box;
    width: 100%;
    max-width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 18mm;
    background-color: white;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
}

.answer-space {
    /* 模板或 JS 会按题目 answer_space 直接写入毫米高度。 */
    min-height: 0;
    margin-top: 8px;
    border-bottom: 1px dashed #d7dce1;
}

.answer-space-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 10px;
    color: #495057;
    font-size: 14px;
}

.answer-space-controls .btn-secondary {
    padding: 6px 12px;
    font-size: 14px;
}

.answer-space-controls button:disabled,
.paper-actions button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.preview-empty {
    text-align: center;
}

/* 打印样式集中在此处，预览页和历史试卷使用同一规则。 */
@page {
    size: A4;
    margin: 18mm;
}

@media print {
    body {
        margin: 0;
        padding: 0;
        background: white;
    }

    .site-header,
    .no-print {
        display: none !important;
    }

    .page-shell,
    .paper-preview-page {
        margin: 0;
        padding: 0;
        background: white;
    }

    .paper-view-container,
    .paper-sheet {
        width: 100%;
        max-width: 100%;
        min-height: 0;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .paper-question {
        margin-bottom: 24px;
        border: none;
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* 答题次数标签：显示在题目知识点标签下方 */
.attempt-badge {
    display: inline-block;
    margin-bottom: 8px;
    padding: 2px 8px;
    border: 1px solid currentColor;
    border-radius: 4px;
    font-size: 13px;
    color: #212529; /* 第2次：默认黑色 */
}

.attempt-badge--warn {
    color: var(--warning); /* 第3次：黄色 */
}

.attempt-badge--danger {
    color: var(--danger); /* 第4次起：红色 */
}

/* 打印时也显示答题次数 */
@media print {
    .attempt-badge--warn {
        color: var(--warning);
    }

    .attempt-badge--danger {
        color: var(--danger);
    }
}

/* A4 分页共用尺寸，操作控件不占用打印空间。 */
[data-paper-pages] { overflow-x: auto; }
[data-paper-pages] .a4-page {
    position: relative;
    width: 210mm;
    max-width: none;
    height: 297mm;
    min-height: 0;
    padding: 18mm;
    margin: 0 auto 24px;
}
.a4-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 174mm;
    height: 261mm;
}
.a4-content > * { flex-shrink: 0; }
.a4-content .paper-header { margin-bottom: 0; }
.a4-content .paper-question {
    /* 固定缩放前宽度，超长题缩小时保持原来的文字换行。 */
    width: 174mm;
    position: relative;
    margin: 0;
    border: 1px solid #dee2e6;
    break-inside: avoid;
}
/* A4 分页共用尺寸，操作控件不占用打印空间。 */
.a4-content .answer-space-controls {
    position: absolute;
    right: 16px;
    bottom: 4px;
    margin: 0;
    background: white;
}
.a4-page-number {
    position: absolute;
    bottom: 7mm;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 12px;
    color: #6c757d;
}
/* 已分页试卷使用完整纸张；18mm 留白由纸张内边距提供。
   页码始终位于纸张内部，避免负定位越过打印区域而产生额外页。 */
@page paper-a4 {
    size: A4;
    margin: 0;
}
@media print {
    /* 外层容器也使用同一纸张，避免最后一页之后切回默认纸张另起空页。 */
    body:has([data-paper-pages]) { page: paper-a4; }
    .paper-preview-page { min-height: 0; }
    .page-shell { max-width: none; width: auto; }
    [data-paper-pages] { overflow: visible; }
    [data-paper-pages] .a4-page {
        width: 210mm;
        height: 297mm;
        padding: 18mm;
        break-inside: avoid;
        margin: 0;
        box-shadow: none;
        break-after: auto;
    }
    /* 仅在第二页及后续页之前分页，不在最后一页后发出分页指令。 */
    [data-paper-pages] .a4-page + .a4-page { break-before: page; }
    .a4-page-number { bottom: 7mm; }
}
