/**
 * Workflow Graph Component Styles
 * Visual state machine editor with nodes and connections
 */

.workflow-graph-container {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 100px; /* Reduced to allow container to shrink with card */
    background: var(--bg-primary);
    border-radius: 12px;
    overflow: hidden;
}

.workflow-graph-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.workflow-graph-viewport:active {
    cursor: grabbing;
}

.workflow-graph-surface {
    position: absolute;
    width: 10000px;
    height: 10000px;
    left: -5000px;
    top: -5000px;
    transform-origin: center center;
    will-change: transform;
}

/* Dot grid background - using pseudo-element so fade doesn't affect content */
.workflow-graph-grid::before {
    content: '';
    position: absolute;
    inset: 0;
    --dot-size: 2px;
    --dot-spacing: 24px;
    --dot-color: rgba(255, 255, 255, 0.12);
    background-image:
        radial-gradient(circle, var(--dot-color) var(--dot-size), transparent var(--dot-size));
    background-size: var(--dot-spacing) var(--dot-spacing);
    background-position: center center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.workflow-graph-grid.grid-visible::before {
    opacity: 1;
}

[data-theme="light"] .workflow-graph-grid::before {
    --dot-color: rgba(0, 0, 0, 0.08);
}

.workflow-graph-content {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* SVG layer for connections - positioned relative to content */
.workflow-graph-connections {
    position: absolute;
    left: 0;
    top: 0;
    pointer-events: none;
    overflow: visible;
}

.workflow-graph-connections svg {
    position: absolute;
    left: 0;
    top: 0;
    width: 3000px;
    height: 3000px;
    overflow: visible;
}

/* ═══════════════════════════════════════════════════════
   NODES
   ═══════════════════════════════════════════════════════ */

.workflow-node {
    position: absolute;
    background: var(--bg-elevated);
    border: 2px solid var(--border-default);
    border-radius: 12px;
    box-sizing: border-box;
    width: 150px;   /* Fixed width to match layout NODE_WIDTH */
    height: 90px;   /* Fixed height to match layout NODE_HEIGHT */
    cursor: pointer;
    box-shadow: var(--shadow-small);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
}

.workflow-node:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-medium);
}

.workflow-node.selected {
    border-color: var(--blue-primary);
    box-shadow: 0 0 0 3px var(--blue-subtle), var(--shadow-medium);
}

.workflow-node.dragging {
    z-index: 1000;
    box-shadow: var(--shadow-large);
}

/* End node - terminal state on happy path (bright green) */
.workflow-node.end-node {
    border-color: var(--green-primary);
}

.workflow-node.end-node .workflow-node-count {
    color: var(--green-primary);
}

