/* ================================================================
   Report Panel — 深度研究报告右栏（双栏布局 + 悬浮把手）
   ================================================================ */

#report-panel {
  width: 0;
  flex-shrink: 0;
  position: relative;
  overflow: visible; /* 把手在收起态也要可见 */
  transition: width 0.2s ease;
  z-index: 20;
}

#report-panel.open {
  width: 45%;
  min-width: 400px;
  max-width: 760px;
  border-left: 1px solid var(--rule);
  /* 文档滚动时吸附视口（面板内容自身滚动） */
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: flex-start;
}

/* ── 悬浮把手（收起/展开两态都贴在聊天栏与报告栏边界） ── */
#report-panel-toggle {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 64px;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--surface-card);
  color: var(--text-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: color var(--transition-fast), border-color var(--transition-fast);
  z-index: 30;
}

#report-panel-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* 把手箭头：hover 时轻移引导 */
#report-panel-toggle svg {
  transition: transform var(--transition-fast);
}

#report-panel-toggle:hover svg {
  transform: translateX(-2px);
}

#report-panel:not(.open) #report-panel-toggle:hover svg {
  transform: translateX(2px);
}

/* 收起态显示「展开」图标（向左箭头），展开态显示「收起」图标 */
#report-panel-toggle .toggle-icon-open { display: none; }
#report-panel-toggle .toggle-icon-close { display: block; }
#report-panel:not(.open) #report-panel-toggle .toggle-icon-open { display: block; }
#report-panel:not(.open) #report-panel-toggle .toggle-icon-close { display: none; }

/* ── 面板主体 ── */
#report-panel-inner {
  display: none;
  flex-direction: column;
  height: 100%;
  background: var(--surface-card);
  overflow: hidden;
}

#report-panel.open #report-panel-inner {
  display: flex;
}

#report-panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
  min-height: 44px;
}

#report-panel-title {
  font-size: var(--fs-l3);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

#report-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

#report-panel-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: var(--space-lg) var(--space-xl);
}

/* ── 空态 ── */
#report-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  height: 60%;
  color: var(--text-tertiary);
  font-size: var(--fs-l3);
  text-align: center;
}

.report-empty-hint {
  font-size: var(--fs-l4);
}

/* ── 报告内容排版（继承 markdown.css，此处做栏宽适配 + 专业报告排版） ── */
#report-content.markdown-body {
  font-size: 14px;
  line-height: 1.8;
}

/* 段落与列表：更宽松的阅读节奏 */
#report-content.markdown-body p {
  margin: 0 0 18px;
}

#report-content.markdown-body ul,
#report-content.markdown-body ol {
  margin: 0 0 18px;
  padding-left: 22px;
}

#report-content.markdown-body li {
  margin-bottom: 8px;
  line-height: 1.75;
}

/* 标题层级：章节间留白加大，h2 带细分隔线 */
#report-content.markdown-body h1 {
  font-size: 24px;
  line-height: 1.35;
  margin: 0 0 20px;
}

#report-content.markdown-body h2 {
  font-size: 19px;
  line-height: 1.4;
  margin: 40px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}

#report-content.markdown-body h3 {
  font-size: 16px;
  margin: 28px 0 12px;
}

#report-content.markdown-body h4 {
  font-size: 14px;
  margin: 22px 0 10px;
}

/* 配图：居中 + 圆角 + 轻阴影，紧随的斜体行作为图注 */
#report-content.markdown-body img {
  display: block;
  margin: 20px auto 6px;
  max-width: 92%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow-md);
  cursor: zoom-in;   /* 点击经图片灯箱放大（markdown.js 委托） */
}

#report-content.markdown-body img + em,
#report-content.markdown-body p:has(> img:only-child) + p > em:only-child {
  display: block;
  text-align: center;
  font-size: var(--fs-l4);
  color: var(--text-tertiary);
  margin-bottom: 20px;
}

/* 表格：更舒展的单元格与斑马纹 */
#report-content.markdown-body table {
  margin: 20px 0 24px;
  font-size: var(--fs-l3);
}

#report-content.markdown-body th {
  padding: 10px 14px;
}

#report-content.markdown-body td {
  padding: 10px 14px;
  line-height: 1.6;
}

#report-content.markdown-body tbody tr:nth-child(even) td {
  background: var(--surface-secondary);
}

/* callout 与引用块：更从容的内边距 */
#report-content.markdown-body .callout {
  margin: 20px 0;
  padding: 14px 18px;
}

#report-content.markdown-body blockquote {
  margin: 20px 0;
  padding: 12px 18px;
}

/* mermaid / echarts 容器间距 */
#report-content.markdown-body .mermaid-container,
#report-content.markdown-body .echarts-container {
  margin: 20px 0 24px;
}

/* ── 研究中断横幅（error 态报告） ── */
.report-error-banner {
  margin-bottom: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border-left: 3px solid var(--error);
  border-radius: var(--radius-md);
  background: var(--error-bg);
  color: var(--error);
  font-size: var(--fs-l3);
}

