/* ===== Papyrus 自定义样式 ===== */

/* 上传区域 */
#upload-card {
    transition: all 0.3s ease;
}
#upload-zone-full {
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px dashed #dee2e6;
    border-radius: 0.5rem;
    margin: 1rem;
}
#upload-zone-full:hover {
    border-color: #0d6efd;
    background-color: #f8f9ff;
}
#upload-zone-compact {
    border-radius: 0.5rem;
    transition: all 0.3s ease;
}
#upload-card.border-primary {
    border-color: #0d6efd !important;
    background-color: #e8f0ff;
}

/* ===== 等宽表格布局 ===== */
#main-table-card .table-responsive {
    contain: layout paint style;  /* 不含size，避免容器塌陷 */
}

/* 表格滚动区：容器内垂直滚动（上下手抓、滚轮平滑都在此容器内生效） */
#table-scroll-area {
    position: relative;
    max-height: calc(100vh - 225px);
    overflow-y: auto;
}
/* 卡片头部压缩留白（工具栏顺序不变，仅缩小上下间距） */
#main-table-card .card-header {
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
}

/* th/td 建立定位基准：列宽手柄、分类颜色条等绝对定位元素正确对齐 */
.table-fixed th,
.table-fixed td {
    position: relative;
}

/* 空格子的"双击编辑"提示 */
.empty-hint {
    color: #adb5bd;
    font-style: italic;
}

/* ===== Excel 式冻结窗格 ===== */
/* 表头行固定顶部（容器内垂直滚动时始终可见） */
#papers-table thead th {
    position: sticky;
    top: 0;
    z-index: 4;
    background: #f8f9fa;  /* 不透明：内容从下方穿过时不可见 */
}
/* 最左两列（选择列+标题列）固定左侧 */
#papers-table th.col-sticky,
#papers-table td.col-sticky {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 3;
}
/* 左上角表头单元（表头行∩冻结列）盖在一切之上 */
#papers-table thead th.col-sticky {
    z-index: 6;
    background: #f8f9fa;
}
/* 冻结列右边界阴影，模拟 Excel 的分隔线 */
#papers-table tr > :nth-child(2) {
    box-shadow: 3px 0 6px rgba(0, 0, 0, 0.08);
}
/* 悬停时冻结格子底色与普通格子一致 */
#papers-table tbody tr:hover td.col-sticky {
    background: #f0f4ff;
}
.table-fixed {
    table-layout: fixed;
    width: 240%;
    border-collapse: separate;
    /* 文本渲染：滚动时优先速度（英文长词断词场景收益明显） */
    text-rendering: optimizeSpeed;
}

.table-fixed th,
.table-fixed td {
    overflow-wrap: break-word;
    word-break: break-word;
    vertical-align: middle;
    padding: 0.45rem 0.5rem;
    text-align: center;
}



/* ===== 点击编辑 ===== */
.edit-mode .cell-content {
    cursor: text;
}
.edit-mode .cell-content:focus {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
    border-radius: 2px;
}
.edit-mode .cell-content[contenteditable="true"] {
    background: #fff;
    min-height: 40px;
    overflow-y: auto;
    max-height: 200px;
}

/* ===== 列头 ===== */
.col-adjustable {
    user-select: none;
    position: relative;
}
.edit-mode .col-adjustable {
    cursor: pointer;
}
.edit-mode .col-adjustable:hover {
    background-color: #e9ecef;
}
.align-indicator {
    font-size: 0.7rem;
    color: #adb5bd;
    margin-left: 2px;
    display: none;
}
.edit-mode .align-indicator {
    display: inline;
}

/* 固定列 */
.col-fixed {
    cursor: default;
}

/* 列宽拖拽手柄 — 仅编辑模式可见 */
.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    background: transparent;
    display: none;
}
.edit-mode .col-resize-handle {
    display: block;
}
.edit-mode .col-resize-handle:hover,
.edit-mode .col-resize-handle.active {
    background: #0d6efd;
}

/* ===== 单元格内容（限高 + 滚动条悬浮不挤占） ===== */
.cell-content {
    max-height: 120px;
    overflow-y: hidden;
}
.cell-content:hover {
    overflow-y: auto;
}

/* 细滚动条 */
.cell-content::-webkit-scrollbar {
    width: 5px;
}
.cell-content::-webkit-scrollbar-track {
    background: transparent;
}
.cell-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}
.cell-content::-webkit-scrollbar-thumb:hover {
    background: #888;
}

