:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e3e8ef;
  --text: #1e293b;
  --dim: #64748b;
  --mute: #94a3b8;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #059669;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -16px rgba(15, 23, 42, .28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  overflow: hidden;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  padding: 6px 12px;
  transition: all .15s;
}
button:hover { border-color: #c7d2e0; background: #fafbfd; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #1d4ed8; }
button.ghost { color: var(--dim); }
button.danger { color: var(--danger); border-color: #fbd5d5; background: #fff5f5; }
button.danger:hover { background: #fee2e2; }
button.block { width: 100%; }
button:disabled { opacity: .45; cursor: not-allowed; }

input, select {
  font: inherit;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[disabled] { background: #f8fafc; color: var(--mute); }

/* ---------------- 顶栏 ---------------- */

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.grow { flex: 1; }

.floors { display: flex; gap: 4px; margin-left: 10px; }
.floors button { padding: 5px 12px; border-radius: 7px; color: var(--dim); }
.floors button.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.floors button.add { padding: 5px 9px; color: var(--mute); }

.modes { display: flex; gap: 2px; padding: 3px; background: #f1f5f9; border-radius: 9px; }
.modes button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; color: var(--dim); }
.modes button.active { background: #fff; color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }

.field { display: flex; align-items: center; gap: 6px; color: var(--dim); white-space: nowrap; }
.field input { width: 68px; padding: 5px 7px; }

.state { font-size: 12px; color: var(--mute); min-width: 72px; }
.state.dirty { color: var(--warn); }
.state.saved { color: var(--ok); }

/* ---------------- 主体三栏 ---------------- */

main {
  display: grid;
  grid-template-columns: 246px minmax(0, 1fr) 312px;
  height: calc(100% - 56px);
}

.side { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.side.left { border-right: 1px solid var(--line); }
.side.right { border-left: 1px solid var(--line); }

.card { background: var(--panel); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 12.5px; font-weight: 600; color: var(--dim); letter-spacing: .3px; display: flex; align-items: center; gap: 6px; }
.card h3 .count { color: var(--mute); font-weight: 400; }
.hint { margin: 6px 0 0; font-size: 11.5px; color: var(--mute); line-height: 1.6; }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.legend li { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 12px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend i.sq { border-radius: 3px; }

/* ---------------- 画布 ---------------- */

.stage { position: relative; overflow: hidden; background: #fff; }
#canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
#canvas.mode-select { cursor: default; }
#canvas.panning { cursor: grabbing; }
#canvas.dragging { cursor: move; }

.hud {
  position: absolute; left: 14px; bottom: 14px;
  padding: 7px 12px; border-radius: 9px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  color: var(--dim); font-size: 12px;
  backdrop-filter: blur(6px);
  pointer-events: none;
  max-width: calc(100% - 28px);
}
.hud b { color: var(--text); font-weight: 600; }

/* ---------------- 属性面板 ---------------- */

.props { display: flex; flex-direction: column; gap: 9px; }
.props label { display: block; font-size: 11.5px; color: var(--dim); }
.props label input, .props label select { margin-top: 4px; }
.props .row { display: flex; gap: 8px; }
.props .row > label { flex: 1; }
.props .check { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text); }
.props .check input { width: auto; margin: 0; }
.props .divider { height: 1px; background: var(--line); margin: 2px 0; }
.props .meta { font-size: 11.5px; color: var(--mute); }

/* ---------------- 问题列表 ---------------- */

.problems { display: flex; flex-direction: column; gap: 5px; max-height: 320px; overflow-y: auto; }
.problem {
  display: flex; gap: 7px; padding: 6px 8px; border-radius: 7px;
  font-size: 11.5px; line-height: 1.5; cursor: pointer; border: 1px solid transparent;
}
.problem:hover { background: #f8fafc; border-color: var(--line); }
.problem .tag { flex: none; font-size: 10.5px; padding: 1px 5px; border-radius: 4px; height: 17px; }
.problem.error .tag { background: #fee2e2; color: var(--danger); }
.problem.warn .tag { background: #fef3c7; color: var(--warn); }
.problem .txt { color: var(--dim); }

/* ---------------- 终端 ---------------- */

.term-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.term {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 12px;
}
.term .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term .node { color: var(--mute); font-size: 11px; }
.term .x { border: 0; background: none; color: var(--mute); padding: 0 2px; font-size: 14px; line-height: 1; }
.term .x:hover { color: var(--danger); }
.term.bad { border-color: #fbd5d5; background: #fffafa; }
.term-form { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px dashed var(--line); }
.term-form .row { display: flex; gap: 6px; }
.term-form .row input:last-child { width: 74px; flex: none; }

/* ---------------- 提示条 ---------------- */

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: #1e293b; color: #fff; padding: 9px 18px; border-radius: 9px;
  font-size: 12.5px; opacity: 0; pointer-events: none; transition: all .22s;
  z-index: 99; max-width: 70vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #b91c1c; }
.toast.good { background: #047857; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d5dce7; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
