/* 详情面板顶部拉伸条 */
.detail-resizer {
  height: 6px;
  cursor: ns-resize;
  background: #e5e7eb;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1001;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
}
/* 让detail-panel支持绝对定位子元素 */
.detail-panel {
  position: fixed;
  /* ...existing code... */
  overflow-y: auto;
}
/* 阶段表格单元格固定宽度 */
.stage-table td.stage-name-cell,
.stage-table th:first-child {
  width: 200px;
  min-width: 200px;
  max-width: 200px;
}
.stage-table td.stage-value-cell,
.stage-table th:last-child {
  width: 80px;
  min-width: 80px;
  max-width: 80px;
}
/* 右栏 time/memory 选择按钮样式 */
.stage-mode-label {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.stage-mode-label input[type="radio"] {
  margin-right: 2px;
}
/* 展开按钮三角形旋转动画 */
#stageExpandBtn {
  background: none;
  border: none;
  box-shadow: none;
  color: inherit;
  padding: 0;
  margin-bottom: 0; /* 改为 0，防止把第一行撑高 */
  cursor: pointer;
  outline: none;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0; /* 防止按钮被挤压变扁 */
}
#stageExpandBtn .triangle {
  display: inline-block;
  width: 0;
  height: 0;
  /* 调整比例，让它看起来更精致 */
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid #4b5563; /* 使用你项目中常用的灰色 */
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  margin-left: 2px; /* 微调视觉中心 */
}
#stageExpandBtn.expanded .triangle {
  transform: rotate(90deg);
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
  background: #ffffff;
  color: #1f2937;
  overflow: auto;
  height: 100vh;
}
.stage-charts.hidden {
  display: none;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #ffffff;
}

/* 内存图区域 */
.memory-chart-section {
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  border-bottom: 2px solid #e5e7eb;
  background: #ffffff;
}

/* 编译时间线区域 */
.timeline-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 两列布局：左侧时间线 + 右侧阶段侧栏 */
/* 页面级两栏布局：左侧（内存图+时间线） + 中间分隔条 + 右侧阶段侧栏 */
.container.two-columns {
  --stage-sidebar-width: 600px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6px var(--stage-sidebar-width); /* 左侧/分隔条/右侧侧栏 */
  grid-template-rows: auto 280px 1fr auto; /* 头/内存图/时间线/统计 */
  column-gap: 0;
  height: 100vh;
}

/* 标题栏跨全宽 */
.container.two-columns .header {
  grid-column: 1 / 4;
  grid-row: 1 / 2;
}

/* 左侧：内存图定位到第二行 */
.container.two-columns .memory-chart-section {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
  min-width: 0;
}

/* 左侧：时间线定位到第三行 */
.container.two-columns .timeline-section {
  grid-column: 1 / 2;
  grid-row: 3 / 4;
  min-width: 0;
}

/* 中间分隔条跨越内存图、时间线到统计区域（第2到第5行） */
.container.two-columns .stage-resizer {
  grid-column: 2 / 3;
  grid-row: 2 / 5;
  background: transparent;
  cursor: col-resize;
}
.container.two-columns .stage-resizer:hover {
  background: rgba(11, 94, 215, 0.08);
}

/* 右侧阶段侧栏跨越内存图、时间线以及统计区域 */
.container.two-columns .stage-sidebar {
  grid-column: 3 / 4;
  grid-row: 2 / 5;
  border-left: 1px solid #e5e7eb;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

/* 阶段图在右侧侧栏内垂直堆叠 */
.stage-sidebar .stage-charts {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  flex: 1; /* 占满侧栏高度 */
}
.stage-charts.hidden {
  display: none;
}

.stage-chart {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex: 1; /* 两个图等比分配垂直空间 */
}
.stage-chart-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 8px;
}
.stage-chart canvas {
  flex: 1;
}

/* 标题栏 */
.header {
  background: #f5f7fa;
  padding: 16px 24px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
  color: #0b5ed7;
  letter-spacing: 0.5px;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, #e8f1ff 0%, #d9e8ff 100%);
  color: #0b5ed7;
  border: 1px solid #0b5ed7;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn:hover {
  background: linear-gradient(135deg, #d6e6ff 0%, #c7dcff 100%);
  box-shadow: 0 0 10px rgba(11, 94, 215, 0.25);
}

.btn:active {
  transform: scale(0.98);
}

.time-range {
  font-size: 12px;
  color: #888;
  margin-left: 16px;
  min-width: 200px;
  text-align: right;
}

/* 时间线容器 */

.timeline-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  background: #ffffff;
  min-width: 0;
}