/* ===== 收藏星标 — 始终黄色，空心/实心区分，有圈 ===== */
.fav-always {
    color: #f5c518 !important;
    border: 1px solid #f5c518 !important;
}
.fav-always:hover {
    background: #f5c518 !important;
    color: #fff !important;
}
/* ===== 置顶图钉 — 点亮后有圈 ===== */
.pin-active {
    color: #0d6efd !important;
    border: 1px solid #0d6efd !important;
}
.pin-active:hover {
    background: #0d6efd !important;
    color: #fff !important;
}

/* ===== 图标按钮 ===== */
.icon-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.icon-btn::after {
    content: attr(title);
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    white-space: nowrap;
    background: #333;
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}
.icon-btn:hover::after {
    opacity: 1;
}

/* ===== 新文献标记 ===== */
.new-badge {
    font-size: 0.7rem;
    animation: fadeInNew 0.3s ease;
}
@keyframes fadeInNew {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* ===== 领域标签 ===== */
.field-badge {
    font-size: 0.7rem;
    font-weight: 400;
    display: block;
    margin-top: 2px;
    background-color: #cfe2ff;
    color: #0d6efd;
    opacity: 0;
    transition: opacity 0.2s ease;
}
tr:hover .field-badge {
    opacity: 1;
}

/* ===== 自定义列内联编辑 ===== */
.custom-col-name {
    cursor: pointer;
}
.custom-col-name:hover {
    text-decoration: underline;
    color: #0d6efd;
}
.custom-col-del {
    cursor: pointer;
    color: #dc3545;
    font-size: 0.8rem;
    margin-left: 4px;
    vertical-align: middle;
    opacity: 0.7;
}
.custom-col-del:hover {
    opacity: 1;
}
.custom-col-add {
    cursor: pointer;
    color: #6c757d;
    font-size: 0.85rem;
    white-space: nowrap;
}
.custom-col-add:hover {
    color: #0d6efd;
}
.custom-col-add-placeholder {
    background-color: #f8f9fa;
}
.template-toggle {
    vertical-align: middle;
}
.template-toggle:hover {
    color: #0d6efd !important;
}
.template-inline-select {
    vertical-align: middle;
}

/* ===== 列类型标记（AI 分析 / 手动） ===== */
.col-type-badge {
    font-size: 0.55rem;
    padding: 0 3px;
    border-radius: 3px;
    vertical-align: middle;
    margin-left: 2px;
    line-height: 1.2;
    font-weight: 600;
}
.col-type-ai {
    background: #cfe2ff;
    color: #0d6efd;
    border: 1px solid #9ec5fe;
}
.col-type-manual {
    background: #e9ecef;
    color: #6c757d;
    border: 1px solid #ced4da;
}
/* AI 列头略蓝底 */
.edit-mode th[data-key^="custom_"].col-ai-header {
    background: #f0f6ff;
}
.edit-mode th[data-key^="custom_"].col-manual-header {
    background: #fafafa;
}
/* 类型切换按钮 */
.col-type-toggle .col-type-btn {
    transition: all 0.15s ease;
}
.col-type-toggle .col-type-btn.active[data-type="ai"] {
    background: #0d6efd !important;
    color: #fff !important;
    border-color: #0d6efd !important;
}
.col-type-toggle .col-type-btn.active[data-type="manual"] {
    background: #6c757d !important;
    color: #fff !important;
    border-color: #6c757d !important;
}

/* ===== 检索高亮（CSS Highlight API — 不修改 DOM，不影响字间距） ===== */
::highlight(papyrus-search) {
    background-color: #ffc107;
    color: #000;
}
/* 降级方案：旧浏览器用 mark 标签高亮 */
.cell-content mark {
    background-color: #ffc107;
    color: #000;
}

/* ===== 表格中的换行文本 ===== */
.text-pre-wrap {
    white-space: pre-wrap;
}

/* 进度条圆角 */
.progress {
    border-radius: 1rem;
}

/* ===== 批量操作行（选中文献后出现，工具栏下方居中） ===== */
.batch-action-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: #fdf6e3;
    border-bottom: 1px solid #f0e0b0;
}

/* ===== 空状态覆盖层 ===== */
#empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    user-select: none;
}
#main-table-card .card-body {
    position: relative;
    min-height: 300px;
}

