/* ===== 指标树状图（超管 / 商户后台概览） ===== */

.mt-shell {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.mt-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.mt-head .mt-h-title { font-size: 13.5px; font-weight: 650; letter-spacing: 0.01em; }
.mt-head .mt-h-live {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
}
.mt-live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 var(--ok-soft);
  animation: mtPulse 2.2s ease-out infinite;
}
.mt-live-dot.stale { background: var(--warn); animation: none; }
@keyframes mtPulse {
  0% { box-shadow: 0 0 0 0 rgba(18, 161, 80, 0.4); }
  70% { box-shadow: 0 0 0 7px rgba(18, 161, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(18, 161, 80, 0); }
}
.mt-head .spacer { flex: 1; }
.mt-seg { display: inline-flex; background: var(--panel-3); border-radius: 9px; padding: 3px; gap: 2px; }
.mt-seg button {
  border: 0; background: transparent; color: var(--muted); font-size: 11.5px;
  padding: 5px 11px; border-radius: 7px; cursor: pointer; font-family: inherit;
  transition: background 0.16s ease, color 0.16s ease;
}
.mt-seg button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- 缩放条 ---------- */
.mt-zoom { display: inline-flex; align-items: center; background: var(--panel-3); border-radius: 9px; padding: 3px; gap: 2px; }
.mt-zoom button {
  border: 0; background: transparent; color: var(--muted); font-size: 13px; line-height: 1;
  min-width: 26px; height: 26px; padding: 0 6px; border-radius: 7px; cursor: pointer;
  font-family: inherit; display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.16s ease, color 0.16s ease;
}
.mt-zoom button:hover:not(:disabled) { background: var(--panel); color: var(--text); }
.mt-zoom button:disabled { opacity: 0.4; cursor: default; }
.mt-zoom .mt-zoom-val {
  min-width: 50px; font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--muted);
}
.mt-zoom .mt-zoom-val.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
.mt-stamp { font-size: 11px; color: var(--muted-2); font-variant-numeric: tabular-nums; }

/* 容器：内容放不下时（用户放大后）才出现滚动条，任何时候都不裁切内容 */
.mt-wrap {
  overflow: auto;
  padding: 6px 4px 10px;
  scrollbar-gutter: stable;       /* 只给右侧留滚动条位置，左侧不留空白 */
  overscroll-behavior: contain;
  cursor: default;
  touch-action: pan-x pan-y;      /* 手指可正常滑动，不锁死滚动 */
}
.mt-wrap.mt-zoomed { cursor: grab; }
.mt-wrap.mt-panning { cursor: grabbing; user-select: none; }
.mt-wrap::-webkit-scrollbar { width: 9px; height: 9px; }
.mt-wrap::-webkit-scrollbar-track { background: transparent; }
.mt-wrap::-webkit-scrollbar-thumb {
  background: var(--line-2); border-radius: 8px;
  border: 2px solid transparent; background-clip: content-box;
}
.mt-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted-2); background-clip: content-box; }

/* 缩放适配盒：尺寸 = 画布 × 实际缩放，保证容器与内容严格贴合。
   左右外边距由 JS 控制（装得下才居中），不能写死 auto：
   Safari / 微信内置浏览器对「比容器宽 + margin:auto」的元素会居中并向两侧溢出，
   左侧溢出的宽度滚动不到，表现就是「左边的方块看不到」。 */
.mt-fit { margin: 0; position: relative; flex: none; }

