/* 册谱页面基础样式 */
:root {
    --header-height: 60px;
    --drawer-width: 320px;
    --bg-preview: #525659;
    --page-shadow: 0 0 15px rgba(0,0,0,0.4);
    --primary-color: #8b0000;
}

/* 册谱管理弹窗样式 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 3000; /* 确保在抽屉之上 */
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    overflow: hidden;
}

.modal-header {
    padding: 15px 25px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal {
    font-size: 28px;
    cursor: pointer;
    color: #999;
}

.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 15px;
}

.booklet-modal-content {
    width: 90% !important;
    max-width: 900px !important;
    height: 90vh;
    display: flex;
    flex-direction: column;
    border-radius: 20px;
}

.modal-header {
    background: linear-gradient(135deg, #4a90d9 0%, #357abd 100%);
    padding: 16px 25px;
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.close-modal {
    font-size: 24px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    transition: color 0.2s;
}

.close-modal:hover {
    color: #fff;
}

.booklet-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 0 !important;
    background: #f8fafc;
}

.booklet-sidebar {
    display: none; /* 彻底移除编辑器内部的侧边栏 */
}

.booklet-editor-area {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: transparent;
}

.section-editor {
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.editor-header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

#sectionTitle {
    font-size: 18px;
    font-weight: 600;
    padding: 10px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    width: 100%;
    max-width: 400px;
    outline: none;
    transition: border-color 0.2s;
}

#sectionTitle:focus {
    border-color: #4a90d9;
}

.editor-controls {
    display: flex;
    gap: 20px;
    align-items: center;
}

.editor-controls label {
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-insert-page-break {
    border: 1px dashed #94a3b8;
    background: #f8fafc;
    color: #334155;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}

/* 分页管理视图 (九宫格) */
.page-grid-view {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0 20px 0;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 20px;
}

.grid-title {
    font-size: 18px;
    font-weight: 700;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-back-to-sections {
    background: #f1f5f9;
    border: none;
    color: #64748b;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}

.grid-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

.btn-add-page {
    background: #4a90d9;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.grid-header-mobile {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
    padding-bottom: 0;
    border-bottom: none;
}

.grid-controls-row {
    display: flex;
    justify-content: center;
    gap: 30px;
    align-items: center;
    background: transparent;
    padding: 10px 15px 15px 15px;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 0;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    line-height: 1; /* 修正文字垂直对齐 */
}

.checkbox-label input {
    width: 18px;
    height: 18px;
    margin: 0; /* 修正复选框偏移 */
    accent-color: #4a90d9;
}

.btn-add-page-full {
    width: 100%;
    background: #4a90d9;
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(74, 144, 217, 0.2);
    transition: background 0.2s;
}

.btn-add-page-full:hover {
    background: #357abd;
}

.rollback-tip {
    background: #ecfdf5;
    color: #065f46;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.rollback-tip button {
    background: #059669;
    color: white;
    border: none;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.grid-item {
    background: white;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    container-type: inline-size;
}

.grid-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
}

.thumbnail-wrapper {
    width: 100%;
    aspect-ratio: 210/297;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    cursor: pointer;
}

.dom-thumbnail-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}

/* 根据容器宽度和 A4 像素宽度(794)计算缩放比例。假设 grid-item 宽度约 180px，则 180/794 ≈ 0.226 */
.dom-thumbnail-container {
    width: 794px;
    height: 1123px;
    transform: scale(0.226);
    transform-origin: top left;
    background: white;
    padding: 15mm 15mm 15mm 25mm;
    box-sizing: border-box;
    font-family: "SimSun", "STSong", serif;
    color: #111;
    pointer-events: none; /* 防止缩略图内的元素拦截点击事件 */
}

/* 适配更小屏幕时的缩放比例修正 */
@container (max-width: 140px) {
    .dom-thumbnail-container {
        transform: scale(0.16);
    }
}
@container (min-width: 141px) and (max-width: 165px) {
    .dom-thumbnail-container {
        transform: scale(0.19);
    }
}
@container (min-width: 166px) and (max-width: 200px) {
    .dom-thumbnail-container {
        transform: scale(0.22);
    }
}
@container (min-width: 201px) {
    .dom-thumbnail-container {
        transform: scale(0.25);
    }
}

.page-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #94a3b8;
    font-size: 12px;
}

.thumb-overlay {
    display: none;
}

.page-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding: 0 4px;
}

.page-actions {
    display: flex;
    gap: 8px;
}

.btn-icon-edit, .btn-icon-delete {
    background: #f1f5f9;
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    color: #475569;
}

.btn-icon-edit:hover {
    background: #e2e8f0;
    color: #2563eb;
}

.btn-icon-delete:hover {
    background: #fee2e2;
    color: #ef4444;
}

.page-label {
    font-size: 14px;
    font-weight: 600;
    color: #475569;
}

.sortable-ghost {
    opacity: 0.4;
    background: #cbd5e1;
    border: 2px dashed #64748b;
}

.editor-controls input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #4a90d9;
}

#editorWrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ql-container.ql-snow {
    border-radius: 0 0 10px 10px;
    border-color: #e2e8f0 !important;
    font-size: 16px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    background: white;
}

.ql-toolbar.ql-snow {
    border-radius: 10px 10px 0 0;
    border-color: #e2e8f0 !important;
    background: #f8fafc;
}

.core-section-tip {
    background: #fff9eb;
    border: 1px solid #ffeeba;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    color: #856404;
    font-size: 15px;
    margin: auto;
    max-width: 500px;
    line-height: 1.6;
}

.modal-footer-save {
    padding: 15px 20px;
    background: #fff;
    border-top: 1px solid #f1f5f9;
    display: flex;
    justify-content: center;
}

.btn-save-all {
    width: 100%;
    max-width: 400px;
    padding: 12px;
    background: linear-gradient(135deg, #4a90d9 0%, #357abd 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.25);
    text-align: center;
}

.btn-save-all:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(74, 144, 217, 0.35);
}

/* 移动端适配 */
@media screen and (max-width: 768px) {
    .grid-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .grid-item {
        padding: 8px;
    }
    .page-actions {
        gap: 4px;
    }
    .btn-icon-edit, .btn-icon-delete {
        width: 26px;
        height: 26px;
        font-size: 12px;
    }
    .page-label {
        font-size: 13px;
    }

    .booklet-modal-content {
        width: 100% !important;
        height: 100% !important;
        border-radius: 0;
    }

    .booklet-layout {
        padding: 5px !important;
    }

    .booklet-editor-area {
        padding: 0 2px !important; /* 让 sectionEditor 尽量撑满屏幕 */
    }

    .section-editor {
        width: calc(100% - 5px);
        margin: 0 auto;
        box-sizing: border-box;
    }

    .editor-header {
        flex-direction: column;
        align-items: stretch;
    }

    #sectionTitle {
        max-width: none;
    }

    .editor-controls {
        justify-content: space-around;
    }

    /* 优化移动端按钮 */
    .btn-save-all {
        max-width: none; /* 撑满底部 */
    }
}

.btn-restore:hover {
    background: #8b0000;
    color: #fff;
}

.special-config-area {
    margin-top: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 4px;
}

/* 富文本内容在册谱中的基础样式 */
.booklet-content-page {
    padding: 0; /* 移除冗余 padding，统一使用 .a4-page 的 20mm padding */
    box-sizing: border-box;
    height: 100%;
    display: flex !important;
    flex-direction: column !important;
}

.booklet-content-page h1 { 
    font-size: 24pt !important; 
    text-align: center !important; 
    margin: 0 0 5mm 0 !important; 
    padding: 0 !important;
}

.booklet-content-page h2 { 
    font-size: 18pt !important; 
    margin-top: 5mm !important; 
}

/* 核心：强制所有段落紧凑排列 */
.booklet-content-page p, 
.booklet-content-page .rich-content p, 
.booklet-content-page .poem-content p { 
    font-size: 12pt !important; 
    line-height: 1.1 !important; 
    margin: 0 !important; 
    padding: 0 !important;
    text-indent: 2em; /* 默认开启首行缩进 */
    text-align: left; 
}

