/* =========================================================
   deeBoard v4 — Floating Flowchart Windows
   Mirrors notes.css window architecture (header/body/drag/resize)
========================================================= */

/* ---------- Header trigger (place next to notes-trigger-btn) ---------- */
.flowchart-trigger-btn {
  width: auto !important;
  padding: 0 12px !important;
  gap: 6px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-md);
}
.flowchart-trigger-btn .flowchart-trigger-label {
  font-size: 13px;
  font-weight: 600;
}
@media (max-width: 640px) {
  .flowchart-trigger-btn .flowchart-trigger-label { display: none; }
  .flowchart-trigger-btn { padding: 0 8px !important; }
}

/* ---------- Flowchart window (same shell as note-window) ---------- */
.flowchart-window {
  position: absolute;
  pointer-events: all;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px var(--shadow-color);
  min-width: 420px;
  min-height: 320px;
  overflow: hidden;
  resize: none;
  animation: noteWindowIn 0.16s cubic-bezier(0.16, 1, 0.3, 1);
  /* iOS Safari fires its own text-selection/"copy" callout on any
     tap-and-hold — including on SVG elements — unless explicitly
     disabled. This was hijacking our custom long-press-to-delete-edge
     gesture on iPad. Applied here at the window root (not just while
     .dragging) so it also covers plain long-press on edges/nodes that
     never enters a drag state at all. The node comment textarea below
     explicitly re-enables text selection for itself (see .flowchart-node-comment).*/
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.flowchart-window.dragging,
.flowchart-window.resizing {
  transition: none;
}
.flowchart-window.focused {
  border-color: var(--accent);
  box-shadow: 0 24px 60px var(--shadow-color), 0 0 0 1px var(--accent-soft);
}

.flowchart-window-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-soft);
  cursor: grab;
  flex-shrink: 0;
  user-select: none;
}
.flowchart-window-header:active { cursor: grabbing; }

.flowchart-window-title {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  padding: 4px 6px;
  border-radius: 6px;
}
.flowchart-window-title:focus { background: var(--surface-hover); }

.flowchart-window-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.flowchart-window-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-size: 15px;
}
.flowchart-window-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.flowchart-window-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}
.flowchart-window-btn.close:hover {
  background: var(--accent-rose-soft);
  color: var(--accent-rose);
}
.flowchart-window-save-indicator {
  font-size: 10.5px;
  color: var(--text-tertiary);
  padding: 0 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.flowchart-window-body {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden; /* the canvas itself pans via transform, body clips it */
  background:
    radial-gradient(circle, var(--border-soft) 1px, transparent 1px);
  background-size: 22px 22px;
  cursor: grab;
}
.flowchart-window-body.panning { cursor: grabbing; }

/* ---------- Inner pannable canvas ---------- */
.flowchart-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  /* No CSS transition here on purpose: pan AND zoom are both driven by a
     JS requestAnimationFrame loop (see setupPanning in flowchart.js) that
     lerps toward a target every frame. A CSS transition running at the
     same time as JS writing to the same `transform` property every frame
     would fight itself and look janky/stuttery instead of smooth. */
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* will-change is only turned on while a transform is actually changing
   (live drag, or the rAF glide) — leaving it on at rest pins the canvas
   to its own compositing layer permanently, which is what was making
   node/edge text look soft/blurry all the time. */
.flowchart-window-body.panning .flowchart-canvas,
.flowchart-canvas.animating {
  will-change: transform;
}

/* SVG layer for connector arrows — lives INSIDE .flowchart-canvas so it
   pans together with the nodes under the same transform. Sits behind
   nodes via normal DOM order (appended first). */
.flowchart-edges-svg {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}
.flowchart-edge-path {
  fill: none;
  stroke: var(--text-tertiary);
  stroke-width: 2;
  /* marker-end is set inline per-path in JS (drawEdges), pointing at a
     marker id unique to this window — NOT here, because a shared/hardcoded
     id here would resolve against whichever window's <marker> happens to
     be in the DOM, causing arrows to randomly lose their heads when more
     than one flowchart window is open. */
}
.flowchart-edge-comment-bg {
  fill: var(--bg-elevated);
}
.flowchart-edge-comment-text {
  fill: var(--text-secondary);
  font-family: "Inter", sans-serif;
  font-size: 11px;
}

/* ---------- Empty state ---------- */
.flowchart-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.flowchart-empty-add {
  pointer-events: all;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px dashed var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.flowchart-empty-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.06);
}
.flowchart-empty-state p {
  font-size: 13px;
  text-align: center;
  max-width: 220px;
}

