:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --pv: #2563eb;
  --uc: #16a34a;
  --us: #d97706;
  --sel: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* Top bar */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.plan-title {
  font-size: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 220px;
  background: transparent;
}
.plan-title:hover, .plan-title:focus { border-color: var(--border); outline: none; }
.actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }

.btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
.btn.primary:hover { background: #1e293b; }
.btn.danger { color: var(--sel); }
.btn.add.pv { color: var(--pv); border-color: color-mix(in srgb, var(--pv) 40%, white); }
.btn.add.uc { color: var(--uc); border-color: color-mix(in srgb, var(--uc) 40%, white); }
.btn.add.us { color: var(--us); border-color: color-mix(in srgb, var(--us) 40%, white); }
.btn.small { padding: 3px 8px; font-size: 12px; }

/* Layout */
.layout { display: flex; height: calc(100% - 56px); }

.board {
  position: relative;
  flex: 1;
  overflow: auto;
  background-color: var(--bg);
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 20px 20px;
}
.canvas { position: relative; width: 4000px; height: 3000px; }
.edges { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.edge { fill: none; stroke: #64748b; stroke-width: 2; marker-end: url(#arrow); pointer-events: none; }
.edge.selected { stroke: var(--sel); marker-end: url(#arrowSel); }
.edge.temp { stroke-dasharray: 6 4; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; pointer-events: stroke; }
.edge-label {
  font-size: 12px;
  fill: var(--text);
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  pointer-events: none;
}

.empty-hint {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--muted);
  pointer-events: none;
  max-width: 420px;
}

/* Event cards */
.node {
  position: absolute;
  width: 230px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 4px solid var(--c);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .08);
  cursor: grab;
  user-select: none;
}
.node.dragging { cursor: grabbing; box-shadow: 0 6px 18px rgba(15, 23, 42, .18); }
.node.selected { outline: 2px solid var(--c); outline-offset: 1px; }
.node[data-type="page_view"] { --c: var(--pv); }
.node[data-type="user_click"] { --c: var(--uc); }
.node[data-type="user_shown"] { --c: var(--us); }

.node-head { padding: 8px 10px 4px; }
.node-type {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 10%, white);
  padding: 1px 6px;
  border-radius: 4px;
}
.node-name { font-weight: 600; margin-top: 4px; word-break: break-word; }
.node-area { font-size: 12px; color: var(--muted); word-break: break-word; }
.node-body {
  padding: 4px 10px 8px;
  font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #334155;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}
.node-body .k { color: var(--muted); }
.node-body .more { color: var(--muted); font-style: italic; }

.port {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--c);
  cursor: crosshair;
}
.port.in { left: -8px; }
.port.out { right: -8px; }
.port:hover, .port.target { background: var(--c); }

/* Inspector */
.inspector {
  width: 360px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 16px;
}
.inspector h2 { font-size: 15px; margin: 0 0 12px; }
.inspector h3 { font-size: 13px; margin: 18px 0 8px; display: flex; align-items: center; justify-content: space-between; }
.inspector .muted { color: var(--muted); font-size: 13px; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field input, .field textarea, .field select, .kv input {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.field textarea { resize: vertical; min-height: 54px; }
.field input:focus, .field textarea:focus, .kv input:focus { outline: none; border-color: #94a3b8; }

.kv { display: grid; grid-template-columns: 1fr 1fr 26px; gap: 4px; margin-bottom: 4px; }
.kv input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; padding: 5px 6px; }
.kv .del {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.kv .del:hover { color: var(--sel); }

.row { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.conn-list { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.conn-list li { padding: 4px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }
.conn-list a { color: var(--text); cursor: pointer; text-decoration: underline; }
.event-list li { cursor: pointer; }
.event-list li:hover { background: #f8fafc; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
pre.preview {
  background: #0f172a;
  color: #e2e8f0;
  padding: 10px;
  border-radius: 6px;
  font-size: 11px;
  overflow-x: auto;
  margin: 0;
}

/* In-page confirm dialog (replaces native confirm/alert) */
dialog.ask {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .25);
}
dialog.ask::backdrop { background: rgba(15, 23, 42, .35); }
dialog.ask p { margin: 0; white-space: pre-line; }
dialog.ask .row { justify-content: flex-end; }
.btn.danger.solid { background: var(--sel); border-color: var(--sel); color: #fff; }