/* 居中段落处理 - 专门识别 Quill 的居中类名 */
.booklet-content-page .ql-align-center,
.booklet-content-page p.ql-align-center,
.booklet-content-page .poem-content .ql-align-center {
    text-align: center !important;
    text-indent: 0 !important;
}

/* 针对 H2 等标题的居中处理 */
.booklet-content-page h2.ql-align-center {
    text-align: center !important;
}

/* 右对齐处理 */
.booklet-content-page .ql-align-right,
.booklet-content-page p.ql-align-right {
    text-align: right !important;
    text-indent: 0 !important;
}

/* 字辈诗内容区域不应强制居中，应交给 P 标签控制 */
.poem-content {
    width: 100%;
    text-align: inherit;
}

.booklet-content-page img { 
    max-width: 100%; 
    height: auto; 
    display: block; 
    margin: 5mm auto; 
}

/* 编辑器内可见分页符，便于手动插入分页 */
.ql-editor hr.booklet-page-break {
    border: 0;
    border-top: 2px dashed #94a3b8;
    margin: 14px 0;
}

.ql-editor hr.booklet-page-break::after {
    content: '分页符';
    display: inline-block;
    color: #64748b;
    font-size: 12px;
    margin-top: -10px;
    background: #fff;
    padding-right: 8px;
}

/* 输出到册谱页时，分页符作为分页控制标记，不参与显示 */
.rich-content hr.booklet-page-break {
    display: none !important;
}

.rich-content {
    width: 100%;
    text-align: left;
}

.empty-section-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 150mm;
    color: #999;
    font-size: 16pt;
    font-style: italic;
    border: 1px dashed #eee;
}

/* 目录页样式 */
.toc-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.toc-page h1 { 
    font-size: 24pt; 
    text-align: center; 
    margin: 0 0 12mm 0; 
}

.toc-body {
    flex: 1;
    width: 100%; 
    max-width: none; 
    margin: 0;
    padding: 0 5mm; /* 缩减左右边距，让内容更分散 */
    display: flex;
    flex-direction: column;
    overflow: visible; 
}

.toc-item {
    display: flex;
    width: 100%; 
    justify-content: space-between; 
    align-items: baseline;
    margin-bottom: 2mm; /* 缩减条目间距 3.5mm -> 2mm */
    cursor: pointer;
    transition: color 0.2s;
}

.toc-item:hover {
    color: #8b0000;
}

.toc-item.level-0 {
    font-weight: bold;
    margin-top: 4mm; /* 缩减间距 5mm -> 4mm */
}

.toc-item.level-1 {
    padding-left: 15mm; /* 保持缩进以体现层级，18mm -> 15mm */
}

.toc-gen-label {
    font-size: 10pt; /* 缩小字体 11pt -> 10pt */
    font-weight: bold;
    color: #666;
    margin: 3mm 0 1.5mm 6mm; /* 世代标签间距缩小 */
    border-left: 3px solid #8b0000;
    padding-left: 2mm; /* 缩减内边距 */
    text-align: left;
    width: auto; 
    clear: both;
}

.toc-title {
    font-size: 11pt; /* 缩小姓名标题 13pt -> 11pt */
    white-space: nowrap;
    flex-shrink: 0; /* 防止名字被压缩 */
}

.toc-item.level-0 .toc-title {
    font-size: 13pt; /* 缩小板块标题 15pt -> 13pt */
}

.toc-dots {
    flex: 1; /* 自动填充中间剩余空间 */
    border-bottom: 2px dotted #ccc; 
    margin: 0 4mm;
    position: relative;
    top: -5px; 
}

.toc-page-num {
    font-size: 13pt;
    font-family: "Times New Roman", serif;
    min-width: 12mm;
    text-align: right;
    color: #333;
    flex-shrink: 0; /* 防止页码被压缩 */
}

/* 
移除 SPA 模式下的全局污染样式
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    height: 100%;
    font-family: "Microsoft YaHei", -apple-system, sans-serif;
    overflow: hidden;
    background: var(--bg-preview);
}
*/

.cepu-app {
    display: flex;
    flex-direction: column;
    height: 100%; /* 改为 100% 以适配父容器 */
    max-height: 100vh;
    background: var(--bg-preview); /* 将背景移到这里 */
    overflow: hidden;
}