/* 表格行悬停 */
.table-hover tbody tr:hover {
    background-color: #f0f4ff;
}

/* 卡片阴影 */
.card {
    border: none;
}

/* ===== 分类侧边栏 ===== */
#app-layout {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    max-width: 100%;
}
#category-sidebar {
    flex: 0 0 110px;
    width: 110px;
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
#main-content {
    flex: 1 1 auto;
    min-width: 0;  /* 防止 flex 子元素溢出 */
}
.sidebar-header {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #f0f0f0;
}
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.55rem;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 0.78rem;
    gap: 0.4rem;
    border-left: 3px solid transparent;
    user-select: none;
}
/* 窄侧栏：分类名超出部分省略号截断，完整名称见悬浮提示 */
.sidebar-item .cat-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-item:hover {
    background: #f0f4ff;
}
.sidebar-item.active {
    background: #e8f0ff;
    border-left-color: #0d6efd;
    font-weight: 500;
}
.sidebar-item .cat-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
/* 窄侧栏：隐藏数量徽章，节省宽度 */
.sidebar-item .cat-count {
    display: none;
}
.sidebar-item .cat-del {
    display: none;
    color: #dc3545;
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0 2px;
    flex-shrink: 0;
}
.sidebar-item:hover .cat-del {
    display: inline;
}
.sidebar-item .cat-rename {
    display: none;
    color: #6c757d;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0 2px;
    flex-shrink: 0;
}
.sidebar-item:hover .cat-rename {
    display: inline;
}
.sidebar-add {
    padding: 0.5rem 0.4rem;
    border-top: 1px solid #f0f0f0;
    margin-top: auto;
}
.sidebar-add input {
    font-size: 0.78rem;
}
.sidebar-color-picker {
    display: flex;
    gap: 2px;
    padding: 0.25rem 0.4rem 0.5rem 0.4rem;
    flex-wrap: wrap;
}
.sidebar-color-picker .color-option {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s;
    flex-shrink: 0;
}
.sidebar-color-picker .color-option:hover {
    transform: scale(1.2);
}
.sidebar-color-picker .color-option.selected {
    border-color: #333;
    transform: scale(1.15);
}

/* 分类分配弹窗 */
.assign-cat-item {
    background: transparent;
}
.assign-cat-item:hover {
    background: #f0f4ff;
}
.assign-cat-item.selected {
    background: #dee2e6;
}
.assign-cat-item.selected:hover {
    background: #ced4da;
}

/* 单篇"移动至"浮动菜单 */
.move-to-menu .move-to-item:hover {
    background: #f0f4ff;
}
.move-to-menu .move-to-item.selected {
    background: #dee2e6;
}

/* 侧边栏滚动条 */
#category-sidebar::-webkit-scrollbar {
    width: 4px;
}
#category-sidebar::-webkit-scrollbar-track {
    background: transparent;
}
#category-sidebar::-webkit-scrollbar-thumb {
    background: #d1d1d1;
    border-radius: 2px;
}

/* 文献行分类颜色条（位于复选框格内，不占表格流） */
.cat-color-strip {
    position: absolute;
    left: 2px;
    top: 3px;
    bottom: 3px;
    width: 4px;
    border-radius: 2px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    z-index: 1;
}
.cat-color-strip .cat-strip-segment {
    flex: 1 1 0;
    min-height: 3px;
}

/* 分类过滤激活时表格标题提示 */
#category-filter-badge {
    display: inline-block;
    font-size: 0.8rem;
    padding: 2px 10px;
    border-radius: 1rem;
    font-weight: 400;
}

/* 批量分类按钮 */
#btn-batch-category {
    transition: all 0.2s ease;
}