/* 内存图头部 */
.memory-chart-header {
  display: flex;
  height: 40px;
  background: #f8fafc;
  border-bottom: 1px solid #e5e7eb;
}

.memory-label {
  width: 100px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 12px;
  color: #4b5563;
  border-right: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
}

.memory-ruler {
  flex: 1;
  overflow-x: hidden;
  position: relative;
  background: #f8fafc;
}

/* 内存图主体 */
.memory-chart-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  align-items: stretch;
}

.memory-y-axis {
  width: 100px;
  background: #f8fafc;
  border-right: 1px solid #e5e7eb;
  position: relative;
  overflow: hidden;
  height: 100%;
  padding: 10px 0;
}

.memory-canvas-wrapper {
  flex: 1;
  overflow-x: hidden;
  overflow-y: hidden;
  position: relative;
  background: #ffffff;
  min-width: 0;
}

.memory-canvas-wrapper::-webkit-scrollbar {
  height: 12px;
  background: #ffffff;
}

.memory-canvas-wrapper::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 6px;
  border: 2px solid #ffffff;
}

.memory-canvas-wrapper::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

#memoryCanvas {
  display: block;
  cursor: crosshair;
}

.timeline-header {
  display: flex;
  height: 40px;
  background: #f8fafc;
  border-bottom: 1px solid #e5e7eb;
  padding: 0;
}

.tracks-label {
  width: 100px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 12px;
  color: #4b5563;
  border-right: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
}

.timeline-ruler {
  flex: 1;
  display: block;
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
}

.timeline-ruler::-webkit-scrollbar {
  display: none; /* Chrome, Safari and Opera */
}

.timeline-ruler-mark {
  position: absolute;
  height: 100%;
  border-left: 1px solid #e5e7eb;
  display: flex;
  align-items: flex-end;
  padding-bottom: 4px;
  font-size: 10px;
  color: #6b7280;
}

/* 时间线主体 */

.timeline-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tracks-container {
  width: 100px;
  background: #f8fafc;
  border-right: 1px solid #e5e7eb;
  overflow-y: auto;
  overflow-x: hidden;
}

.track {
  height: 30px;
  border-bottom: 1px solid #e5e7eb;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  font-size: 11px;
  color: #4b5563;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track:hover {
  background: #f1f5f9;
}

.track-label {
  font-weight: 500;
  color: #0b5ed7;
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow-x: auto;
  overflow-y: auto;
  background: #ffffff;
  min-width: 0;
  box-sizing: border-box;
  scrollbar-gutter: stable;
}

canvas {
  display: block;
  background: #ffffff;
}

/* 提示信息 */
.tooltip {
  position: absolute;
  background: #ffffff;
  color: #0b5ed7;
  padding: 4px 8px;
  border: 1px solid #0b5ed7;
  border-radius: 4px;
  font-size: 11px;
  pointer-events: none;
  display: none;
  z-index: 1000;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 阶段图卡片样式（保持） */
.stage-chart {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 12px;
  min-height: 180px;
  display: flex;
  flex-direction: column;
}
.stage-chart-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 8px;
}
.stage-chart canvas {
  flex: 1;
}

/* 统计信息 */
.stats {
  background: #f8fafc;
  border-top: 1px solid #e5e7eb;
  padding: 12px 24px;
  font-size: 12px;
  color: #4b5563;
  max-height: 100px;
  overflow-y: auto;
}

/* 统计信息仅在左侧，位于时间线下方 */
.container.two-columns .stats {
  grid-column: 1 / 2;
  grid-row: 4 / 5;
}

#statsContent {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.stat-item {
  padding: 4px 0;
}

.stat-label {
  color: #666;
  display: inline;
}

.stat-value {
  color: #00d4ff;
  font-weight: 600;
  margin-left: 8px;
}

/* 颜色方案 */
.color-0 {
  background: #26c281;
}
.color-1 {
  background: #f8d863;
}
.color-2 {
  background: #e895d8;
}
.color-3 {
  background: #f0ad9e;
}
.color-4 {
  background: #5db5e8;
}
.color-5 {
  background: #ff9171;
}
.color-6 {
  background: #66d966;
}
.color-7 {
  background: #ff8787;
}
.color-8 {
  background: #5dd9d9;
}
.color-9 {
  background: #c9d979;
}
.color-10 {
  background: #b999cc;
}
.color-11 {
  background: #ff6b9d;
}