/* ---------- Node ---------- */
.flowchart-node {
  position: absolute;
  width: 220px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 14px var(--shadow-color);
  padding: 10px 12px;
  cursor: grab;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.flowchart-node:hover,
.flowchart-node.active {
  border-color: var(--accent);
  box-shadow: 0 8px 22px var(--shadow-color);
}
.flowchart-node.dragging-move {
  cursor: grabbing;
  border-color: var(--accent);
  box-shadow: 0 10px 26px var(--shadow-color);
  z-index: 3;
}
/* Same look the old title field had (bold, slightly larger) — this is now
   the node's only text field, so its content reads like a heading while
   still being a free-form description rather than a strict "title". */
.flowchart-node-comment {
  width: 100%;
  resize: none;
  background: transparent;
  border: none;
  outline: none;
  cursor: text;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.4;
  min-height: 18px;
  overflow: hidden; /* auto-resized via JS (input handler sets scrollHeight) */
  padding: 2px 0;
  /* .flowchart-window disables selection/callout globally (for the
     long-press-to-delete-edge gesture) — undo that specifically inside
     the editable textarea so normal text editing/selection still works. */
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
.flowchart-node-comment::placeholder { color: var(--text-tertiary); }

/* ---------- Link-note button (inside, below the comment) ----------
   DISEMBUNYIKAN SEMENTARA — fitur link catatan belum siap rilis.
   Tinggal hapus baris "display: none !important;" ini untuk mengaktifkan
   kembali; sisa style di bawah tidak diubah supaya gampang di-restore. */
.flowchart-node-link-note {
  display: none !important;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--surface-hover);
  color: var(--text-tertiary);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  opacity: 1;  /* always visible on mobile */
}
.flowchart-node-link-note:hover {
  color: var(--accent-strong);
  border-color: var(--accent);
}
.flowchart-node-link-note.has-links {
  color: var(--accent-strong);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.flowchart-node-link-note-count {
  font-weight: 600;
}
@media (min-width: 641px) {
  /* Only hide on hover on desktop; mobile needs it always visible */
  .flowchart-node-link-note {
    opacity: 0.6;
  }
  .flowchart-node:hover .flowchart-node-link-note {
    opacity: 1;
  }
}

.flowchart-node-del {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--accent-rose-soft);
  color: var(--accent-rose);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.flowchart-node:hover .flowchart-node-del { opacity: 1; }
.flowchart-node-del:hover { transform: scale(1.1); }

/* ---------- Directional handles (now drag-to-connect, not click-to-add) ---------- */
.flowchart-node-add {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: grab;
  opacity: 0;
  transition: opacity 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
  z-index: 2;
}
.flowchart-node:hover .flowchart-node-add { opacity: 1; }
.flowchart-node-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.15);
}
.flowchart-node-add:active { cursor: grabbing; }
.flowchart-node-add.dir-top    { top: -11px; left: 50%; margin-left: -11px; }
.flowchart-node-add.dir-bottom { bottom: -11px; left: 50%; margin-left: -11px; }
.flowchart-node-add.dir-left   { left: -11px; top: 50%; margin-top: -11px; }
.flowchart-node-add.dir-right  { right: -11px; top: 50%; margin-top: -11px; }

/* While a connect-drag is in progress, keep the grabbing cursor over the
   whole canvas (not just the handle) and suppress the body's own
   grab/pan cursor so the two gestures never visually fight each other. */
.flowchart-window-body.connect-dragging {
  cursor: grabbing;
}

/* ---------- Node connect drag preview line ---------- */
.flowchart-drag-preview {
  fill: none;
  stroke: var(--text-tertiary);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease, stroke 0.1s ease;
}
.flowchart-drag-preview.active { opacity: 0.75; }
/* Dropping here would create a new node too close to the origin node —
   cancels silently on release. */
.flowchart-drag-preview.invalid {
  stroke: var(--accent-rose);
  opacity: 0.85;
}
/* Hovering an existing node — releasing here connects to it instead of
   creating a new node. Solid line (not dashed) previews the real edge. */
.flowchart-drag-preview.snapping {
  stroke: var(--accent);
  stroke-dasharray: none;
  opacity: 0.9;
}

/* ---------- Edge comment "add" affordance (double-click hint handled in JS) ---------- */
.flowchart-edge-hitbox {
  stroke: transparent;
  stroke-width: 14;
  fill: none;
  pointer-events: all;
  cursor: pointer;
}

/* ---------- Resize handle — thumb-sized, same on mobile & desktop ----------
   Single mechanism (JS-driven, see setupResizeHandleTouch in flowchart.js):
   native CSS `resize` is off, this is the only way to resize a window,
   width or height, always clamped to the viewport. */
.flowchart-window-resize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 44px;
  height: 44px;
  touch-action: none;
  cursor: nwse-resize;
  z-index: 5;
}
.flowchart-window-resize-handle::after {
  content: "";
  width: 16px;
  height: 16px;
  background:
    linear-gradient(135deg, transparent 0 50%, var(--accent) 50% 58%, transparent 58% 100%),
    linear-gradient(135deg, transparent 0 68%, var(--accent) 68% 76%, transparent 76% 100%);
  opacity: 0.85;
}

@media (max-width: 640px) {
  .flowchart-window {
    min-width: 300px;
    min-height: 260px;
    touch-action: none;
  }
  .flowchart-window-body {
    touch-action: none;
  }
  .flowchart-window-header {
    touch-action: none;
  }
}