/* ==========================================================================
   思维导图（无限画布）— 独立样式文件，只影响 #mindmapEditor，不碰其他项目类型
   ========================================================================== */

/* 右侧撑满、不留内边距：由 style.css 里 .main:has(#episodeView…) 统一处理 */
/* 这个文件里的灰色是导图画布专用的冷灰，集中在这里，要改只改这几个 */
#mindmapEditor {
  --mm-bg: #f6f7f9;       /* 画布底色 */
  --mm-dot: #cfd3db;      /* 画布网格点 */
  --mm-edge: #d8dce5;     /* 节点卡片描边 */
  --mm-sep: #e3e6ec;      /* 备注上方虚线 */
  --mm-hint: #a5aab5;     /* 输入提示字 */
  --mm-img-bg: #e8eaee;   /* 图片占位底色 */
  --mm-note: #555;        /* 备注文字 */
}
#mindmapEditor {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--mm-bg);
}

/* ---------- 顶部工具条 ---------- */
.mm-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  z-index: 5;
}
.mm-btn {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--black);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.4;
}
.mm-btn:hover { border-color: var(--black); background: var(--paper); }
.mm-btn:disabled { opacity: .35; cursor: default; }
.mm-btn:disabled:hover { border-color: var(--line); background: var(--white); }
.mm-sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.mm-zoom-label { min-width: 44px; text-align: center; padding-left: 4px; padding-right: 4px; }
.mm-hint { font-size: 12px; color: var(--mid); margin-left: auto; }
#mindmapEditor:not(.mm-edit) .mm-edit-only { display: none !important; }

/* ---------- 画布 ---------- */
.mm-viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--mm-bg);
  background-image: radial-gradient(var(--mm-dot) 1px, transparent 1px);
  background-size: 22px 22px;
}
.mm-viewport.panning { cursor: grabbing; }
.mm-world {
  position: absolute;
  left: 0; top: 0;
  width: 0; height: 0;
  transform-origin: 0 0;
}
.mm-svg {
  position: absolute;
  left: 0; top: 0;
  width: 1px; height: 1px;
  overflow: visible;
  pointer-events: none;
}
.mm-link {
  fill: none;
  stroke-width: 3.5;
  stroke-linecap: round;
  pointer-events: none;
}
.mm-link-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: none;
}
.mm-edit .mm-link-hit { pointer-events: stroke; cursor: pointer; }
.mm-link.sel { stroke-width: 6; }
.mm-link-del { cursor: pointer; pointer-events: all; }
.mm-link-del circle { fill: var(--accent); stroke: var(--white); stroke-width: 2; }
.mm-link-del text { fill: var(--black); font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.mm-link-temp { fill: none; stroke-width: 3; stroke-dasharray: 7 6; stroke-linecap: round; pointer-events: none; }

/* ---------- 节点 ---------- */
.mm-nodes { position: absolute; left: 0; top: 0; }
.mm-node {
  position: absolute;
  --c: #00a8e8;
}
.mm-card {
  position: relative;
  background: var(--white);
  border: 1px solid var(--mm-edge);
  border-left: 5px solid var(--c);
  border-radius: 8px;
  padding: 7px 12px 7px 10px;
  width: max-content;
  max-width: 360px;
  min-width: 60px;
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  cursor: default;
}
.mm-edit .mm-node { cursor: move; }
.mm-edit .mm-card { cursor: move; }
.mm-node.sel .mm-card { box-shadow: 0 0 0 2px var(--c), 0 6px 18px rgba(0,0,0,.14); }
.mm-node.drop-target .mm-card { box-shadow: 0 0 0 3px var(--accent), 0 6px 18px rgba(0,0,0,.18); }
.mm-node.file-over .mm-card { outline: 2px dashed var(--c); outline-offset: 3px; }

/* 自动撑宽 + 自动换行的文本框：隐藏的镜像文字决定大小，textarea 叠在上面 */
.mm-auto {
  display: inline-grid;
  max-width: 320px;
  vertical-align: top;
}
.mm-auto::after {
  content: attr(data-v) " ";
  grid-area: 1 / 1;
  visibility: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
}
.mm-auto > textarea {
  grid-area: 1 / 1;
  width: 100%;
  min-width: 0;
  resize: none;
  overflow: hidden;
  border: none !important;
  outline: none !important;
  background: transparent !important;
  box-shadow: none !important;
  margin: 0;
  display: block;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
}
.mm-auto::after, .mm-auto > textarea {
  font-family: inherit;
  padding: 1px 2px;
  line-height: 1.5;
}
.mm-t { display: grid; }
.mm-t.mm-auto { display: inline-grid; }
.mm-t::after, .mm-t > textarea { font-size: 14px; font-weight: 700; color: var(--black); }
.mm-n { display: none; margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--mm-sep); }
.mm-n.mm-auto { display: none; }
.mm-n.open.mm-auto, .mm-n.has.mm-auto { display: inline-grid; }
.mm-n::after, .mm-n > textarea { font-size: 12.5px; font-weight: 400; color: var(--mm-note); line-height: 1.55; }
.mm-n > textarea:focus { color: var(--black); }
.mm-text { display: flex; flex-direction: column; align-items: flex-start; }