/* Branch end node - terminal state on branch path (dark/muted green) */
.workflow-node.end-node.branch-end {
    border-color: var(--green-secondary, #2D6A4F);
}

.workflow-node.end-node.branch-end .workflow-node-count {
    color: var(--green-secondary, #2D6A4F);
}

/* Bottleneck styling (takes precedence over end-node) */
.workflow-node.bottleneck {
    border-color: var(--orange-primary);
}

.workflow-node.bottleneck.critical {
    border-color: var(--red-primary);
}

/* Node header */
.workflow-node-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.workflow-node-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.workflow-node-icon {
    font-size: 12px;
    flex-shrink: 0;
}

/* Node body */
.workflow-node-body {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.workflow-node-count {
    font-size: 22px;
    font-weight: 700;
    color: var(--blue-primary);
}

.workflow-node.bottleneck .workflow-node-count {
    color: var(--orange-primary);
}

.workflow-node.bottleneck.critical .workflow-node-count {
    color: var(--red-primary);
}

.workflow-node-label {
    font-size: 11px;
    color: var(--text-secondary);
}

/* ═══════════════════════════════════════════════════════
   SOCKETS
   ═══════════════════════════════════════════════════════ */

.workflow-socket {
    position: absolute;
    box-sizing: border-box;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--blue-primary);
    /* No border - allows seamless connection with lines */
    cursor: crosshair;
    z-index: 10;
}

.workflow-socket:hover {
    box-shadow: 0 0 8px var(--blue-primary);
}

.workflow-socket.connecting {
    box-shadow: 0 0 12px var(--blue-primary);
}

.workflow-socket.valid-target {
    background: var(--green-primary);
    box-shadow: 0 0 16px var(--green-primary);
}

/* Hover/state transforms must preserve positioning transforms */
.workflow-socket-input:hover,
.workflow-socket-output:hover {
    transform: translateY(-50%) scale(1.2);
}

.workflow-socket-input.connecting,
.workflow-socket-output.connecting {
    transform: translateY(-50%) scale(1.3);
}

.workflow-socket-input.valid-target,
.workflow-socket-output.valid-target {
    transform: translateY(-50%) scale(1.5);
}

.workflow-socket-top:hover,
.workflow-socket-bottom:hover {
    transform: translateX(-50%) scale(1.2);
}

.workflow-socket-top.connecting,
.workflow-socket-bottom.connecting {
    transform: translateX(-50%) scale(1.3);
}

.workflow-socket-top.valid-target,
.workflow-socket-bottom.valid-target {
    transform: translateX(-50%) scale(1.5);
}

.workflow-socket.invalid-target {
    background: var(--red-primary);
}

.workflow-socket-input {
    left: -8px;   /* Socket center at node edge: -(radius + border) = -(6+2) */
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: auto;
}

/* Show when valid connection target during drag */
.workflow-socket-input.valid-target {
    opacity: 1;
}

.workflow-socket-output {
    right: -8px;  /* Socket center at node edge: -(radius + border) = -(6+2) */
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: auto;
}

.workflow-socket-output.valid-target {
    opacity: 1;
}

/* Top socket (for branch edges to targets above) */
.workflow-socket-top {
    top: -8px;   /* Socket center at node edge: -(radius + border) = -(6+2) */
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: auto;
}

.workflow-socket-top.valid-target {
    opacity: 1;
}

/* Bottom socket (for branch edges to targets below) */
.workflow-socket-bottom {
    bottom: -8px;  /* Socket center at node edge: -(radius + border) = -(6+2) */
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: auto;
}

.workflow-socket-bottom.valid-target {
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════
   CONNECTIONS
   ═══════════════════════════════════════════════════════ */

.workflow-connection {
    fill: none;
    stroke: var(--blue-primary);
    stroke-width: 2;
    pointer-events: stroke;
    cursor: pointer;
    transition: filter 0.2s ease;
}

.workflow-connection.hover {
    filter:
        drop-shadow(0 0 3px var(--blue-primary))
        drop-shadow(0 0 8px var(--blue-primary))
        drop-shadow(0 0 12px rgba(0, 122, 255, 0.5));
}

.workflow-connection.selected {
    filter:
        drop-shadow(0 0 4px var(--blue-primary))
        drop-shadow(0 0 10px var(--blue-primary));
}

/* Branch connections */
.workflow-connection.branch {
    stroke: var(--border-default);
    stroke-width: 1.5;
}

.workflow-connection.branch.hover {
    filter:
        drop-shadow(0 0 2px var(--text-secondary))
        drop-shadow(0 0 6px var(--text-tertiary));
}

/* Hide the old shadow - no longer needed */
.workflow-connection-shadow {
    display: none;
}

.workflow-connection-preview {
    fill: none;
    stroke: var(--border-default);
    stroke-width: 1.5;
    pointer-events: none;
}

/* Branch edge - border color (always contrasts with bg) */
.workflow-connection.branch {
    stroke: var(--border-default);
    stroke-width: 1.5;
}

.workflow-connection.branch:hover {
    stroke: var(--border-strong);
}

/* Delete mode - visual feedback when dragging line to delete */
.workflow-connection.deleting {
    stroke-dasharray: 8 4;
    animation: deleteFlash 0.3s ease-in-out infinite alternate;
}

@keyframes deleteFlash {
    from {
        filter: drop-shadow(0 0 2px rgba(255, 82, 82, 0.5));
    }
    to {
        filter: drop-shadow(0 0 6px rgba(255, 82, 82, 0.8));
    }
}

/* Individual arrowhead - scalable per-connection for proximity feedback */
.workflow-arrowhead {
    transition: transform 0.15s ease, filter 0.15s ease;
    will-change: transform;
}

.workflow-arrowhead.hover {
    filter:
        drop-shadow(0 0 3px var(--blue-primary))
        drop-shadow(0 0 8px var(--blue-primary))
        drop-shadow(0 0 12px rgba(0, 122, 255, 0.5));
}

.workflow-arrowhead.branch.hover {
    filter:
        drop-shadow(0 0 2px var(--text-secondary))
        drop-shadow(0 0 6px var(--text-tertiary));
}

/* Auto-task indicator on edge (⚡ icon) */
.workflow-autotask-indicator {
    pointer-events: all;
    cursor: pointer;
}

.workflow-autotask-indicator:hover circle {
    stroke-width: 2;
}

.workflow-autotask-indicator text {
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ═══════════════════════════════════════════════════════
   CONTROLS
   ═══════════════════════════════════════════════════════ */

.workflow-graph-controls {
    position: absolute;
    bottom: 4px;
    left: 4px;
    display: flex;
    flex-direction: row;
    gap: 0;
    z-index: 100;
    opacity: 1; /* Always visible, not faded */
    transition: opacity 0.2s ease;
    border: none; /* Remove any inherited border */
}

.workflow-graph-controls:hover {
    opacity: 1;
}

.workflow-graph-control-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
    backdrop-filter: blur(8px);
}

/* Center icons within control buttons */
.workflow-graph-control-btn svg {
    flex-shrink: 0;
}

.workflow-graph-control-btn:hover {
    background: var(--interactive-hover);
    transform: scale(1.05);
}

.workflow-graph-control-btn:active {
    transform: scale(0.95);
}

/* Delayed tooltips (1 second) */
.workflow-graph-control-btn[data-tooltip] {
    position: relative;
}

.workflow-graph-control-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 10px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    transition-delay: 0s;
    pointer-events: none;
    margin-bottom: 6px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.workflow-graph-control-btn[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    transition-delay: 1s;
}

/* Zoom indicator (editable input) - matches control button style */
.workflow-graph-zoom {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 44px;
    height: 32px;
    padding: 0;
    background: var(--bg-elevated);
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-primary);
    backdrop-filter: blur(8px);
    z-index: 100;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s ease;
}

.workflow-graph-zoom:hover {
    background: var(--interactive-hover);
}

.workflow-graph-zoom:focus {
    outline: none;
    background: var(--interactive-hover);
    cursor: text;
}

/* Info hint */
.workflow-graph-hint {
    position: absolute;
    top: 16px;
    left: 16px;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    backdrop-filter: blur(8px);
    z-index: 100;
    max-width: 220px;
}

.workflow-graph-hint-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.workflow-graph-hint-list {
    margin: 0;
    padding-left: 14px;
    line-height: 1.6;
}

/* Filter buttons for orphan nodes (placed in card header externally) */
.workflow-graph-filter {
    display: inline-flex;
    gap: 4px;
    margin-inline-start: 12px;
    align-self: flex-end;
    margin-bottom: 2px;
}

.workflow-graph-filter-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    font-weight: 400;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color 0.15s ease;
}

.workflow-graph-filter-btn:hover {
    color: var(--text-secondary);
}

.workflow-graph-filter-btn.active {
    color: var(--text-primary);
}

/* Separator between filter buttons */
.workflow-graph-filter-btn:not(:last-child)::after {
    content: '/';
    margin-inline-start: 4px;
    color: var(--text-tertiary);
    pointer-events: none;
}

/* Empty state */
.workflow-graph-empty {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-tertiary);
}

