* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; } /* 防止 flex 等显示规则覆盖 hidden 属性 */
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: #f4f6f9;
  color: #2b3440;
}

/* ---------- 工具栏 ---------- */
#toolbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid #e3e8ee;
  box-shadow: 0 1px 4px rgba(40,60,90,.08);
}
#mapName {
  width: 150px; padding: 5px 8px;
  border: 1px solid #ccd6e0; border-radius: 6px;
  font-size: 13px; outline: none;
}
#mapName:focus { border-color: #2f6fb0; }
.btns { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#toolbar button {
  padding: 5px 11px; font-size: 13px;
  border: 1px solid #ccd6e0; border-radius: 6px;
  background: #fff; color: #2b3440; cursor: pointer;
}
#toolbar button:hover { background: #f0f4f8; }
#toolbar button:active { transform: translateY(1px); }
#toolbar button.primary { background: #2f6fb0; border-color: #2f6fb0; color: #fff; }
#toolbar button.primary:hover { background: #2a629c; }
#toolbar button.danger { color: #c0392b; border-color: #e0b4ae; }
#toolbar button.danger:hover { background: #fdf0ee; }
.sep { width: 1px; height: 20px; background: #dde4ec; margin: 0 2px; }

/* 工具栏收起态：整条只保留一行（名字 + 按钮同排） */
#toolbar.collapsed { flex-wrap: nowrap; overflow: hidden; }
#toolbar.collapsed #mapName { width: 110px; flex: none; }
.btns.collapsed {
  flex-wrap: nowrap; max-height: 34px;
  overflow-x: auto; overflow-y: hidden;   /* 按钮超出屏宽时可横滑 */
  scrollbar-width: none; -ms-overflow-style: none;
}
.btns.collapsed::-webkit-scrollbar { display: none; }
.btns.collapsed .sep { flex: none; }
#btnToggleBar { white-space: nowrap; font-size: 12px; }
#btnFullscreen { white-space: nowrap; font-size: 12px; }

/* 伪全屏：保留工具栏（文件名 + 退出全屏按钮），其余界面隐藏 */
body.fs .btns, body.fs #hint, body.fs #footer,
body.fs #status, body.fs #zoomCtl { display: none; }

/* 手机收起态：按钮文字太多，整组隐藏（只留文件名 + 全屏 + 展开按钮） */
@media (max-width: 768px) {
  .btns.collapsed { display: none; }
}

/* ---------- 左侧缩放控件 ---------- */
#zoomCtl {
  position: fixed; left: 10px; top: 50%; transform: translateY(-50%);
  z-index: 20; display: flex; flex-direction: column;
  align-items: center; gap: 4px;
}
#zoomCtl button {
  width: 34px; height: 34px; font-size: 18px; line-height: 1;
  border: 1px solid #ccd6e0; border-radius: 8px;
  background: rgba(255,255,255,.94); color: #2b3440; cursor: pointer;
  box-shadow: 0 1px 4px rgba(40,60,90,.08);
}
#zoomCtl button:hover { background: #f0f4f8; }
#zoomCtl button:active { transform: translateY(1px); }
#zoomPct { font-size: 11px; color: #8a97a5; min-width: 36px; text-align: center; }

/* ---------- 画布 ---------- */
#canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;   /* 关键：允许 pointer 事件自定义手势（拖拽/双指缩放） */
  cursor: grab;
}
#canvas.panning { cursor: grabbing; }

#edges path { fill: none; }

.node { cursor: pointer; }
.node.dragging { cursor: grabbing; }

#editor {
  position: fixed; z-index: 30; display: none;
  padding: 6px 8px;
  border: 2px solid #2f6fb0; border-radius: 8px;
  background: #fff; color: #2b3440;
  font-family: inherit;
  text-align: center;
  resize: none; outline: none;
  box-shadow: 0 4px 16px rgba(40,60,90,.25);
  overflow: hidden;
  line-height: 1.45;
}
#editor.show { display: block; }

/* ---------- 状态栏 / 提示 ---------- */
#status {
  position: fixed; left: 10px; bottom: 8px; z-index: 20;
  font-size: 12px; color: #8a97a5;
  background: rgba(255,255,255,.85);
  padding: 3px 8px; border-radius: 10px;
  pointer-events: none;
}
#hint {
  position: fixed; right: 10px; bottom: 8px; z-index: 20;
  font-size: 12px; color: #a8b3c0;
  background: rgba(255,255,255,.85);
  padding: 3px 8px; border-radius: 10px;
  pointer-events: none;
}
@media (max-width: 640px) {
  #hint { display: none; }
  #mapName { width: 110px; }
}

#toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  z-index: 60; padding: 8px 18px; /* 高于弹窗遮罩，报错可见 */
  background: rgba(43,52,64,.92); color: #fff;
  font-size: 13px; border-radius: 8px;
  pointer-events: none; opacity: 0; transition: opacity .25s;
}
#toast.show { opacity: 1; }

/* ---------- 底部版权 ---------- */
#footer {
  position: fixed; bottom: 6px; left: 0; right: 0;
  text-align: center; z-index: 5;
  font-size: 12px; color: #a8b3c0;
  pointer-events: none; /* 不挡画布操作 */
  user-select: none; -webkit-user-select: none;
}
#footer a { color: #8a97a5; text-decoration: none; pointer-events: auto; }
#footer a:hover { color: #2f6fb0; text-decoration: underline; }

