* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: flex; flex-direction: column;
  color: #1a1a1a; background: #fff;
  overflow: hidden;
}

/* ---------- верхняя панель ---------- */
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid #e2e2e2; background: #fafafa;
  flex: 0 0 auto;
}
#brand { font-weight: 700; white-space: nowrap; }
.spacer { flex: 1; }
#crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
#crumbs a { color: #2563eb; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
#crumbs a:hover { text-decoration: underline; }
#crumbs .sep { color: #999; }
#mapName {
  font-size: 15px; font-weight: 600; border: 1px solid transparent; border-radius: 6px;
  padding: 3px 6px; min-width: 60px; max-width: 320px; background: transparent;
}
#mapName:hover, #mapName:focus { border-color: #ccc; background: #fff; outline: none; }

#peers { display: flex; gap: 4px; }
.peer {
  width: 26px; height: 26px; border-radius: 50%;
  color: #fff; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 0 0 1px #ddd;
}
#me, #helpBtn {
  border: 1px solid #d5d5d5; background: #fff; border-radius: 8px;
  padding: 5px 10px; cursor: pointer; font-size: 13px;
}
#me:hover, #helpBtn:hover { background: #f0f0f0; }
#helpBtn { font-weight: 700; width: 30px; }

/* ---------- раскладка ---------- */
#main { flex: 1; display: flex; min-height: 0; position: relative; }

#sidebar { width: 232px; flex: 0 0 auto; border-right: 1px solid #e5e5e5; overflow: auto; background: #fcfcfc; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; font-weight: 700; font-size: 13px; color: #555;
  text-transform: uppercase; letter-spacing: .04em;
}
#newMapBtn {
  border: 1px solid #d5d5d5; background: #fff; border-radius: 6px;
  padding: 3px 8px; cursor: pointer; font-size: 12px;
}
#newMapBtn:hover { background: #eef4ff; border-color: #2563eb; color: #2563eb; }
#mapList { list-style: none; margin: 0; padding: 0 6px 12px; max-height: 42vh; overflow: auto; }
#mapList li {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
#mapList li:hover { background: #f0f0f0; }
#mapList li.active { background: #e3edff; font-weight: 600; }
#mapList .mname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mapList .mdel {
  border: none; background: none; color: #bbb; cursor: pointer;
  font-size: 15px; padding: 0 4px; border-radius: 4px; visibility: hidden;
}
#mapList li:hover .mdel { visibility: visible; }
#mapList .mdel:hover { color: #dc2626; background: #fee2e2; }

#canvasWrap { flex: 1; position: relative; min-width: 0; background: #fff; }
#map { width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- панель инструментов (в сайдбаре) ---------- */
#toolbar {
  display: flex; flex-direction: column; gap: 2px; padding: 0 10px 14px;
}
#toolbar button {
  border: none; background: none; border-radius: 7px; text-align: left;
  padding: 7px 10px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
#toolbar button:hover { background: #f0f0f0; }
#toolbar button.active { background: #2563eb; color: #fff; }

/* ---------- панель свойств ---------- */
/* панель — оверлей поверх холста: её появление не сдвигает карту */
#props {
  position: absolute; right: 0; top: 0; bottom: 0; z-index: 6;
  width: 252px; border-left: 1px solid #e5e5e5;
  padding: 14px; overflow: auto; background: #fcfcfcf2; font-size: 13.5px;
  box-shadow: -4px 0 14px rgba(0,0,0,.06);
}
#props h3 { margin: 0 0 12px; font-size: 14px; }
#props label { display: block; margin-bottom: 10px; color: #444; }
#props label.check { display: flex; align-items: center; gap: 7px; cursor: pointer; }
#props input[type="text"], #props textarea, #props select {
  width: 100%; margin-top: 4px; padding: 6px 8px;
  border: 1px solid #d5d5d5; border-radius: 6px; font: inherit; background: #fff;
}
#props textarea { min-height: 80px; resize: vertical; }
#props .group { border-top: 1px solid #e5e5e5; margin-top: 12px; padding-top: 10px; }
#props .group-title { font-weight: 600; margin-bottom: 8px; color: #333; }
#props button {
  border: 1px solid #d5d5d5; background: #fff; border-radius: 6px;
  padding: 6px 10px; cursor: pointer; font-size: 13px; margin: 0 6px 6px 0;
}
#props button:hover { background: #f0f0f0; }
#props button.primary { background: #2563eb; border-color: #2563eb; color: #fff; }
#props button.primary:hover { background: #1d4ed8; }
#props button.danger { color: #dc2626; border-color: #fca5a5; }
#props button.danger:hover { background: #fee2e2; }
#props .muted { color: #888; font-size: 12.5px; margin-bottom: 8px; }

/* ---------- SVG ---------- */
#map [data-kind="comp"] { cursor: grab; }
#map [data-role="evolve"] { cursor: ew-resize; }
#map [data-role="p1"], #map [data-role="p2"] { cursor: ew-resize; }
#map [data-kind="note"] { cursor: grab; }
#map [data-role="ntarget"] { cursor: move; }
#map [data-kind="link"] { cursor: pointer; }
#map [data-kind="stage"] { cursor: text; }
#map .nodelabel { user-select: none; pointer-events: none; paint-order: stroke; stroke: #ffffff; stroke-width: 3px; stroke-linejoin: round; }
#map text { user-select: none; }
#canvasWrap.mode-add #map { cursor: crosshair; }
#canvasWrap.mode-link #map [data-kind="comp"] { cursor: alias; }

/* ---------- плавающий редактор ---------- */
.floating-input {
  position: fixed; z-index: 50;
  border: 1.5px solid #2563eb; border-radius: 6px;
  padding: 4px 7px; font: 14px system-ui, sans-serif;
  box-shadow: 0 3px 12px rgba(0,0,0,.15);
}

/* ---------- справка ---------- */
#help {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
}
#help[hidden] { display: none; }
#helpCard {
  background: #fff; border-radius: 14px; padding: 20px 26px;
  max-width: 640px; max-height: 86vh; overflow: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.help-head { display: flex; align-items: center; justify-content: space-between; }
.help-head h2 { margin: 0; font-size: 18px; }
#helpClose { border: none; background: none; font-size: 26px; cursor: pointer; color: #888; }
#helpClose:hover { color: #111; }
.legend { border-collapse: collapse; margin-top: 12px; }
.legend td { padding: 6px 8px; vertical-align: middle; font-size: 13.5px; border-bottom: 1px solid #f0f0f0; }
.legend td:first-child { text-align: center; }
#helpCard h3 { font-size: 14px; margin: 16px 0 6px; }
.hints { margin: 0; padding-left: 18px; font-size: 13.5px; color: #444; }
.hints li { margin-bottom: 4px; }
