/* 导入老谱自动识别：左侧老谱预览面板 + 文献目录折叠 */

/* ---------- 文献目录折叠 ---------- */
/* 侧栏本身用 flex:0 0 clamp(...) 定宽，收起时要把 flex-basis 一起压掉才不会留白 */
body.doc-catalog-collapsed .doc-sidebar-left {
    flex: 0 0 0 !important;
    width: 0 !important;
    border-right-width: 0;
    overflow: hidden;
}

.doc-catalog-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 600;
    color: #4b5563;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #f9fafb;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.doc-catalog-toggle:hover {
    color: #8b0000;
    border-color: #8b0000;
    background: #fff;
}

/* 收起后留在最左侧的细边，点它展开 */
.doc-catalog-rail {
    display: none;
    flex: 0 0 14px;
    width: 14px;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #e5e7eb;
    background: #f3f4f6;
    cursor: pointer;
    transition: background .15s;
}

body.doc-catalog-collapsed .doc-catalog-rail {
    display: flex;
}

.doc-catalog-rail:hover {
    background: #e5e7eb;
}

.doc-catalog-rail-label {
    writing-mode: vertical-rl;
    font-size: 11px;
    letter-spacing: 2px;
    color: #6b7280;
    user-select: none;
}

/* ---------- 编辑/预览条上的导入按钮 ---------- */
.old-book-import-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #8b0000;
    border: 1px solid #e6c9c9;
    border-radius: 6px;
    background: #fff7f7;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.old-book-import-btn:hover {
    border-color: #8b0000;
    background: #fdeeee;
}

/* 编辑/预览条改成三段：左端目录开关、中间「导入老谱 + 编辑/预览」、右侧留白配平 */
#editor-view-mode-bar .editor-view-mode-lead,
#editor-view-mode-bar .editor-view-mode-trail {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 0;
    min-width: 0;
}

#editor-view-mode-bar .editor-view-mode-trail {
    justify-content: flex-end;
}

/* 导入按钮和「编辑」挨着放，中间只留一点缝 */
#editor-view-mode-bar .editor-view-mode-bar-anchor {
    gap: 10px;
}

/* ---------- 老谱预览面板 ---------- */
#old-book-panel {
    position: relative;
    flex: 0 0 clamp(28rem, 42vw, 46rem);
    width: clamp(28rem, 42vw, 46rem);
    min-width: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    border-right: 1px solid #e5e7eb;
    background: #fff;
    overflow: hidden;
}

#old-book-panel.hidden {
    display: none;
}

/* 窄屏（1366×768 这类笔记本）挤不下时临时收起，只留一条竖边 */
body.old-book-collapsed #old-book-panel {
    flex: 0 0 0 !important;
    width: 0 !important;
    border-right-width: 0;
}

/* 右侧拉手：拖到右边把预览区拉宽，给后面的框选留出操作空间 */
.old-book-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 10px;
    height: 100%;
    z-index: 6;
    cursor: col-resize;
    touch-action: none;
}

.old-book-resize-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 3px;
    width: 3px;
    height: 36px;
    margin-top: -18px;
    border-radius: 2px;
    background: #d1d5db;
    transition: background .15s, height .15s;
}

.old-book-resize-handle:hover::before,
body.old-book-resizing .old-book-resize-handle::before {
    background: #8b0000;
    height: 56px;
    margin-top: -28px;
}

body.old-book-collapsed .old-book-resize-handle,
#old-book-panel.hidden .old-book-resize-handle {
    display: none;
}

body.old-book-resizing {
    cursor: col-resize;
    user-select: none;
}

.old-book-rail {
    display: none;
    flex: 0 0 22px;
    width: 22px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-right: 1px solid #e5e7eb;
    background: #faf5f5;
    color: #8b0000;
    cursor: pointer;
}

body.old-book-collapsed .old-book-rail {
    display: flex;
}

.old-book-rail:hover {
    background: #f3e7e7;
}

.old-book-rail-label {
    writing-mode: vertical-rl;
    font-size: 11px;
    letter-spacing: 2px;
    user-select: none;
}

.old-book-side {
    flex: 0 0 168px;
    width: 168px;
    min-width: 168px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-left: 1px solid #e5e7eb;
    background: #fff;
}

.old-book-head {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 2.25rem;
    padding: 0 8px;
    border-bottom: 1px solid #e5e7eb;
    background: #faf5f5;
    flex-shrink: 0;
}

.old-book-head-title {
    font-size: 13px;
    font-weight: 700;
    color: #8b0000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1 1 auto;
}

.old-book-head-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.old-book-page-label {
    padding: 6px 8px 0;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.45;
    white-space: pre-line;
    word-break: break-all;
    flex-shrink: 0;
}

.old-book-toolbar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px;
    border-bottom: 1px solid #f3f4f6;
    flex-shrink: 0;
}

.old-book-tool-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.old-book-tool-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 28px;
    height: 28px;
    padding: 0 7px;
    font-size: 12px;
    color: #4b5563;
    border: 1px solid #e5e7eb;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.old-book-tool-btn:hover:not(:disabled) {
    color: #8b0000;
    border-color: #8b0000;
}

.old-book-tool-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.old-book-tool-btn.is-primary {
    color: #fff;
    border-color: #8b0000;
    background: #8b0000;
}

.old-book-tool-btn.is-primary:hover:not(:disabled) {
    color: #fff;
    background: #a30000;
}

.old-book-tool-btn.is-block {
    width: 100%;
    height: 30px;
}

/* 当前处于框选模式的开关 */
.old-book-tool-btn.is-on {
    color: #8b0000;
    border-color: #8b0000;
    background: #fdf2f2;
    font-weight: 600;
}

.old-book-tool-btn.is-grow {
    flex: 1 1 0;
}