/* ===== 文献对比弹窗 ===== */
/* Excel 式对比布局：每个字段一行，各篇内容是同一行里的并排单元格（天然等高对齐） */
.compare-field-row {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid #f0f0f0;
}
.compare-field-row:last-child {
    border-bottom: none;
}
.compare-label-cell {
    flex: 0 0 16%;
    min-width: 96px;
    padding: 0.6rem 0.5rem;
    font-size: 0.7rem;
    color: #6c757d;
    letter-spacing: 0.3px;
    text-align: center;
    word-break: break-word;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-right: 1px solid #f0f0f0;
}
.compare-cell {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.6rem 0.5rem;
    text-align: center;
    word-break: break-word;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.compare-cell + .compare-cell {
    border-left: 1px solid #f0f0f0;
}
.compare-header-row {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fff;
}
.compare-header-row .compare-cell {
    background: #f8f9fa;
}
/* 标题格可拖动换位 */
.compare-header-row .compare-cell.compare-title-cell {
    cursor: grab;
    touch-action: none;  /* 触屏拖动换位时不触发页面滚动 */
}
.compare-header-row .compare-cell.compare-title-cell:active {
    cursor: grabbing;
}
.compare-header-row .compare-cell.cmp-drag-source {
    opacity: 0.45;
}
.compare-header-row .compare-cell.cmp-drop-target {
    background: #e8f0ff;
    outline: 2px dashed #0d6efd;
    outline-offset: -4px;
}
#compare-container {
    max-height: 70vh;
    overflow-y: auto;
}
.compare-panel-header {
    position: sticky;
    top: 0;
    z-index: 2;
}

/* ===== 手抓平移模式 ===== */
#main-table-card.grab-mode .table-responsive {
    cursor: grab;
    user-select: none;
}
#main-table-card.grab-mode .table-responsive.dragging {
    cursor: grabbing;
}
/* 表格内交互元素保持可点击（拖拽从单元格空白处启动） */
#main-table-card.grab-mode .table-responsive button,
#main-table-card.grab-mode .table-responsive input,
#main-table-card.grab-mode .table-responsive select,
#main-table-card.grab-mode .table-responsive a {
    cursor: pointer;
}
#main-table-card.grab-mode .table-responsive .cell-content {
    cursor: grab;
}
/* 标题行：抓手模式不生效，用于列换位和格式调整 */
#main-table-card.grab-mode #papers-table thead th {
    cursor: pointer;
}
#btn-grab-mode.active {
    background: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}

/* 响应式：窄屏（手机）侧边栏收成抽屉，由工具栏"分类"按钮开关 */
@media (max-width: 991.98px) {
    #app-layout {
        display: block;
    }
    #category-sidebar {
        display: none;
        position: fixed;
        left: 0.5rem;
        top: 3.6rem;
        z-index: 1050;
        width: 220px;
        flex: 0 0 auto;
        max-height: 80vh;
        box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);
    }
    #category-sidebar.open {
        display: flex;
    }
    .sidebar-add {
        display: none;
    }
}

/* 手机横屏（高度小）：表格区高度重新校准，占满屏幕 */
@media (max-height: 500px) {
    #table-scroll-area {
        max-height: calc(100vh - 120px);
    }
}

/* 手机竖屏提示遮罩 */
#rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.97);
    display: flex;
    align-items: center;
    justify-content: center;
}
#rotate-hint .rotate-hint-box {
    text-align: center;
    color: #495057;
}
#rotate-hint .rotate-hint-box i {
    font-size: 4rem;
    color: #0d6efd;
    display: block;
    margin-bottom: 0.75rem;
}
#rotate-hint .rotate-hint-box p {
    font-size: 1.05rem;
    margin-bottom: 1rem;
}

/* 导航栏 */
.navbar-brand {
    font-weight: 400;
    letter-spacing: 0.5px;
}

/* Loading spinner */
.spinner-border {
    width: 2.5rem;
    height: 2.5rem;
}

/* ===== 列拖拽排序 — 仅编辑模式 ===== */
.edit-mode .col-draggable {
    cursor: grab;
}
.edit-mode .col-draggable:active {
    cursor: grabbing;
}
.col-dragging-source {
    opacity: 0.3;
}
.col-drop-marker {
    pointer-events: none;
}


/* 选中行浅灰底色 */
#papers-tbody tr.row-selected > td {
    background-color: #f1f3f5 !important;
}

/* ===== 对比弹窗手抓平移（跟随表格手抓开关）===== */
body.grab-mode #compare-container {
    cursor: grab;
    user-select: none;
}
body.grab-mode #compare-container.dragging {
    cursor: grabbing;
}

/* ===== 用户体验调查：选项格 ===== */
.survey-cell {
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    padding: .35rem .15rem;
    cursor: pointer;
    user-select: none;
    transition: background-color .15s, border-color .15s;
}
.survey-cell .survey-radio {
    margin: 0 auto;
}
.survey-cell:hover {
    border-color: #0d6efd;
}
.survey-cell-active {
    border-color: #0d6efd !important;
    background-color: #e7f1ff;
}