/* ---------- 画布：点阵底纹 + 缓慢漂移的光晕 ---------- */
.mt-canvas {
  position: relative;
  margin: 0;                 /* 必须为 0：缩放原点在左上角，居中会让放大后的右侧溢出 */
  isolation: isolate;
  transform-origin: 0 0;
  /* 不做 width/height 过渡：过渡期间画布尺寸与适配盒不同步，会瞬间露出裁切边 */
}
.mt-canvas::before {
  content: '';
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(circle, var(--line-2) 0.9px, transparent 0.9px);
  background-size: 21px 21px;
  background-position: 6px 6px;
  opacity: 0.5;
  -webkit-mask-image: radial-gradient(ellipse 78% 72% at 46% 48%, #000 30%, transparent 100%);
  mask-image: radial-gradient(ellipse 78% 72% at 46% 48%, #000 30%, transparent 100%);
}
.mt-glow {
  position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  border-radius: 16px;
}
.mt-glow::before,
.mt-glow::after {
  content: '';
  position: absolute;
  width: 520px; height: 520px; border-radius: 50%;
  will-change: transform;
}
.mt-glow::before {
  top: -180px; left: 2%;
  background: radial-gradient(circle at center, rgba(79, 110, 247, 0.16), rgba(79, 110, 247, 0) 68%);
  animation: mtDriftA 21s ease-in-out infinite alternate;
}
.mt-glow::after {
  right: 0; bottom: -220px;
  background: radial-gradient(circle at center, rgba(14, 165, 164, 0.14), rgba(14, 165, 164, 0) 68%);
  animation: mtDriftB 26s ease-in-out infinite alternate;
}
@keyframes mtDriftA {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(70px, 46px, 0) scale(1.14); }
}
@keyframes mtDriftB {
  from { transform: translate3d(0, 0, 0) scale(1.08); }
  to { transform: translate3d(-80px, -36px, 0) scale(0.94); }
}

.mt-links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; z-index: 1; }
.mt-link { fill: none; stroke: var(--line-2); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.mt-link.lvl1 { stroke: var(--accent); opacity: 0.3; stroke-width: 1.8; animation: mtFadeIn 0.9s ease both; }

/* 沿根→分组的曲线上流动的数据包 */
.mt-link.mt-flow {
  stroke: var(--accent);
  stroke-width: 3.2;
  stroke-dasharray: 1.5 34;
  opacity: 0.62;
  animation: mtPackets 2.8s linear infinite;
}
@keyframes mtPackets {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -71; }
}

/* 分叉线：结构变化时重放一次「生长」（pathLength=1 归一化） */
.mt-link.lvl2 { stroke-dasharray: 1; stroke-dashoffset: 0; }
.mt-link.lvl2.draw { animation: mtDraw 1s cubic-bezier(0.32, 0.72, 0.28, 1) both; }
@keyframes mtDraw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}
@keyframes mtFadeIn {
  from { opacity: 0; }
  to { opacity: 0.3; }
}

/* ---------- 窄屏纵向堆叠布局 ---------- */
.mt-slot-panel { z-index: 1; }
.mt-panel {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.mt-canvas.mt-stack .mt-node.mt-root { padding: 14px 16px; }
.mt-canvas.mt-stack .mt-node.mt-group { padding: 7px 12px 7px 16px; }
.mt-canvas.mt-stack .mt-node.mt-group .mt-value b { font-size: 21px; }
.mt-canvas.mt-stack .mt-node.mt-group .mt-value { margin-top: 1px; }
.mt-canvas.mt-stack .mt-node.mt-metric,
.mt-canvas.mt-stack .mt-node.mt-merchant,
.mt-canvas.mt-stack .mt-node.mt-agent { box-shadow: var(--shadow-sm); }
/* 面板里的指标卡窄，隐藏迷你曲线时提示文字可以占满一行 */
.mt-node.mt-no-spark .mt-mini-spark { display: none; }
.mt-node.mt-no-spark .mt-leaf-foot .mt-hint { max-width: none; }

/* ---------- 节点：slot 负责定位，node 负责自身动画 ---------- */

.mt-shell { --mt-sweep: rgba(99, 122, 255, 0.12); }
[data-theme="dark"] .mt-shell { --mt-sweep: rgba(150, 172, 255, 0.16); }

.mt-slot {
  position: absolute;
  left: 0; top: 0;
  z-index: 2;
  transform: translate3d(var(--x, 0px), var(--y, 0px), 0);
  will-change: transform;
  transition:
    transform 0.44s cubic-bezier(0.22, 0.72, 0.28, 1),
    opacity 0.2s ease;
}
.mt-slot.mt-out { opacity: 0; pointer-events: none; }

.mt-node {
  position: relative;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 11px;
  overflow: hidden;
  animation: mtIn 0.52s cubic-bezier(0.2, 0.78, 0.3, 1) backwards;
  animation-delay: calc(var(--i, 0) * 18ms);
  transition:
    border-color 0.18s ease,
    box-shadow 0.22s ease,
    background 0.2s ease,
    transform 0.2s ease;
}
/* 方块表面：一道柔光按索引错峰扫过，数据像是被「巡检」了一遍 */
.mt-node::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(100deg, transparent 42%, var(--mt-sweep) 50%, transparent 58%);
  transform: translateX(-130%);
  opacity: 0;
  animation: mtSweep 9s cubic-bezier(0.45, 0, 0.55, 1) infinite;
  animation-delay: calc(var(--i, 0) * 220ms);
}
@keyframes mtSweep {
  0%, 60% { transform: translateX(-130%); opacity: 0; }
  67% { opacity: 0.95; }
  87%, 100% { transform: translateX(130%); opacity: 0; }
}