button {
    -webkit-tap-highlight-color: transparent;
    outline: none !important;
}

button:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* 顶部工具栏 */
.cepu-header {
    height: var(--header-height);
    background: #2c3e50;
    border-bottom: none;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.cepu-header h1 {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-back, .btn-toggle-settings, .btn-print-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    gap: 5px;
    transition: all 0.2s;
}

.btn-back:hover, .btn-toggle-settings:hover, .btn-print-icon:hover {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.3);
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* 设置抽屉 */
.settings-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--drawer-width);
    height: 100%;
    /* 【移动端优化】：确保层级高于底部导航栏 (通常 1000~2000) */
    z-index: 6000;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden !important; /* 强制初始隐藏 */
}

.settings-drawer.active {
    transform: translateX(0);
    visibility: visible !important;
}

.drawer-content {
    width: 100%;
    height: 100%;
    background: #f5f7fa; /* 统一使用树谱设置页的背景色 */
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    padding: 0; /* 移除外层 padding，改为内部各区域 padding */
    overflow-y: auto;
}

.drawer-header {
    background: linear-gradient(135deg, #4a90d9 0%, #357abd 100%);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.25);
    z-index: 10;
}

.drawer-header h2 {
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.3px;
}

.btn-close-drawer {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-close-drawer:hover {
    background: rgba(255, 255, 255, 0.35);
}

.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.3s;
}

.settings-drawer.active .drawer-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.drawer-body {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.settings-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
    background: #f8fafc;
    margin: 0 0 15px 0;
    padding: 16px 20px;
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid #f1f5f9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-group {
    background: #fff;
    border-radius: 12px;
    margin-bottom: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    padding: 0 0 10px 0;
}

.settings-group h3 {
    font-size: 14px;
    font-weight: 600;
    color: #64748b;
    background: #f8fafc;
    margin: 0 0 15px 0;
    padding: 16px 20px;
    border-bottom: 1px solid #f1f5f9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-item-row {
    padding: 0 20px;
    margin-bottom: 15px;
}

.settings-item-row:last-child {
    margin-bottom: 0;
}

label {
    font-size: 15px;
    font-weight: 500;
    color: #1e293b;
    display: block;
    margin-bottom: 8px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    margin-bottom: 0;
    font-size: 15px;
    color: #334155;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid #f8fafc;
}

.checkbox-item:last-child {
    border-bottom: none;
}

.checkbox-item:hover {
    background: #f8fafc;
}

.checkbox-item input {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    accent-color: #4a90d9;
}

select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    font-size: 15px;
    color: #334155;
    background: #fff;
    outline: none;
    transition: all 0.3s;
    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='%2364748b' 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 12px center;
    background-size: 16px;
}

select:focus {
    border-color: #4a90d9;
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.1);
}

select:disabled {
    background-color: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
}

.settings-group input[type="range"] {
    width: 100%;
    margin-top: 8px;
    accent-color: #4a90d9;
}

.btn-print-full, .btn-export-pdf {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin: 0;
    padding: 14px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    text-align: center;
}

.btn-print-full {
    background: linear-gradient(135deg, #4a90d9 0%, #357abd 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(74, 144, 217, 0.2);
}

.btn-export-pdf {
    background: #2c3e50;
    color: white;
    box-shadow: 0 4px 12px rgba(44, 62, 80, 0.15);
}

.btn-print-full:hover, .btn-export-pdf:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}

.btn-print-full:active, .btn-export-pdf:active {
    transform: translateY(0);
}

/* 右侧预览区 */
.cepu-preview {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    /* 取消 padding，全部通过 margin auto 居中计算 */
    padding: 0;
    display: flex;
    flex-direction: column;
    /* 移除 align-items: center，完全依赖内部元素的 margin: auto 实现不裁切居中 */
    scroll-behavior: smooth;
    position: relative;
    background: #2c2c2c; /* 深灰色背景，增加边界感 */
    width: 100%; /* 确保宽度 100% */
    /* 去除多余的下边距/背景 */
    margin: 0;
    max-width: 100vw;
    height: 100%;
}

