/* FSM Draw - 样式 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e2e6ec;
  --border-strong: #c9d0da;
  --text: #2e3440;
  --text-dim: #7b8694;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --shadow: 0 1px 3px rgba(46,52,64,.08), 0 4px 14px rgba(46,52,64,.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}
html, body { height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------------- 登录页 ---------------- */
.login-page {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eef2f7 0%, #e3eaf3 60%, #dce6f2 100%);
}
.login-card {
  width: 360px; padding: 36px 32px 30px;
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
}
.login-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff; display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px; box-shadow: 0 6px 16px rgba(37,99,235,.3);
}
.login-card h1 { font-size: 19px; font-weight: 600; letter-spacing: .5px; }
.login-sub { color: var(--text-dim); font-size: 12.5px; margin: 6px 0 24px; }
#login-password {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1.5px solid var(--border-strong); border-radius: 8px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#login-password:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
#login-btn {
  width: 100%; margin-top: 14px; padding: 10px 0; font-size: 14.5px; font-weight: 600;
  color: #fff; background: var(--accent); border: none; border-radius: 8px;
  transition: background .15s;
}
#login-btn:hover { background: #1d4ed8; }
#login-btn:disabled { opacity: .6; cursor: default; }
.login-error { margin-top: 12px; color: var(--danger); font-size: 13px; }