.mt-node:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(79, 110, 247, 0.14);
  transform: translateY(-1px);
}

/* 入场 */
@keyframes mtIn {
  from { opacity: 0; transform: translate3d(-16px, 0, 0) scale(0.965); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

/* 数值变化：独立的光环层，不干扰方块自身的浮动/入场动画 */
.mt-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 0 0 0 rgba(79, 110, 247, 0);
}
.mt-ring.on { animation: mtBumpRing 0.9s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes mtBumpRing {
  0% { box-shadow: 0 0 0 0 rgba(79, 110, 247, 0.34), 0 0 0 0 rgba(79, 110, 247, 0.18); }
  55% { box-shadow: 0 0 0 5px rgba(79, 110, 247, 0.07), 0 0 14px 2px rgba(79, 110, 247, 0.16); }
  100% { box-shadow: 0 0 0 11px rgba(79, 110, 247, 0), 0 0 0 0 rgba(79, 110, 247, 0); }
}

.mt-title, .mt-name {
  font-size: 11.5px; line-height: 1.35; color: var(--muted); letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mt-name { font-size: 12px; color: var(--text-2); }

.mt-value { display: flex; align-items: baseline; gap: 4px; margin-top: 3px; }
.mt-value b {
  font-size: 21px; font-weight: 700; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; color: var(--text);
  transition: color 0.2s ease; display: inline-block;
}
.mt-value.big b { font-size: 28px; }
.mt-unit { font-style: normal; font-size: 10.5px; color: var(--muted-2); }
.mt-hint {
  font-size: 10.5px; color: var(--muted-2); margin-top: 3px; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mt-total { margin-left: 6px; opacity: 0.8; }

/* 根节点：渐变强调 + 定期扫光 */
.mt-node.mt-root {
  background: var(--grad); border: 0; color: #fff;
  box-shadow: 0 12px 28px rgba(79, 110, 247, 0.28);
  padding: 14px 16px;
  animation: mtIn 0.52s cubic-bezier(0.2, 0.78, 0.3, 1) backwards, mtRootGlow 5.6s ease-in-out infinite;
  animation-delay: 0ms, 0.6s;
}
@keyframes mtRootGlow {
  0%, 100% { box-shadow: 0 12px 28px rgba(79, 110, 247, 0.26); }
  50% { box-shadow: 0 16px 40px rgba(79, 110, 247, 0.42); }
}
.mt-node.mt-root::before {
  content: '';
  position: absolute; top: -40%; left: -70%;
  width: 42%; height: 180%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0));
  transform: skewX(-18deg);
  pointer-events: none;
  animation: mtShine 7.5s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
@keyframes mtShine {
  0%, 58% { transform: translateX(0) skewX(-18deg); opacity: 0; }
  64% { opacity: 0.9; }
  86%, 100% { transform: translateX(420%) skewX(-18deg); opacity: 0; }
}
.mt-node.mt-root .mt-title { color: rgba(255, 255, 255, 0.82); font-size: 12.5px; font-weight: 600; }
.mt-node.mt-root .mt-value b { color: #fff; }
.mt-node.mt-root .mt-unit { color: rgba(255, 255, 255, 0.75); }
.mt-node.mt-root .mt-hint { color: rgba(255, 255, 255, 0.72); }
.mt-node.mt-root .mt-spark-line { stroke: rgba(255, 255, 255, 0.95); }
.mt-node.mt-root .mt-spark-area { fill: rgba(255, 255, 255, 0.16); }
.mt-node.mt-root .mt-spark-dot { fill: #fff; }
.mt-node.mt-root:hover { border-color: transparent; box-shadow: 0 16px 34px rgba(79, 110, 247, 0.36); }
.mt-node.mt-root::after { display: none; } /* 根节点已有扫光，避免两道光打架 */
.mt-dot {
  position: absolute; right: 0; width: 7px; height: 7px; border-radius: 50%;
  background: #fff; transform: translate(50%, -50%); opacity: 0.9;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7);
  animation: mtDotPulse 3s ease-out infinite;
}
@keyframes mtDotPulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.55); }
  70% { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

/* 分组节点 */
.mt-node.mt-group {
  background: var(--panel-2);
  padding-left: 15px;
  /* 浮动用独立的 translate 属性，和 transform 类动画互不覆盖 */
  animation: mtIn 0.52s cubic-bezier(0.2, 0.78, 0.3, 1) backwards, mtFloat 7.2s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 18ms), calc(var(--i, 0) * 130ms + 680ms);
}
@keyframes mtFloat {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -2px; }
}
.mt-node.mt-group::before {
  content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
  animation: mtBarBreath 3.8s ease-in-out infinite;
}
@keyframes mtBarBreath {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.95; }
}
.mt-group-head { display: flex; align-items: center; gap: 6px; }
.mt-group-head .mt-title {
  flex: 1; font-size: 12.5px; color: var(--text); font-weight: 600; letter-spacing: 0.01em;
}
.mt-toggle {
  flex: none; width: 18px; height: 18px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: 0.16s ease;
}
.mt-toggle:hover { color: var(--accent); border-color: var(--accent); }
.mt-toggle svg { transition: transform 0.24s cubic-bezier(0.3, 0.8, 0.3, 1); }
.mt-node.collapsed .mt-toggle svg { transform: rotate(-90deg); }
.mt-node.mt-group .mt-value b { font-size: 22px; }

/* 叶子指标 */
.mt-node.mt-metric { background: var(--panel); }
.mt-node.mt-metric:hover { background: var(--panel-2); }
.mt-leaf-val b { font-size: 16px; font-weight: 650; }
.mt-node.mt-merchant { background: var(--accent-soft); border-color: transparent; }
.mt-node.mt-merchant:hover { border-color: var(--accent); }
.mt-node.mt-agent { background: var(--panel-2); }
.mt-node.mt-merchant .mt-leaf-val b, .mt-node.mt-agent .mt-leaf-val b { font-size: 15.5px; }

.mt-leaf-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.mt-leaf-top .mt-name { flex: 1; min-width: 0; }
.mt-leaf-val { display: flex; align-items: baseline; gap: 2px; flex: none; }
.mt-leaf-foot { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.mt-leaf-foot .mt-hint { flex: 1; min-width: 0; margin: 0; }
.mt-mini-spark { width: 44px; height: 14px; flex: none; opacity: 0.85; display: block; }
.mt-mini-spark .mt-spark { height: 14px; }

/* 迷你趋势 */
.mt-spark-wrap { position: absolute; right: 12px; bottom: 8px; width: calc(100% - 24px); height: 26px; opacity: 0.9; }
.mt-node.mt-group .mt-spark-wrap { right: 9px; bottom: 8px; width: 92px; height: 26px; opacity: 0.62; }
.mt-node.mt-group .mt-hint { max-width: calc(100% - 104px); }
.mt-node.mt-root .mt-spark-wrap { bottom: 10px; height: 30px; }
.mt-spark-wrap.inline { position: static; width: 52px; height: 16px; }
.mt-spark { width: 100%; height: 100%; display: block; }
.mt-spark-line {
  fill: none; stroke: var(--accent); stroke-width: 1.5;
  stroke-linejoin: round; stroke-linecap: round;
}
.mt-spark-area { fill: var(--accent-soft); }
.mt-spark-dot { fill: var(--accent); }
/* 曲线首次绘制：从左到右长出来 */
.mt-spark.mt-spark-in .mt-spark-line { animation: mtSparkDraw 1.1s cubic-bezier(0.3, 0.8, 0.3, 1) both; }
.mt-spark.mt-spark-in .mt-spark-area { animation: mtFadeInSoft 1.1s ease both; }
.mt-spark.mt-spark-in .mt-spark-dot { animation: mtPop 0.5s 0.85s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
@keyframes mtSparkDraw {
  from { stroke-dasharray: 1; stroke-dashoffset: 1; }
  to { stroke-dasharray: 1; stroke-dashoffset: 0; }
}
@keyframes mtFadeInSoft {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes mtPop {
  from { opacity: 0; transform: scale(0.2); }
  to { opacity: 1; transform: scale(1); }
}

/* 用量进度条 */
.mt-bar {
  position: absolute; left: 15px; right: 12px; bottom: 10px; height: 3px;
  background: var(--panel-3); border-radius: 2px; overflow: hidden;
}
.mt-bar i {
  display: block; height: 100%; width: 0; background: var(--grad); border-radius: 2px;
  transition: width 0.75s cubic-bezier(0.25, 0.75, 0.3, 1);
}

/* 数值变化高亮（滚动结束时的强调色） */
.mt-value b.up, .mt-leaf-val b.up { color: var(--ok); animation: mtBump 0.7s ease; }
.mt-value b.down, .mt-leaf-val b.down { color: var(--danger); animation: mtBump 0.7s ease; }
@keyframes mtBump {
  0% { transform: scale(1); }
  35% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

.mt-foot {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 18px 12px; font-size: 11px; color: var(--muted-2);
}
.mt-legend { display: inline-flex; align-items: center; gap: 5px; }
.mt-legend i { width: 8px; height: 8px; border-radius: 3px; display: inline-block; }

@media (max-width: 860px) {
  .mt-head { padding: 12px 14px 10px; }
  /* 手机端卡片是 overflow:hidden + 圆角，容器上下多留呼吸，避免内容贴边被圆角切到 */
  .mt-wrap { padding: 8px 4px 12px; }
  .mt-foot { padding: 8px 14px 10px; }
}
@media (max-width: 560px) {
  .mt-head { gap: 8px; }
  .mt-head .mt-stamp { display: none; }
  .mt-zoom { padding: 2px; }
  .mt-zoom button { min-width: 24px; height: 24px; }
  .mt-zoom .mt-zoom-val { min-width: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  .mt-live-dot, .mt-value b.up, .mt-value b.down,
  .mt-node, .mt-node::after, .mt-node.mt-root::before, .mt-ring.on,
  .mt-link.mt-flow, .mt-link.lvl1, .mt-link.lvl2.draw,
  .mt-spark.mt-spark-in *, .mt-node.mt-group::before, .mt-dot,
  .mt-glow::before, .mt-glow::after { animation: none !important; }
  .mt-node, .mt-slot, .mt-bar i, .mt-canvas { transition: none !important; }
}