/* 新增的包装层：利用 flex 的 margin: auto 神奇特性 */
.page-scale-wrapper {
    margin: auto;
    flex-shrink: 0;
    position: relative;
    box-sizing: border-box;
}

/* 针对 SPA 模式下的 Loading 状态样式优化 */
.loading-state {
    padding: 100px 20px;
    text-align: center;
    color: #e2e8f0;
    font-size: 16px;
    width: 100%;
}

/* 分页控制栏样式 - 全局固定悬浮 */
.pagination-controls {
    display: none; /* 初始隐藏，由 JS 渲染完成后显示 */
    align-items: center;
    justify-content: center;
    gap: 8px;
    /* 去除白底大包围，改为透明，只留按钮本身 */
    background: transparent;
    padding: 0;
    position: fixed; /* 全局统一使用 fixed */
    bottom: 80px; /* 提高位置，避免被底部导航栏 (56px) 遮挡 */
    left: 50%;
    transform: translateX(-50%);
    z-index: 2500;
    width: fit-content;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none; /* 让外部容器不遮挡点击 */
    flex-wrap: nowrap;
}

.btn-page {
    pointer-events: auto; /* 恢复按钮本身的点击 */
    padding: 6px 16px; /* 适当缩小内边距 */
    border: none;
    background: rgba(74, 144, 217, 0.9); /* 半透明主题蓝，更轻盈 */
    color: white;
    border-radius: 16px;
    cursor: pointer;
    font-size: 13px; /* 适当缩小字号 */
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); /* 给按钮独立加阴影 */
    transition: all 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px); /* 按钮本身毛玻璃 */
    white-space: nowrap;
    line-height: 1;
}