/* 只读：没有内容的标题不占位 */
#mindmapEditor:not(.mm-edit) .mm-t.empty { display: none; }
#mindmapEditor:not(.mm-edit) .mm-card.blank { min-width: 34px; min-height: 22px; }
#mindmapEditor:not(.mm-edit) .mm-auto > textarea { pointer-events: none; }
.mm-edit .mm-auto > textarea::placeholder { color: var(--mm-hint); font-weight: 400; }

/* 图片宫格：1 张撑满，2 张起可切 2 / 3 列 */
.mm-imgs { display: grid; gap: 4px; margin-top: 7px; width: var(--iw, 240px); }
.mm-imgs.cols-1 { --iw: 240px; grid-template-columns: 1fr; }
.mm-imgs.cols-2 { --iw: 264px; grid-template-columns: repeat(2, 1fr); }
.mm-imgs.cols-3 { --iw: 330px; grid-template-columns: repeat(3, 1fr); }
.mm-imgs:empty { display: none; }
.mm-img { position: relative; border-radius: 4px; overflow: hidden; background: var(--mm-img-bg); aspect-ratio: 16 / 10; }
.mm-imgs.cols-1 .mm-img { aspect-ratio: auto; max-height: 240px; }
.mm-img img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; -webkit-user-drag: none; }
.mm-imgs.cols-1 .mm-img img { height: auto; max-height: 240px; object-fit: contain; }
.mm-img-del {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; padding: 0;
  border-radius: 50%; border: none; background: rgba(0,0,0,.65); color: var(--white);
  font-size: 11px; line-height: 20px; text-align: center; cursor: pointer; display: none;
}
.mm-edit .mm-img:hover .mm-img-del { display: block; }

/* 选中/悬停时节点上方的小工具条（不占节点内部空间） */
.mm-tools {
  position: absolute;
  left: 0; bottom: 100%;
  padding-bottom: 6px;
  display: none;
  z-index: 30;
  cursor: default;
}
.mm-tools-in {
  display: flex; align-items: center; gap: 5px;
  background: var(--black); padding: 4px 8px; border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); white-space: nowrap;
}
.mm-edit .mm-node:hover .mm-tools,
.mm-edit .mm-node.sel .mm-tools { display: block; }
.mm-sw { width: 15px; height: 15px; border-radius: 50%; border: 2px solid transparent; padding: 0; cursor: pointer; background: var(--sc); }
.mm-sw.on { border-color: var(--white); }
.mm-tbtn { background: transparent; color: var(--white); border: none; font-size: 12px; padding: 2px 5px; border-radius: 4px; cursor: pointer; }
.mm-tbtn:hover { background: var(--w-16); }
.mm-tbtn.danger:hover { background: var(--accent); color: var(--black); }
.mm-tsep { width: 1px; height: 14px; background: var(--w-28); }

/* 右侧：连线把手（拖出去连别的节点）+ 一键新增子节点 */
.mm-port {
  position: absolute; right: -8px; top: 50%; margin-top: -8px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--c); border: 2.5px solid var(--white); box-shadow: 0 1px 4px rgba(0,0,0,.3);
  cursor: crosshair; display: none; z-index: 12; touch-action: none;
}
.mm-add {
  position: absolute; right: -36px; top: 50%; margin-top: -11px;
  width: 22px; height: 22px; padding: 0; border-radius: 50%;
  background: var(--c); color: var(--white); border: 2px solid var(--white); font-size: 14px; font-weight: 700; line-height: 18px;
  box-shadow: 0 2px 5px rgba(0,0,0,.25); cursor: pointer; display: none; z-index: 12;
}
.mm-edit .mm-node:hover .mm-port, .mm-edit .mm-node.sel .mm-port,
.mm-edit .mm-node:hover .mm-add, .mm-edit .mm-node.sel .mm-add { display: block; }
.mm-add:hover { transform: scale(1.15); }
/* 手机/触屏没有悬停：编辑时一直显示 */
@media (hover: none) {
  .mm-edit .mm-port, .mm-edit .mm-add { display: block; }
}

/* ---------- 图片灯箱 ---------- */
.mm-lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 99999;
  display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out;
}
.mm-lightbox img { max-width: 94vw; max-height: 92vh; border-radius: 8px; object-fit: contain; box-shadow: 0 12px 40px rgba(0,0,0,.5); }

@media (max-width: 720px) {
  .mm-hint { display: none; }
  .mm-toolbar { padding: 6px 8px; }
}
