/* ---------- LOGIC BUILDER PAGE ---------- */
/* the canvas utility toolbar and the trigger/action node palette are
   shared components, see .canvas-toolbar and .palette-panel in the
   shared dashboard.css (the same pieces the Visual Builder uses). */

  /* holds the canvas and the live preview side by side, always both
     visible: replaces the old toggle-between-them behavior so the
     real page is on screen the whole time you're wiring a flow, not
     just when you remember to switch to it. */
  .logic-canvas-preview-split{
    display: flex;
    flex: 1;
    min-width: 0;
    gap: 12px;
    height: calc(100vh - 260px);
    min-height: 420px;
  }

  .logic-canvas-wrap{
    flex: 1;
    min-width: 0;
    height: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: auto;
    position: relative;
  }

  /* static sibling pane, not the absolute overlay Builder's live
     preview uses (.builder-live-preview in dashboard.css). Logic
     needs both the canvas and the real page visible at once so
     clicking an element in here can set it as a node's target. */
  .logic-live-preview-pane{
    width: 400px;
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  .logic-live-preview-pane iframe{
    flex: 1;
    width: 100%;
    border: none;
    background: #ffffff;
  }

  @media (max-width: 1100px){
    .logic-canvas-preview-split{
      flex-direction: column;
      height: auto;
    }
    .logic-canvas-wrap{
      height: 420px;
    }
    .logic-live-preview-pane{
      width: 100%;
      height: 360px;
    }
  }

  .logic-canvas{
    width: 100%;
    height: 100%;
    min-height: 800px;
    min-width: 1000px;
    position: relative;
    background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
    background-size: 20px 20px;
  }

  /* the canvas itself is deliberately wider/taller than the wrap
     (min-width/min-height above) so there's room to place nodes, but
     that means centering this message with position:absolute inset:0
     centers it in the CANVAS, not the visible viewport. on a phone,
     where the wrap is much narrower than the canvas, that puts the
     text off-screen to the right until you scroll sideways to find
     it. position:sticky centers it in the currently-visible part of
     the scrollable wrap instead, wherever that happens to be scrolled. */
  .logic-empty{
    position: sticky;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: max-content;
    max-width: min(320px, calc(100vw - 80px));
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 40px 20px;
  }

  /* ---------- NODES ---------- */

  .logic-node{
    position: absolute;
    width: 160px;
    min-height: 56px;
    background: linear-gradient(165deg, var(--surface2) 0%, var(--surface) 65%);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    cursor: grab;
    user-select: none;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), transform 0.2s var(--ease), background 0.2s var(--ease);
    box-shadow: var(--shadow-sm);
  }

  .logic-node:hover:not(.dragging){
    border-color: var(--accent-dim);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }

  .logic-node.selected{
    border-color: var(--accent);
    background: linear-gradient(165deg, rgba(108,99,255,0.14) 0%, var(--surface2) 45%, var(--surface) 100%);
    box-shadow: 0 0 0 2px rgba(108,99,255,0.22), var(--shadow-md), 0 0 22px -8px rgba(108,99,255,0.45);
  }

  .logic-node.dragging{
    cursor: grabbing;
    opacity: 0.9;
    z-index: 10;
    transition: none;
    box-shadow: var(--shadow-lg);
  }

  .logic-node-label{
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
  }

  .logic-node-tag{
    font-family: var(--mono);
    font-size: 9px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 4px;
  }

  /* ---------- CONNECTIONS ---------- */

  .logic-connections-svg{
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
  }

  #logicNodesLayer{
    position: absolute;
    inset: 0;
  }

  .conn-hit-path{
    stroke: transparent;
    stroke-width: 14px;
    fill: none;
    pointer-events: stroke;
    cursor: pointer;
  }

  .conn-visible-path{
    stroke: var(--muted);
    stroke-width: 2px;
    fill: none;
    pointer-events: none;
    transition: stroke 0.15s var(--ease), stroke-width 0.15s var(--ease);
  }

  .conn-visible-path.selected{
    stroke: var(--accent);
    stroke-width: 2.5px;
    filter: drop-shadow(0 0 3px rgba(108,99,255,0.45));
  }

  .conn-draft-path{
    stroke: var(--accent);
    stroke-width: 2px;
    stroke-dasharray: 5 4;
    fill: none;
    pointer-events: none;
    filter: drop-shadow(0 0 4px rgba(108,99,255,0.6));
  }

  .conn-arrowhead{
    fill: var(--muted);
  }

  .conn-arrowhead.selected{
    fill: var(--accent);
  }

  .logic-node{ z-index: 2; }

  .logic-node-port{
    position: absolute;
    top: 50%;
    right: -7px;
    transform: translateY(-50%);
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--accent);
    cursor: crosshair;
    z-index: 3;
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s var(--ease), background 0.18s var(--ease), box-shadow 0.18s var(--ease);
  }

  .logic-node-port:hover{
    background: var(--accent);
    transform: translateY(-50%) scale(1.25);
    box-shadow: 0 0 0 4px rgba(108,99,255,0.18), 0 0 14px -2px rgba(108,99,255,0.55);
  }

  /* ---------- NODE TYPES (8.3) ---------- */

  .logic-node.category-trigger{ border-left: 3px solid var(--ok); }
  .logic-node.category-action{ border-left: 3px solid var(--accent); }

  .logic-node-icon-row{
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .logic-node-icon{
    width: 15px;
    height: 15px;
    flex-shrink: 0;
  }

  .logic-node-icon svg{ width: 100%; height: 100%; }

  .category-trigger .logic-node-icon{ color: var(--ok); }
  .category-action .logic-node-icon{ color: var(--accent); }

  .logic-node-tag.trigger-tag{ color: var(--ok); }
  .logic-node-tag.action-tag{ color: var(--accent); }

  .logic-node-preview{
    font-family: var(--mono);
    font-size: 10px;
    color: var(--muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .prop-hint a{
    color: var(--accent);
    text-decoration: none;
  }

  .prop-hint a:hover{ text-decoration: underline; }