.btn-page:hover:not(:disabled) {
    background: rgba(53, 122, 189, 0.95);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.btn-page:disabled {
    background: rgba(226, 232, 240, 0.9);
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.page-info {
    pointer-events: auto;
    font-weight: 600;
    color: #334155;
    background: rgba(255, 255, 255, 0.85); /* 给文字单独加一个小半透明底 */
    padding: 4px 12px;
    border-radius: 12px;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    min-width: 70px;
    text-align: center;
    font-size: 13px;
    white-space: nowrap;
    line-height: 1;
}

/* 移动端适配与缩放优化 */
@media screen and (max-width: 768px) {
    .cepu-preview {
        /* 预览优先：去掉上下保留区，最大化可视内容 */
        padding: 0 !important; 
    }

    .page-container {
        /* 取消 CSS 中硬编码的 transform-origin，统一交由 JS 动态计算 */
        margin-top: 0px;
    }

    .pagination-controls {
        width: fit-content !important;
        max-width: none !important;
        padding: 0 !important;
        /* 提高 mobile 端的 bottom 以避开底部导航栏 (通常 60px) */
        bottom: calc(70px + env(safe-area-inset-bottom)) !important;
        box-shadow: none !important;
        background: transparent !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    .btn-page {
        padding: 5px 14px !important;
        font-size: 12px !important;
        border-radius: 14px !important;
    }

    .page-info {
        font-size: 12px !important;
        padding: 4px 10px !important;
        min-width: auto !important;
    }

    /* 优化移动端册谱设置抽屉样式：全屏宽 */
    .settings-drawer {
        width: 100% !important;
    }
}

.page-container {
    display: flex;
    flex-direction: column;
    width: 100%; /* 修改为100%继承父级宽度 */
    height: 100%; /* 修改为100%继承父级高度 */
    margin: 0; /* 移除 auto，避免影响子元素的绝对对齐 */
    padding: 0;
    position: relative;
}

/* 单页显示模式：预览时隐藏非当前页 */
.a4-page {
    display: none; /* 默认隐藏 */
    width: 100%; /* 继承 page-container 也就是 wrapper 的物理尺寸 */
    height: 100%; /* 继承高度 */
    min-height: unset; /* 移除写死的 297mm，统一由 JS 计算的 wrapper 约束 */
    background: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); /* 强化投影 */
    padding: 15mm 15mm 15mm 25mm; /* 默认左侧装订位，右侧留15mm使内容区在边框中居中 */
    position: absolute; /* 绝对定位到容器左上角，确保与 wrapper 严丝合缝 */
    top: 0;
    left: 0;
    box-sizing: border-box;
    flex-direction: column;
    border: 1px solid #000;
    overflow: hidden; /* 阻止内容撑出 A4 边界并触发预览区纵向滚动 */
}

/* 右侧装订逻辑 (不使用 transform: scaleX，直接切换内边距) */
.a4-page.binding-right {
    padding-left: 15mm; /* 左侧留15mm使内容区在边框中居中 */
    padding-right: 25mm;
}

/* 古典黑色双边框 (基础样式) */
.a4-page::before {
    content: "";
    position: absolute;
    top: 5mm;
    bottom: 5mm;
    left: 15mm; 
    right: 5mm;
    border: 2px solid #000;
    pointer-events: none;
    z-index: 10;
}

.a4-page::after {
    content: "";
    position: absolute;
    top: 6.5mm;
    bottom: 6.5mm;
    left: 16.5mm;
    right: 6.5mm;
    border: 0.5px solid #000;
    pointer-events: none;
    z-index: 10;
}

/* 右侧装订时的边框位置修正 (向左偏移以在右侧留出 25mm) */
.a4-page.binding-right::before {
    left: 5mm;
    right: 15mm;
}

.a4-page.binding-right::after {
    left: 6.5mm;
    right: 16.5mm;
}

/* 右侧装订时的世系图 (生平卡片) 改为从右向左排列 */
.a4-page.binding-right .member-details-grid {
    direction: rtl;
}

.a4-page.binding-right .member-detail-card {
    direction: ltr; /* 卡片内部文字恢复从左往右阅读 */
    text-align: left;
}

.a4-page.active {
    display: flex; /* 仅激活页显示 */
}

/* 册谱设置手风琴菜单样式 */
.settings-category {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
    background: #fff;
}

.settings-category:hover {
    background: #f8fafc;
}

.settings-category-icon {
    font-size: 24px;
    margin-right: 16px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    border-radius: 12px;
}

.settings-category-info {
    flex: 1;
}

.settings-category-title {
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
}

.settings-category-desc {
    font-size: 13px;
    color: #64748b;
}

.settings-arrow {
    font-size: 22px;
    color: #94a3b8;
    font-weight: bold;
    transition: transform 0.3s;
}

.settings-category.active .settings-arrow {
    transform: rotate(90deg);
}

.settings-submenu {
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    padding: 15px 0;
    display: none;
}

.settings-submenu .settings-section-title {
    background: transparent;
    border: none;
    padding: 0 20px;
    margin-bottom: 10px;
    color: #3b82f6; /* 统一为蓝色小标题 */
}

.settings-submenu .settings-item-row {
    padding: 0 20px;
}

.settings-submenu .checkbox-item {
    background: transparent;
    padding: 10px 20px;
    border-bottom: none;
}

.settings-submenu .checkbox-item:hover {
    background: #f1f5f9;
}

/* 侧边栏板块列表样式 */
.drawer-section-list {
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.drawer-section-item {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.drawer-section-item:hover {
    border-color: #4a90d9;
    background: #f8fafc;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.drawer-section-item.disabled {
    opacity: 0.6;
    background: #f1f5f9;
}

.drawer-section-item .drag-handle {
    color: #94a3b8;
    cursor: grab;
    font-size: 18px;
}

.drawer-section-item .section-name {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
}

.drawer-section-item .section-type {
    font-size: 11px;
    color: #64748b;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
}

.drawer-section-item .btn-edit-section {
    padding: 4px 10px;
    font-size: 12px;
    background: #4a90d9;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.drawer-section-item .btn-edit-section:hover {
    background: #357abd;
}

/* 抽屉内输入框样式 */
.settings-submenu input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    color: #1e293b;
    outline: none;
    transition: all 0.2s;
}

.settings-submenu input[type="text"]:focus {
    border-color: #4a90d9;
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.1);
}

.drawer-section-actions {
    padding: 15px 20px;
    display: flex;
    gap: 10px;
}

.btn-drawer-add, .btn-drawer-init {
    flex: 1;
    padding: 10px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-drawer-add {
    background: #fff;
    border: 1.5px solid #4a90d9;
    color: #4a90d9;
}

.btn-drawer-add:hover {
    background: #4a90d9;
    color: #fff;
}

.btn-drawer-init {
    background: #f1f5f9;
    border: 1.5px solid #e2e8f0;
    color: #64748b;
}

.btn-drawer-init:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* 索引页样式 */
.index-page h1 {
    text-align: center;
    font-size: 24pt;
    margin: 0 0 10mm 0; /* 固定标题区高度，避免浏览器默认 h1 margin 造成分页抖动 */
    line-height: 1.2;
    border-bottom: 2px solid #333;
    padding-bottom: 5mm;
}

.index-grid {
    display: grid;
    gap: 0 15mm;
    align-content: start; /* 顶部对齐 */
    grid-auto-rows: 7mm; /* 统一每行高度，避免不同页因文字换行导致高度漂移 */
}

.index-grid.with-header {
    height: calc(100% - 45mm);
}

.index-grid.no-header {
    height: 100%;
}

.index-grid.columns-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.index-grid.columns-2 {
    grid-template-columns: 1fr 1fr;
}

.index-gen-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13pt;
    font-weight: 700;
    color: #0f172a;
    background: #e8edf5;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 0 2mm;
    margin: 0;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.index-item {
    display: flex;
    align-items: center;
    font-size: 11pt;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
    padding: 2px 4px;
    border-radius: 4px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
}

.index-item:hover {
    background: #f0f4f8;
}

.index-name {
    font-weight: bold;
    min-width: 3em;
    max-width: 8em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.index-dots {
    flex: 1;
    border-bottom: 1px dotted #ccc;
    margin: 0 5px;
    height: 1px;
    min-width: 10px;
}

.index-page-num {
    font-family: serif;
    color: #000;
    min-width: 1.5em;
    text-align: right;
}

/* 打印适配 */
@media print {
    /* 隐藏所有非册谱相关的 UI 元素 */
    .top-toolbar, 
    .bottom-nav, 
    .btn-reset-view, 
    .canvas-container,
    #chatPage,
    #profilePage,
    #treePage,
    .cepu-header, 
    .settings-drawer, 
    .pagination-controls,
    .modal,
    .overlay,
    .drawer-overlay {
        display: none !important;
    }
    
    /* 确保主容器和册谱容器在打印时正确布局 */
    #app, .main-container, #cepuPage, .cepu-app {
        display: block !important;
        position: static !important;
        height: auto !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        overflow: visible !important;
        visibility: visible !important;
    }

    body, html {
        background: white !important;
        overflow: visible !important;
        height: auto !important;
        width: 100% !important;
    }

    .cepu-preview {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        background: white !important;
        width: 100% !important;
    }
    
    .page-container {
        display: block !important;
        gap: 0 !important;
        padding-bottom: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        zoom: 1 !important; /* 打印时取消缩放，使用原始 A4 尺寸 */
        transform: none !important;
    }

    .a4-page {
        display: flex !important; /* 打印时必须全部显示 */
        box-shadow: none !important;
        margin: 0 !important;
        width: 210mm !important;
        height: 297mm !important;
        page-break-after: always !important;
        border: none !important;
        position: relative !important;
        overflow: hidden !important;
    }
    
    @page {
        size: A4;
        margin: 0;
    }
}

/* PDF 导出加载层样式 */
html.pdf-export-loading-open,
body.pdf-export-loading-open {
    overflow: hidden !important;
    touch-action: none;
}

.pdf-export-loading {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 24px;
    pointer-events: auto;
    touch-action: none;
    overscroll-behavior: contain;
}

.pdf-loading-content {
    text-align: center;
    color: white;
}

.pdf-loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid #4a90d9;
    border-radius: 50%;
    animation: pdf-spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes pdf-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.pdf-loading-text {
    font-size: 18px;
    line-height: 1.6;
}

.pdf-loading-text small {
    opacity: 0.7;
    font-size: 14px;
}

.loading-state {
    color: white;
    font-size: 1.2rem;
    margin-top: 100px;
}

/* 页面通用布局 */
.page-content-wrapper {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    /* 通过内边距实现 90% 的内容区域，留出四周安全打印空间 */
    padding: 10mm 5mm; 
    box-sizing: border-box;
    overflow: hidden;
}

.page-footer {
    position: absolute;
    bottom: 10mm;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 10pt;
    color: #666;
    border-top: 1px solid #eee;
    padding-top: 5mm;
    margin: 0 20mm;
}

/* 封面样式 */
.page-cover {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none !important;
    margin: 0 !important;
    padding: 10mm;
    width: 210mm;
    height: 297mm;
    box-sizing: border-box;
}

.cover-main {
    text-align: center;
    border: 2px solid #333;
    padding: 40mm 20mm;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
}

.cover-title {
    font-size: 60pt; /* 加大标题 */
    font-family: "SimSun", "STSong", serif;
    font-weight: bold;
    writing-mode: vertical-rl;
    margin: 0 auto;
}

.cover-subtitle {
    font-size: 24pt;
    margin-top: 20mm;
    letter-spacing: 10pt;
}

.cover-footer {
    font-size: 14pt;
}

.cover-footer p {
    margin: 4mm 0; /* 增加行距 */
}

.cover-system-tag, .cover-date {
    color: #666;
    font-size: 13pt;
    font-weight: normal;
}

.cover-author, .cover-location {
    font-size: 12pt; /* 调小字体 */
    color: #444;
}

/* 吊线图样式 */
.lineage-container {
    height: 100%;
}

.lineage-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid #333;
    padding-bottom: 2mm;
    margin-bottom: 5mm;
}

.lineage-svg {
    width: 175mm; /* 匹配 A4 可打印宽度 */
    height: 265mm;
    display: block;
    margin: 0;
    overflow: visible; /* 允许世代标签向左溢出到装订区 */
}

/* 世系生平样式 */
.detail-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 世系图网格布局 */
.member-details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 双列并排 */
    gap: 8mm 12mm; /* 行间距 8mm，列间距 12mm */
    padding: 10mm 5mm 5mm 5mm; /* 增加顶部边距从 5mm 到 10mm，解决顶部太靠上的问题 */
    flex: 1;
}

.member-detail-card {
    border-bottom: 1px solid #eee;
    padding-bottom: 5mm;
    page-break-inside: avoid;
}

.member-info-header {
    display: flex;
    align-items: baseline; /* 使用基线对齐，让名字和世代看起来更整齐 */
    gap: 8px;
    margin-bottom: 10px;
    border-left: 3px solid #1a1a1a;
    padding-left: 8px;
    flex-wrap: nowrap; /* 强制不换行 */
    overflow: hidden;
}

.member-gen {
    font-size: 15px; /* 从 13px 增大到 15px */
    color: #8b0000; /* 设置为深红色，更有古典族谱质感 */
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.member-name {
    font-size: 18px;
    font-weight: bold;
    color: #000;
    white-space: nowrap;
    flex-shrink: 0;
}

.member-rank {
    font-size: 14px;
    color: #000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

.member-global-rank {
    font-size: 15px; /* 从 13px 增大到 15px */
    color: #8b0000; /* 设置为深红色 */
    font-weight: 600;
    margin-left: auto;
    white-space: nowrap;
    flex-shrink: 0;
}

.member-life-meta {
    background: #f9f9f9;
    padding: 5px 8px;
    border-radius: 4px;
    margin-bottom: 8px;
    font-size: 14px; /* 从 12px 增加到 14px */
}

.member-life-meta p {
    margin: 2px 0;
    color: #444;
}

.member-relations {
    font-size: 15px; /* 从 13px 增加到 15px */
    margin-bottom: 8px;
}

.member-relations p {
    margin: 4px 0;
    color: #333;
    line-height: 1.4;
}

.member-biography {
    font-size: 15px; /* 从 13px 增加到 15px */
    color: #555;
    line-height: 1.5;
    border-top: 1px dashed #eee;
    padding-top: 5px;
    /* 增加生平显示行数，提供更全面的内容展示 */
    display: -webkit-box;
    -webkit-line-clamp: 6; /* 从 3 行增加到 6 行 */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.node-brief, .node-info {
    font-size: 11px;
    color: #000;
    line-height: 1.3;
}