.old-book-tool-sep {
    width: 1px;
    height: 18px;
    background: #e5e7eb;
    margin: 0 2px;
}

.old-book-stage {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    background: #f3f4f6;
    cursor: grab;
}

/* 内层要跟着图一起长大（max-content），否则放大后溢出的部分会甩到居中容器左上方，
   滚动条够不着，就成了只能往左上拖。min-*: 100% 保证图比窗口小时仍然居中。 */
.old-book-stage-inner {
    box-sizing: border-box;
    width: max-content;
    height: max-content;
    min-width: 100%;
    min-height: 100%;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.old-book-stage.is-panning,
body.old-book-panning {
    cursor: grabbing;
    user-select: none;
}

/* 框选模式：整块预览区都是十字光标，左键拉框，中键仍可平移 */
#old-book-panel.is-selecting .old-book-stage,
#old-book-panel.is-selecting .old-book-canvas-wrap,
#old-book-panel.is-selecting .old-book-text-layer,
#old-book-panel.is-selecting .old-book-text-layer .ob-char,
body.old-book-marquee {
    cursor: crosshair;
}

body.old-book-marquee {
    user-select: none;
}

.old-book-canvas-wrap {
    position: relative;
    flex-shrink: 0;
    line-height: 0;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .18);
    background: #fff;
    cursor: grab;
}

.old-book-canvas-wrap canvas {
    display: block;
    -webkit-user-drag: none;
}

.old-book-empty {
    margin: auto;
    font-size: 13px;
    color: #9ca3af;
    text-align: center;
    line-height: 1.9;
}

/* ---------- 识别文字覆盖层 ---------- */
/* 每个字一个绝对定位的透明 span，文字本身看不见，但能选中、能复制，
   选区高亮正好压在原图对应的字上。 */
.old-book-text-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    user-select: text;
    -webkit-user-select: text;
    pointer-events: none;
    cursor: grab;
}

.old-book-text-layer .ob-plain {
    pointer-events: auto;
    cursor: text;
}

.old-book-text-layer .ob-char {
    position: absolute;
    display: block;
    color: transparent;
    white-space: pre;
    transform-origin: 0 0;
    line-height: 1;
    pointer-events: auto;
    cursor: text;
}

.old-book-text-layer .ob-char::selection {
    background: rgba(139, 0, 0, .28);
    color: transparent;
}

.old-book-text-layer .ob-marquee {
    position: absolute;
    z-index: 5;
    border: 1px dashed #8b0000;
    background: rgba(139, 0, 0, .08);
    pointer-events: none;
}

/* 置信度低的字：老谱异体字多，标红提示重点核对 */
.old-book-text-layer .ob-char.ob-low {
    outline: 1px solid rgba(220, 38, 38, .75);
    background: rgba(220, 38, 38, .12);
}

/* 双行夹注（小字注）：单独标出来，复制时可选择是否带上 */
.old-book-text-layer .ob-char.ob-note {
    background: rgba(37, 99, 235, .1);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .35);
}

/* 框选命中的字。选区按几何位置算，框外的列一个都不会被带上。
   放在存疑字/夹注之后，命中时的高亮要盖过它们的底色。 */
.old-book-text-layer .ob-char.ob-selected {
    background: rgba(139, 0, 0, .32);
    box-shadow: inset 0 0 0 1px rgba(139, 0, 0, .55);
}

body.old-book-hide-overlay .old-book-text-layer {
    display: none;
}

.old-book-foot {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
    font-size: 12px;
    color: #6b7280;
    flex-shrink: 0;
}

.old-book-quota {
    white-space: normal;
    line-height: 1.5;
}

.old-book-quota.is-empty {
    color: #b91c1c;
    font-weight: 600;
}

.old-book-note-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
}

.old-book-legends {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.old-book-legend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.old-book-legend i {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}

.old-book-legend i.low {
    background: rgba(220, 38, 38, .18);
    border: 1px solid rgba(220, 38, 38, .75);
}

.old-book-legend i.note {
    background: rgba(37, 99, 235, .12);
    border: 1px solid rgba(37, 99, 235, .5);
}

/* ---------- 多页缩略图：拖拽调整顺序 ---------- */
.old-book-thumbs {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    background: #fff;
    flex: 1 1 auto;
    min-height: 0;
}

.old-book-thumbs:empty {
    display: none;
}

.old-book-thumb {
    position: relative;
    flex: 0 0 auto;
    width: 72px;
    height: 96px;
    border: 2px solid #e5e7eb;
    border-radius: 3px;
    background: #f9fafb center/cover no-repeat;
    cursor: pointer;
    font-size: 10px;
    color: #6b7280;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 2px;
    overflow: hidden;
}

.old-book-thumb.active {
    border-color: #8b0000;
}

.old-book-thumb.dragging {
    opacity: .4;
}

.old-book-thumb.drop-before {
    box-shadow: 0 -3px 0 #8b0000;
}

.old-book-thumb.drop-after {
    box-shadow: 0 3px 0 #8b0000;
}

.old-book-thumb-index {
    background: rgba(255, 255, 255, .85);
    border-radius: 2px;
    padding: 0 3px;
    line-height: 1.4;
}

/* ---------- 导入弹窗 ---------- */
.old-book-modal-field {
    margin-bottom: 14px;
}

.old-book-modal-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.old-book-modal-hint {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.7;
}

.old-book-drop {
    border: 1px dashed #d1d5db;
    border-radius: 8px;
    padding: 18px 12px;
    text-align: center;
    font-size: 13px;
    color: #6b7280;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.old-book-drop:hover,
.old-book-drop.is-over {
    border-color: #8b0000;
    background: #fff7f7;
}

.old-book-range {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #374151;
}

.old-book-range input {
    width: 84px;
    padding: 5px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
}
