:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b7280;
  --line: #e6e8ee;
  --accent: #0a59f7;
  --accent-soft: #e8f0fe;
  --shadow: 0 10px 28px rgba(16, 24, 40, 0.08);
  --ok: #059669;
  --warn: #c2410c;
  --danger: #b91c1c;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
#app { height: 100%; display: flex; flex-direction: column; min-height: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 12px; flex-wrap: wrap;
  background: rgba(255,255,255,0.92); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center;
  background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa;
  border-radius: 999px; font-size: 12px; padding: 2px 10px; font-weight: 600;
}
.sub { margin-top: 4px; font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.connected { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-weight: 600; }
.connected i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }

.tabs { display: flex; gap: 6px; background: #e9edf5; padding: 4px; border-radius: 14px; flex-wrap: wrap; }
.tab {
  border: 0; background: transparent; color: #4b5563; font-weight: 600;
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 14px;
}
.tab.on { background: #fff; color: var(--accent); box-shadow: 0 2px 8px rgba(16,24,40,0.08); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.icon-btn, .btn {
  border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 8px 14px; cursor: pointer; font-weight: 700; font-size: 14px; color: var(--text);
}
.icon-btn { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.btn.danger-ghost { background: #fff; color: #4b5563; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.main { flex: 1; display: flex; min-height: 0; position: relative; }
.split { flex: 1; display: flex; min-height: 0; gap: 0; padding: 12px; }
.pane-left, .pane-right { min-width: 0; min-height: 0; }
.pane-left { flex: 1.1; }
.pane-right { flex: 0.9; display: none; }
.crease {
  width: 6px; margin: 4px 8px; border-radius: 8px;
  background: linear-gradient(90deg, rgba(0,0,0,0.06), rgba(255,255,255,0.7), rgba(0,0,0,0.08));
  display: none;
}
@media (min-width: 1600px) {
  .pane-right { display: block; }
  .crease { display: block; }
  .sheet { display: none !important; }
  .bottom-nav { display: none !important; }
}

.canvas-wrap {
  height: 100%; background:
    radial-gradient(circle at 20px 20px, #e7ebf3 1.5px, transparent 1.6px) 0 0 / 28px 28px,
    #fbfcfe;
  border: 1px solid var(--line); border-radius: 20px; position: relative;
  overflow: hidden; box-shadow: var(--shadow);
}
#graph-svg { width: 100%; height: 100%; touch-action: none; cursor: grab; }
#graph-svg.dragging { cursor: grabbing; }
.hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  background: rgba(28,28,30,0.78); color: #fff; padding: 8px 16px;
  border-radius: 999px; font-size: 13px; white-space: nowrap; pointer-events: none;
}
.preview-banner {
  position: absolute; left: 12px; right: 12px; top: 12px; z-index: 5;
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  border-radius: 12px; padding: 10px 14px; font-size: 13px; font-weight: 700;
  display: none; justify-content: space-between; align-items: center; gap: 8px;
}
.preview-banner.show { display: flex; }
.preview-banner span { font-weight: 600; color: #c2410c; }

.detail {
  height: 100%; background: #fff; border: 1px solid var(--line);
  border-radius: 20px; padding: 18px 18px 16px; box-shadow: var(--shadow);
  overflow: auto;
}
.detail h2 { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600;
}
.tag.curtag { background: #0a59f7; color: #fff; }
.desc { margin-top: 12px; font-size: 14px; line-height: 1.55; color: #374151; }
.kv { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kv .cell { background: #f6f8fc; border-radius: 14px; padding: 12px 14px; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-size: 15px; font-weight: 600; margin-top: 4px; }
.rel { margin-top: 18px; }
.rel h3 { font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }
.rel-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; gap: 8px;
}
.rel-item span { color: var(--muted); font-size: 13px; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 100px; text-align: center; }

.nl-box { margin-top: 14px; background: #f6f8fc; border-radius: 14px; padding: 14px; }
.nl-box .lab { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.nl-box .ask { font-size: 15px; line-height: 1.5; font-weight: 600; }
.change { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.pill { flex: 0 0 auto; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 700; }
.pill.add { background: #dcfce7; color: #166534; }
.pill.edit { background: #dbeafe; color: #1d4ed8; }
.pill.delete { background: #fee2e2; color: #b91c1c; }
.change .txt { font-size: 14px; line-height: 1.45; }
.input-row { margin-top: 14px; display: flex; gap: 8px; align-items: center; }
.input-row input, .input-row textarea {
  flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 14px; resize: none;
}
.send {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent);
  color: #fff; border: 0; display: grid; place-items: center; font-size: 18px; font-weight: 700; cursor: pointer;
}

/* 窄屏底部详情 */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  max-height: 55%; background: #fff; border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(16,24,40,0.14); padding: 8px 16px 72px;
  transform: translateY(110%); transition: transform .25s ease; overflow: auto;
}
.sheet.open { transform: translateY(0); }
.grab { width: 48px; height: 5px; border-radius: 8px; background: #d4d7de; margin: 6px auto 12px; }

.bottom-nav {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 25;
  height: 64px; background: rgba(255,255,255,0.96); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; align-items: center; padding-bottom: 6px;
}
.nav-item {
  border: 0; background: transparent; color: var(--muted); font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; min-width: 64px;
}
.nav-item.active { color: var(--accent); font-weight: 700; }
.nav-item .ico { font-size: 18px; }

/* 版本列表 */
.ver {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 6px; border-bottom: 1px solid var(--line);
}
.ver.cur { background: #e8f0fe; margin: 0 -8px; padding: 14px 14px; border-radius: 14px; border-bottom: none; }
.dotv { width: 12px; height: 12px; border-radius: 50%; background: #cbd5e1; margin-top: 6px; flex: 0 0 12px; }
.ver.cur .dotv { background: var(--accent); box-shadow: 0 0 0 6px rgba(10,89,247,0.16); }
.vn { font-size: 16px; font-weight: 700; }
.vm { font-size: 14px; color: #374151; margin-top: 4px; line-height: 1.45; }
.vt { font-size: 12px; color: var(--muted); margin-top: 6px; }
.mini { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.mini .btn { flex: none; padding: 6px 12px; font-size: 13px; border-radius: 10px; }

.empty { color: var(--muted); font-size: 14px; padding: 20px 0; }
.toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: rgba(17,24,39,0.92); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; z-index: 100; display: none;
}
.toast.show { display: block; }

.node-label { font-weight: 700; pointer-events: none; }
.edge-label { fill: #64748b; font-size: 12px; pointer-events: none; }

.identity { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.id-lab { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
.id-lab select {
  min-width: 160px; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; background: #fff; color: var(--text); font-weight: 600; font-size: 13px;
}
.badge-vis { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.nl-note {
  margin-top: 12px; padding: 10px 12px; border-radius: 12px;
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; font-size: 13px; line-height: 1.45;
}
.zoom-tools {
  position: absolute; right: 12px; bottom: 56px; z-index: 6;
  display: flex; flex-direction: column; gap: 6px;
}
.zoom-tools button {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
}

/* —— 登录 / 开通向导 —— */
.auth-gate {
  position: fixed; inset: 0; z-index: 200;
  background: linear-gradient(160deg, #eef2ff 0%, #f8fafc 45%, #ecfeff 100%);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-gate[hidden], #app[hidden], #admin-modal[hidden] { display: none !important; }
.auth-card {
  width: min(420px, 100%);
  background: #fff; border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 28px 26px 24px;
}
.auth-card.wide { width: min(640px, 100%); max-height: 90vh; overflow: auto; }
.auth-card h1 { font-size: 22px; margin: 0 0 6px; }
.auth-card .lead { color: var(--muted); font-size: 13px; line-height: 1.5; margin-bottom: 18px; }
.auth-card label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 12px 0 6px; }
.auth-card input, .auth-card select {
  width: 100%; box-sizing: border-box; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: 14px;
}
.auth-card .row-btns { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.auth-card .err { color: #b91c1c; font-size: 13px; margin-top: 10px; min-height: 1.2em; }
.user-chip { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 600; }
.btn.tiny { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
.admin-table th, .admin-table td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
.admin-table th { color: var(--muted); font-size: 12px; }
