.header {
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  min-width: 330px;
  height: 60px;
  border-radius: 16px;
  background-color: var(--color-nodes-background);
  border: 2px solid var(--color-divider-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);

  &.parent-collapsed {
    top: 0;
    width: 100%;
    min-width: 0;
  }

  .title {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 1rem;
    max-width: 100%;
    overflow: hidden;

    .icon-container {
      color: #d3d3d3;
      font-size: 25px;
      display: flex;
      align-items: center;
      flex-shrink: 0; // Prevent icon from shrinking
    }

    .title-text {
      font-size: 16px;
      font-weight: 500;
      flex: 1;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      color: #e0e0e0;
      padding-bottom: 2px;
      max-width: 100%; // Changed from fixed 320px to be responsive
    }

    .rename-container {
      display: flex;
      align-items: center;
      width: 100%;
      max-width: 100%; // Ensure container doesn't overflow

      .title-input {
        background-color: #333;
        border: 1px solid #444;
        border-radius: 4px;
        color: #e0e0e0;
        font-size: 0.9rem;
        padding: 4px 8px;
        flex: 1;
        min-width: 0; // Allow input to shrink below its default size
        outline: none;
        height: 32px;

        &:focus {
          border-color: var(--accent-color, #2196f3);
        }
      }

      .confirm-button {
        background-color: var(--accent-color, #2196f3);
        border: none;
        border-radius: 4px;
        color: white;
        cursor: pointer;
        margin-left: 8px;
        height: 32px;
        width: 32px;
        flex-shrink: 0; // Prevent button from shrinking
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;

        &:hover {
          background-color: #0d457e;
        }

        &:active {
          transform: scale(0.9);
        }

        i {
          font-size: 16px;
        }
      }
    }
  }

  .actions {
    display: flex;
    opacity: 0;
    position: absolute;
    right: 0;
    top: -46px;
    gap: 8px;
    z-index: 11;
    padding: 8px;

    border-radius: 8px;
    transition: opacity 0.2s ease;

    // Create a larger hit area before the actions
    &::before {
      content: "";
      position: absolute;
      top: -20px;
      left: -20px;
      right: -20px;
      bottom: -20px;
      background: transparent;
      z-index: -1;
    }

    // Additional transparent zone for smoother transitions
    &::after {
      content: "";
      position: absolute;
      top: -30px;
      left: -30px;
      right: -30px;
      bottom: 0;
      background: transparent;
      z-index: -2;
    }

    .action-button {
      width: 28px;
      height: 28px;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      background-color: #2a2a2a;
      transition: all 0.15s cubic-bezier(0.25, 0.8, 0.25, 1); // Smooth animation

      // Click effect
      &:active:not(.disabled) {
        transform: scale(0.85); // Shrink to 85% size when clicked
        background-color: #444; // Slightly darker background for pressed state
      }

      &:hover {
        background-color: #3a3a3a;
      }

      &.rename-button {
        i {
          color: #aaa;
          font-size: 16px;

          &:hover {
            color: #fff;
          }
        }

        &.is-renaming i {
          color: var(--accent-color, #2196f3);
        }
      }

      &.toggle-button {
        i {
          color: var(--accent-color, #2196f3);
          font-size: 16px;
        }

        &.disabled {
          opacity: 0.5;
          cursor: not-allowed;
          pointer-events: none; // Prevents hover effects
        }
      }

      &.ungroup-button i {
        color: var(--accent-color, #2196f3);
        font-size: 16px;
      }
    }
  }

  // Show actions when parent is hovered or header itself is hovered
  &.parent-hovered .actions,
  &:hover .actions {
    opacity: 1;
  }
}

// Keep host-context for selected state as requested
:host-context(.f-selected) .header {
  opacity: 1;
  border-color: var(--vp-selected-node-border-color);

  .actions {
    opacity: 1;
  }
}
