/* 条目溯源弹窗（frontend/src/views/item-trace.js）：头部概况 + 左栏标签页 + 可拖动分隔线 + 右栏原文 */
.modal.trace-modal{width:min(1440px,96vw);max-width:96vw;height:min(88vh,920px);max-height:94vh;display:flex;flex-direction:column;border-radius:16px}

/* 细滚动条：悬停时才显出 */
.trace-modal .trace-col-body,.trace-modal .trace-viewer-content{scrollbar-width:thin;scrollbar-color:transparent transparent}
.trace-modal .trace-col-body:hover,.trace-modal .trace-viewer-content:hover{scrollbar-color:#c9d1dd transparent}
.trace-modal .trace-col-body::-webkit-scrollbar,.trace-modal .trace-viewer-content::-webkit-scrollbar{width:6px;height:6px}
.trace-modal .trace-col-body::-webkit-scrollbar-thumb,.trace-modal .trace-viewer-content::-webkit-scrollbar-thumb{background:transparent;border-radius:6px}
.trace-modal .trace-col-body:hover::-webkit-scrollbar-thumb,.trace-modal .trace-viewer-content:hover::-webkit-scrollbar-thumb{background:#c9d1dd}

/* 头部 */
.trace-head{align-items:flex-start;gap:16px;padding:18px 24px 16px}
.trace-head-main{min-width:0;flex:1}
.trace-title-row{display:flex;align-items:center;flex-wrap:wrap;gap:10px}
.trace-title-row h2{font-size:20px;font-weight:700;margin:0;white-space:nowrap}
.trace-head .task-helper{margin:6px 0 0;font-size:12.5px;color:#798598}
.trace-chips{display:flex;flex-wrap:wrap;gap:6px}
.trace-chip{display:inline-flex;align-items:center;height:22px;padding:0 9px;border-radius:999px;background:#f0f2f6;color:#5b6678;font-size:12px;white-space:nowrap}
.trace-chip.is-blue{background:#eaf2ff;color:#1477f8}
.trace-chip.is-green{background:#e6f6f1;color:#0d8a6a}
.trace-chip.is-red{background:#fdecec;color:#c03030}
.trace-chip.is-amber{background:#fff4e0;color:#9a6200;cursor:help}
.trace-head-actions{display:flex;align-items:center;gap:8px;flex:none}
.trace-head-actions .btn{display:inline-flex;align-items:center;gap:6px}
.trace-head-sep{width:1px;height:20px;background:#e7ebf2;margin:0 2px}

/* 两栏 + 分隔线 */
.trace-grid{--trace-split:40%;flex:1;min-height:0;display:grid;grid-template-columns:var(--trace-split) 8px minmax(0,1fr)}
.trace-grid.is-resizing{cursor:col-resize;user-select:none}
.trace-grid.is-resizing .trace-viewer-content{pointer-events:none}
.trace-col{display:flex;flex-direction:column;min-width:0;min-height:0}
.trace-splitter{position:relative;cursor:col-resize;background:#fff;border-left:1px solid #edf0f5;touch-action:none;outline:none}
.trace-splitter:after{content:"";position:absolute;left:1px;top:50%;width:4px;height:36px;margin-top:-18px;border-radius:4px;background:#d5dbe5;transition:background .15s}
.trace-splitter:hover,.trace-splitter:focus-visible,.trace-grid.is-resizing .trace-splitter{background:#f2f7ff}
.trace-splitter:hover:after,.trace-splitter:focus-visible:after,.trace-grid.is-resizing .trace-splitter:after{background:#1477f8}

.trace-col-title{display:flex;align-items:center;gap:10px;flex:none;height:48px;padding:0 20px;border-bottom:1px solid #edf0f5;background:#fff;font-size:13.5px;font-weight:600;color:#141d2d}
.trace-col-body{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;padding:20px 24px 28px}
.trace-col-body[hidden]{display:none}
.trace-empty{color:#8a95a8;font-size:13px;line-height:1.8}
.trace-warning{margin-bottom:12px;padding:8px 12px;border-radius:8px;background:#fff7e6;color:#9a6200;font-size:12.5px;line-height:1.6}
.trace-section-title{margin:0 0 10px;font-size:12px;font-weight:650;color:#798598;letter-spacing:.04em}

/* 左栏标签 */
.trace-tabs{gap:4px;padding:0 12px}
.trace-tab{position:relative;display:flex;align-items:center;gap:6px;height:100%;padding:0 12px;border:0;background:none;font:inherit;font-size:13.5px;font-weight:500;color:#5b6678;cursor:pointer}
.trace-tab:hover{color:#141d2d}
.trace-tab.is-active{color:#141d2d;font-weight:650}
.trace-tab.is-active:after{content:"";position:absolute;left:12px;right:12px;bottom:-1px;height:2px;border-radius:2px;background:#1477f8}
.trace-tab-count{padding:0 6px;border-radius:999px;background:#f0f2f6;color:#798598;font-size:11px;font-weight:500}
.trace-tab-count:empty{display:none}
.trace-tab.is-active .trace-tab-count{background:#eaf2ff;color:#1477f8}

/* 原文位置卡片 */
.trace-file-badge{flex:none;display:inline-flex;align-items:center;justify-content:center;min-width:28px;height:18px;padding:0 4px;border-radius:4px;background:#e5484d;color:#fff;font-size:9.5px;font-weight:700;letter-spacing:.02em}
.trace-locations{display:flex;flex-direction:column;gap:8px;margin-bottom:24px}
.trace-location{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;width:100%;padding:10px 14px;border:1px solid #e3e9f2;border-left:3px solid #1477f8;border-radius:0 10px 10px 0;background:#fff;color:#141d2d;text-align:left;font:inherit;cursor:pointer}
.trace-location:hover:not(:disabled){background:#f6f9ff}
.trace-location.is-active{border-color:#d6e5fd;border-left-color:#1477f8;background:#f4f8ff}
.trace-location:disabled{border-left-color:#c9d1dd;color:#9aa4b4;cursor:not-allowed}
.trace-location:disabled .trace-file-badge{background:#c9d1dd}
.trace-location-file{display:flex;align-items:center;gap:8px;min-width:0;flex:1 1 180px;font-size:13.5px;font-weight:600}
.trace-location-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.trace-location-page{display:inline-flex;align-items:center;flex:none;margin-left:auto;padding:0 9px;height:22px;border-radius:999px;background:#eaf2ff;color:#1477f8;font-size:12px;font-weight:500;white-space:nowrap}
.trace-location-page.is-unpaged{background:#fff4e0;color:#9a6200;cursor:help}
.trace-location:disabled .trace-location-page{background:#f0f2f6;color:inherit}
.trace-location-count{margin-left:6px;padding:0 6px;border-radius:999px;background:#ffffffa8;font-size:11px}
.trace-location-quote{flex-basis:100%;font-size:12.5px;line-height:1.6;color:#5b6678;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}

/* 正文 */
.trace-text{white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:1.8;color:#2b3546;max-width:72ch}
.trace-truncated{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:16px;padding:10px 12px;border:1px dashed #e3c98f;border-radius:8px;background:#fffaf0;color:#9a6200;font-size:12.5px;line-height:1.6}
.trace-truncated.is-top{margin:0 0 12px}
.trace-link{margin-left:auto;padding:0;border:0;background:none;color:#1477f8;font:inherit;font-weight:600;cursor:pointer}
.trace-link:hover{text-decoration:underline}
.trace-json{max-height:none;font-size:12px;line-height:1.7}

/* 按来源块分段 */
.trace-segments{display:flex;flex-direction:column;gap:10px;max-width:72ch}
.trace-segment{--tone:#1477f8;display:block;width:100%;padding:9px 12px;border:0;border-left:3px solid var(--tone);border-radius:0 8px 8px 0;background:color-mix(in srgb,var(--tone) 6%,#fff);color:#2b3546;font:inherit;font-size:14px;line-height:1.8;text-align:left;white-space:pre-wrap;overflow-wrap:anywhere;cursor:pointer}
.trace-segment:hover{background:color-mix(in srgb,var(--tone) 12%,#fff)}
.trace-segment.is-active{background:color-mix(in srgb,var(--tone) 16%,#fff);box-shadow:0 0 0 2px color-mix(in srgb,var(--tone) 40%,#fff)}
.trace-segment.tone-1{--tone:#12a37f}.trace-segment.tone-2{--tone:#e08a00}.trace-segment.tone-3{--tone:#8b5cf6}.trace-segment.tone-4{--tone:#d9467a}.trace-segment.tone-5{--tone:#0e9fb5}

/* 生成过程：按阶段分组的时间线 */
.trace-phase{margin-bottom:20px}
.trace-phase-head{display:flex;align-items:center;gap:8px;width:100%;margin:0 0 6px;padding:4px 0;border:0;background:none;font:inherit;text-align:left;cursor:pointer}
.trace-phase-caret{width:0;height:0;border-left:4px solid transparent;border-right:4px solid transparent;border-top:5px solid #9aa4b4;transition:transform .15s}
.trace-phase-head[aria-expanded="false"] .trace-phase-caret{transform:rotate(-90deg)}
.trace-phase-title{font-size:13.5px;font-weight:650;color:#141d2d}
.trace-phase-date{font-size:12.5px;color:#798598}
.trace-phase-meta{margin-left:auto;font-size:12px;color:#8a95a8;white-space:nowrap}
.trace-timeline{list-style:none;margin:0;padding:0 0 0 22px;position:relative}
.trace-timeline[hidden]{display:none}
.trace-timeline:before{content:"";position:absolute;left:5px;top:16px;bottom:16px;width:2px;border-radius:2px;background:#c5d0dc}
.trace-step{position:relative}
.trace-step:before{content:"";position:absolute;z-index:1;left:-21px;top:13px;width:10px;height:10px;border-radius:50%;background:#fff;border:2px solid #12a37f;box-sizing:border-box}
.trace-step.is-failed:before{border-color:#d64545;background:#d64545}
.trace-step.is-running:before{border-color:#1477f8}
.trace-step.is-skipped:before,.trace-step.is-unknown:before{border-color:#b7c0cd}
.trace-step-head{display:grid;grid-template-columns:minmax(0,1fr) auto 44px;align-items:center;gap:10px;width:calc(100% + 16px);margin-left:-8px;padding:7px 8px;border:0;border-radius:8px;background:none;font:inherit;text-align:left;cursor:pointer;color:#141d2d;box-sizing:border-box}
.trace-step-head:hover:not(:disabled){background:#f5f7fb}
.trace-step-head:disabled{cursor:default;color:#141d2d;opacity:1}
.trace-step-head[aria-expanded="true"]{background:#f4f8ff}
.trace-step-head[aria-expanded="true"] .trace-step-label{color:#1477f8}
.trace-step-main{display:flex;flex-direction:column;min-width:0}
.trace-step-label{font-size:13.5px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.trace-step-summary{margin-top:2px;font-size:12px;color:#798598;line-height:1.5;overflow-wrap:anywhere}
.trace-step-badges{display:flex;gap:6px;justify-content:flex-end}
.trace-step-badge{padding:1px 8px;border-radius:999px;background:#f0f2f6;color:#5b6678;font-size:11.5px;white-space:nowrap}
.trace-step-badge.is-status{background:#eef1f5;color:#798598}
.trace-step.is-failed .trace-step-badge.is-status{background:#fdecec;color:#c03030}
.trace-step.is-running .trace-step-badge.is-status{background:#eaf2ff;color:#1477f8}
.trace-step-time{font-size:12px;color:#8a95a8;text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
.trace-step-detail{display:grid;grid-template-columns:auto 1fr;gap:4px 14px;margin:2px 0 8px -8px;padding:10px 12px;border:1px solid #e7ebf2;border-radius:8px;background:#fafbfd;font-size:12.5px}
.trace-step-detail[hidden]{display:none}
.trace-step-detail dt{color:#798598}
.trace-step-detail dd{margin:0;overflow-wrap:anywhere;color:#2b3546}

/* 右栏：原文 */
.trace-source{background:#f5f7fb}
.trace-source-name{display:flex;align-items:center;gap:8px;min-width:0;overflow:hidden;white-space:nowrap}
.trace-source-name span:last-child{overflow:hidden;text-overflow:ellipsis}
.trace-viewer-tools{display:flex;align-items:center;gap:6px;margin-left:auto;flex:none;font-size:13px;font-weight:400;color:#5b6678}
.trace-viewer-tools .btn.small{width:30px;height:30px;padding:0;justify-content:center}
.trace-viewer-tools .review-pdf-page{width:48px;height:30px;border:1px solid #dfe4ec;border-radius:8px;text-align:center}
.trace-viewer-tools select{height:30px;margin-left:6px;padding:0 8px;border:1px solid #dfe4ec;border-radius:8px;background:#fff;font-size:12.5px;color:#2b3546}
.trace-viewer-content{flex:1;min-height:0;border-top:0}
.trace-modal .review-pdf-pages{background:#eef1f5}
.trace-status{display:flex;align-items:center;gap:8px;flex:none;min-height:36px;padding:6px 20px;border-top:1px solid #edf0f5;background:#fff;font-size:12.5px;color:#5b6678}
.trace-status-dot{flex:none;width:8px;height:8px;border-radius:50%;background:#c9d1dd}
.trace-status-dot.is-page{background:#12a37f;box-shadow:0 0 0 3px #12a37f22}
.trace-status-dot.is-text{background:#e0a100;box-shadow:0 0 0 3px #e0a10022}
.trace-status-dot.is-miss,.trace-status-dot.is-warn{background:#d64545;box-shadow:0 0 0 3px #d6454522}
.trace-status-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.trace-legend{display:flex;gap:14px;margin-left:auto;flex:none;font-size:12px;color:#8a95a8}
.trace-legend i{display:inline-block;width:7px;height:7px;margin-right:5px;border-radius:50%;vertical-align:1px}
.trace-legend i.is-page{background:#12a37f}.trace-legend i.is-text{background:#e0a100}.trace-legend i.is-miss{background:#d64545}

.review-pdf-box{position:absolute;border:2px solid #12a37f;background:#12a37f1f;border-radius:3px;pointer-events:none;box-sizing:border-box}

@media (max-width:1100px){
  .trace-legend{display:none}
}
@media (max-width:900px){
  .modal.trace-modal{height:94vh}
  .trace-head{flex-wrap:wrap}
  .trace-grid{grid-template-columns:1fr;grid-template-rows:minmax(0,45%) minmax(0,1fr)}
  .trace-splitter{display:none}
  .trace-item{border-bottom:1px solid #edf0f5}
  .trace-col-body{padding:16px}
}
