/* ============================================
   excalidraw-animate.css
   Excalidraw 手绘风 SVG 图表的客户端样式
   配合 excalidraw-animate.js 使用
   ============================================ */

/* ---- 图表容器通用样式 ---- */
.chart-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  margin: 2.5rem 0;
}

.chart-wrapper .mermaid-chart {
  display: flex;
  justify-content: center;
  padding: 1.5rem;
  border-radius: 0.75rem;
  overflow-x: auto;
  position: relative;
  width: 100%;
}

/* 暗色主题 */
[data-theme="dark"] .chart-wrapper .mermaid-chart,
:not([data-theme]) .chart-wrapper .mermaid-chart {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* 亮色主题 */
[data-theme="light"] .chart-wrapper .mermaid-chart {
  background: rgba(0, 0, 0, 0.015);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* ---- 滚动淡入动画 ---- */
.chart-wrapper .mermaid-chart {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.chart-wrapper .mermaid-chart.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---- SVG 响应式 ---- */
.chart-wrapper .mermaid-chart svg,
.mermaid-chart svg {
  max-width: 100%;
  max-height: 75vh;
  width: auto;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* ---- 放大镜按钮 ---- */
.chart-zoom-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 10;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.25s ease, background 0.2s ease, transform 0.2s ease;
}

[data-theme="dark"] .chart-zoom-btn,
:not([data-theme]) .chart-zoom-btn {
  background: rgba(30, 41, 59, 0.8);
  color: #94a3b8;
  backdrop-filter: blur(8px);
}

[data-theme="light"] .chart-zoom-btn {
  background: rgba(255, 255, 255, 0.85);
  color: #64748b;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-wrapper:hover .chart-zoom-btn {
  opacity: 0.8;
}

.chart-zoom-btn:hover {
  opacity: 1 !important;
  transform: scale(1.1);
}

/* ---- 放大 overlay ---- */
.chart-zoom-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeInOverlay 0.2s ease;
}

[data-theme="dark"] .chart-zoom-overlay,
:not([data-theme]) .chart-zoom-overlay {
  background: rgba(2, 6, 23, 0.92);
  backdrop-filter: blur(8px);
}

[data-theme="light"] .chart-zoom-overlay {
  background: rgba(248, 250, 252, 0.92);
  backdrop-filter: blur(8px);
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chart-zoom-content {
  position: relative;
  width: 92vw;
  max-width: 1200px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chart-zoom-body {
  width: 100%;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.chart-zoom-body svg {
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
}

.chart-zoom-close {
  position: absolute;
  top: -1rem;
  right: -1rem;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  z-index: 10;
}

[data-theme="dark"] .chart-zoom-close,
:not([data-theme]) .chart-zoom-close {
  background: #1e293b;
  color: #f8fafc;
}

[data-theme="light"] .chart-zoom-close {
  background: #e2e8f0;
  color: #1e293b;
}

.chart-zoom-close:hover {
  transform: scale(1.15);
}

/* ---- 缺失 SVG 的提示样式 ---- */
.mermaid-missing {
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

[data-theme="dark"] .mermaid-missing,
:not([data-theme]) .mermaid-missing {
  background: #422006;
  border: 1px dashed #f59e0b;
  color: #fbbf24;
}

[data-theme="light"] .mermaid-missing {
  background: #fef3c7;
  border: 1px dashed #f59e0b;
  color: #92400e;
}

/* ---- SVG 内部阴影层（暗色下增强可见度） ---- */
[data-theme="dark"] .chart-shadow {
  opacity: 0.5;
}

[data-theme="light"] .chart-shadow {
  opacity: 0.3;
}

/* ---- 减弱动画偏好 ---- */
@media (prefers-reduced-motion: reduce) {
  .chart-wrapper .mermaid-chart {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .chart-draw-stroke {
    animation: none !important;
    stroke-dashoffset: 0 !important;
  }

  .chart-draw-fill,
  .chart-draw-text {
    animation: none !important;
    opacity: 1 !important;
  }
}

/* ---- 手机端适配 ---- */
@media (max-width: 640px) {
  .chart-wrapper {
    margin: 1.5rem -1rem;
  }

  .chart-wrapper .mermaid-chart {
    padding: 1rem 0.5rem;
    border-radius: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  .chart-wrapper .mermaid-chart svg {
    max-height: 55vh;
    min-width: 280px;
  }

  .chart-zoom-btn {
    width: 32px;
    height: 32px;
    top: 0.5rem;
    right: 0.5rem;
  }

  .chart-zoom-content {
    width: 96vw;
  }
}