.workflow-graph-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.workflow-graph-empty-title {
    font-size: 16px;
    color: var(--text-secondary);
    margin: 0 0 8px 0;
}

.workflow-graph-empty-text {
    font-size: 13px;
    margin: 0;
}

/* ═══════════════════════════════════════════════════════
   ENTRANCE ANIMATIONS
   ═══════════════════════════════════════════════════════ */

/* Shimmer skeleton overlay - shows during expand transition */
.workflow-graph-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.05) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: workflow-shimmer 1.5s ease-in-out infinite;
    pointer-events: none;
    z-index: 50;
}

@keyframes workflow-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Skeleton node placeholders */
.workflow-graph-skeleton-node {
    position: absolute;
    width: 150px;
    height: 80px;
    background: var(--bg-elevated);
    border: 2px solid var(--border-default);
    border-radius: 12px;
    opacity: 0.3;
}

/* Node entrance - initially hidden */
.workflow-node.entrance-hidden {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
}

/* Node entrance animation */
.workflow-node.entrance-animate {
    animation: workflow-node-entrance 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes workflow-node-entrance {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Connection entrance - fade in */
.workflow-graph-connections svg path.entrance-hidden {
    opacity: 0;
}

.workflow-graph-connections svg path.entrance-animate {
    animation: workflow-connection-entrance 0.3s ease-out forwards;
}

@keyframes workflow-connection-entrance {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

/* ═══════════════════════════════════════════════════════
   TRANSITION CONFIG POPUP
   ═══════════════════════════════════════════════════════ */

.transition-config-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(4px);
}

.transition-config-popup {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: 12px;
    padding: 20px;
    min-width: 320px;
    box-shadow: var(--shadow-large);
}

.transition-config-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.transition-config-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    margin-bottom: 16px;
}

.transition-from,
.transition-to {
    font-weight: 600;
    color: var(--text-primary);
    padding: 6px 12px;
    background: var(--bg-elevated);
    border-radius: 6px;
    border: 1px solid var(--border-default);
}

.transition-arrow {
    font-size: 18px;
    color: var(--blue-primary);
}

.transition-config-body {
    margin-bottom: 20px;
}

.transition-config-body p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

.transition-config-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.transition-config-actions button {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.transition-config-actions .btn-cancel {
    background: transparent;
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}

.transition-config-actions .btn-cancel:hover {
    background: var(--interactive-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.transition-config-actions .btn-confirm {
    background: var(--blue-primary);
    border: 1px solid var(--blue-primary);
    color: white;
}

.transition-config-actions .btn-confirm:hover {
    background: var(--blue-hover);
    border-color: var(--blue-hover);
}

/* ═══════════════════════════════════════════════════════
   FLOW ANIMATION
   ═══════════════════════════════════════════════════════ */

.flow-glow-path {
    pointer-events: none;
    will-change: stroke-dasharray, stroke-dashoffset, opacity;
}

/* Play/Stop button - no special styling, just icon changes */

