:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #1b1f24;
  --muted: #6b7280;
  --accent: #2f6bff;
  --accent-soft: #eaf0ff;
  --root: #1f2937;
  --l1: #2f6bff;
  --l2: #0ea5a4;
  --l3: #8b5cf6;
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body { display: flex; flex-direction: column; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 52px; flex: 0 0 52px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: .2px; margin-right: 4px; }
.brand span { color: var(--accent); }
.map-title {
  border: 1px solid transparent; background: transparent; border-radius: 6px;
  padding: 6px 8px; font-size: 14px; font-weight: 600; color: var(--text);
  min-width: 180px; max-width: 320px; outline: none;
}
.map-title:hover { border-color: var(--line); }
.map-title:focus { border-color: var(--accent); background: #fff; }
.save-state { font-size: 12px; color: var(--muted); min-width: 56px; }
.save-state.dirty { color: #b45309; }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; transition: .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #c9d0da; background: #fafbfc; }
.btn:active { transform: translateY(1px); }
.btn-ai { border-color: #d8e2ff; background: var(--accent-soft); color: #1d4ed8; font-weight: 600; }
.btn-ai:hover { background: #dfe8ff; }
.btn.full { width: 100%; }
.icon-btn {
  border: none; background: transparent; font-size: 16px; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px;
}
.icon-btn:hover { background: #f1f3f6; color: var(--text); }

/* ---------- 布局 ---------- */
.layout { display: flex; flex: 1 1 auto; min-height: 0; }

/* 侧栏 */
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--panel);
  border-right: 1px solid var(--line); overflow-y: auto;
  transition: margin-left .18s ease;
}
.sidebar.collapsed { margin-left: -236px; }
.side-head {
  padding: 12px 14px 8px; font-size: 12px; font-weight: 600;
  color: var(--muted); letter-spacing: .3px;
  display: flex; align-items: center; justify-content: space-between;
}
.side-head .icon-btn { width: 24px; height: 24px; font-size: 15px; line-height: 1; }

/* 搜索 + 排序 */
.side-tools { display: flex; gap: 6px; padding: 0 12px 8px; }
.side-tools input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 7px;
  padding: 5px 8px; font-size: 12px; outline: none; background: #fbfcfd;
}
.side-tools input:focus { border-color: var(--accent); background: #fff; }
.side-tools select {
  border: 1px solid var(--line); border-radius: 7px; background: #fbfcfd;
  font-size: 12px; padding: 5px 4px; color: var(--muted); outline: none; max-width: 88px;
}

.map-list { padding: 0 8px 12px; }
.map-item {
  position: relative; display: flex; align-items: flex-start; gap: 6px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px; color: #333;
}
.map-item:hover { background: #f4f6f9; }
.map-item.active { background: var(--accent-soft); color: #1d4ed8; font-weight: 600; }
.map-item .nm {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  line-height: 1.35;
}
.map-item .meta {
  font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 2px;
  display: flex; gap: 6px; align-items: center; white-space: nowrap;
}
.map-item.active .meta { color: #5b7fd4; }
.map-item .meta .memo-dot { color: #b45309; }
.map-item .more {
  opacity: 0; border: none; background: transparent; color: var(--muted);
  font-size: 15px; padding: 0 3px; line-height: 1; border-radius: 5px; flex: 0 0 auto;
}
.map-item:hover .more, .map-item .more.on { opacity: 1; }
.map-item .more:hover { background: #e9edf3; color: var(--text); }
.empty-list { padding: 12px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.side-foot {
  padding: 8px 14px 12px; font-size: 11px; color: #9aa3af;
  border-top: 1px solid var(--line); margin-top: auto;
}
.sidebar { display: flex; flex-direction: column; }
.sidebar .map-list { flex: 1 1 auto; overflow-y: auto; }

/* 列表项操作菜单 */
.item-menu {
  position: fixed; z-index: 60; min-width: 132px; padding: 4px;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 8px 28px rgba(16,24,40,.14);
}
.item-menu button {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 7px 10px; font-size: 12.5px; border-radius: 6px; color: #374151;
}
.item-menu button:hover { background: #f3f5f9; }
.item-menu button.danger { color: var(--danger); }
.item-menu button.danger:hover { background: #fdecec; }
.item-menu .sep { height: 1px; background: var(--line); margin: 4px 2px; }


/* 画布 */
.canvas-wrap { flex: 1; position: relative; overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#canvas.dragging { cursor: grabbing; }

.empty-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--muted);
  pointer-events: none; text-align: center; padding: 0 24px;
}
.empty-hint h2 { font-size: 18px; color: #374151; margin: 0 0 8px; }
.empty-hint p { font-size: 13px; margin: 0; }

.zoombar {
  position: absolute; right: 16px; bottom: 56px; display: flex; align-items: center;
  gap: 2px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 2px; box-shadow: var(--shadow); font-size: 12px;
}
.zoombar button {
  border: none; background: transparent; width: 26px; height: 26px;
  border-radius: 6px; font-size: 15px; color: var(--muted);
}
.zoombar button:hover { background: #f1f3f6; color: var(--text); }
.zoombar span { min-width: 42px; text-align: center; color: var(--muted); }

.sheet-tabs {
  position: absolute; left: 0; right: 0; bottom: 0; height: 40px;
  display: flex; align-items: center; gap: 6px; padding: 0 12px;
  background: linear-gradient(to top, #fff, rgba(255,255,255,.9));
  border-top: 1px solid var(--line); overflow-x: auto;
}
.sheet-tab {
  border: 1px solid var(--line); background: #fff; padding: 5px 12px;
  border-radius: 999px; font-size: 12px; color: var(--muted); white-space: nowrap;
}
.sheet-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- AI 面板 ---------- */
.ai-panel {
  width: 300px; flex: 0 0 300px; background: var(--panel);
  border-left: 1px solid var(--line); display: flex; flex-direction: column;
  overflow-y: auto;
}
.ai-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); font-weight: 700; font-size: 13px;
}
.ai-head .tag {
  font-size: 11px; font-weight: 500; color: var(--accent);
  background: var(--accent-soft); padding: 2px 8px; border-radius: 999px;
  margin-left: auto;
}
.ai-sec { padding: 14px; border-bottom: 1px solid #f1f3f6; }
.ai-sec label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.ai-sec textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 9px;
  font-size: 13px; font-family: inherit; resize: vertical; outline: none; margin-bottom: 8px;
}
.ai-sec textarea:focus { border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin-bottom: 8px; padding: 7px 9px; background: #f7f8fa; border-radius: 6px; }
.hint.on { color: #1d4ed8; background: var(--accent-soft); }
.row { display: flex; gap: 6px; margin-bottom: 6px; }
.tips { font-size: 12px; color: var(--muted); line-height: 1.9; }
.tips p { margin: 0; }
.tips code { background: #f1f3f6; padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ---------- 登录 ---------- */
.login-layer {
  position: fixed; inset: 0; background: rgba(246,247,249,.96);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.login-box {
  background: #fff; padding: 32px 28px; border-radius: 16px;
  box-shadow: var(--shadow); width: 320px; text-align: center;
}
.login-box h1 { font-size: 20px; margin: 0 0 6px; }
.login-box p { font-size: 13px; color: var(--muted); margin: 0 0 18px; }
.login-box input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; outline: none; margin-bottom: 12px;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%; padding: 10px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
}
.err { color: var(--danger); font-size: 12px; margin-top: 10px; min-height: 16px; }

/* ---------- 画布元素 ---------- */
.node-rect { transition: stroke .12s, filter .12s; }
.node-group { cursor: pointer; }
.node-group:hover .node-rect { filter: brightness(.98); }
/* 选中态用 CSS 覆盖，这样点选时不必整图重绘（重绘会让第二次点击丢失） */
.node-group.selected .node-rect { stroke: #111827; stroke-width: 2.2; }
.node-text { pointer-events: none; user-select: none; }
.toggle-btn { cursor: pointer; }
.toggle-btn circle { transition: .12s; }
.toggle-btn:hover circle { r: 8; }

/* 内联编辑框 */
.inline-edit {
  position: absolute; z-index: 30; border: 2px solid var(--accent);
  border-radius: 8px; padding: 4px 8px; font-size: 13px; font-family: inherit;
  outline: none; background: #fff; box-shadow: var(--shadow); resize: none;
  overflow: hidden; line-height: 1.4;
}

/* ---------- 节点行内 AI 工具条 ---------- */
.ai-live .wait { color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }
.ai-live {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: #f7f9fc; border: 1px solid #e8edf5;
  max-height: 180px; overflow-y: auto;
  font-size: 12px; line-height: 1.7; color: #374151;
  white-space: pre-wrap; word-break: break-word;
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 72px; transform: translate(-50%, 12px);
  background: #1f2937; color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

@media (max-width: 820px) {
  .desk { display: none !important; }
  .topbar .only-mobile { display: inline-flex; align-items: center; }
  .brand { display: none; }
  .topbar { height: 54px; flex: 0 0 54px; gap: 6px; padding: 0 8px; padding-top: env(safe-area-inset-top); }
  .map-title { flex: 1; min-width: 0; max-width: none; font-size: 15px; padding: 6px; }
  .save-state { display: none; }
  .btn { padding: 8px 10px; }
  #btnAI { padding: 8px 12px; }

  /* 侧栏改成覆盖式抽屉 */
  .sidebar {
    position: fixed; top: 54px; bottom: 0; left: 0; width: 268px; flex-basis: 268px;
    z-index: 72; box-shadow: 10px 0 30px rgba(16,24,40,.14);
    transition: transform .2s ease;
  }
  .sidebar.collapsed { margin-left: 0; transform: translateX(-104%); }

  /* AI 面板改成底部抽屉 */
  .ai-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; flex-basis: auto; max-height: 68vh; z-index: 76;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 40px rgba(16,24,40,.16);
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    animation: sheetup .18s ease;
  }
  .ai-panel .ai-head { position: sticky; top: 0; background: #fff; z-index: 2; }

  .memo-drawer { width: 100%; top: 54px; }

  .zoombar { right: 10px; bottom: 52px; }
  .toast { bottom: 96px; max-width: 88vw; text-align: center; }
  .struct-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-layer { padding: 12px; align-items: flex-end; }
  .modal { max-width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; }

  /* 触屏不要 300ms 延迟/双击缩放，画布手势自己处理 */
  #canvas { touch-action: none; }
  .inline-edit { font-size: 16px !important; }
  .chips button { padding: 6px 11px; font-size: 13px; }
  .seg button { padding: 8px 16px; }
}

/* ---------- 新建导图弹窗 ---------- */
.badge {
  display: inline-block; min-width: 16px; height: 16px; line-height: 16px;
  padding: 0 4px; margin-left: 4px; border-radius: 8px;
  background: #f59e0b; color: #fff; font-size: 10.5px; font-weight: 700;
  text-align: center; vertical-align: 1px;
}
.modal-layer {
  position: fixed; inset: 0; z-index: 80; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(17, 24, 39, .38); backdrop-filter: blur(2px);
  animation: fadein .14s ease;
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  background: #fff; border-radius: 14px; padding: 18px 20px 16px;
  box-shadow: 0 24px 60px rgba(16,24,40,.24);
  animation: popin .16s ease;
}
@keyframes popin { from { transform: translateY(8px) scale(.985); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: #4b5563; margin-bottom: 6px; }
.field > span em { font-style: normal; font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 11px; }
.field input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 13.5px; outline: none; background: #fbfcfd;
}
.field input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(47,107,255,.1); }

.struct-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.struct {
  border: 1.5px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 8px 6px; text-align: left; transition: .15s;
}
.struct b { display: block; font-size: 12.5px; color: var(--text); }
.struct i {
  display: block; font-style: normal; font-size: 10.5px; color: var(--muted);
  margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.struct svg { width: 100%; height: 30px; margin-top: 6px; }
.struct svg circle, .struct svg rect { fill: #b7c7e4; }
.struct svg path { stroke: #9fb3d6; stroke-width: 1.6; fill: none; stroke-linecap: round; }
.struct:hover { border-color: #c3cfec; background: #fbfcff; }
.struct.on { border-color: var(--accent); background: var(--accent-soft); }
.struct.on svg circle, .struct.on svg rect { fill: var(--accent); }
.struct.on svg path { stroke: #7ba0f5; }

.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal .err { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: -4px; }

/* ---------- 备忘录抽屉 ---------- */
.memo-drawer {
  position: fixed; top: 52px; right: 0; bottom: 0; width: 340px; z-index: 45;
  display: flex; flex-direction: column; background: #fff;
  border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(16,24,40,.08);
  animation: slidein .18s ease;
}
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
.memo-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); font-size: 13.5px; font-weight: 600;
}
.memo-head .tag {
  font-size: 11px; font-weight: 400; color: var(--muted);
  background: #f3f5f9; padding: 2px 7px; border-radius: 6px;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.memo-head .icon-btn { margin-left: auto; }
.memo-add { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.memo-add textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font-size: 13px; font-family: inherit; resize: vertical; outline: none; background: #fbfcfd;
  min-height: 56px;
}
.memo-add textarea:focus { border-color: var(--accent); background: #fff; }
.memo-add-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.memo-tip { flex: 1; font-size: 10.5px; color: #9aa3af; line-height: 1.4; }
.memo-add-row .btn { padding: 6px 14px; }

.memo-filter {
  display: flex; align-items: center; gap: 4px; padding: 8px 14px;
  border-bottom: 1px solid var(--line);
}
.memo-filter button {
  border: none; background: transparent; font-size: 12px; color: var(--muted);
  padding: 4px 9px; border-radius: 6px;
}
.memo-filter button:hover { background: #f3f5f9; }
.memo-filter button.on { background: var(--accent-soft); color: #1d4ed8; font-weight: 600; }
.memo-filter .memo-clear { margin-left: auto; font-size: 11px; color: #9aa3af; }
.memo-filter .memo-clear:hover { color: var(--danger); background: #fdecec; }

.memo-list { flex: 1 1 auto; overflow-y: auto; padding: 10px 14px 20px; }
.memo-item {
  display: flex; gap: 8px; padding: 9px 10px; border-radius: 9px;
  border: 1px solid var(--line); margin-bottom: 8px; background: #fff;
}
.memo-item:hover { border-color: #d3dbe8; }
.memo-item .chk {
  flex: 0 0 auto; width: 16px; height: 16px; margin-top: 1px; cursor: pointer;
  accent-color: var(--accent);
}
.memo-item .body { flex: 1; min-width: 0; }
.memo-item .txt {
  font-size: 13px; line-height: 1.55; color: #374151; word-break: break-word;
  white-space: pre-wrap;
}
.memo-item.done .txt { color: #9aa3af; text-decoration: line-through; }
.memo-item .time { font-size: 10.5px; color: #a8b0bb; margin-top: 3px; }
.memo-item .acts { display: flex; gap: 2px; opacity: 0; flex: 0 0 auto; }
.memo-item:hover .acts { opacity: 1; }
.memo-item .acts button {
  border: none; background: transparent; color: var(--muted);
  font-size: 11px; padding: 2px 5px; border-radius: 5px;
}
.memo-item .acts button:hover { background: #f1f3f6; color: var(--text); }
.memo-item .acts button.del:hover { background: #fdecec; color: var(--danger); }
.memo-empty { text-align: center; color: var(--muted); font-size: 12.5px; padding: 32px 12px; line-height: 1.7; }

@media (max-width: 900px) {
  .memo-drawer { width: 100%; }
  .struct-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 节点「＋」加键 ---------- */
/* 命中区域由 JS 按几何计算，元素本身不接收指针事件，
   避免透明热区挡住画布拖拽、或在空白处误加节点 */
.add-btn { opacity: 0; transition: opacity .12s ease; pointer-events: none; }
.add-btn.hot { opacity: 1; }
.node-group.selected .add-btn { opacity: 1; }
.node-group[data-depth="0"] .add-btn { opacity: .9; }
.add-btn.hot .add-ring { fill: var(--accent); stroke: var(--accent); }
.add-btn.hot .add-sign { fill: #fff; }

/* 触屏没有 hover：加键常显，手指才找得到 */
body.touch-ui .add-btn { opacity: .8; }

/* 顶栏开关按钮的“开启”态 */
.btn.on { border-color: #d8e2ff; background: var(--accent-soft); color: #1d4ed8; font-weight: 600; }

/* 就地新建节点的输入框 */
.inline-edit.is-new {
  border: 1.5px dashed var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .12), var(--shadow);
}
.inline-edit::placeholder { color: #a8b3c4; font-weight: 400; }

/* ---------- AI 分支数选择 ---------- */
.ai-count {
  display: flex; align-items: center; gap: 8px; margin: 0 0 8px;
  font-size: 12px; color: var(--muted);
}
.chips { display: flex; gap: 4px; margin-left: auto; }
.chips button {
  border: 1px solid var(--line); background: #fff; color: #4b5563;
  font-size: 12px; padding: 3px 9px; border-radius: 999px; line-height: 1.4;
}
.chips button.on { background: var(--accent-soft); border-color: #c7d7ff; color: #1d4ed8; font-weight: 600; }

/* ---------- 设置 ---------- */
.set-modal { max-width: 460px; }
.set-pane { min-height: 120px; }
.set-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 13px 2px; border-bottom: 1px solid #f1f3f6;
  background: transparent; border-left: 0; border-right: 0; border-top: 0;
  font-size: 13.5px; color: var(--text); text-align: left;
}
.set-label { flex: 1; }
.set-note { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.set-note i { font-style: normal; color: #b6bdc8; font-size: 16px; line-height: 1; }
.set-link { cursor: pointer; }
.set-link:hover .set-label { color: var(--accent); }
.set-group { font-size: 11.5px; color: var(--muted); padding: 14px 2px 6px; }
.set-tip { font-size: 11.5px; color: #9aa3af; line-height: 1.7; margin: 14px 0 0; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  border: none; background: #fff; padding: 5px 14px; font-size: 12.5px; color: #4b5563;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }

.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.stepper button {
  border: none; background: #fbfcfd; width: 30px; height: 28px; font-size: 15px; color: var(--muted);
}
.stepper button:hover { background: #f1f3f6; }
.stepper input {
  width: 46px; border: none; text-align: center; font-size: 13px; outline: none;
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  height: 28px; background: #fff; -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i {
  position: absolute; inset: 0; background: #d7dce5; border-radius: 999px;
  transition: .18s; pointer-events: none;
}
.switch i::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(16,24,40,.2);
}
.switch input:checked + i { background: #34c759; }
.switch input:checked + i::after { transform: translateX(18px); }

.opt-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.opt-list button {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  border: none; background: #fff; padding: 12px 14px; font-size: 13.5px; color: var(--text);
  text-align: left;
}
.opt-list button + button { border-top: 1px solid #f1f3f6; }
.opt-list button:hover { background: #f8fafc; }
.opt-list button.on { color: var(--accent); font-weight: 600; }
.opt-list button.on span::after { content: '✓'; margin-left: 8px; }

/* ---------- 手机「更多」抽屉 ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 90; background: rgba(17,24,39,.4); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; background: #fff; border-radius: 16px 16px 0 0; padding: 6px 10px calc(14px + env(safe-area-inset-bottom));
  animation: sheetup .18s ease; max-height: 82vh; overflow-y: auto;
}
@keyframes sheetup { from { transform: translateY(30px); opacity: .6; } }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: #e2e6ec; margin: 6px auto 8px; }
.sheet button {
  display: block; width: 100%; border: none; background: transparent;
  padding: 14px 12px; font-size: 14.5px; text-align: center; color: var(--text); border-radius: 10px;
}
.sheet button:hover { background: #f4f6f9; }
.sheet button + button { border-top: 1px solid #f4f6f9; }
.sheet .sheet-cancel { color: var(--muted); margin-top: 6px; border-top: none; }

.only-mobile { display: none; }

/* ---------- 双击节点 → AI 就地生成分支的流式气泡 ---------- */
.grow-chip {
  position: fixed; z-index: 62; pointer-events: none;
  width: 218px; max-height: 152px; overflow: hidden;
  padding: 9px 11px; border-radius: 10px;
  background: rgba(255,255,255,.98); border: 1px solid #dbe4f5;
  box-shadow: 0 10px 28px rgba(20, 40, 80, .14);
  font-size: 12px; line-height: 1.6; color: #374151;
  display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start;
  animation: chipIn .16s ease;
}
@keyframes chipIn { from { opacity: 0; transform: translateY(-4px); } }
.grow-chip .wait { color: var(--muted); }
.grow-chip .chip {
  display: inline-block; padding: 1px 7px; border-radius: 6px;
  background: #eef3ff; color: #2f57b8;
}
.grow-chip .cur {
  display: inline-block; width: 2px; height: 12px; background: var(--accent);
  animation: blink 1s steps(1) infinite;
}

/* ---------- 外观与配色（色盘 / 背景 / 形状 / 版式） ---------- */
.palette-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 4px; }
.palette-card {
  border: 1.5px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 10px 7px; display: flex; flex-direction: column; gap: 6px;
  align-items: flex-start; cursor: pointer; transition: .15s;
}
.palette-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,107,255,.14); }
.palette-card .dots { display: flex; gap: 3px; }
.palette-card .dots i { width: 11px; height: 11px; border-radius: 50%; display: block; }
.palette-card b { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.palette-card.on b { color: var(--accent); }

.bg-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 9px 0 6px; }
.bg-swatch {
  width: 52px; height: 34px; border-radius: 9px; border: 1.5px solid var(--line);
  font-size: 10.5px; color: #6b7280; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: .15s; padding: 0;
}
.bg-swatch.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,107,255,.14); }
.color-pick {
  width: 48px; height: 32px; border: 1.5px solid var(--line); border-radius: 8px;
  background: #fff; padding: 2px; cursor: pointer;
}

.palette-editor { display: flex; flex-wrap: wrap; gap: 10px; padding: 10px 2px 14px; }
.pc-chip { position: relative; width: 36px; height: 36px; }
.pc-chip label {
  display: block; width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid rgba(0,0,0,.08); overflow: hidden; cursor: pointer;
}
.pc-chip input { width: 200%; height: 200%; margin: -50% 0 0 -50%; opacity: 0; cursor: pointer; }
.pc-del {
  position: absolute; top: -7px; right: -7px; width: 17px; height: 17px;
  border-radius: 50%; background: #111827; color: #fff; font-size: 11px; line-height: 1;
  border: 2px solid #fff; padding: 0; cursor: pointer;
}
.pc-add {
  height: 36px; padding: 0 12px; border: 1.5px dashed var(--line); border-radius: 10px;
  background: #fff; color: var(--muted); font-size: 12px; cursor: pointer;
}

/* 外观设置里的横向选项组（比竖排列表省地方） */
.opt-list.inline {
  display: flex; flex-wrap: wrap; gap: 8px;
  border: none; border-radius: 0; overflow: visible; padding: 6px 0 2px;
}
.opt-list.inline button {
  width: auto; display: inline-flex; align-items: center; gap: 4px;
  border: 1.5px solid var(--line); border-radius: 9px;
  padding: 7px 13px; font-size: 12.5px; background: #fff;
}
.opt-list.inline button + button { border-top: none; }
.opt-list.inline button.on {
  border-color: var(--accent); background: var(--accent-soft); color: #1d4ed8;
}
.opt-list.inline button.on span::after { content: ''; margin: 0; }
.bg-swatch { white-space: nowrap; }
.bg-list .bg-swatch { flex: 0 0 auto; white-space: nowrap; min-width: 54px; }
.palette-list .palette-card { flex: 0 0 auto; }

/* ================= 账号 / 管理后台 / 对话 / 图片预览 ================= */
.account-btn { display: inline-flex; align-items: center; gap: 6px; padding-left: 6px; }
.avatar {
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent);
  color: #fff; font-size: 11px; font-weight: 700; display: inline-flex;
  align-items: center; justify-content: center; flex: 0 0 auto; text-transform: uppercase;
}
.avatar.lg { width: 40px; height: 40px; font-size: 16px; }
.acc-name { font-size: 12.5px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-head { display: flex; align-items: center; gap: 12px; padding: 6px 14px 14px; text-align: left; }
.acc-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sheet button.danger { color: #dc2626; }

.link-btn {
  width: 100%; background: none; border: none; color: var(--accent);
  font-size: 12.5px; padding: 6px 0 0; cursor: pointer;
}
.login-box .hidden { display: none; }

/* AI 面板页签 */
.ai-tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); }
.ai-tabs button {
  flex: 1; border: none; background: none; padding: 8px 0 9px; font-size: 12.5px;
  color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; cursor: pointer;
}
.ai-tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.ai-tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.ai-tab-body.hidden { display: none; }

/* 对话 */
.chat-list { flex: 1; min-height: 90px; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 10px; }
.chat-tip { font-size: 12px; color: var(--muted); line-height: 1.6; background: #f7f9fc; border-radius: 10px; padding: 9px 11px; }
.chat-msg { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.chat-msg .who { font-size: 10.5px; color: #9aa3b2; }
.chat-msg .bubble {
  font-size: 13px; line-height: 1.65; padding: 8px 11px; border-radius: 10px;
  white-space: pre-wrap; word-break: break-word;
}
.chat-msg.me { align-items: flex-end; }
.chat-msg.me .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg.ai .bubble { background: #f4f6fa; color: var(--text); border-bottom-left-radius: 3px; }
.chat-msg .acts { font-size: 11px; color: #0f7a4d; background: #e9f8f0; border-radius: 7px; padding: 4px 8px; display: inline-block; }
.chat-busy { font-size: 11.5px; color: var(--muted); }
.chat-quick { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 8px; }
.chat-quick button {
  border: 1px solid var(--line); background: #fff; border-radius: 20px;
  font-size: 11.5px; padding: 4px 10px; color: #43506b; cursor: pointer;
}
.chat-quick button:active { background: var(--accent-soft); }
.chat-input { display: flex; gap: 6px; padding: 8px 12px 12px; border-top: 1px solid var(--line); }
.chat-input textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 16px; font-family: inherit; line-height: 1.5;
  outline: none; max-height: 108px;
}
.chat-input textarea:focus { border-color: var(--accent); }
.chat-input .btn { align-self: flex-end; padding: 8px 14px; }

/* 通用弹窗 */
.modal-layer {
  position: fixed; inset: 0; background: rgba(17,24,39,.42); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-layer.hidden { display: none; }
.modal {
  background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(15,23,42,.28);
  width: min(720px, 100%); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal.narrow { width: min(420px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.modal-body { padding: 14px 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-body input, .modal-body textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font-size: 16px; font-family: inherit; outline: none; width: 100%;
}
.modal-body input:focus, .modal-body textarea:focus { border-color: var(--accent); }
.err { color: #dc2626; font-size: 12px; min-height: 16px; }
.muted { color: var(--muted); font-size: 12px; }

/* 管理后台 */
.admin-modal { width: min(760px, 100%); }
.admin-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-stats span {
  background: #f4f6fa; border-radius: 8px; padding: 6px 10px; font-size: 12px; color: #43506b;
}
.admin-stats b { color: var(--accent); }
.admin-block { border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.admin-block-title { font-size: 12.5px; font-weight: 600; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.link-row { display: flex; gap: 6px; }
.link-row input { flex: 1; font-size: 13px !important; background: #fbfcfd; }
.admin-create { display: flex; gap: 7px; flex-wrap: wrap; }
.admin-create input { flex: 1 1 130px; width: auto; font-size: 15px !important; padding: 7px 10px !important; }
.admin-create .btn { flex: 0 0 auto; padding: 7px 14px; }
.sw-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #43506b; white-space: nowrap; }
.sw-inline input { width: auto; }
.admin-filter { display: flex; align-items: center; gap: 8px; }
.admin-filter input { flex: 1; font-size: 15px !important; }
.admin-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.admin-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 9px; font-size: 12.5px;
}
.admin-row .who { flex: 1; min-width: 0; }
.admin-row .who b { font-size: 13px; }
.admin-row .who div { color: var(--muted); font-size: 11px; margin-top: 2px; }
.admin-row .tag-mini { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: #eef2f8; color: #5b6780; }
.admin-row .tag-mini.admin { background: #eaf0ff; color: #1d4ed8; }
.admin-row .tag-mini.off { background: #fdecec; color: #dc2626; }
.admin-row button {
  border: 1px solid var(--line); background: #fff; border-radius: 6px;
  font-size: 11.5px; padding: 4px 8px; color: #43506b; cursor: pointer;
}
.admin-row button:hover { border-color: var(--accent); color: var(--accent); }
.admin-row button.danger { color: #dc2626; }
.batch-out { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; line-height: 1.6; }

/* 图片预览 */
.img-modal { width: min(560px, 100%); }
.img-wrap {
  background: #f4f6fa; border-radius: 10px; padding: 8px; max-height: 52vh;
  overflow: auto; display: flex; justify-content: center;
}
.img-wrap img { max-width: 100%; height: auto; display: block; border-radius: 6px; }
.img-actions { display: flex; gap: 8px; }
.img-actions .btn { flex: 1; }

/* 手机端：弹窗改成底部抽屉，按钮更大 */
@media (max-width: 820px) {
  .modal-layer { align-items: flex-end; padding: 0; }
  .modal, .modal.narrow, .admin-modal, .img-modal {
    width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0;
  }
  .admin-row button { padding: 7px 10px; font-size: 12px; }
  .acc-name { display: none; }
}

/* AI 面板内部改为「页签 + 独立滚动」，容器不再整体滚动 */
.ai-panel { overflow: hidden; }
.ai-tab-body { overflow-y: auto; }
.ai-tab-body[data-body="chat"] { overflow: hidden; padding-bottom: 2px; }
.ai-tab-body[data-body="chat"] .chat-list { min-height: 120px; }

/* 导出分辨率 */
.num-input {
  width: 108px; text-align: right; border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; font-size: 16px; font-family: inherit;
  outline: none; color: var(--text); background: #fff;
}
.num-input:focus { border-color: var(--accent); }
.set-hint { font-size: 11.5px; color: var(--muted); line-height: 1.55; margin: -2px 0 2px; padding: 0 14px; }

/* 分辨率输入与图片按钮：手机上别挤成一坨 */
.num-input { width: 124px; }
@media (max-width: 820px) {
  .img-actions { flex-wrap: wrap; }
  .img-actions .btn { flex: 1 1 30%; min-width: 96px; font-size: 13px; padding: 9px 6px; }
}

/* ================= 安装到桌面（PWA） ================= */
.inst-steps { margin: 0 0 4px; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; }
.inst-steps li { font-size: 13.5px; line-height: 1.65; color: var(--text); }
.inst-steps b { color: var(--accent); }
.inst-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 20px; border: 1.5px solid var(--accent); border-radius: 4px;
  color: var(--accent); font-size: 12px; vertical-align: -4px; margin: 0 2px;
}
.inst-ok { font-size: 14px; font-weight: 600; color: #0f7a4d; margin: 0; }
.inst-url {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 8px 7px 11px; background: #fbfcfd;
}
.inst-url span {
  flex: 1; font-size: 12px; color: #43506b; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.inst-url .btn { flex: 0 0 auto; padding: 5px 11px; font-size: 12px; }
.btn.full { width: 100%; }

/* 安装引导要在登录遮罩之上（登录层 z-index:100） */
#installLayer { z-index: 110; }
.inst-qr {
  display: flex; align-items: center; gap: 12px; margin-top: 12px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fbfcfd;
}
.inst-qr img { width: 90px; height: 90px; flex: 0 0 auto; border-radius: 6px; background: #fff; }
.inst-qr-tip { font-size: 12px; color: var(--muted); line-height: 1.7; }

/* 登录页「装到桌面」：次级按钮，别和「登录」抢视觉 */
.login-box .install-btn {
  width: 100%; margin-top: 4px; padding: 9px 10px; font-size: 13px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft); border: 1px solid transparent;
  border-radius: 10px; cursor: pointer; font-family: inherit;
}
.login-box .install-btn:active { background: #dfe8ff; }
.inst-profile {
  border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.inst-profile-title { font-size: 13px; font-weight: 700; color: var(--text); }
.inst-profile .btn { text-decoration: none; display: block; text-align: center; }
.inst-profile .btn.btn-ai {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
}

/* ================= 本机模式横幅（服务器离线） ================= */
.local-bar {
  flex: 0 0 auto; padding: 7px 14px; font-size: 12px; line-height: 1.5;
  color: #8a5300; background: linear-gradient(90deg, #fff6df, #ffefd0);
  border-bottom: 1px solid #f3ddaa; text-align: center;
}
.local-bar b { font-weight: 700; }

/* ================= AI 密钥设置 ================= */
.aikey-box { padding: 4px 14px 10px; display: flex; flex-direction: column; gap: 10px; }
.aikey-box input {
  width: 100%; box-sizing: border-box; padding: 10px 12px; font-size: 13px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg2, #fff); color: var(--text);
}
.aikey-box input:focus { outline: none; border-color: var(--accent); }
.aikey-btns { display: flex; gap: 10px; }
.aikey-btns .btn { flex: 1; justify-content: center; }
.aikey-btns .btn.btn-ai { background: var(--accent); color: #fff; border: none; font-weight: 600; }
.set-note.ok { color: #0ca678; font-weight: 600; }
#aiKeyMsg:empty { display: none; }

/* 游客模式横幅里的登录链接 */
.local-bar a { color: #8a5300; text-decoration: underline; text-underline-offset: 2px; }
.local-bar a b { font-weight: 700; }