/* ── done 态报告 meta 信息行 ── */
.report-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-lg);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--rule);
  font-size: var(--fs-l4);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

#report-content .echarts-view {
  height: 280px;
}

/* ── 探索态视图（M3 填充数据） ── */
#report-exploring {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.explore-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.explore-title {
  font-size: var(--fs-l2);
  font-weight: 600;
  color: var(--text-primary);
}

.explore-stats {
  display: flex;
  gap: var(--space-lg);
  font-size: var(--fs-l4);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.explore-progress {
  height: 4px;
  background: var(--surface-secondary);
  border-radius: 2px;
  overflow: hidden;
}

.explore-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.explore-nodes {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.explore-node {
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--surface-secondary);
  transition: border-color var(--transition-fast), transform var(--transition-fast), background var(--transition-fast);
}

/* 探索节点卡片 hover 反馈 */
.explore-node:hover {
  border-color: var(--rule-strong);
  transform: translateY(-1px);
}

/* 树模式子节点容器：左侧引导线体现父子层级（替代旧的 depth margin 缩进） */
.explore-children {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
  margin-left: 7px;
  padding-left: 16px;
  border-left: 2px solid var(--rule);
}

/* 子节点相对引导线伸出短横线，形成 └─ 的树形连接感 */
.explore-children > .explore-node {
  position: relative;
}
.explore-children > .explore-node::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 18px;
  width: 12px;
  border-top: 2px solid var(--rule);
}

.explore-node-head {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--fs-l4);
  color: var(--text-primary);
}

.explore-node-status {
  flex-shrink: 0;
  width: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.explore-node[data-status="pending"] .explore-node-status { color: var(--text-tertiary); }

.explore-node[data-status="running"] .explore-node-head { color: var(--accent); }
.explore-node[data-status="done"] .explore-node-status { color: var(--success); }
.explore-node[data-status="error"] .explore-node-status { color: var(--error); }
.explore-node[data-status="pending"] .explore-node-head { color: var(--text-tertiary); }

.explore-node-learnings {
  margin-top: var(--space-xs);
  font-size: var(--fs-l4);
  color: var(--text-secondary);
  line-height: 1.5;
}

.explore-node-learnings li {
  margin-left: 16px;
  list-style: disc;
}

.explore-timeline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
  font-size: var(--fs-l4);
  color: var(--text-tertiary);
}

.explore-timeline-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.explore-timeline-icon {
  flex-shrink: 0;
}

/* 长文本（URL/标题）在 flex 项上截断——text-overflow 须设在内部元素而非 flex 容器 */
.explore-timeline-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explore-timeline-item.error {
  color: var(--error);
}

.explore-timeline-item a {
  color: var(--accent);
  text-decoration: none;
}

.explore-section-label {
  font-size: var(--fs-l4);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* 研究过程复盘（done/error 报告内的可折叠检索轨迹） */
.explore-replay {
  margin-bottom: 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
}

.explore-replay > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: var(--fs-l3);
  color: var(--text-secondary);
  user-select: none;
}

.explore-replay > summary:hover {
  color: var(--text-primary);
}

.explore-replay-body {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.explore-replay .explore-timeline {
  max-height: 240px;
  overflow-y: auto;
}

/* spinner for running nodes */
.explore-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: explore-spin 0.8s linear infinite;
}

@keyframes explore-spin {
  to { transform: rotate(360deg); }
}

/* ── 深挖轮：进度区下方的原报告（只读、弱化区分） ── */
#report-existing-content {
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--rule);
  opacity: 0.75;
}

/* ── 选中引用浮动按钮 ── */
#report-quote-btn {
  position: fixed;
  z-index: 10000;
  padding: 5px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--rule);
  background: var(--surface-card);
  color: var(--accent);
  font-size: var(--fs-l4);
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: none;
}

#report-quote-btn:hover {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

#report-quote-btn:active {
  background: var(--surface-pressed);
}

/* ── 导出下拉菜单 ── */
#report-export-menu {
  position: fixed;
  z-index: 10000;
  min-width: 180px;
  background: var(--surface-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: none;
}

#report-export-menu.open {
  display: block;
}

.report-export-option {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--fs-l3);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.report-export-option:hover {
  background: var(--surface-hover);
}

.report-export-option small {
  font-size: var(--fs-l4);
  color: var(--text-tertiary);
}

/* ── 窄窗口：报告栏降级为覆盖层 ── */
@media (max-width: 1100px) {
  #report-panel.open {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(85%, 560px);
    min-width: 0;
    max-width: none;
    box-shadow: var(--shadow-lg);
    background: var(--surface-card);
  }

  #report-panel-toggle {
    /* 覆盖层模式下把手贴到面板左缘外侧 */
    transform: translate(-100%, -50%);
    border-radius: 9px 0 0 9px;
    border-right: none;
  }
}

/* ── 报告修改后的视觉反馈 ── */
@keyframes report-flash-glow {
  0% { background: var(--accent-subtle); }
  100% { background: transparent; }
}

#report-content.report-flash {
  animation: report-flash-glow 1.2s ease-out;
}
