:root {
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --line: #e3e6eb;
  --accent: #3b6ef6;
  --accent-soft: #eaf0ff;
  --danger: #e5484d;
  --bg: #ffffff;
  --panel: #ffffff;
  --grid-dot: #eef0f3;
  --node-bg: #ffffff;
  --node-border: #c7cdd8;
  --node-selected: #3b6ef6;
  --label-bg: #ffffff;
  --shadow-sm: 0 1px 2px rgba(20, 24, 33, 0.06);
  --shadow-md: 0 6px 20px rgba(20, 24, 33, 0.12);
  --radius: 10px;
  --cursor-black: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 22 22'><path d='M2 1 L2 16.5 L6 13 L8.7 19 L11.5 17.7 L8.8 12 L14.5 12 Z' fill='black' stroke='white' stroke-width='1.2' stroke-linejoin='round'/></svg>") 2 1, auto;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}
body {
  display: flex;
  flex-direction: column;
}

/* Everything below the toolbar: the canvas plus the media sidebar, side by
   side. min-height: 0 is what lets .canvas-viewport's own height:100% (see
   canvas.css) actually be constrained by this flex row instead of pushing
   the body taller than the viewport. */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

button { font-family: inherit; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 52px;
  flex-shrink: 0;
  padding: 0 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.toolbar-end { margin-left: auto; }

.toolbar-brand {
  gap: 6px;
  padding-right: 6px;
  border-right: 1px solid var(--line);
  min-width: 0;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #3b6ef6, #6a8bff);
  color: white;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.map-title-wrap { display: flex; flex-direction: column; line-height: 1.15; min-width: 40px; max-width: 72px; flex-shrink: 1; }

.map-title {
  font-size: 14px;
  font-weight: 600;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 5px;
}
.map-title:hover { background: #f4f5f7; }
.map-title:focus { background: var(--accent-soft); }

.save-status { font-size: 11px; color: var(--ink-soft); padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-status.dirty { color: #b5850a; }
.save-status.saved { color: #1a9e6b; }
.save-status.readonly { color: var(--accent); font-weight: 600; }

.tbtn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 9px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.tbtn:hover { background: #f2f4f7; }
.tbtn:active { background: #e7eaef; }
.tbtn.icon-only { padding: 0; width: 27px; justify-content: center; }
.tbtn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.tbtn.primary { background: var(--accent); color: white; }
.tbtn.primary:hover { background: #2f5fe0; }
.tbtn.tool-active { background: var(--accent-soft); color: var(--accent); }
.tbtn.tool-active:hover { background: var(--accent-soft); }
.tbtn.danger { background: var(--danger); color: white; }
.tbtn.danger:hover { background: #d13236; }
.tbtn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }

.zoom-label { font-size: 11px; color: var(--ink-soft); width: 30px; text-align: center; user-select: none; flex-shrink: 0; }