/* ---------------- 主布局 ---------------- */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 20;
}
.topbar-title { font-weight: 600; font-size: 15px; color: var(--text); white-space: nowrap; }
.icon-btn {
  width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 7px;
  background: #fff; color: var(--text-dim); font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: #f1f4f8; color: var(--text); }
.doc-name-wrap { position: relative; display: flex; align-items: center; margin-left: 8px; }
.dirty-dot {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: #f59e0b;
}
#doc-name {
  width: 260px; padding: 7px 12px 7px 24px; font-size: 14px;
  border: 1.5px solid transparent; border-radius: 8px; background: transparent;
  outline: none; color: var(--text); transition: border-color .15s, background .15s;
}
#doc-name:hover { background: #f4f6f9; }
#doc-name:focus { border-color: var(--accent); background: #fff; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.tb-btn {
  padding: 7px 14px; font-size: 13.5px; border-radius: 7px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  transition: background .12s, border-color .12s;
}
.tb-btn:hover { background: #f1f4f8; }
.tb-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.tb-btn.primary:hover { background: #1d4ed8; }
.tb-btn.ghost { color: var(--text-dim); }
.tb-btn.ghost:hover { color: var(--danger); border-color: #f3c1c1; background: #fdf3f3; }
.tb-sep { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; }

.main-area { flex: 1; display: flex; min-height: 0; position: relative; }

/* ---------------- 侧边栏 ---------------- */
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  transition: margin-left .18s ease;
}
.sidebar.collapsed { margin-left: -250px; }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 10px; font-size: 12.5px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px;
}
.flow-count { font-weight: 400; }
.flow-list { list-style: none; overflow-y: auto; padding: 0 8px 10px; flex: 1; }
.flow-item {
  position: relative; padding: 9px 10px 9px 12px; border-radius: 8px;
  cursor: pointer; transition: background .12s; margin-bottom: 2px;
}
.flow-item:hover { background: #f1f4f8; }
.flow-item.active { background: var(--accent-soft); }
.flow-item .flow-name {
  font-size: 13.5px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.flow-item.active .flow-name { color: #1d4ed8; }
.flow-item .flow-time { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.flow-item .flow-more {
  position: absolute; right: 6px; top: 7px;
  width: 24px; height: 24px; border: none; background: transparent;
  border-radius: 6px; color: var(--text-dim); font-size: 15px; line-height: 1;
  display: none; align-items: center; justify-content: center;
}
.flow-item:hover .flow-more { display: flex; }
.flow-item .flow-more:hover { background: #e2e8f0; color: var(--text); }
.flow-empty { padding: 24px 14px; color: var(--text-dim); font-size: 13px; text-align: center; }

.sidebar-grip {
  position: absolute; left: 0; top: 0; bottom: 0; width: 12px;
  cursor: pointer; z-index: 15;
  display: none; align-items: center; justify-content: center;
  background: linear-gradient(to right, rgba(46,52,64,.06), transparent);
}
.sidebar-grip:hover span { color: var(--accent); }
.sidebar-grip span {
  font-size: 13px; color: var(--text-dim);
  background: #fff; border: 1px solid var(--border);
  border-radius: 50%; width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
}
body.sidebar-collapsed .sidebar-grip { display: flex; }

/* ---------------- 工具栏 ---------------- */
.editor-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 7px 12px; background: var(--panel);
  border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap;
}
.tool-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 11px; font-size: 13px; color: var(--text);
  border: 1px solid transparent; border-radius: 7px; background: transparent;
  transition: background .12s, border-color .12s, color .12s;
}
.tool-btn:hover { background: #f1f4f8; }
.tool-btn.active { background: var(--accent-soft); color: #1d4ed8; border-color: #bfdbfe; }
.tool-btn:disabled { opacity: .35; cursor: default; }
.tool-btn:disabled:hover { background: transparent; }
.tool-btn svg { flex-shrink: 0; }

/* ---------------- 画布 ---------------- */
.canvas-wrap {
  position: relative; flex: 1; min-height: 0; overflow: hidden;
  background: #fafbfd; cursor: default;
}
.canvas-wrap.panning { cursor: grabbing; }
.canvas-wrap.placing { cursor: crosshair; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.grid-rect { pointer-events: none; }

/* SVG 元素样式 */
.node-shape { fill: #ffffff; stroke: #2e3440; stroke-width: 1.5; filter: url(#node-shadow); }
g.node.selected .node-shape { stroke: var(--accent); stroke-width: 2.5; }
g.node:hover .node-shape { stroke: #4c566a; }
g.node.selected:hover .node-shape { stroke: var(--accent); }
.node-text {
  font-size: 13px; fill: var(--text); text-anchor: middle; dominant-baseline: middle;
  pointer-events: none; user-select: none; line-height: 1.35;
}
.anchor {
  fill: #fff; stroke: var(--accent); stroke-width: 1.6;
  cursor: crosshair; opacity: 0; pointer-events: none;
  transition: opacity .12s;
}
g.node:hover .anchor, .anchor.dragging { opacity: 1; pointer-events: all; }

.edge-path { fill: none; stroke: #3b4252; stroke-width: 1.6; }
g.edge.selected .edge-path { stroke: var(--accent); stroke-width: 2.4; }
g.edge .edge-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
.edge-label-bg { fill: #ffffff; stroke: var(--border); stroke-width: 1; }
.edge-label {
  font-size: 12px; fill: #4c566a; text-anchor: middle; dominant-baseline: middle;
  pointer-events: none; user-select: none;
}
g.edge.selected .edge-label { fill: #1d4ed8; }
g.edge.selected .edge-label-bg { stroke: #bfdbfe; }

.rubber-line { stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 6 4; fill: none; pointer-events: none; }

/* ---------------- HUD ---------------- */
.zoom-hud {
  position: absolute; right: 14px; bottom: 14px;
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(4px);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 6px 5px 12px; box-shadow: var(--shadow);
}
#zoom-label { font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 44px; }
.hud-btn {
  padding: 4px 10px; font-size: 12px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
}
.hud-btn:hover { background: #f1f4f8; }
.mode-hint {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  background: rgba(37,99,235,.92); color: #fff; font-size: 12.5px;
  padding: 6px 16px; border-radius: 20px; box-shadow: var(--shadow);
  pointer-events: none;
}

/* ---------------- 文字编辑器 ---------------- */
.text-editor {
  position: absolute; z-index: 60;
  border: 2px solid var(--accent); border-radius: 6px;
  background: rgba(255,255,255,.97); color: var(--text);
  font-size: 13px; line-height: 1.35; text-align: center;
  padding: 4px 6px; outline: none; resize: none; overflow: hidden;
  box-shadow: 0 4px 14px rgba(37,99,235,.18);
  min-width: 60px;
}

/* ---------------- 上下文菜单 ---------------- */
.ctx-menu {
  position: fixed; z-index: 100; min-width: 130px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); padding: 4px;
}
.ctx-menu button {
  display: block; width: 100%; text-align: left;
  padding: 7px 12px; font-size: 13px; border: none; background: transparent;
  border-radius: 6px; color: var(--text);
}
.ctx-menu button:hover { background: #f1f4f8; }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu button.danger:hover { background: #fdf3f3; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  z-index: 150; background: #2e3440; color: #fff; font-size: 13.5px;
  padding: 9px 20px; border-radius: 8px; box-shadow: var(--shadow);
  animation: toast-in .18s ease;
}
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }

/* 滚动条 */
.flow-list::-webkit-scrollbar { width: 8px; }
.flow-list::-webkit-scrollbar-thumb { background: #d4dae2; border-radius: 4px; }
.flow-list::-webkit-scrollbar-thumb:hover { background: #c2c9d4; }
