/* 
code-custom.css：负责

复制按钮功能及样式
颜色主题覆盖
特定字体覆盖
 */

/* 代码块容器基本样式 */
.code-block-container {
  margin-top: 5px;
  margin-bottom: 2em;
  width: 100%;
  position: relative;
  box-shadow: 0 4px 16px var(--vscode-code-shadow);
  border-radius: 6px;
  overflow: hidden;
  height: auto !important;
}


/* 代码块复制按钮样式优化 */
/* 隐藏复制按钮文本，只显示图标 */
.copy-btn::before, 
.copy-button::before {
  content: "";
  display: none !important;
}

/* 复制按钮统一样式 */
.copy-btn, 
.copy-button {
  width:  26px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--vscode-code-copy-btn);
  border: 1px solid var(--vscode-code-copy-btn-border);
  border-radius: 4px;
  color: var(--vscode-code-copy-btn-text);
  cursor: pointer;
  transition: all 0.2s ease;
  position: absolute;
  top: 4px;
  right: 4px;
  opacity: 0;
  z-index: 5;
  box-shadow: 0 2px 6px var(--vscode-code-shadow);
}

/* 代码块容器悬停时显示复制按钮 */
pre:hover .copy-button,
.code-block-container:hover .copy-btn {
  opacity: 1;
}

/* 复制按钮悬停和激活状态 */
.copy-btn:hover,
.copy-button:hover {
  background: var(--vscode-code-copy-btn-hover);
  color: var(--vscode-code-copy-btn-hover-text);
}

.copy-btn.copied,
.copy-button.copied {
  background: var(--vscode-accent);
  color: var(--vscode-bg);
  border-color: var(--vscode-accent);
}

/* 代码区域颜色覆盖 - 仅保留颜色相关覆盖，布局由 code.css 负责 */
.highlight {
  background: var(--vscode-code-bg);
  color: var(--vscode-text);
}

.highlight pre {
  background: var(--vscode-code-bg);
  color: var(--vscode-text);
  padding: 16px; /* 从 1rem 改为 16px，保持一致 */
  overflow-x: auto;
  border-radius: 6px;
}

/* 特殊字体覆盖 */
.code-language {
  font-family: 'JetBrains Mono', monospace, 'Segoe UI', sans-serif;
  font-size: 12px;
}

/* 美化普通代码块 */
pre:not(.line-numbers-pre):not(.code-content) {
  background: var(--vscode-code-bg);
  color: var(--vscode-text);
  padding: 16px;
  margin: 2em 0;
  border-radius: 6px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 1.6;
  position: relative;
  box-shadow: 0 4px 16px var(--vscode-code-shadow);
  width: 100%;
  box-sizing: border-box;
  display: block;
}

/* 统一行号和代码颜色 */
.hljs {
  background: var(--vscode-code-bg) !important;
  color: var(--vscode-text) !important;
}

/* 添加代码类型标记到普通代码块 */
pre:not(.line-numbers-pre):not(.code-content):not(.mermaid.enhanced)::before {
  content: "code";
  position: absolute;
  top: 0;
  right: 0;
  background: var(--vscode-code-line-number-bg);
  color: var(--vscode-code-copy-btn-text);
  padding: 2px 8px;
  font-size: 12px;
  border-bottom-left-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
}

/* Enhanced Mermaid block label */
pre.mermaid.enhanced::before {
  content: "mermaid";
  position: absolute;
  top: 0;
  right: 0;
  background: var(--vscode-code-copy-btn);
  color: var(--vscode-text-light);
  padding: 4px 10px;
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Segoe UI', sans-serif;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-bottom-left-radius: 8px;
  box-shadow: 0 2px 4px var(--vscode-code-shadow);
  transition: all 0.3s ease;
}

pre.mermaid.enhanced:hover::before {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--vscode-shadow);
  background: var(--vscode-code-copy-btn-hover);
  color: var(--vscode-text);
}

/* 滚动指示效果 - 深色主题 */
:root[data-theme="dark"] .code-pre-wrapper.scrollable::after,
:root[data-theme="dark"] pre.scrollable::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 16px;
  background: linear-gradient(90deg, rgba(30,30,30,0) 0%, rgba(30,30,30,1) 100%);
  pointer-events: none;
  opacity: 0.8;
}

/* 滚动时的指示效果 - 深色主题 */
:root[data-theme="dark"] .code-pre-wrapper.scrolled::before,
:root[data-theme="dark"] pre.scrolled::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 16px;
  background: linear-gradient(270deg, rgba(30,30,30,0) 0%, rgba(30,30,30,1) 100%);
  pointer-events: none;
  opacity: 0.8;
}

/* 滚动指示效果 - 白色主题 */
:root[data-theme="white"] .code-pre-wrapper.scrollable::after,
:root[data-theme="white"] pre.scrollable::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 16px;
  background: linear-gradient(90deg, rgba(248,248,248,0) 0%, rgba(248,248,248,1) 100%);
  pointer-events: none;
  opacity: 0.8;
}

