/* Plan → Diagrams. Everything here is under .dg-, and themed through the
   app's own variables so light and dark both read. */

.dg-board {
  --dg-dot: #d5d7de;
  --dg-tile: var(--tf-canvas);
  --dg-edge: #5b6275;
  --dg-shadow: 0 1px 2px rgb(16 24 40 / .06), 0 4px 12px rgb(16 24 40 / .06);
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--tf-shell);
}
[data-theme="dark"] .dg-board {
  --dg-dot: #2f2a3d;
  --dg-tile: #201c2b;
  --dg-edge: #a9a2be;
  --dg-shadow: 0 1px 2px rgb(0 0 0 / .4), 0 6px 16px rgb(0 0 0 / .3);
}

/* ---- its own tab: the canvas is the window ---- */
body.dg-standalone { margin: 0; height: 100vh; overflow: hidden; background: var(--tf-shell); color: var(--tf-ink); font-family: var(--tf-ui); }
body.dg-standalone .dg-board { height: 100vh; }
.dg-back {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: var(--tf-radius-sm);
  color: var(--tf-ink-2); text-decoration: none; font-size: 13px; white-space: nowrap; max-width: 18ch;
}
.dg-back span { overflow: hidden; text-overflow: ellipsis; }
.dg-back:hover { background: var(--tf-hover); color: var(--tf-ink); }
.dg-owner { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; color: var(--tf-ink-3); white-space: nowrap; }
.dg-owner .form-select { width: auto; max-width: 26ch; }

/* ---- index ---- */
.dg-new { display: flex; gap: 8px; margin-bottom: 18px; }
.dg-new .form-control { flex: 1; }
.dg-new .btn { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.dg-list { padding: 4px 0; }
.dg-list-row { display: flex; align-items: center; gap: 8px; padding: 0 10px 0 0; }
.dg-list-row + .dg-list-row { border-top: 1px solid var(--tf-line-soft); }
.dg-list-link { flex: 1; display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: inherit; text-decoration: none; }
.dg-list-link:hover strong { color: var(--tf-violet); }
.dg-list-icon {
  flex: none; width: 34px; height: 34px; border-radius: var(--tf-radius); display: grid; place-items: center;
  color: var(--tf-violet); background: var(--tf-violet-tint);
}
.dg-owner-chip {
  display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; color: var(--tf-ink-2); background: var(--tf-hover); vertical-align: 1px;
}
.dg-list-delete:hover { color: var(--tf-red) !important; }

/* ---- on a project, task or epic ---- */
.dg-attached-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.dg-attached-link {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--tf-radius);
  color: inherit; text-decoration: none;
}
.dg-attached-link:hover { background: var(--tf-hover); }
.dg-attached-link:hover strong { color: var(--tf-violet); }
.dg-attached-link .dg-list-icon { width: 28px; height: 28px; }
.dg-attached-new { margin: 0; }
.dg-attached-new .btn { display: inline-flex; align-items: center; gap: 6px; }

/* ---- bar ---- */
.dg-bar {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  border-bottom: 1px solid var(--tf-line); background: var(--tf-canvas);
}
.dg-bar .btn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.dg-title {
  font-weight: 650; font-size: 15px; border: 1px solid transparent; background: none; color: var(--tf-ink);
  padding: 4px 8px; border-radius: var(--tf-radius-sm); width: 30ch; min-width: 8ch;
}
input.dg-title:hover, input.dg-title:focus { border-color: var(--tf-line); outline: none; }
.dg-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--tf-hover); color: var(--tf-ink-2); }
.dg-status { font-size: 12px; color: var(--tf-ink-3); white-space: nowrap; }
.dg-status.is-saving { color: var(--tf-violet); }
.dg-status.is-error { color: var(--tf-red); font-weight: 600; }
.dg-spacer { flex: 1; }
.dg-peers { display: flex; }
.dg-peer {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff; background: hsl(var(--hue) 55% 48%);
  border: 2px solid var(--tf-canvas); margin-left: -6px;
}

/* ---- body ---- */
.dg-body { flex: 1; min-height: 0; display: flex; }
.dg-palette {
  flex: none; width: 196px; padding: 12px; overflow: auto;
  border-right: 1px solid var(--tf-line); background: var(--tf-canvas);
}
.dg-palette-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--tf-ink-3); margin-bottom: 8px; font-weight: 600;
}
.dg-palette-item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin-bottom: 4px; font-size: 13px;
  border: 1px solid var(--tf-line); border-radius: var(--tf-radius); cursor: grab; background: var(--dg-tile); user-select: none;
}
.dg-palette-item:hover { border-color: var(--c); }
.dg-palette-item .dg-icon { width: 22px; height: 22px; padding: 2px; color: var(--c); }
.dg-help { margin-top: 14px; font-size: 12px; color: var(--tf-ink-3); }
.dg-help p { margin: 0 0 8px; }
.dg-help kbd {
  font: 11px var(--tf-mono); padding: 0 4px; border: 1px solid var(--tf-line); border-radius: 4px;
  background: var(--tf-shell); color: var(--tf-ink-2);
}