/* 滚动条样式 */
.canvas-wrapper::-webkit-scrollbar,
.tracks-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.canvas-wrapper::-webkit-scrollbar-track,
.tracks-container::-webkit-scrollbar-track {
  background: #ffffff;
}

.canvas-wrapper::-webkit-scrollbar-thumb,
.tracks-container::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.canvas-wrapper::-webkit-scrollbar-thumb:hover,
.tracks-container::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* 响应式 */
/* 详情面板 */
.detail-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 2px solid #0b5ed7;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  max-height: 300px;
  overflow-y: auto;
  scrollbar-gutter: stable; /* 预留滚动条空间，避免滚动条出现时挤压内容 */
  display: none;
  z-index: 999;
}

.detail-panel.show {
  display: flex;
  flex-direction: column;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: #f8fafc;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}

.detail-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
}

.detail-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #6b7280;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.detail-close:hover {
  color: #1f2937;
}

.detail-content {
  padding: 16px 24px;
  overflow-y: auto;
}

.detail-item {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 16px;
  margin-bottom: 12px;
  align-items: flex-start;
}

.detail-item.full-width {
  grid-template-columns: 100px 1fr;
}

.detail-label {
  font-weight: 600;
  color: #4b5563;
  font-size: 13px;
}

.detail-value {
  color: #1f2937;
  font-size: 13px;
  word-break: break-all;
}

.detail-command-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.detail-command {
  flex: 1;
  background: #f3f4f6;
  padding: 8px 12px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 12px;
  color: #1f2937;
  overflow-y: auto;
  overflow-x: hidden;
  word-break: break-all;
  max-height: 200px;
  border: 1px solid #e5e7eb;
}

.detail-copy-btn {
  background: #0b5ed7;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  width: 60px;
  text-align: center;
  transition: background-color 0.2s;
}

.detail-copy-btn:hover {
  background: #0a58ca;
}

.detail-copy-btn:active {
  background: #084298;
}

.detail-copy-btn:disabled {
  background: #6c757d;
  cursor: not-allowed;
  opacity: 0.7;
}

/* 详情面板左右两栏布局 */
.detail-flex {
  display: flex;
  flex-direction: row;
  gap: 24px;
  padding-right: 17px; /* 预留滚动条宽度空间，避免出现滚动条时挤压内容 */
}
.detail-left {
  width: 1225px;
  min-width: 1225px;
  max-width: 1225px;
  flex: none;
}
.detail-right {
  flex: 1 1 0;
  min-width: 560px;
  max-width: 560px;
  border-left: 1px solid #e5e7eb;
  padding-left: 16px;
  overflow-x: auto;
  display: flex; /* 开启 Flex */
  flex-wrap: wrap; /* 允许内容换行 */
  align-items: center; /* 垂直居中对齐按钮和文字 */
  align-items: flex-start;
  padding-top: 0px;
}

#stageExpandBtn,
.stage-main-label,
.stage-mode-label {
  display: inline-flex;
  align-items: center; /* 这会让这三个小元素在它们那一行内部居中对齐 */
  height: 24px; /* 统一高度，确保对齐 */
  margin-top: 0;
}
#stageExpandContent {
  width: 520px; /* 固定宽度，避免滚动条挤压 */
  margin-top: 10px;
  overflow-x: auto;
}
.stage-table {
  width: 520px; /* 固定表格宽度 */
  min-width: 520px;
  max-width: 520px;
  border-collapse: collapse;
  margin-top: 8px;
  table-layout: fixed;
}
.stage-table th,
.stage-table td {
  border: 1px solid #e5e7eb;
  padding: 4px 8px;
  font-size: 13px;
}
.stage-table th {
  background: #f8fafc;
  font-weight: bold;
}

/* 树形阶段表格折叠/展开 */
.stage-toggle {
  display: inline-block;
  width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  font-size: 10px;
  color: #6b7280;
  cursor: pointer;
  margin-right: 4px;
  transition:
    transform 0.15s ease,
    color 0.15s ease;
  user-select: none;
}
.stage-toggle:hover {
  color: #3b82f6;
}
.stage-table tr[data-level] td.stage-name-cell {
  white-space: nowrap;
}
.stage-table tr[data-level]:hover {
  background-color: #f0f9ff;
}

/* 响应式 */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 12px;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
  }

  .time-range {
    min-width: auto;
    margin-left: 0;
  }

  .detail-panel {
    max-height: 40vh;
  }
}
