@layer components {
  .flow-graph-container {
    position: relative;
    width: 100%;
    height: 700px;
    border: 1px solid var(--border-light);
    border-radius: 1rem;
    background-color: var(--color-surface-muted);
    background-image: linear-gradient(var(--color-border) 1px, transparent 1px),
      linear-gradient(90deg, var(--color-border) 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }

  @media (max-width: 768px) {
    .flow-graph-container {
      height: 500px;
      border-radius: 0.5rem;
    }
  }

  @media (max-width: 480px) {
    .flow-graph-container {
      height: 400px;
    }
  }

  .edges {
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
  }

  .edges line {
    pointer-events: stroke;
    cursor: pointer;
    stroke-linecap: round;
  }

  @media (pointer: coarse) {
    .edges line {
      stroke-width: 4px;
    }
  }

  .flow-graph-container.panning {
    cursor: grabbing;
  }

  .flow-graph-container.panning::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.02);
    pointer-events: none;
  }

  .zoom-target {
    transform-origin: 0 0;
    width: 100%;
    height: 100%;
    transition: transform 0.1s ease-out;
  }

  .zoom-controls {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--color-white);
    padding: 0.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px -1px oklch(0% 0 0 / 0.1), 0 2px 4px -1px oklch(0% 0 0 / 0.06);
    z-index: 30;
    border: 1px solid var(--border-light);
  }

  .zoom-level {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary-light);
    min-width: 3rem;
    text-align: center;
  }

  .btn-zoom {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    color: var(--text-secondary-light);
    transition: all 0.2s;
  }

  @media (pointer: coarse) {
    .btn-zoom {
      width: 2.75rem;
      height: 2.75rem;
      min-width: 44px;
      min-height: 44px;
    }
  }

  .btn-zoom:hover {
    background-color: var(--color-surface-alt);
    color: var(--text-light);
  }

  .flow-graph-toolbar {
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
    width: 100%;
  }

  @media (max-width: 640px) {
    .flow-graph-toolbar {
      flex-direction: column;
      align-items: stretch;
    }

    .flow-graph-toolbar .btn {
      width: 100%;
      justify-content: center;
    }
  }

  .node {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    background-color: color-mix(in oklab, var(--color-surface-alt) 80%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--color-neutral-900);
    min-width: 220px;
    max-width: 300px;
    z-index: 10;
    cursor: move;
    box-shadow: 0 10px 15px -3px oklch(0% 0 0 / 0.1), 0 4px 6px -2px oklch(0% 0 0 / 0.05);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .node:active {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
    z-index: 100;
  }

  /* Smaller nodes on mobile for better fit */
  @media (max-width: 640px) {
    .node {
      min-width: 180px;
      max-width: 250px;
      padding: 0.75rem;
      gap: 0.5rem;
    }
  }

  .node:last-child {
    margin-bottom: 0;
  }

  .node-title {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--color-neutral-900);
    margin-bottom: 0.25rem;
    display: block;
  }

  @media (max-width: 640px) {
    .node-title {
      font-size: 1rem;
    }
  }

  .node-subtitle {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
  }

  .pin-container {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px dashed var(--color-neutral-400);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background-color: transparent;
    transition: all 0.2s;
  }

  .pin-container.connected {
    background-color: var(--success-light);
    border-color: var(--success);
    border-style: solid;
  }

  .pin-container:last-child {
    margin-bottom: 0;
  }

  .pin-text {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    width: 100%;
  }

  .pin-text-scroll {
    white-space: normal;
    max-height: 8rem;
    overflow-y: auto;
  }

  .pin-container.missing-required {
    border-color: var(--error);
    background-color: var(--error-light);
    border-style: solid;
  }

  .pin.pin-missing {
    background-color: var(--error);
    border-color: var(--error);
    box-shadow: 0 0 0 2px var(--error-light);
  }

  .pin {
    position: absolute;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background-color: var(--color-surface-muted);
    cursor: pointer;
    transition: transform 0.2s;
    z-index: 20;
    touch-action: none;
  }

  @media (pointer: coarse) {
    .pin {
      /* Create invisible touch area around the pin */
      width: 1.25rem;
      height: 1.25rem;
    }

    .pin::before {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 2.75rem;
      height: 2.75rem;
      min-width: 44px;
      min-height: 44px;
      border-radius: 50%;
    }
  }

  .pin:hover {
    transform: scale(1.2) translateY(-7px);
  }

  .pin:active,
  .pin.active {
    transform: scale(1.3) translateY(-6px);
    border-color: #10b981;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.3);
  }

  .pin-output {
    right: -0.6rem;
    top: 50%;
    transform: translateY(-50%);
  }

  .pin-input {
    left: -0.6rem;
    top: 50%;
    transform: translateY(-50%);
  }

  .pin.connected {
    background-color: var(--color-success);
    border-color: var(--color-success);
  }

  .pin.highlight {
    animation: pulse-highlight 1s ease-in-out infinite;
    border-color: var(--color-success);
  }

  @keyframes pulse-highlight {

    0%,
    100% {
      box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.4);
    }

    50% {
      box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.2);
    }
  }

  .pin.highlight.pin-missing {
    background-color: var(--color-surface-muted);
  }

  .pin.dim {
    border-color: var(--color-error);
    opacity: 0.5;
  }

  .pin.connected.dim {
    background-color: var(--color-error);
  }

  .node-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
  }

  div#edges-container {
    height: 100%;
    position: relative;
    pointer-events: none;
  }

  svg.edges {
    height: 100%;
    width: 100%;
    pointer-events: visibleStroke;
  }
}