/* ---- canvas ---- */
.dg-viewport {
  flex: 1; min-width: 0; position: relative; overflow: hidden; outline: none;
  touch-action: none; user-select: none; -webkit-user-select: none;
  background-color: var(--tf-shell);
  background-image: radial-gradient(circle, var(--dg-dot) 1.1px, transparent 1.3px);
}
.dg-viewport.is-panning { cursor: grabbing; }
.dg-viewport.is-gone { opacity: .5; pointer-events: none; }
.dg-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.dg-layer, .dg-edges { position: absolute; left: 0; top: 0; }
.dg-edges { overflow: visible; }
.dg-empty {
  position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%);
  color: var(--tf-ink-3); pointer-events: none; font-size: 15px;
}
.dg-marquee {
  position: absolute; border: 1px solid var(--tf-violet); pointer-events: none;
  background: color-mix(in srgb, var(--tf-violet) 10%, transparent);
}

/* ---- tiles ---- */
.dg-node {
  --c: #3b82f6;
  position: absolute; display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-radius: 10px; background: var(--dg-tile); border: 2px solid var(--c);
  box-shadow: var(--dg-shadow); color: var(--tf-ink);
}
.dg-board:not(.is-read-only) .dg-node { cursor: move; }
.dg-node.is-selected { outline: 3px solid color-mix(in srgb, var(--tf-violet) 45%, transparent); outline-offset: 3px; }
.dg-node.is-drop-target { outline: 3px solid var(--tf-violet); outline-offset: 3px; }
.dg-icon svg { width: 100%; height: 100%; display: block; }
.dg-node > .dg-icon {
  flex: none; width: 30px; height: 30px; border-radius: 8px; padding: 5px;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
}
.dg-node-label {
  flex: 1; min-width: 0; max-height: 100%; overflow: hidden; outline: none;
  font-weight: 600; font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; white-space: pre-wrap;
}
.dg-node-label[contenteditable="true"] {
  user-select: text; -webkit-user-select: text; cursor: text; overflow: auto;
  background: color-mix(in srgb, var(--tf-violet) 8%, transparent); border-radius: 4px;
}
.dg-node-notes { position: absolute; right: 6px; top: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--c); opacity: .7; }
.dg-node-notes[hidden] { display: none; }

.dg-node.dg-kind-database { border-radius: 10px / 18px; }
.dg-node.dg-kind-external { border-style: dashed; }
.dg-node.dg-kind-user { border-radius: 999px; }
.dg-node.dg-kind-note {
  align-items: flex-start; border: 0; border-radius: 4px; background: color-mix(in srgb, var(--c) 28%, var(--dg-tile));
}
.dg-node.dg-kind-note > .dg-icon { display: none; }
.dg-node.dg-kind-note .dg-node-label { font-weight: 500; }
.dg-node.dg-kind-group {
  align-items: flex-start; box-shadow: none;
  background: color-mix(in srgb, var(--c) 7%, transparent);
  border: 2px dashed color-mix(in srgb, var(--c) 70%, transparent);
}
.dg-node.dg-kind-group > .dg-icon { width: 24px; height: 24px; padding: 3px; }
.dg-node.dg-kind-group .dg-node-label { flex: none; max-width: calc(100% - 40px); color: color-mix(in srgb, var(--c) 70%, var(--tf-ink)); }

.dg-handle {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; border-radius: 50%;
  background: var(--tf-canvas); border: 2px solid var(--tf-violet); cursor: crosshair; opacity: 0; transition: opacity var(--tf-ease);
}
.dg-handle[data-side="n"] { left: 50%; top: 0; }
.dg-handle[data-side="s"] { left: 50%; top: 100%; }
.dg-handle[data-side="w"] { left: 0; top: 50%; }
.dg-handle[data-side="e"] { left: 100%; top: 50%; }
.dg-handle:hover { transform: scale(1.3); background: var(--tf-violet); }
.dg-resize {
  position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; cursor: nwse-resize; opacity: 0;
  background: linear-gradient(135deg, transparent 50%, var(--tf-violet) 50%); border-bottom-right-radius: 8px;
}
.dg-node:hover .dg-handle, .dg-node.is-selected .dg-handle, .dg-node:hover .dg-resize, .dg-node.is-selected .dg-resize,
.dg-viewport.is-connecting .dg-handle { opacity: 1; }