/* ---------- 云端弹窗 ---------- */
.dlg-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,30,45,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 12px;
}
.dlg-mask[hidden] { display: none; }
.dlg {
  width: min(640px, 94vw);
  background: #fff; border-radius: 10px;
  box-shadow: 0 10px 40px rgba(20,40,80,.3);
  padding: 14px 16px;
  max-height: 82vh; overflow: auto;
}
.dlg-title {
  font-size: 15px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.dlg-x { border: none; background: none; font-size: 16px; cursor: pointer; color: #8a97a5; }
.dlg-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.dlg-row input {
  flex: 1; min-width: 130px; padding: 6px 8px;
  border: 1px solid #ccd6e0; border-radius: 6px;
  font-size: 13px; outline: none;
}
.dlg-row input:focus { border-color: #2f6fb0; }
.dlg-tip { font-size: 12px; color: #8a97a5; margin-bottom: 8px; }
.dlg-sec { font-size: 13px; font-weight: 600; color: #5c6b7a; margin: 10px 0 8px; }
.dlg-list {
  border: 1px solid #e3e8ee; border-radius: 8px;
  margin-bottom: 10px; max-height: 180px; overflow: auto;
}
.dlg-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; font-size: 13px;
  border-bottom: 1px solid #f0f3f6;
}
.dlg-item:last-child { border-bottom: none; }
.dlg-fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-meta { font-size: 12px; color: #a8b3c0; white-space: nowrap; }
.dlg-btn {
  padding: 3px 9px; font-size: 12px;
  border: 1px solid #ccd6e0; border-radius: 6px;
  background: #fff; cursor: pointer;
}
.dlg-btn:hover { background: #f0f4f8; }
.dlg-btn.danger { color: #c0392b; border-color: #e0b4ae; }
.dlg-empty { padding: 14px; text-align: center; color: #a8b3c0; font-size: 13px; }

/* ---------- 手机端弹窗适配：文件名独占一行 ---------- */
@media (max-width: 768px) {
  /* 输入行：文件名整行显示，按钮换到下一行 */
  .dlg-row { row-gap: 6px; }
  .dlg-row input { flex: 1 1 100%; }

  /* 文件列表：第一行文件名（可换行），第二行 日期/大小 + 操作按钮 */
  .dlg-item { flex-wrap: wrap; row-gap: 4px; }
  .dlg-fn { flex: 1 1 100%; white-space: normal; word-break: break-all; }
  .dlg-meta { order: 1; margin-right: auto; white-space: normal; }
  .dlg-btn { order: 2; }
}

/* 弹窗内的主按钮（.primary 原本只在工具栏作用域生效） */
#cloudMask button.primary {
  padding: 6px 14px; font-size: 13px;
  background: #2f6fb0; border: 1px solid #2f6fb0;
  color: #fff; border-radius: 6px; cursor: pointer;
}
#cloudMask button.primary:hover { background: #2a629c; }
#cloudMask button.primary:active { transform: translateY(1px); }

/* ---------- 账号区 ---------- */
.acct {
  border: 1px solid #e3e8ee; border-radius: 8px;
  padding: 8px 10px; margin-bottom: 8px;
  background: #f8fafc;
}
.acct-row { display: flex; gap: 8px; padding: 2px 0; font-size: 12px; }
.acct-k { width: 34px; color: #8a97a5; flex: none; }
.acct-v {
  font-family: Menlo, Consolas, monospace;
  word-break: break-all; color: #2b3440;
}
.acct-v.masked {
  color: #a8b3c0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 二维码弹窗 ---------- */
.qr-box { display: flex; justify-content: center; margin-bottom: 10px; }
.qr-box img { width: 220px; height: 220px; image-rendering: pixelated; }
.qr-text {
  width: 100%; min-height: 56px; margin-bottom: 8px;
  padding: 6px 8px; border: 1px solid #ccd6e0; border-radius: 6px;
  font-size: 11px; font-family: Menlo, Consolas, monospace;
  color: #5c6b7a; resize: vertical; outline: none;
}
/* 节点内容编辑/查看区：随显示区域自适应（约 40% 视口高） */
.note-text {
  width: 100%;
  height: clamp(180px, 40vh, 480px);
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid #ccd6e0; border-radius: 6px;
  font-size: 15px; line-height: 1.6;
  color: #2b3440; resize: vertical; outline: none;
}
.note-text:focus { border-color: #2f6fb0; }
#scanBox { margin-bottom: 8px; }
#scanVideo {
  width: 100%; max-height: 240px;
  border-radius: 8px; background: #000; display: block;
}
#cloudMask button.danger, #qrMask button.danger { color: #c0392b; border-color: #e0b4ae; }
#cloudMask button.danger:hover, #qrMask button.danger:hover { background: #fdf0ee; }

/* ---------- 节点右键菜单 ---------- */
svg {
  touch-action: none; /* 关键：禁止浏览器接管触摸手势，否则 iPad 长按会被 pointercancel 终止 */
}
svg, svg * {
  -webkit-touch-callout: none; /* 阻止 iOS 长按弹出系统菜单 */
  -webkit-user-select: none;
  user-select: none;
}
#ctxMenu {
  position: fixed; z-index: 70; min-width: 160px;
  background: #fff; border: 1px solid #dde4ec; border-radius: 8px;
  box-shadow: 0 6px 24px rgba(20,40,80,.18);
  padding: 4px;
}
#ctxMenu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; font-size: 13px;
  border: none; background: none; border-radius: 6px;
  cursor: pointer; color: #2b3440;
}
#ctxMenu button:hover { background: #eaf3fb; }

/* ---------- 内容与附件弹窗 ---------- */
.note-title {
  font-weight: 400; font-size: 13px; color: #5c6b7a;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 200px; display: inline-block; vertical-align: bottom;
}