/* 滚动时的指示效果 - 白色主题 */
:root[data-theme="white"] .code-pre-wrapper.scrolled::before,
:root[data-theme="white"] pre.scrolled::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 16px;
  background: linear-gradient(270deg, rgba(248,248,248,0) 0%, rgba(248,248,248,1) 100%);
  pointer-events: none;
  opacity: 0.8;
}

/* 默认滚动指示效果（深色主题） */
.code-pre-wrapper.scrollable::after,
pre.scrollable::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 16px;
  background: linear-gradient(90deg, rgba(30,30,30,0) 0%, rgba(30,30,30,1) 100%);
  pointer-events: none;
  opacity: 0.8;
}

/* 默认滚动时的指示效果（深色主题） */
.code-pre-wrapper.scrolled::before,
pre.scrolled::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 16px;
  background: linear-gradient(270deg, rgba(30,30,30,0) 0%, rgba(30,30,30,1) 100%);
  pointer-events: none;
  opacity: 0.8;
}

/* 确保代码块中的内容正确显示 */
.code-pre-wrapper {
  display: flex;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  align-items: flex-start; /* 确保不拉伸内部元素 */
  min-height: 0; /* 确保能够正确计算高度 */
  box-sizing: border-box;
  background: var(--vscode-code-container-bg);
  padding: 0; /* 确保没有默认内边距 */
  margin: 0; /* 确保没有默认外边距 */
  position: relative; /* 约束滚动指示伪元素的定位范围 */
}

/* 行号区域宽度自适应 */
.line-numbers-pre {
  width: auto;
  flex: 0 0 auto;
  padding: 4px 6px; /* 减小垂直内边距与code.css保持一致 */
  margin: 0;
  box-sizing: border-box; /* 确保边框盒模型一致 */
}

/* 代码内容区域自适应 */
.code-content {
  flex: 1;
  width: 0; /* 初始宽度为0，通过flex-grow伸展 */
  min-width: 0; /* 允许内容区域收缩 */
  overflow-x: auto;
  padding: 4px 8px !important; /* 减小垂直内边距与code.css保持一致 */
  margin: 0;
  box-sizing: border-box; /* 确保边框盒模型一致 */
}

/* 提高代码可读性 */
.hljs {
  background: var(--vscode-code-bg) !important;
  color: var(--vscode-text) !important;
  max-width: 100%; /* 确保不会超出父容器 */
  box-sizing: border-box; /* 确保padding不会导致宽度计算问题 */
  padding: 0; /* 移除内边距 */
  margin: 0; /* 移除外边距 */
}

/* 超长代码换行控制 */
.code-content code {
  white-space: pre;
  word-wrap: normal;
  tab-size: 4;
  line-height: 1.5;
}

/* 处理特殊高度的代码行 */
.code-content .line img,
.code-content .line svg,
.code-content .line pre,
.code-content .line div {
  max-height: none; /* 确保内联元素不会导致行高异常 */
  vertical-align: middle; /* 确保垂直对齐一致 */
}

/* 白色主题特殊样式 - 添加边框以提升视觉区分度 */
:root[data-theme="white"] figure.highlight,
:root[data-theme="white"] .code-block-container,
:root[data-theme="white"] .code-pre-wrapper,
:root[data-theme="white"] pre:not(.line-numbers-pre):not(.code-content) {
  border: 1px solid var(--vscode-code-border);
}

/* 在小屏幕上优化显示 */
@media (max-width: 768px) {
  .line-numbers-pre {
    padding: 4px 6px; /* 与非移动版保持一致 */
  }
  
  .code-content {
    padding: 4px 8px !important; /* 与非移动版保持一致 */
  }
}

/* 折叠状态的代码块 */
.code-pre-wrapper.collapsed {
  height: 0 !important;
  padding: 0;
  margin: 0;
  border: none;
  overflow: hidden;
  transition: all 0.3s ease;
  opacity: 0;
}

/* 确保按钮在折叠和展开状态下都有正确的视觉效果 */
.toggle-btn .fa-chevron-down {
  transition: transform 0.3s ease;
}

.toggle-btn .fa-chevron-right {
  transition: transform 0.3s ease;
}

/* 调整普通代码块复制按钮位置，避免与code标签重叠 */
pre:not(.line-numbers-pre):not(.code-content) .copy-button {
  right: 45px; /* 向左移动，给"code"标签留出空间 */
  opacity: 0; /* 默认隐藏 */
  transition: opacity 0.2s ease; /* 平滑显示/隐藏过渡 */
}

/* 仅在鼠标悬停时显示普通代码块的复制按钮 */
pre:not(.line-numbers-pre):not(.code-content):hover .copy-button {
  opacity: 1;
}