/* ---- connections ---- */
.dg-edge-hit { stroke: transparent; stroke-width: 16; fill: none; cursor: pointer; pointer-events: stroke; }
.dg-edge-glow { fill: none; stroke: none; pointer-events: none; }
.dg-edge-line { fill: none; stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.dg-edge-arrow { pointer-events: none; }
.dg-edge.is-selected .dg-edge-line { stroke-width: 3.5; }
.dg-edge.is-selected .dg-edge-glow { stroke: color-mix(in srgb, var(--tf-violet) 30%, transparent); stroke-width: 10; }
.dg-edge-ghost { fill: none; stroke: var(--tf-violet); stroke-width: 2; stroke-dasharray: 6 5; pointer-events: none; }
.dg-edge-label {
  position: absolute; transform: translate(-50%, -50%); padding: 2px 8px; border-radius: 6px;
  white-space: pre; font-size: 12px; font-weight: 600; cursor: pointer;
  background: var(--tf-canvas); border: 1px solid var(--tf-line); color: var(--tf-ink); box-shadow: var(--dg-shadow);
}
.dg-edge-label.is-selected { border-color: var(--tf-violet); }
.dg-edge-label.is-empty { display: none; }
.dg-edge-label input {
  border: 0; outline: none; background: none; color: inherit; width: 14ch; font-weight: 600; font-size: 12px; text-align: center;
}

/* ---- inspector ---- */
.dg-inspector {
  flex: none; width: 264px; padding: 14px; overflow: auto;
  border-left: 1px solid var(--tf-line); background: var(--tf-canvas);
}
.dg-inspector[hidden] { display: none; }
.dg-inspector h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--tf-ink-3); font-weight: 600; }
.dg-inspector label { display: block; font-size: 12px; color: var(--tf-ink-2); margin: 12px 0 4px; font-weight: 600; }
.dg-inspector textarea { resize: vertical; min-height: 96px; }
.dg-route { font-size: 13px; color: var(--tf-ink-2); }
.dg-read-label { font-weight: 600; white-space: pre-wrap; }
.dg-read-notes { white-space: pre-wrap; font-size: 13px; color: var(--tf-ink-2); }
.dg-swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.dg-swatch {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
  background: var(--s); box-shadow: inset 0 0 0 1px rgb(0 0 0 / .1);
}
.dg-swatch.is-default { background: conic-gradient(#3b82f6 0 25%, #10b981 0 50%, #f59e0b 0 75%, #8b5cf6 0); }
.dg-swatch.is-on { border-color: var(--tf-ink); }
.dg-seg { display: flex; border: 1px solid var(--tf-line); border-radius: var(--tf-radius-sm); overflow: hidden; }
.dg-seg button { flex: 1; padding: 5px 0; border: 0; background: none; color: var(--tf-ink); cursor: pointer; }
.dg-seg button + button { border-left: 1px solid var(--tf-line); }
.dg-seg button.is-on { background: var(--tf-violet); color: #fff; }
.dg-row { display: flex; gap: 8px; margin-top: 18px; }
.dg-row button {
  flex: 1; padding: 6px; border-radius: var(--tf-radius-sm); border: 1px solid var(--tf-line);
  background: none; color: var(--tf-ink); cursor: pointer; font-size: 13px;
}
.dg-row button:hover { background: var(--tf-hover); }
.dg-row .is-danger { color: var(--tf-red); }

/* ---- zoom ---- */
.dg-zoom {
  position: absolute; right: 14px; bottom: 14px; display: flex; overflow: hidden;
  background: var(--tf-canvas); border: 1px solid var(--tf-line); border-radius: var(--tf-radius); box-shadow: var(--dg-shadow);
}
.dg-zoom button { border: 0; background: none; color: var(--tf-ink); padding: 6px 11px; min-width: 34px; cursor: pointer; font-size: 13px; }
.dg-zoom button + button { border-left: 1px solid var(--tf-line); }
.dg-zoom button:hover { background: var(--tf-hover); }
.dg-zoom [data-diagram-target="zoom"] { min-width: 60px; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .dg-palette { display: none; }
  .dg-inspector { position: absolute; right: 0; bottom: 0; top: auto; width: 100%; max-height: 45%; border-left: 0; border-top: 1px solid var(--tf-line); z-index: 2; }
  .dg-body { position: relative; }
  .dg-title { width: 16ch; }
  .dg-owner span, .dg-back span, .dg-bar .btn span { display: none; }
}
