/* ===== 全局重置与变量 ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.4);
  --accent-subtle: rgba(56, 189, 248, 0.15);
  --tab-active-bg: #38bdf8;
  --tab-active-text: #0f172a;
  --overlay-bg: rgba(56, 189, 248, 0.08);
  --overlay-border: rgba(56, 189, 248, 0.25);
  --overlay-hover-bg: rgba(56, 189, 248, 0.18);
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== 顶部区域 ===== */
.header {
  width: 100%;
  max-width: 1600px;
  padding: 1.25rem 1.5rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  white-space: nowrap;
}

/* ===== 标签页导航 ===== */
.tab-bar {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 0.5rem 1.1rem;
  border: 1px solid var(--bg-card);
  border-radius: 0.5rem;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}

.tab-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--accent);
}

.tab-btn.active {
  background: var(--tab-active-bg);
  color: var(--tab-active-text);
  border-color: var(--tab-active-bg);
  font-weight: 600;
  box-shadow: 0 0 12px var(--accent-glow);
}


/* ===== 主展示区 ===== */
.viewer-wrapper {
  width: 100%;
  max-width: 1600px;
  padding: 1rem 1.5rem 2rem;
  flex: 1;
}

.viewer {
  position: relative;
  width: 100%;
  background: #ffffff;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.viewer img.svg-base {
  display: block;
  width: 100%;
  height: auto;
}

/* ===== 覆盖层容器 ===== */
.overlay-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ===== 单个节点覆盖层 ===== */
.node-overlay {
  position: absolute;
  border-radius: 3px;
  pointer-events: auto;
  cursor: pointer;
  background: var(--overlay-bg);
  border: 1px solid transparent;
  transition: transform 0.25s ease, background 0.2s ease,
    border-color 0.2s ease, box-shadow 0.25s ease;
}

.node-overlay:hover {
  background: var(--overlay-hover-bg);
  border-color: var(--overlay-border);
  z-index: 10;
  transform: scale(1.08);
  box-shadow: 0 0 14px 3px var(--accent-glow);
}

/* ===== Tooltip ===== */
.node-overlay .tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.75rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.375rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  z-index: 100;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-overlay:hover .tooltip {
  opacity: 1;
}

/* ===== 加载状态 ===== */
.loading-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.loading-indicator .spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--bg-card);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 0.4rem;
}

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

/* ===== 底部提示 ===== */
.footer {
  width: 100%;
  text-align: center;
  padding: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.6;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .header {
    padding: 0.75rem 1rem 0;
    flex-direction: column;
    align-items: flex-start;
  }

  .header h1 {
    font-size: 1.1rem;
  }

  .tab-btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }

  .viewer-wrapper {
    padding: 0.75rem 1rem 1.5rem;
  }
}

/* ===== AI 助手对话框 ===== */
.ai-chat {
  position: fixed;
  left: 1.25rem;
  bottom: 1.25rem;
  z-index: 9999;
  font-family: inherit;
}

/* 触发按钮 */
.ai-chat-toggle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(56, 189, 248, 0.45);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.ai-chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(56, 189, 248, 0.6);
}

/* 面板 */
.ai-chat-panel {
  position: absolute;
  bottom: 64px;
  left: 0;
  width: 360px;
  height: 480px;
  border-radius: 1rem;
  background: rgba(30, 41, 59, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(56, 189, 248, 0.18);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom left;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.22s ease;
  transform: scale(1);
  opacity: 1;
}

/* 折叠态 */
.ai-chat.collapsed .ai-chat-panel {
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
}

/* 头部 */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.6);
  border-bottom: 1px solid rgba(56, 189, 248, 0.12);
}

.ai-chat-header span {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.03em;
}

.ai-chat-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.ai-chat-close:hover {
  background: rgba(248, 113, 113, 0.2);
  color: #f87171;
}

/* 消息区 */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.25);
  border-radius: 4px;
}

/* 消息行 */
.ai-msg {
  display: flex;
  max-width: 85%;
}

.ai-msg-user {
  align-self: flex-end;
}

.ai-msg-bot {
  align-self: flex-start;
}

/* 气泡 */
.ai-msg-bubble {
  padding: 0.55rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.85rem;
  line-height: 1.55;
  word-break: break-word;
}

.ai-msg-user .ai-msg-bubble {
  background: var(--accent);
  color: var(--bg-primary);
  border-bottom-right-radius: 0.25rem;
}

.ai-msg-bot .ai-msg-bubble {
  background: rgba(51, 65, 85, 0.85);
  color: var(--text-primary);
  border-bottom-left-radius: 0.25rem;
}

/* "正在输入"动画 */
.ai-msg-typing .ai-msg-bubble::after {
  content: "";
  display: inline-block;
  width: 1.6em;
  text-align: left;
  animation: dotPulse 1.2s steps(4, end) infinite;
}

@keyframes dotPulse {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
  100% { content: ""; }
}

/* 输入区 */
.ai-chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid rgba(56, 189, 248, 0.12);
  background: rgba(15, 23, 42, 0.4);
}

.ai-chat-input-area input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.ai-chat-input-area input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.ai-chat-input-area input:focus {
  border-color: var(--accent);
}

.ai-chat-input-area button {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: none;
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}

.ai-chat-input-area button:hover {
  background: #7dd3fc;
  transform: scale(1.04);
}

.ai-chat-input-area button:active {
  transform: scale(0.97);
}

/* ===== 节点详情图片悬浮窗 ===== */
.image-popover {
  position: fixed;
  z-index: 10000;
  max-width: 300px;
  padding: 6px;
  border-radius: 0.625rem;
  border: 1px solid rgba(56, 189, 248, 0.25);
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  display: none;
}

.image-popover.visible {
  display: block;
}

.image-popover.show {
  opacity: 1;
}

.image-popover.locked {
  pointer-events: auto;
}

.image-popover img {
  display: block;
  width: 100%;
  border-radius: 0.375rem;
  background: var(--bg-card);
  min-height: 80px;
}

/* ===== 节点右键菜单 ===== */
.node-ctx-menu {
  position: fixed;
  z-index: 10001;
  min-width: 200px;
  padding: 4px 0;
  border-radius: 0.5rem;
  border: 1px solid rgba(56, 189, 248, 0.22);
  background: rgba(30, 41, 59, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  display: none;
  font-size: 0.8rem;
  color: var(--text-primary);
}

.node-ctx-menu.visible {
  display: block;
}

.node-ctx-menu-title {
  padding: 6px 12px;
  font-size: 0.7rem;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  user-select: none;
}

.node-ctx-menu-item {
  padding: 7px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease;
  user-select: none;
}

.node-ctx-menu-item:hover {
  background: rgba(56, 189, 248, 0.12);
}

.node-ctx-menu-item .ctx-label {
  color: var(--text-secondary);
  min-width: 52px;
}

.node-ctx-menu-item .ctx-value {
  color: var(--accent);
  font-family: "Consolas", "Monaco", monospace;
  word-break: break-all;
}

.node-ctx-menu-item .ctx-copied {
  margin-left: auto;
  color: #4ade80;
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.node-ctx-menu-item .ctx-copied.show {
  opacity: 1;
}

/* 响应式 */
@media (max-width: 768px) {
  .ai-chat {
    left: 0.75rem;
    bottom: 0.75rem;
  }

  .ai-chat-panel {
    width: calc(100vw - 2rem);
    height: 400px;
  }

  .image-popover {
    max-width: 220px;
  }
}
